]> Sergey Matveev's repositories - public-inbox.git/commitdiff
spamcheck/spamc: use localized slurp to read from spamc
authorEric Wong <e@yhbt.net>
Tue, 19 May 2020 22:45:32 +0000 (22:45 +0000)
committerEric Wong <e@yhbt.net>
Wed, 20 May 2020 23:58:16 +0000 (23:58 +0000)
The <EXPR> perlop, `readline', and `read' functions will all
retry on EINTR, so there's no need to retry and loop ourselves
with `sysread'.

lib/PublicInbox/Spamcheck/Spamc.pm

index b6098669fc3c41a0584c76912b4f0c21cad8f5e9..3ba2c3c9eab2708ca8d7fc11facb47b0801d24a2 100644 (file)
@@ -23,19 +23,11 @@ sub spamcheck {
 
        my $rdr = { 0 => _msg_to_fh($self, $msg) };
        my ($fh, $pid) = popen_rd($self->{checkcmd}, undef, $rdr);
-       my $r;
        unless (ref $out) {
                my $buf = '';
                $out = \$buf;
        }
-again:
-       do {
-               $r = sysread($fh, $$out, 65536, length($$out));
-       } while (defined($r) && $r != 0);
-       unless (defined $r) {
-               goto again if $!{EINTR};
-               die "read failed: $!";
-       }
+       $$out = do { local $/; <$fh> };
        close $fh or die "close failed: $!";
        waitpid($pid, 0);
        ($? || $$out eq '') ? 0 : 1;