From f9c5b67b14d715ecabc1364564b2523748dcb16d Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 26 Apr 2004 14:19:14 +0000 Subject: perl 5.6 does not do open3("-"), so we need to fork() and do lots of pipe() ourselves --- Echolot/Pinger/Mix.pm | 34 ++++++++++++++++++++++++++++------ Echolot/Tools.pm | 4 ++-- 2 files changed, 30 insertions(+), 8 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; }; diff --git a/Echolot/Tools.pm b/Echolot/Tools.pm index 0264cfd..ed1a022 100644 --- a/Echolot/Tools.pm +++ b/Echolot/Tools.pm @@ -286,6 +286,8 @@ sub readwrite_gpg($$$$$) { my $sin = IO::Select->new(); my $offset = 0; + Echolot::Log::debug("input is $inputfd; output is $stdoutfd; err is $stderrfd; status is ".(defined $statusfd ? $statusfd : 'undef')."."); + $inputfd->blocking(0); $stdoutfd->blocking(0); $statusfd->blocking(0) if defined $statusfd; @@ -295,8 +297,6 @@ sub readwrite_gpg($$$$$) { $sout->add($statusfd) if defined $statusfd; $sin->add($inputfd); - Echolot::Log::debug("input is $inputfd; output is $stdoutfd; err is $stderrfd; status is ".(defined $statusfd ? $statusfd : 'undef')."."); - my ($stdout, $stderr, $status) = ("", "", ""); my ($readyr, $readyw, $written); -- cgit v1.2.3