if (SendmailWait > 0) { Signals &= ~S_ALARM; act.sa_handler = alarm_handler; #ifdef SA_INTERRUPT  act.sa_flags = SA_INTERRUPT; #else act.sa_flags = 0; #endif sigaction (SIGALRM, &act, &oldalrm); alarm (SendmailWait); } if (SendmailWait >= 0) { w = waitpid (pid, &st, 0); err = errno;  dprint (1, (debugfile, "send_msg(): waitpid returned %d (%s)\n", w, (w < 0 ? strerror (errno) : "OK"))); } if (SendmailWait > 0) { alarm (0); sigaction (SIGALRM, &oldalrm, NULL); } if (SendmailWait < 0 || ((Signals & S_ALARM) && w < 0 && err == EINTR)) {  mutt_add_child_pid (pid);  unlink (*tempfile); FREE (tempfile); #ifdef DEBUG if (Signals & S_ALARM) dprint (1, (debugfile, "send_msg(): received SIGALRM\n")); dprint (1, (debugfile, "send_msg(): putting sendmail in the background\n")); #endif st = EX_OK & 0xff; } else if (w < 0) {  st = (err == EINTR) ? (EX_OK & 0xff) : 127; }
sigprocmask (SIG_UNBLOCK, &set, NULL);  if (pid != -1 && waitpid (pid, &st, 0) > 0) st = WIFEXITED (st) ? WEXITSTATUS (st) : S_ERR;
send_msg (const char *path, char **args, const char *msg, char **tempfile){  int fd, st, w = 0, err = 0;  pid_t pid;  struct sigaction act, oldint, oldquit, oldalrm;  memset (&act, 0, sizeof (struct sigaction));  sigemptyset (&(act.sa_mask));  act.sa_handler = SIG_IGN;  sigaction (SIGINT, &act, &oldint);  sigaction (SIGQUIT, &act, &oldquit);  if (SendmailWait)  {    char tmp[_POSIX_PATH_MAX];    mutt_mktemp (tmp);    *tempfile = safe_strdup (tmp);  }  if ((pid = fork ()) == 0)  {    /* reset signals for the child */    act.sa_handler = SIG_DFL;    /* we need SA_RESTART for the open() below */#ifdef SA_RESTART    act.sa_flags = SA_NOCLDSTOP | SA_RESTART;#else    act.sa_flags = SA_NOCLDSTOP;#endif    sigaction (SIGCHLD, &act, NULL);    act.sa_flags = 0;    sigaction (SIGINT, &act, NULL);    sigaction (SIGQUIT, &act, NULL);    /* if it is possible that we will deliver in the background, then we have       to detach the child from this process group or it will die when the       parent process exists, causing the mail to not get delivered.  The       problem here is that any error messages will get lost... */    if (SendmailWait)      setsid ();    if ((pid = fork ()) == 0)    {      fd = open (msg, O_RDONLY, 0);      if (fd < 0)	_exit (127);      dup2 (fd, 0);      close (fd);      if (SendmailWait)      {	/* write stdout to a tempfile */	w = open (*tempfile, O_WRONLY | O_CREAT | O_EXCL, 0600);	if (w < 0)	  _exit (errno);	dup2 (w, 1);	close (w);      }      sigaction (SIGCHLD, &act, NULL);      execv (path, args);      unlink (msg);      _exit (127);    }    else if (pid == -1)    {      unlink (msg);      _exit (errno);    }    if (waitpid (pid, &st, 0) > 0)    {      st = WIFEXITED (st) ? WEXITSTATUS (st) : 127;      if (st == (EX_OK & 0xff) && SendmailWait)	unlink (*tempfile); /* no longer needed */    }    else    {      st = 127;      if (SendmailWait)	unlink (*tempfile);    }    unlink (msg);    _exit (st);  }  /* SendmailWait > 0: SIGALRM will interrupt wait() after alrm seconds     SendmailWait = 0: wait forever     SendmailWait < 0: don't wait */  if (SendmailWait > 0)  {    Signals &= ~S_ALARM;    act.sa_handler = alarm_handler;#ifdef SA_INTERRUPT    /* need to make sure the waitpid() is interrupted on SIGALRM */    act.sa_flags = SA_INTERRUPT;#else    act.sa_flags = 0;#endif    sigaction (SIGALRM, &act, &oldalrm);    alarm (SendmailWait);  }  if (SendmailWait >= 0)  {    w = waitpid (pid, &st, 0);    err = errno; /* save error since it might be clobbered by another		    system call before we check the value */    dprint (1, (debugfile, "send_msg(): waitpid returned %d (%s)\n", w,	    (w < 0 ? strerror (errno) : "OK")));  }  if (SendmailWait > 0)  {    alarm (0);    sigaction (SIGALRM, &oldalrm, NULL);  }  if (SendmailWait < 0 || ((Signals & S_ALARM) && w < 0 && err == EINTR))  {    /* add to list of children pids to reap */    mutt_add_child_pid (pid);    /* since there is no way for the user to be notified of error in this case,       remove the temp file now */    unlink (*tempfile);    FREE (tempfile);#ifdef DEBUG    if (Signals & S_ALARM)      dprint (1, (debugfile, "send_msg(): received SIGALRM\n"));    dprint (1, (debugfile, "send_msg(): putting sendmail in the background\n"));#endif    st = EX_OK & 0xff;  }  else if (w < 0)  {    /* if err==EINTR, alarm interrupt, child status unknown,       otherwise, there was an error invoking the child */    st = (err == EINTR) ? (EX_OK & 0xff) : 127;  }  else  {#ifdef DEBUG    if (WIFEXITED (st))    {      dprint (1, (debugfile, "send_msg(): child exited %d\n", WEXITSTATUS (st)));    }    else    {      dprint (1, (debugfile, "send_msg(): child did not exit\n"));    }#endif /* DEBUG */    st = WIFEXITED (st) ? WEXITSTATUS (st) : -1; /* return child status */  }  sigaction (SIGINT, &oldint, NULL);  sigaction (SIGQUIT, &oldquit, NULL);  /* restore errno so that the caller can build an error message */  errno = err;  return (st);}