2 ** pidwait.c -- wait for child to exit
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 #include <h/signals.h>
14 #ifdef HAVE_SYS_WAIT_H
15 # include <sys/wait.h>
19 pidwait(pid_t id, int sigsok)
22 SIGNAL_HANDLER istat = NULL, qstat = NULL;
24 #ifdef HAVE_UNION_WAIT
31 /* ignore a couple of signals */
32 istat = SIGNAL(SIGINT, SIG_IGN);
33 qstat = SIGNAL(SIGQUIT, SIG_IGN);
37 while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
40 while ((pid = wait(&status)) != -1 && pid != id)
45 /* reset the signal handlers */
46 SIGNAL(SIGINT, istat);
47 SIGNAL(SIGQUIT, qstat);
50 #ifdef HAVE_UNION_WAIT
51 return (pid == -1 ? -1 : status.w_status);
53 return (pid == -1 ? -1 : status);