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