Clean up process wait to use POSIX waitpid() interface.
[mmh] / sbr / pidstatus.c
1
2 /*
3  * pidstatus.c -- report child's status
4  *
5  * This code is Copyright (c) 2002, by the authors of nmh.  See the
6  * COPYRIGHT file in the root directory of the nmh distribution for
7  * complete copyright information.
8  */
9
10 #include <h/mh.h>
11
12 /*
13  * auto-generated header
14  */
15 #include <sigmsg.h>
16
17 #ifndef WTERMSIG
18 # define WTERMSIG(s) ((int)((s) & 0x7F))
19 #endif
20
21 #ifndef WCOREDUMP
22 # define WCOREDUMP(s) ((s) & 0x80)
23 #endif
24
25 int
26 pidstatus (int status, FILE *fp, char *cp)
27 {
28     int signum;
29
30 /*
31  * I have no idea what this is for (rc)
32  * so I'm commenting it out for right now.
33  *
34  *  if ((status & 0xff00) == 0xff00)
35  *      return status;
36  */
37
38     /* If child process returned normally */
39     if (WIFEXITED(status)) {
40         if ((signum = WEXITSTATUS(status))) {
41             if (cp)
42                 fprintf (fp, "%s: ", cp);
43             fprintf (fp, "exit %d\n", signum);
44         }
45     } else if (WIFSIGNALED(status)) {
46         /* If child process terminated due to receipt of a signal */
47         signum = WTERMSIG(status);
48         if (signum != SIGINT) {
49             if (cp)
50                 fprintf (fp, "%s: ", cp);
51             fprintf (fp, "signal %d", signum);
52             if (signum >= 0 && signum < sizeof(sigmsg) && sigmsg[signum] != NULL)
53                 fprintf (fp, " (%s%s)\n", sigmsg[signum],
54                          WCOREDUMP(status) ? ", core dumped" : "");
55             else
56                 fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
57         }
58     }
59
60     return status;
61 }