From 43b38cc6c82b85aff3a5868289ecebeb20215b9c Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 15 Jan 2015 17:53:20 +0100 Subject: [PATCH] Convert pidXwait() from macro to function Plus some refactoring and syntactic sugar in pidstatus(). --- h/mh.h | 2 -- h/prototypes.h | 1 + sbr/pidstatus.c | 41 ++++++++++++++++++++++++++--------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/h/mh.h b/h/mh.h index f3fda88..9d22c2b 100644 --- a/h/mh.h +++ b/h/mh.h @@ -191,8 +191,6 @@ extern int msg_count; /* m_getfld() indicators (That's a hack!) */ ** miscellaneous macros */ -#define pidXwait(pid,cp) pidstatus(pidwait(pid, NOTOK), stdout, cp) - #ifndef max # define max(a,b) ((a) > (b) ? (a) : (b)) #endif diff --git a/h/prototypes.h b/h/prototypes.h index 1333a84..f162ef5 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -78,6 +78,7 @@ char *norm_charmap(char *); char *new_fs(char *, char *); int pidwait(pid_t, int); int pidstatus(int, FILE *, char *); +int pidXwait(int, char *); void print_help(char *, struct swit *, int); void print_sw(char *, struct swit *, char *, FILE *); void print_version(char *); diff --git a/sbr/pidstatus.c b/sbr/pidstatus.c index edd6749..cb0cb1c 100644 --- a/sbr/pidstatus.c +++ b/sbr/pidstatus.c @@ -35,30 +35,41 @@ pidstatus(int status, FILE *fp, char *cp) ** return status; */ - /* If child process returned normally */ if (WIFEXITED(status)) { + /* child process returned normally */ if ((signum = WEXITSTATUS(status))) { - if (cp) + 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 */ + /* 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)" : ""); + 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; } + + +int +pidXwait(int pid, char *cp) +{ + return pidstatus(pidwait(pid, -1), stdout, cp); +} -- 1.7.10.4