From 63bca29310bc899ce6c7068f376cbfb426da3571 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 1 Jun 2017 10:43:59 +0200 Subject: postfix-sender-login: handle EINTR in read(2) and write(2) calls. --- .../MSA/files/usr/local/bin/postfix-sender-login.pl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'roles/MSA') 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 987482e..5f563c3 100755 --- a/roles/MSA/files/usr/local/bin/postfix-sender-login.pl +++ b/roles/MSA/files/usr/local/bin/postfix-sender-login.pl @@ -64,7 +64,6 @@ server(); sub server() { while(1) { accept(my $conn, $S) or do { - # try again if accept(2) was interrupted by a signal next if $! == EINTR; die "accept: $!"; }; @@ -77,6 +76,7 @@ sub server() { for (my $i = 0; $i < $len;) { my $n = syswrite($conn, $reply, $len-$i, $i) // do { + next if $! == EINTR; warn "Can't write: $!"; last; }; @@ -92,7 +92,10 @@ sub process_request($) { # keep reading until the request length is determined do { - my $n = sysread($conn, $buf, $BUFSIZE, $offset) // return "TEMP can't read: $!"; + my $n = sysread($conn, $buf, $BUFSIZE, $offset) // do { + next if $! == EINTR; + return "TEMP can't read: $!"; + }; return "TEMP EOF" if $n == 0; $offset += $n; } until ($buf =~ /\A(0|[1-9][0-9]*):/); @@ -101,7 +104,10 @@ sub process_request($) { my $strlen = length("$1") + 1; # [len]":" my $len = $strlen + $1 + 1; # [len]":"[string]"," while ($offset < $len) { - my $n = sysread($conn, $buf, $BUFSIZE, $offset) // return "TEMP can't read: $!"; + my $n = sysread($conn, $buf, $BUFSIZE, $offset) // do { + next if $! == EINTR; + return "TEMP can't read: $!"; + }; return "TEMP EOF" if $n == 0; $offset += $n; } @@ -116,10 +122,10 @@ sub process_request($) { $key =~ /\A(.+)@([^\@]+)\z/ or return "NOTFOUND "; # invalid sender address my ($localpart, $domainpart) = ($1, $2); - my $ldap = Net::LDAPI::->new( $LDAPI ) - // return "TEMP couldn't create Net::LDAPI object"; - $ldap->bind( undef, sasl => Authen::SASL::->new(mechanism => 'EXTERNAL') ) - or return "TEMP LDAP: couldn't bind"; + my $ldap = Net::LDAPI::->new( $LDAPI ) // + return "TEMP couldn't create Net::LDAPI object"; + $ldap->bind( undef, sasl => Authen::SASL::->new(mechanism => 'EXTERNAL') ) or + return "TEMP LDAP: couldn't bind"; my $reply = lookup_sender($ldap, $localpart, $domainpart); $ldap->unbind(); -- cgit v1.2.3