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