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