Use POSIX::dup2() instead of open() with <& since I found the latter failed

regularly for me - POSIX::dup2() was just plain more reliable. Odd, I know.


git-svn-id: https://svn.perl.org/qpsmtpd/trunk@176 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Matt Sergeant 2003-10-09 17:21:49 +00:00
parent 1f92301f6a
commit 38317f082e

View File

@ -18,6 +18,8 @@ If set the environment variable QMAILQUEUE overrides this setting.
=cut =cut
use POSIX ();
sub register { sub register {
my ($self, $qp, @args) = @_; my ($self, $qp, @args) = @_;
$self->register_hook("queue", "queue_handler"); $self->register_hook("queue", "queue_handler");
@ -88,13 +90,12 @@ sub queue_handler {
exit 3; exit 3;
} }
# save the original STDIN and STDOUT # save the original STDIN and STDOUT in case exec() fails below
open(SAVE_STDIN, "<&STDIN"); open(SAVE_STDIN, "<&STDIN");
open(SAVE_STDOUT, ">&STDOUT"); open(SAVE_STDOUT, ">&STDOUT");
# what are those exit values for? Why don't we die with a useful error message? POSIX::dup2(fileno(MESSAGE_READER), 0) or die "Unable to dup MESSAGE_READER: $!";
open(STDIN, "<&MESSAGE_READER") or exit 4; POSIX::dup2(fileno(ENVELOPE_READER), 1) or die "Unable to dup ENVELOPE_READER: $!";
open(STDOUT, "<&ENVELOPE_READER") or exit 5;
$self->log(7, "Queuing to $queue_exec"); $self->log(7, "Queuing to $queue_exec");
@ -104,6 +105,8 @@ sub queue_handler {
open(STDIN, "<&SAVE_STDIN"); open(STDIN, "<&SAVE_STDIN");
open(STDOUT, ">&SAVE_STDOUT"); open(STDOUT, ">&SAVE_STDOUT");
# NB: The "if not $rc" is redundant since exec() won't return if it
# succeeds.
exit 6 if not $rc; exit 6 if not $rc;
} }
} }