]> diplodocus.org Git - nmh/blob - sbr/pidstatus.c
mhbuildsbr.c: Flip logic, moving goto to then-block; no need for else.
[nmh] / sbr / pidstatus.c
1 /* pidstatus.c -- report child's status
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10 #ifndef WTERMSIG
11 # define WTERMSIG(s) ((int)((s) & 0x7F))
12 #endif
13
14 #ifndef WCOREDUMP
15 # define WCOREDUMP(s) ((s) & 0x80)
16 #endif
17
18 /*
19 * Return 0 if the command exited with an exit code of zero, a nonzero code
20 * otherwise.
21 *
22 * Print out an appropriate status message we didn't exit with an exit code
23 * of zero.
24 */
25
26 int
27 pidstatus (int status, FILE *fp, char *cp)
28 {
29 int signum;
30 char *signame;
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 return signum;
48 }
49
50 if (WIFSIGNALED(status)) {
51 /* If child process terminated due to receipt of a signal */
52 signum = WTERMSIG(status);
53 if (signum != SIGINT) {
54 if (cp)
55 fprintf (fp, "%s: ", cp);
56 fprintf (fp, "signal %d", signum);
57 errno = 0;
58 signame = strsignal(signum);
59 if (errno)
60 signame = NULL;
61 if (signame)
62 fprintf (fp, " (%s%s)\n", signame,
63 WCOREDUMP(status) ? ", core dumped" : "");
64 else
65 fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
66 }
67 }
68
69 return status;
70 }