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