Remove RCS keywords, since they no longer work after git migration.
[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
15 #ifdef HAVE_SYS_WAIT_H
16 # include <sys/wait.h>
17 #endif
18
19 int
20 pidwait (pid_t id, int sigsok)
21 {
22     pid_t pid;
23     SIGNAL_HANDLER istat = NULL, qstat = NULL;
24
25 #ifdef HAVE_UNION_WAIT
26     union wait status;
27 #else
28     int status;
29 #endif
30
31     if (sigsok == -1) {
32         /* ignore a couple of signals */
33         istat = SIGNAL (SIGINT, SIG_IGN);
34         qstat = SIGNAL (SIGQUIT, SIG_IGN);
35     }
36
37 #ifdef HAVE_WAITPID
38     while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
39         ;
40 #else
41     while ((pid = wait(&status)) != -1 && pid != id)
42         continue;
43 #endif
44
45     if (sigsok == -1) {
46         /* reset the signal handlers */
47         SIGNAL (SIGINT, istat);
48         SIGNAL (SIGQUIT, qstat);
49     }
50
51 #ifdef HAVE_UNION_WAIT
52     return (pid == -1 ? -1 : status.w_status);
53 #else
54     return (pid == -1 ? -1 : status);
55 #endif
56 }