chiark / gitweb /
Better reporting of child exit statuses (esp. deaths due to signals).
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Aug 2014 19:38:41 +0000 (20:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 10 Aug 2014 19:38:41 +0000 (20:38 +0100)
debian/changelog
dgit

index 978ad1097a7a5e211a114cac970369fd93f915d1..f70f2ff689b26fb43feb8304b91d567fa6783a07 100644 (file)
@@ -37,6 +37,7 @@ dgit (0.22~experimental1) experimental; urgency=low
   * Improve error message for .dsc having already been signed (iff
     using libdpkg-perl 1.17.x).  Closes:#731635.
   * Improve error message for .dsc parsing failures more generally.
   * Improve error message for .dsc having already been signed (iff
     using libdpkg-perl 1.17.x).  Closes:#731635.
   * Improve error message for .dsc parsing failures more generally.
+  * Better reporting of child exit statuses (esp. deaths due to signals).
 
   Major new feature, currently stalled awaiting server infrastructure:
   * dgit-repos-server: New program for receiving signed-tag-based
 
   Major new feature, currently stalled awaiting server infrastructure:
   * dgit-repos-server: New program for receiving signed-tag-based
diff --git a/dgit b/dgit
index b24264676f23de3e67c5a78592c51b7d6c921982..e3fc0eefd33bb6bf0372044f070cc7db03e0ad15 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -30,6 +30,7 @@ use Dpkg::Version;
 use POSIX;
 use IPC::Open2;
 use Digest::SHA;
 use POSIX;
 use IPC::Open2;
 use Digest::SHA;
+use Config;
 
 our $our_version = 'UNRELEASED'; ###substituted###
 
 
 our $our_version = 'UNRELEASED'; ###substituted###
 
@@ -133,6 +134,23 @@ END {
     }
 };
 
     }
 };
 
+our @signames = split / /, $Config{sig_name};
+
+sub waitstatusmsg () {
+    if (!$?) {
+       return "terminated, reporting successful completion";
+    } elsif (!($? & 255)) {
+       return "failed with error exit status ".WEXITSTATUS($?);
+    } elsif (WIFSIGNALED($?)) {
+       my $signum=WTERMSIG($?);
+       return "died due to fatal signal ".
+           ($signames[$signum] // "number $signum").
+           ($? & 128 ? " (core dumped)" : ""); # POSIX(3pm) has no WCOREDUMP
+    } else {
+       return "failed with unknown wait status ".$?;
+    }
+}
+
 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
 
 sub fail { 
 sub printdebug { print DEBUG $debugprefix, @_ or die $!; }
 
 sub fail { 
@@ -350,10 +368,8 @@ sub failedcmd {
     { local ($!); printcmd \*STDERR, "$us: failed command:", @_ or die $!; };
     if ($!) {
        fail "failed to fork/exec: $!";
     { local ($!); printcmd \*STDERR, "$us: failed command:", @_ or die $!; };
     if ($!) {
        fail "failed to fork/exec: $!";
-    } elsif (!($? & 0xff)) {
-       fail "subprocess failed with error exit status ".($?>>8);
     } elsif ($?) {
     } elsif ($?) {
-       fail "subprocess crashed (wait status $?)";
+       fail "subprocess ".waitstatusmsg();
     } else {
        fail "subprocess produced invalid output";
     }
     } else {
        fail "subprocess produced invalid output";
     }