From 680dbf26892ac7455e0e121d2fe01426a20c6dc1 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Mon, 3 Jul 2017 16:25:29 -0700 Subject: [PATCH] handle SIGPIPE in spamc by skipping the message --- bin/debbugs-spamscan-log | 58 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/bin/debbugs-spamscan-log b/bin/debbugs-spamscan-log index 04d4a4a..08e7526 100755 --- a/bin/debbugs-spamscan-log +++ b/bin/debbugs-spamscan-log @@ -137,28 +137,44 @@ for my $bug_num (@ARGV) { print STDERR "already spam\n" if $DEBUG; next; } - my ($spamc,$child_out); - my $childpid = - open3($spamc,$child_out,0, - $options{spamc},'-c',@{$options{spamc_opts}}) or - die "Unable to fork spamc: $!"; - if (not $childpid) { - die "Unable to fork spamc"; - } - print {$spamc} $record->{text}; - close($spamc) or die "Unable to close spamc: $!"; - waitpid($childpid,0); - if ($DEBUG) { - print STDERR "[$?;".($? >> 8)."] "; - print STDERR map {s/\n//; $_ } <$child_out>; - print STDERR " "; - } - close($child_out); - if ($? >> 8) { - print STDERR "it's spam\n" if $DEBUG; - $spam->add_spam($msg_id); + my $is_spam; + eval { + my ($spamc,$child_out); + my $old_sig = $SIG{"PIPE"}; + $SIG{"PIPE"} = sub { + die "SIGPIPE in child for some reason"; + }; + my $childpid = + open3($spamc,$child_out,0, + $options{spamc},'-E',@{$options{spamc_opts}}) or + die "Unable to fork spamc: $!"; + if (not $childpid) { + die "Unable to fork spamc"; + } + print {$spamc} $record->{text}; + close($spamc) or die "Unable to close spamc: $!"; + waitpid($childpid,0); + if ($DEBUG) { + print STDERR "[$?;".($? >> 8)."] "; + print STDERR map {s/\n//; $_ } <$child_out>; + print STDERR " "; + } + close($child_out); + $SIG{"PIPE"} = $old_sig; + if ($? >> 8) { + $is_spam = 1; + } + }; + if ($@) { + print STDERR "processing of $msg_id failed [$@]\n"; } else { - print STDERR "it's ham\n" if $DEBUG; + if ($is_spam) { + print STDERR "it's spam\n" if $DEBUG; + $spam->add_spam($msg_id); + } + else { + print STDERR "it's ham\n" if $DEBUG; + } } } $spam->save(); -- 2.39.2