summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xroles/MSA/files/usr/local/bin/postfix-sender-login.pl9
1 files changed, 7 insertions, 2 deletions
diff --git a/roles/MSA/files/usr/local/bin/postfix-sender-login.pl b/roles/MSA/files/usr/local/bin/postfix-sender-login.pl
index 5f563c3..e792457 100755
--- a/roles/MSA/files/usr/local/bin/postfix-sender-login.pl
+++ b/roles/MSA/files/usr/local/bin/postfix-sender-login.pl
@@ -32,54 +32,59 @@ use Authen::SASL ();
# clean up PATH
$ENV{PATH} = join ':', qw{/usr/bin /bin};
delete @ENV{qw/IFS CDPATH ENV BASH_ENV/};
my $nProc = 2; # number of pre-forked servers
my $POSTMASTER = 'postmaster@fripost.org'; # returned for forbidden envelope sender addresses
my $BASEDN = 'ou=virtual,dc=fripost,dc=org';
my $BUFSIZE = 65536; # try to read that many bytes at the time
my $LDAPI = 'ldapi://%2Fvar%2Fspool%2Fpostfix-msa%2Fprivate%2Fldapi/';
sub server();
# fdopen(3) the file descriptor FD
die "This service must be socket-activated.\n"
unless defined $ENV{LISTEN_PID} and $ENV{LISTEN_PID} == $$
and defined $ENV{LISTEN_FDS} and $ENV{LISTEN_FDS} == 1;
open my $S, '+<&=', 3 or die "fdopen: $!";
+my @CHILDREN;
for (my $i = 0; $i < $nProc-1; $i++) {
my $pid = fork() // die "fork: $!";
- unless ($pid) {
+ if ($pid) {
+ push @CHILDREN, $pid;
+ } else {
server(); # child, never return
exit;
}
}
server();
+waitpid $_ => 0 foreach @CHILDREN;
+exit $?;
#############################################################################
sub server() {
- while(1) {
+ for (my $n = 0; $n < 32; $n++) {
accept(my $conn, $S) or do {
next if $! == EINTR;
die "accept: $!";
};
my $reply = process_request($conn);
# encode the reply as a netstring and send it back
# https://cr.yp.to/proto/netstrings.txt
$reply = length($reply).':'.$reply.',';
my $len = length($reply);
for (my $i = 0; $i < $len;) {
my $n = syswrite($conn, $reply, $len-$i, $i) // do {
next if $! == EINTR;
warn "Can't write: $!";
last;
};
$i += $n;
}
close $conn or warn "Can't close: $!";