X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/3b6170b27ba8fedbb4d67d2842bfaa38d4417962..b46d49ba:/uip/whom.c?ds=sidebyside diff --git a/uip/whom.c b/uip/whom.c index 145190b7..76f434e4 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -6,6 +6,7 @@ */ #include +#include "h/done.h" #include #include #include "sbr/m_maildir.h" @@ -59,7 +60,8 @@ main (int argc, char **argv) { pid_t child_id = OK; int status, isdf = 0; - int distsw = 0, vecp = 0; + int vecp = 0; + bool distsw; char *cp, *dfolder = NULL, *dmsg = NULL; char *msg = NULL, **ap, **argp, backup[BUFSIZ]; char buf[BUFSIZ], **arguments, *vec[MAXARGS]; @@ -166,46 +168,40 @@ main (int argc, char **argv) cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); msg = vec[vecp++] = cp; } - if ((cp = getenv ("mhdist")) - && *cp - && (distsw = atoi (cp)) - && (cp = getenv ("mhaltmsg")) - && *cp) { + + distsw = (cp = getenv("mhdist")) && *cp && atoi(cp) && + (cp = getenv("mhaltmsg")) && *cp; + if (distsw) { if (distout (msg, cp, backup) == NOTOK) done (1); vec[vecp++] = "-dist"; - distsw++; } vec[vecp] = NULL; closefds (3); - if (distsw) - child_id = fork(); - - switch (distsw ? child_id : OK) { - case NOTOK: - inform("unable to fork, so checking directly..."); - /* FALLTHRU */ - 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); - - status = pidwait(child_id, OK); - - (void) m_unlink (msg); - if (rename (backup, msg) == NOTOK) - adios (msg, "unable to rename %s to", backup); - done (status); + if (distsw) { + if ((child_id = fork()) == -1) + adios("fork", "failed:"); + + if (child_id) { + SIGNAL (SIGHUP, SIG_IGN); + SIGNAL (SIGINT, SIG_IGN); + SIGNAL (SIGQUIT, SIG_IGN); + SIGNAL (SIGTERM, SIG_IGN); + + status = pidwait(child_id, OK); + + (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); }