]> diplodocus.org Git - nmh/commitdiff
whom.c: Re-work fork/exec logic to clarify interaction with distsw.
authorRalph Corderoy <ralph@inputplus.co.uk>
Mon, 18 Sep 2017 11:31:58 +0000 (12:31 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Mon, 18 Sep 2017 12:10:13 +0000 (13:10 +0100)
uip/whom.c

index c16d2a1..f0eee7e 100644 (file)
@@ -179,32 +179,28 @@ main (int argc, char **argv)
 
     closefds (3);
 
-    if (distsw)
-       child_id = fork();
-
-    switch (distsw ? child_id : OK) {
-       case NOTOK:
+    if (distsw) {
+        if ((child_id = fork()) == -1)
             adios("fork", "failed:");
 
-       case OK:
-           execvp (postproc, vec);
-           fprintf (stderr, "unable to exec ");
-           perror (postproc);
-           _exit (-1);
-
-       default:
-           SIGNAL (SIGHUP, SIG_IGN);
-           SIGNAL (SIGINT, SIG_IGN);
-           SIGNAL (SIGQUIT, SIG_IGN);
-           SIGNAL (SIGTERM, SIG_IGN);
+        if (child_id) {
+            SIGNAL (SIGHUP, SIG_IGN);
+            SIGNAL (SIGINT, SIG_IGN);
+            SIGNAL (SIGQUIT, SIG_IGN);
+            SIGNAL (SIGTERM, SIG_IGN);
 
-           status = pidwait(child_id, OK);
+            status = pidwait(child_id, OK);
 
-           (void) m_unlink (msg);
-           if (rename (backup, msg) == NOTOK)
-               adios (msg, "unable to rename %s to", backup);
-           done (status);
+            (void) m_unlink (msg);
+            if (rename (backup, msg) == NOTOK)
+                adios (msg, "unable to rename %s to", backup);
+            done (status);
+        }
     }
 
-    return 0;  /* dead code to satisfy the compiler */
+    /* Either the child, or no fork occurred. */
+    execvp (postproc, vec);
+    fprintf (stderr, "unable to exec ");
+    perror (postproc);
+    _exit (-1);
 }