Convert pidXwait() from macro to function
authormarkus schnalke <meillo@marmaro.de>
Thu, 15 Jan 2015 16:53:20 +0000 (17:53 +0100)
committermarkus schnalke <meillo@marmaro.de>
Thu, 15 Jan 2015 16:53:20 +0000 (17:53 +0100)
Plus some refactoring and syntactic sugar in pidstatus().

h/mh.h
h/prototypes.h
sbr/pidstatus.c

diff --git a/h/mh.h b/h/mh.h
index f3fda88..9d22c2b 100644 (file)
--- 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
index 1333a84..f162ef5 100644 (file)
@@ -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 *);
index edd6749..cb0cb1c 100644 (file)
@@ -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);
+}