0
|
1 /* pidwait.c - wait for child to exit */
|
|
2 #ifndef lint
|
12
|
3 static char ident[] = "@(#)$Id: pidwait.c,v 1.1.1.1 2005/04/18 14:46:06 kono Exp $";
|
0
|
4 #endif /* lint */
|
|
5
|
|
6 #include "../h/mh.h"
|
|
7 #include <signal.h>
|
|
8 #include <stdio.h>
|
|
9 #if defined (BSD42) || defined (SVR4)
|
|
10 #include <sys/wait.h>
|
|
11 #endif
|
|
12
|
|
13
|
|
14 int pidwait (id, sigsok)
|
|
15 register int id,
|
|
16 sigsok;
|
|
17 {
|
|
18 register int pid;
|
|
19 TYPESIG (*hstat) (), (*istat) (), (*qstat) (), (*tstat) ();
|
|
20 #if defined(BSD42) && !defined(WAITINT)
|
|
21 union wait status;
|
|
22 #else
|
|
23 int status;
|
|
24 #endif
|
|
25
|
|
26 if (sigsok == NOTOK) {
|
|
27 #ifdef notdef /* I don't see why to trap these... */
|
|
28 hstat = signal (SIGHUP, SIG_IGN);
|
|
29 tstat = signal (SIGTERM, SIG_IGN);
|
|
30 #endif
|
|
31 istat = signal (SIGINT, SIG_IGN);
|
|
32 qstat = signal (SIGQUIT, SIG_IGN);
|
|
33 }
|
|
34
|
|
35 #ifdef SVR4
|
|
36 pid = waitpid (id, &status, WUNTRACED);
|
|
37 #else
|
|
38 while ((pid = wait (&status)) != NOTOK && pid != id)
|
|
39 continue;
|
|
40 #endif
|
|
41
|
|
42 if (sigsok == NOTOK) {
|
|
43 #ifdef notdef
|
|
44 (void) signal (SIGHUP, hstat);
|
|
45 (void) signal (SIGTERM, tstat);
|
|
46 #endif
|
|
47 (void) signal (SIGINT, istat);
|
|
48 (void) signal (SIGQUIT, qstat);
|
|
49 }
|
|
50
|
|
51 #if defined(BSD42) && !defined(WAITINT)
|
|
52 return (pid == NOTOK ? NOTOK : status.w_status);
|
|
53 #else
|
|
54 return (pid == NOTOK ? NOTOK : status);
|
|
55 #endif
|
|
56 }
|