tags 949992 +patch
kthxbye

Attached is a patch. Warning, I'm not a Perl-coder. Seems to work though.

--
 .''`.   martin f. krafft <madduck@d.o> @martinkrafft
: :'  :  proud Debian developer
`. `'`   http://people.debian.org/~madduck
  `-  Debian - when you have better things to do than fixing systems
"i never travel without my diary. one should always have something
 sensational to read on the train."
                                                      -- oscar wilde
--- /tmp/run-mailcap	2020-01-29 09:12:51.002973844 +1300
+++ /usr/bin/run-mailcap	2020-01-29 10:37:56.385391104 +1300
@@ -12,6 +12,7 @@
 use Encode qw(decode);
 use I18N::Langinfo qw(langinfo CODESET);
 use File::Spec;
+use POSIX ":sys_wait_h";
 
 $debug=($ENV{RUN_MAILCAP_DEBUG} || 0);
 $norun=0;
@@ -25,8 +26,17 @@
 $quotedsemi=chr(255);
 $quotedprct=chr(254);
 $retcode=0;
+$wait_on_child_pid=0;
 
+sub signal_handler {
+    my($sig) = @_;
+    print STDERR " - caught signal $sig, cleaning up...\n" if $debug;
+    kill $sig, $wait_on_child_pid;
+    die "Terminated on signal $sig";
+}
 
+$SIG{INT} = \&signal_handler;
+$SIG{TERM} = \&signal_handler;
 
 sub Usage {
     my($error) = @_;
@@ -542,22 +552,28 @@
 	    print $comm,"\n";
 	    $res = 0;
 	} else {
-	    $res = system $comm;
-	    if ($res != 0) {
-		if (!($res & 0xFF)) {
-                    print STDERR "Warning: program returned non-zero exit code \#$res\n";
-                    $retcode = $res >> 8;
-		} elsif ($res == -1) {
-		    print STDERR "Error: program failed to execute: $!\n";
-		    $retcode = -1;
-		} else {
+	    my $pid = fork;
+	    die "Unable to fork" unless defined $pid;
+	    if ($pid == 0) {
+		exec $comm;
+	    } else {
+		$wait_on_child_pid=$pid; # so the signal handler knows what to kill.
+		waitpid($pid, 0);
+
+		if ($? & 0xFF) {
 		    my $signal = $? & 0x7F;
 		    my $core = ($? & 0x80) ? ' (core dumped)' : '';
 		    print STDERR "Warning: program died on signal ${signal}${core}\n";
 		    $retcode = -1;
+		} elsif ($? == -1) {
+		    print STDERR "Error: program failed to execute: $!\n";
+		    $retcode = -1;
+		} elsif ($? > 0) {
+		    print STDERR "Warning: program returned non-zero exit code \#$?\n";
+		    $retcode = $?;
 		}
-            }
-        }
+	    }
+	}
         $done=1;
         unlink $tmpfile if $tmpfile;
         unlink $tmplink if $tmplink;

Attachment: digital_signature_gpg.asc
Description: Digital GPG signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)

Reply via email to