Updated build-nmh-cygwin for release of Cygwin nmh 1.5-2. To use:
[mmh] / 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 #include <errno.h>
13 #include <signal.h>
14 #include <sys/wait.h>
15
16 int
17 pidwait (pid_t id, int sigsok)
18 {
19     pid_t pid;
20     SIGNAL_HANDLER istat = NULL, qstat = NULL;
21
22     int status;
23
24     if (sigsok == -1) {
25         /* ignore a couple of signals */
26         istat = SIGNAL (SIGINT, SIG_IGN);
27         qstat = SIGNAL (SIGQUIT, SIG_IGN);
28     }
29
30     while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
31         ;
32
33     if (sigsok == -1) {
34         /* reset the signal handlers */
35         SIGNAL (SIGINT, istat);
36         SIGNAL (SIGQUIT, qstat);
37     }
38
39     return (pid == -1 ? -1 : status);
40 }