]> diplodocus.org Git - nmh/blob - sbr/pidwait.c
3c926e74d62740c26dfad66c362762eb812234fe
[nmh] / sbr / pidwait.c
1 /*
2 * pidwait.c -- wait for child to exit
3 *
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.
7 */
8
9 #include <h/mh.h>
10 #include <h/signals.h>
11
12 int
13 pidwait (pid_t id, int sigsok)
14 {
15 pid_t pid;
16 SIGNAL_HANDLER istat = NULL, qstat = NULL;
17
18 int status;
19
20 if (sigsok == -1) {
21 /* ignore a couple of signals */
22 istat = SIGNAL (SIGINT, SIG_IGN);
23 qstat = SIGNAL (SIGQUIT, SIG_IGN);
24 }
25
26 while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
27 ;
28
29 if (sigsok == -1) {
30 /* reset the signal handlers */
31 SIGNAL (SIGINT, istat);
32 SIGNAL (SIGQUIT, qstat);
33 }
34
35 return (pid == -1 ? -1 : status);
36 }