qmail-queue: a few tweaks and a lot of whitespace

This commit is contained in:
Matt Simerson 2012-06-23 00:57:04 -04:00
parent 52b5227cd5
commit e69893a961

View File

@ -20,6 +20,11 @@ If set the environment variable QMAILQUEUE overrides this setting.
=cut
use strict;
use warnings;
use Qpsmtpd::Constants;
use POSIX ();
sub register {
@ -27,35 +32,33 @@ sub register {
if (@args > 0) {
$self->{_queue_exec} = $args[0];
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 1);
}
else {
$self->{_queue_exec} = ($ENV{QMAIL} || '/var/qmail') . "/bin/qmail-queue";
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if @args > 1;
}
$self->{_queue_exec} ||= ($ENV{QMAIL} || '/var/qmail') . "/bin/qmail-queue";
$self->{_queue_exec} = $ENV{QMAILQUEUE} if $ENV{QMAILQUEUE};
}
sub hook_queue {
my ($self, $transaction) = @_;
# these bits inspired by Peter Samuels "qmail-queue wrapper"
pipe(MESSAGE_READER, MESSAGE_WRITER) or die("Could not create message pipe");
pipe(ENVELOPE_READER, ENVELOPE_WRITER) or die("Could not create envelope pipe");
# these bits inspired by Peter Samuels "qmail-queue wrapper"
pipe(MESSAGE_READER, MESSAGE_WRITER) or die "Could not create message pipe";
pipe(ENVELOPE_READER, ENVELOPE_WRITER) or die "Could not create envelope pipe";
local $SIG{PIPE} = sub { die "SIGPIPE" };
local $SIG{PIPE} = sub { die 'SIGPIPE' };
my $child = fork();
not defined $child and die("Could not fork");
! defined $child and die "Could not fork";
if ($child) {
# Parent
my $oldfh = select(MESSAGE_WRITER); $| = 1;
select(ENVELOPE_WRITER); $| = 1;
select($oldfh);
# Parent
my $oldfh = select MESSAGE_WRITER; $| = 1;
select ENVELOPE_WRITER; $| = 1;
select $oldfh;
close MESSAGE_READER or die("close msg reader fault");
close ENVELOPE_READER or die("close envelope reader fault");
close MESSAGE_READER or die "close msg reader fault";
close ENVELOPE_READER or die "close envelope reader fault";
$transaction->header->print(\*MESSAGE_WRITER);
$transaction->body_resetpos;
@ -80,21 +83,21 @@ sub hook_queue {
return (OK, "Queued! " . time . " qp $child $msg_id");
}
elsif (defined $child) {
# Child
# Child
close MESSAGE_WRITER or exit 1;
close ENVELOPE_WRITER or exit 2;
# Untaint $self->{_queue_exec}
# Untaint $self->{_queue_exec}
my $queue_exec = $self->{_queue_exec};
if ($queue_exec =~ /^(\/[\/\-\_\.a-z0-9A-Z]*)$/) {
$queue_exec = $1;
} else {
$self->log(LOGERROR, "FATAL ERROR: Unexpected characters in qmail-queue plugin argument");
# This exit is ok as we're exiting a forked child process.
# This exit is ok as we're exiting a forked child process.
exit 3;
}
# save the original STDIN and STDOUT in case exec() fails below
# save the original STDIN and STDOUT in case exec() fails below
open(SAVE_STDIN, "<&STDIN");
open(SAVE_STDOUT, ">&STDOUT");
@ -102,11 +105,11 @@ sub hook_queue {
POSIX::dup2(fileno(ENVELOPE_READER), 1) or die "Unable to dup ENVELOPE_READER: $!";
my $ppid = getppid();
$self->log(LOGNOTICE, "(for $ppid ) Queuing qp $$ to $queue_exec");
$self->log(LOGNOTICE, "(for $ppid) Queuing to $queue_exec");
my $rc = exec $queue_exec;
# close the pipe
# close the pipe
close(MESSAGE_READER);
close(MESSAGE_WRITER);