summaryrefslogtreecommitdiff
path: root/Echolot/Pinger
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2004-04-26 14:19:14 +0000
committerPeter Palfrader <peter@palfrader.org>2004-04-26 14:19:14 +0000
commitf9c5b67b14d715ecabc1364564b2523748dcb16d (patch)
tree70c3128c6d997d6c5c560b9668e110e8a51cfb5c /Echolot/Pinger
parente6f5207c86d738be9a8ba503f97e6867e83c6846 (diff)
perl 5.6 does not do open3("-"), so we need to fork() and do lots of pipe() ourselves
Diffstat (limited to 'Echolot/Pinger')
-rw-r--r--Echolot/Pinger/Mix.pm34
1 files changed, 28 insertions, 6 deletions
diff --git a/Echolot/Pinger/Mix.pm b/Echolot/Pinger/Mix.pm
index 2270ca1..4783f7e 100644
--- a/Echolot/Pinger/Mix.pm
+++ b/Echolot/Pinger/Mix.pm
@@ -18,7 +18,7 @@ This package provides functions for sending mixmaster (type II) pings.
use strict;
use English;
-use IPC::Open3;
+use IO::Handle;
use Echolot::Log;
sub ping($$$$$) {
@@ -67,28 +67,50 @@ sub ping($$$$$) {
Echolot::Log::warn("Cannot close $mixcfg: $!."),
return 0;
- my($wtr, $rdr, $err);
- my $pid = open3($wtr, $rdr, $err, "|-");
+ my ($stdinR, $stdinW) = (IO::Handle->new(), IO::Handle->new());
+ my ($stdoutR, $stdoutW) = (IO::Handle->new(), IO::Handle->new());
+ my ($stderrR, $stderrW) = (IO::Handle->new(), IO::Handle->new());
+ pipe $stdinR, $stdinW;
+ pipe $stdoutR, $stdoutW;
+ pipe $stderrR, $stderrW;
+ my $pid = fork();
defined $pid or
Echolot::Log::warn("Cannot fork for calling mixmaster: $!."),
return 0;
unless ($pid) { # child
+ $stdinW->close;
+ $stdoutR->close;
+ $stderrR->close;
+ close STDIN;
+ close STDOUT;
+ close STDERR;
+ open (STDIN, "<&".$stdinR->fileno) or Echolot::Log::warn ("Cannot dup stdinR (fd ".$stdinR->fileno.") as STDIN: $!");
+ open (STDOUT, ">&".$stdoutW->fileno) or Echolot::Log::warn ("Cannot dup stdoutW (fd ".$stdoutW->fileno.") as STDOUT: $!");
+ open (STDERR, ">&".$stderrW->fileno) or Echolot::Log::warn ("Cannot dup stderrW (fd ".$stderrW->fileno.") as STDERE: $!");
$ENV{'MIXPATH'} = Echolot::Config::get()->{'mixhome'};
{ exec(Echolot::Config::get()->{'mixmaster'}, qw{-m -S -l}, $chaincomma); };
Echolot::Log::warn("Cannot exec mixpinger: $!.");
exit(1);
};
+ $stdinR->close;
+ $stdoutW->close;
+ $stderrW->close;
+
my $msg;
$msg .= "From: Echolot Pinger <$address>\n" if $with_from;
$msg .= "To: $to\n\n$body\n";
- my ($stdout, $stderr, undef) = Echolot::Tools::readwrite_gpg($msg, $wtr, $rdr, $err, undef);
+ Echolot::Log::debug("mixping: fds: stdinW $stdinW; stdoutR $stdoutR; stderrR $stderrR."),
+ my ($stdout, $stderr, undef) = Echolot::Tools::readwrite_gpg($msg, $stdinW, $stdoutR, $stderrR, undef);
waitpid $pid, 0;
+ $stderr =~ s/\n+$//;
+ Echolot::Log::debug("Mixmaster said on unfiltered stderr: $stderr") if ($stderr ne '');
$stderr =~ s/^Chain: .*//mg;
$stderr =~ s/^Warning: The message has a From: line.*//mg;
- Echolot::Log::info("Mixmaster said on stdout: $stdout");
- Echolot::Log::warn("Mixmaster said on stderr: $stderr");
+ $stderr =~ s/\n+$//;
+ Echolot::Log::info("Mixmaster said on stdout: $stdout") if ($stdout ne '');
+ Echolot::Log::warn("Mixmaster said on stderr: $stderr") if ($stderr ne '');
return 1;
};