summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorkbyanc <kbyanc@FreeBSD.org>2003-04-12 01:57:04 +0000
committerkbyanc <kbyanc@FreeBSD.org>2003-04-12 01:57:04 +0000
commitd9072317cb60f96bc88647eb9e08d98b3edad3c6 (patch)
tree09e25608421bb59b58f9e2dfab50824c34967e78 /sys
parent886a932d7b1cd41365958f4e97e27591bc428d40 (diff)
downloadFreeBSD-src-d9072317cb60f96bc88647eb9e08d98b3edad3c6.zip
FreeBSD-src-d9072317cb60f96bc88647eb9e08d98b3edad3c6.tar.gz
Fix race between a process registering a NOTE_EXIT EVFILT_PROC event and
the target process exiting which causes attempts to register the kevent to randomly fail depending on whether the target runs to completion before the parent can call kevent(2). The bug actually effects EVFILT_PROC events on any zombie process, but the most common manifestation is with parents trying to monitor child processes. MFC after: 2 weeks Sponsored by: NTT Multimedia Communications Labs
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_event.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c
index 8c552d1..c8501a2 100644
--- a/sys/kern/kern_event.c
+++ b/sys/kern/kern_event.c
@@ -190,11 +190,17 @@ static int
filt_procattach(struct knote *kn)
{
struct proc *p;
+ int immediate;
int error;
+ immediate = 0;
p = pfind(kn->kn_id);
if (p == NULL)
return (ESRCH);
+ if (p == NULL && (kn->kn_sfflags & NOTE_EXIT)) {
+ p = zpfind(kn->kn_id);
+ immediate = 1;
+ }
if ((error = p_cansee(curthread, p))) {
PROC_UNLOCK(p);
return (error);
@@ -213,6 +219,15 @@ filt_procattach(struct knote *kn)
}
SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext);
+
+ /*
+ * Immediately activate any exit notes if the target process is a
+ * zombie. This is necessary to handle the case where the target
+ * process, e.g. a child, dies before the kevent is registered.
+ */
+ if (immediate && filt_proc(kn, NOTE_EXIT))
+ KNOTE_ACTIVATE(kn);
+
PROC_UNLOCK(p);
return (0);
OpenPOWER on IntegriCloud