Greg Ward avatar Greg Ward committed 505024e

capture: distinguish exit status from signal

Comments (0)

Files changed (2)

         done = result->stdout.eof && result->stderr.eof;
     }
 
-    waitpid(pid, &result->status, 0);
+    int status;
+    waitpid(pid, &status, 0);
+    result->status = result->signal = 0;
+    if (WIFEXITED(status))
+        result->status = WEXITSTATUS(status);
+    else if (WIFSIGNALED(status))
+        result->signal = WTERMSIG(status);
+
     if (result->status != 0)
         debug("child process %s exited with status %d",
-              file, WEXITSTATUS(result->status));
+              file, result->status);
+    if (result->signal != 0)
+        debug("child process %s killed by signal %d",
+              file, result->signal);
     if (result->stderr.len > 0)
         debug("child process %s wrote to stderr:\n%s",
               file, result->stderr.buf);
            result->stdout.len, result->stdout.buf);
     printf("read %ld bytes from child stderr: >%s<\n",
            result->stderr.len, result->stderr.buf);
-    status = WEXITSTATUS(result->status);
-    printf("child exit status: %d\n", status);
+    status = result->status;
+    printf("child status = %d, signal =%d\n", status, result->signal);
     free_capture(result);
     return status;
 }
 typedef struct {
     dynbuf stdout;
     dynbuf stderr;
-    int status;
+    int status;                 /* exit status that child passed (if any) */
+    int signal;                 /* signal that killed the child (if any) */
 } capture_t;
 
 /* fork() and exec() a child process, capturing its entire stdout and
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.