Use the same mh_hostname() function from test/common.h in mhsign(1)
[mmh] / sbr / pidstatus.c
index ff8cf48..cab45f5 100644 (file)
@@ -6,16 +6,14 @@
 ** complete copyright information.
 */
 
+#include <signal.h>
 #include <h/mh.h>
 
 /*
 ** auto-generated header
 */
-#include <sigmsg.h>
-
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
+#include "sigmsg.h"
+#include <sys/wait.h>
 
 #ifndef WTERMSIG
 # define WTERMSIG(s) ((int)((s) & 0x7F))
@@ -26,7 +24,7 @@
 #endif
 
 int
-pidstatus (int status, FILE *fp, char *cp)
+pidstatus(int status, FILE *fp, char *cp)
 {
        int signum;
 
@@ -38,27 +36,41 @@ pidstatus (int status, FILE *fp, char *cp)
        **      return status;
        */
 
-       /* If child process returned normally */
        if (WIFEXITED(status)) {
+               /* child process returned normally */
                if ((signum = WEXITSTATUS(status))) {
-                       if (cp)
-                               fprintf (fp, "%s: ", cp);
-                       fprintf (fp, "exit %d\n", signum);
+                       if (cp) {
+                               fprintf(fp, "%s: ", cp);
+                       }
+                       fprintf(fp, "exit %d\n", signum);
                }
        } else if (WIFSIGNALED(status)) {
-               /* If child process terminated due to receipt of a signal */
+               /* 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 < 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)" : "");
+               if (signum == SIGINT) {
+                       return status;
+               }
+               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)" : "");
                }
        }
 
        return status;
 }
+
+
+int
+pidXwait(int pid, char *cp)
+{
+       return pidstatus(pidwait(pid, -1), stdout, cp);
+}