]> diplodocus.org Git - nmh/blob - sbr/pidstatus.c
Alter mh-chart(7)'s NAME to be lowercase.
[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 #ifndef WTERMSIG
13 # define WTERMSIG(s) ((int)((s) & 0x7F))
14 #endif
15
16 #ifndef WCOREDUMP
17 # define WCOREDUMP(s) ((s) & 0x80)
18 #endif
19
20 /*
21 * Return 0 if the command exited with an exit code of zero, a nonzero code
22 * otherwise.
23 *
24 * Print out an appropriate status message we didn't exit with an exit code
25 * of zero.
26 */
27
28 int
29 pidstatus (int status, FILE *fp, char *cp)
30 {
31 int signum;
32 char *signame;
33
34 /*
35 * I have no idea what this is for (rc)
36 * so I'm commenting it out for right now.
37 *
38 * if ((status & 0xff00) == 0xff00)
39 * return status;
40 */
41
42 /* If child process returned normally */
43 if (WIFEXITED(status)) {
44 if ((signum = WEXITSTATUS(status))) {
45 if (cp)
46 fprintf (fp, "%s: ", cp);
47 fprintf (fp, "exit %d\n", signum);
48 }
49 return signum;
50 }
51
52 if (WIFSIGNALED(status)) {
53 /* If child process terminated due to receipt of a signal */
54 signum = WTERMSIG(status);
55 if (signum != SIGINT) {
56 if (cp)
57 fprintf (fp, "%s: ", cp);
58 fprintf (fp, "signal %d", signum);
59 errno = 0;
60 signame = strsignal(signum);
61 if (errno)
62 signame = NULL;
63 if (signame)
64 fprintf (fp, " (%s%s)\n", signame,
65 WCOREDUMP(status) ? ", core dumped" : "");
66 else
67 fprintf (fp, "%s\n", WCOREDUMP(status) ? " (core dumped)" : "");
68 }
69 }
70
71 return status;
72 }