X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fpidstatus.c;h=cab45f5440c762eb94e13c61cccafe307e986d1b;hp=aa664649a887a5fc901523b8fd45c3c70fff4690;hb=1642d62841486ade88ec2c48dd581e3249c98c94;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/sbr/pidstatus.c b/sbr/pidstatus.c index aa66464..cab45f5 100644 --- a/sbr/pidstatus.c +++ b/sbr/pidstatus.c @@ -1,20 +1,19 @@ - /* - * pidstatus.c -- report child's status - * - * $Id$ - */ +** 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 #include /* - * auto-generated header - */ -#include - -#ifdef HAVE_SYS_WAIT_H -# include -#endif +** auto-generated header +*/ +#include "sigmsg.h" +#include #ifndef WTERMSIG # define WTERMSIG(s) ((int)((s) & 0x7F)) @@ -25,39 +24,53 @@ #endif int -pidstatus (int status, FILE *fp, char *cp) +pidstatus(int status, FILE *fp, char *cp) { - int signum; + 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); - } - } 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 < 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)" : ""); + /* + ** 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 (WIFEXITED(status)) { + /* child process returned normally */ + if ((signum = WEXITSTATUS(status))) { + if (cp) { + fprintf(fp, "%s: ", cp); + } + fprintf(fp, "exit %d\n", signum); + } + } else if (WIFSIGNALED(status)) { + /* child process terminated due to receipt of a signal */ + signum = WTERMSIG(status); + if (signum == SIGINT) { + return status; + } + 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; + return status; +} + + +int +pidXwait(int pid, char *cp) +{ + return pidstatus(pidwait(pid, -1), stdout, cp); }