From 8cfd584400a9852c4bd7c4b3d50ff0cacc8ec019 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 1 Jun 2017 11:00:58 +0200 Subject: postfix-sender-login: terminate the worker after 32*$nProc connections to release ressources. --- roles/MSA/files/usr/local/bin/postfix-sender-login.pl | 9 +++++++-- 1 file 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 @@ -49,20 +49,25 @@ die "This service must be socket-activated.\n" 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: $!"; -- cgit v1.2.3