]> diplodocus.org Git - nmh/blobdiff - sbr/pidstatus.c
new.c: Order two return statements to match comment.
[nmh] / sbr / pidstatus.c
index 1c1f734896455c19efe4f827a5a2d3b16e72001d..1800ccd9d58c28f53ca4e998057d4596f9a2c918 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * pidstatus.c -- report child's status
+/* pidstatus.c -- report child's status
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -9,19 +7,6 @@
 
 #include <h/mh.h>
 
 
 #include <h/mh.h>
 
-/*
- * auto-generated header
- */
-#include <sigmsg.h>
-
-#ifndef WTERMSIG
-# define WTERMSIG(s) ((int)((s) & 0x7F))
-#endif
-
-#ifndef WCOREDUMP
-# define WCOREDUMP(s) ((s) & 0x80)
-#endif
-
 /*
  * Return 0 if the command exited with an exit code of zero, a nonzero code
  * otherwise.
 /*
  * Return 0 if the command exited with an exit code of zero, a nonzero code
  * otherwise.
 int
 pidstatus (int status, FILE *fp, char *cp)
 {
 int
 pidstatus (int status, FILE *fp, char *cp)
 {
-    int signum;
+    char *mesg;
+    int num;
+    bool lookup;
+    char *signame;
 
 
-/*
- * I have no idea what this is for (rc)
- * so I'm commenting it out for right now.
- *
- *  if ((status & 0xff00) == 0xff00)
- *      return status;
- */
-
-    /* If child process returned normally */
     if (WIFEXITED(status)) {
     if (WIFEXITED(status)) {
-       if ((signum = WEXITSTATUS(status))) {
+       status = WEXITSTATUS(status);
+       if (status) {
            if (cp)
                fprintf (fp, "%s: ", cp);
            if (cp)
                fprintf (fp, "%s: ", cp);
-           fprintf (fp, "exit %d\n", signum);
-       }
-       return signum;
-    } else if (WIFSIGNALED(status)) {
-       /* If child process terminated due to receipt of a signal */
-       signum = WTERMSIG(status);
-       if (signum != SIGINT) {
-           if (cp)
-               fprintf (fp, "%s: ", cp);
-           fprintf (fp, "signal %d", signum);
-           if (signum >= 0 && signum < (int) sizeof(sigmsg) &&
-                  sigmsg[signum] != NULL)
-               fprintf (fp, " (%s%s)\n", sigmsg[signum],
-                        WCOREDUMP(status) ? ", core dumped" : "");
-           else
-               fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
+           fprintf(fp, "exited %d\n", status);
        }
        }
+       return status;
+    }
+
+    if (WIFSIGNALED(status)) {
+        mesg = "signalled";
+        num = WTERMSIG(status);
+       if (num == SIGINT)
+            return status;
+        lookup = true;
+    } else if (WIFSTOPPED(status)) {
+        mesg = "stopped";
+        num = WSTOPSIG(status);
+        lookup = true;
+    } else if (WIFCONTINUED(status)) {
+        mesg = "continued";
+        num = -1;
+        lookup = false;
+    } else {
+        mesg = "bizarre wait(2) status";
+        num = status;
+        lookup = false;
+    }
+
+    if (cp)
+        fprintf(fp, "%s: ", cp);
+    fputs(mesg, fp);
+
+    if (num != -1) {
+        fprintf(fp, " %#x", num);
+        if (lookup) {
+            errno = 0;
+            signame = strsignal(num);
+            if (errno)
+                signame = "invalid";
+            putc(' ', fp);
+            fputs(signame, fp);
+        }
     }
     }
+    if (WCOREDUMP(status))
+        fputs(", core dumped", fp);
+    putc('\n', fp);
 
     return status;
 }
 
     return status;
 }