3 * pidwait.c -- wait for child to exit
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/signals.h>
15 #ifdef HAVE_SYS_WAIT_H
16 # include <sys/wait.h>
20 pidwait (pid_t id, int sigsok)
23 SIGNAL_HANDLER istat = NULL, qstat = NULL;
25 #ifdef HAVE_UNION_WAIT
32 /* ignore a couple of signals */
33 istat = SIGNAL (SIGINT, SIG_IGN);
34 qstat = SIGNAL (SIGQUIT, SIG_IGN);
38 while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
41 while ((pid = wait(&status)) != -1 && pid != id)
46 /* reset the signal handlers */
47 SIGNAL (SIGINT, istat);
48 SIGNAL (SIGQUIT, qstat);
51 #ifdef HAVE_UNION_WAIT
52 return (pid == -1 ? -1 : status.w_status);
54 return (pid == -1 ? -1 : status);