+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Edward Wang at The University of California, Berkeley.
+ *
+ * %sccs.include.redist.c%
+ */
+
#ifndef lint
-static char *sccsid = "@(#)wwchild.c 1.1 83/07/12";
-#endif
+static char sccsid[] = "@(#)wwchild.c 3.15 (Berkeley) %G%";
+#endif /* not lint */
#include "ww.h"
+#include <sys/types.h>
#include <sys/wait.h>
+void
wwchild()
{
- register struct ww *wp;
+ extern errno;
+ int olderrno;
+ register struct ww **wp;
union wait w;
int pid;
- /*
- char buf[100];
- */
+ char collected = 0;
- while ((pid = wait3(&w, WNOHANG|WUNTRACED, 0)) > 0) {
- for (wp = _wwhead; wp; wp = wp->ww_next) {
- if (wp->ww_pid == pid) {
- wp->ww_state = WW_DEAD;
- /*
- (void) sprintf(buf, "\r\n%d: Died\r\n", pid);
- wwputstr(buf);
- */
+ olderrno = errno;
+ while ((pid =
+ wait3((int *)&w, WNOHANG|WUNTRACED, (struct rusage *)0)) > 0) {
+ for (wp = wwindex; wp < &wwindex[NWW]; wp++) {
+ if (*wp && (*wp)->ww_state == WWS_HASPROC
+ && (*wp)->ww_pid == pid) {
+ (*wp)->ww_state = WWS_DEAD;
+ collected = 1;
break;
}
}
- /*
- if (wp == 0) {
- (void) sprintf(buf, "\r\n%d: No such child\r\n", pid);
- wwputstr(buf);
- }
- */
}
+ errno = olderrno;
+ /* jump out of wwiomux when somebody dies */
+ if (collected)
+ wwsetintr();
}