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