]> diplodocus.org Git - nmh/blob - sbr/pidstatus.c
show: remove unreachable code
[nmh] / 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 <sys/wait.h>
11 #include <h/mh.h>
12
13 /*
14 * auto-generated header
15 */
16 #include <sigmsg.h>
17
18 #ifndef WTERMSIG
19 # define WTERMSIG(s) ((int)((s) & 0x7F))
20 #endif
21
22 #ifndef WCOREDUMP
23 # define WCOREDUMP(s) ((s) & 0x80)
24 #endif
25
26 int
27 pidstatus (int status, FILE *fp, char *cp)
28 {
29 int signum;
30
31 /*
32 * I have no idea what this is for (rc)
33 * so I'm commenting it out for right now.
34 *
35 * if ((status & 0xff00) == 0xff00)
36 * return status;
37 */
38
39 /* If child process returned normally */
40 if (WIFEXITED(status)) {
41 if ((signum = WEXITSTATUS(status))) {
42 if (cp)
43 fprintf (fp, "%s: ", cp);
44 fprintf (fp, "exit %d\n", signum);
45 }
46 } else if (WIFSIGNALED(status)) {
47 /* If child process terminated due to receipt of a signal */
48 signum = WTERMSIG(status);
49 if (signum != SIGINT) {
50 if (cp)
51 fprintf (fp, "%s: ", cp);
52 fprintf (fp, "signal %d", signum);
53 if (signum >= 0 && signum < (int) sizeof(sigmsg) &&
54 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 }