]> diplodocus.org Git - nmh/blob - sbr/pidwait.c
Fix invalid pointer arithmetic.
[nmh] / sbr / pidwait.c
1 /* pidwait.c -- wait for child to exit
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9 #include <h/signals.h>
10
11 int
12 pidwait (pid_t id, int sigsok)
13 {
14 pid_t pid;
15 SIGNAL_HANDLER istat = NULL, qstat = NULL;
16
17 int status;
18
19 if (sigsok == -1) {
20 /* ignore a couple of signals */
21 istat = SIGNAL (SIGINT, SIG_IGN);
22 qstat = SIGNAL (SIGQUIT, SIG_IGN);
23 }
24
25 while ((pid = waitpid(id, &status, 0)) == -1 && errno == EINTR)
26 ;
27
28 if (sigsok == -1) {
29 /* reset the signal handlers */
30 SIGNAL (SIGINT, istat);
31 SIGNAL (SIGQUIT, qstat);
32 }
33
34 return pid == -1 ? -1 : status;
35 }