Index: kern_event.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_event.c,v retrieving revision 1.64 diff -u -p -r1.64 kern_event.c --- kern_event.c 9 Nov 2003 09:17:24 -0000 1.64 +++ kern_event.c 10 Nov 2003 20:00:36 -0000 @@ -218,7 +218,8 @@ filt_procattach(struct knote *kn) kn->kn_flags &= ~EV_FLAG1; } - SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); + if (immediate == 0) + SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); /* * Immediately activate any exit notes if the target process is a @@ -278,13 +279,6 @@ filt_proc(struct knote *kn, long hint) kn->kn_flags |= (EV_EOF | EV_ONESHOT); return (1); } - - /* - * Process will already be reported as gone. - * Do not report anything else, as the knote will be destroyed soon. - */ - if (kn->kn_status & KN_DETACHED) - return (0); /* * process forked, and user wants to track the new process, Index: kern_exit.c =================================================================== RCS file: /home/ncvs/src/sys/kern/kern_exit.c,v retrieving revision 1.217 diff -u -p -r1.217 kern_exit.c --- kern_exit.c 15 Jun 2003 00:31:23 -0000 1.217 +++ kern_exit.c 10 Nov 2003 19:34:46 -0000 @@ -436,6 +436,14 @@ exit1(struct thread *td, int rv) * Notify interested parties of our demise. */ KNOTE(&p->p_klist, NOTE_EXIT); + /* + * Just delete all entries in the p_klist. At this point we won't + * report any more events, and there are nasty race conditions that + * can beat us if we don't. + */ + while (SLIST_FIRST(&p->p_klist)) + SLIST_REMOVE_HEAD(&p->p_klist, kn_selnext); + /* * Notify parent that we're gone. If parent has the PS_NOCLDWAIT