xref: /original-bsd/usr.bin/window/wwchild.c (revision 0a33e010)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)wwchild.c	3.12 (Berkeley) 06/06/90";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 #include <sys/wait.h>
17 
18 wwchild()
19 {
20 	extern errno;
21 	int olderrno;
22 	register struct ww **wp;
23 	union wait w;
24 	int pid;
25 	char collected = 0;
26 
27 	olderrno = errno;
28 	while ((pid = wait3(&w, WNOHANG|WUNTRACED, (struct rusage *)0)) > 0) {
29 		for (wp = wwindex; wp < &wwindex[NWW]; wp++) {
30 			if (*wp && (*wp)->ww_state == WWS_HASPROC
31 			    && (*wp)->ww_pid == pid) {
32 				(*wp)->ww_state = WWS_DEAD;
33 				collected = 1;
34 				break;
35 			}
36 		}
37 	}
38 	errno = olderrno;
39 	/* jump out of wwiomux when somebody dies */
40 	if (collected)
41 		wwsetintr();
42 }
43