util/wrap.pl: Correct exit code when signalled
authorRichard Levitte <levitte@openssl.org>
Sun, 22 Mar 2020 03:15:14 +0000 (04:15 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 25 Mar 2020 09:51:21 +0000 (10:51 +0100)
On Unix, a caught signal that exits the process does so with an exit
code that is 'signal | 128'.  This modifies util/wrap.pl to mimic
that.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11379)

util/wrap.pl

index 4c3d4713f17f5cfb51abf7c404accf927ae0800e..fd24c42c8b3b4270ec8de81f2ab54ac0e31a0f5d 100755 (executable)
@@ -35,5 +35,12 @@ my $waitcode = system @cmd;
 # (exitcode << 8 | signalcode)
 die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
     if $waitcode == -1;
 # (exitcode << 8 | signalcode)
 die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
     if $waitcode == -1;
-exit($? & 255) if ($? & 255) != 0;
+
+# When the subprocess aborted on a signal, mimic what Unix shells do, by
+# converting the signal code to an exit code by setting the high bit.
+# This only happens on Unix flavored operating systems, the others don't
+# have this sort of signaling to date, and simply leave the low byte zero.
+exit(($? & 255) | 128) if ($? & 255) != 0;
+
+# When not a signal, just shift down the subprocess exit code and use that.
 exit($? >> 8);
 exit($? >> 8);