xref: /original-bsd/usr.bin/window/wwchild.c (revision 6ab384a1)
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.13 (Berkeley) 08/12/90";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 #include <sys/wait.h>
17 
18 void
19 wwchild()
20 {
21 	extern errno;
22 	int olderrno;
23 	register struct ww **wp;
24 	union wait w;
25 	int pid;
26 	char collected = 0;
27 
28 	olderrno = errno;
29 	while ((pid = wait3(&w, WNOHANG|WUNTRACED, (struct rusage *)0)) > 0) {
30 		for (wp = wwindex; wp < &wwindex[NWW]; wp++) {
31 			if (*wp && (*wp)->ww_state == WWS_HASPROC
32 			    && (*wp)->ww_pid == pid) {
33 				(*wp)->ww_state = WWS_DEAD;
34 				collected = 1;
35 				break;
36 			}
37 		}
38 	}
39 	errno = olderrno;
40 	/* jump out of wwiomux when somebody dies */
41 	if (collected)
42 		wwsetintr();
43 }
44