]> diplodocus.org Git - nmh/blob - sbr/pidstatus.c
pending-release-notes: add mhshow's "-prefer", and mh-format's %(kibi/kilo)
[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 <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 /*
26 * Return 0 if the command exited with an exit code of zero, a nonzero code
27 * otherwise.
28 *
29 * Print out an appropriate status message we didn't exit with an exit code
30 * of zero.
31 */
32
33 int
34 pidstatus (int status, FILE *fp, char *cp)
35 {
36 int signum;
37
38 /*
39 * I have no idea what this is for (rc)
40 * so I'm commenting it out for right now.
41 *
42 * if ((status & 0xff00) == 0xff00)
43 * return status;
44 */
45
46 /* If child process returned normally */
47 if (WIFEXITED(status)) {
48 if ((signum = WEXITSTATUS(status))) {
49 if (cp)
50 fprintf (fp, "%s: ", cp);
51 fprintf (fp, "exit %d\n", signum);
52 }
53 return signum;
54 } else if (WIFSIGNALED(status)) {
55 /* If child process terminated due to receipt of a signal */
56 signum = WTERMSIG(status);
57 if (signum != SIGINT) {
58 if (cp)
59 fprintf (fp, "%s: ", cp);
60 fprintf (fp, "signal %d", signum);
61 if (signum >= 0 && signum < (int) sizeof(sigmsg) &&
62 sigmsg[signum] != NULL)
63 fprintf (fp, " (%s%s)\n", sigmsg[signum],
64 WCOREDUMP(status) ? ", core dumped" : "");
65 else
66 fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
67 }
68 }
69
70 return status;
71 }