From: Guillaume Morin <guillaume@morinfr.org>
To: matt.helsley@gmail.com, torvalds@linux-foundation.org,
akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] exit.c: call proc_exit_connector() after exit_state is set
Date: Mon, 24 Feb 2014 20:27:34 +0100 [thread overview]
Message-ID: <20140224192734.GA15573@bender.morinfr.org> (raw)
From: Guillaume Morin <guillaume@morinfr.org>
The process events connector delivers a notification when a process
exits. This is really convenient for a process that spawns and wants
to monitor its children through an epoll-able() interface.
Unfortunately, there is a small window between when the event is
delivered and the child become wait()-able.
This is creates a race if the parent wants to make sure that it knows
about the exit, e.g
pid_t pid = fork();
if (pid > 0) {
register_interest_for_pid(pid);
if (waitpid(pid, NULL, WNOHANG) > 0)
{
/* We might have raced with exit() */
}
return;
}
/* Child */
execve(...)
register_interest_for_pid() would be telling the the connector socket
reader to pay attention to events related to pid.
Though this is not a bug, I think it would make the connector a bit
more usable if this race was closed by simply moving the call to
proc_exit_connector() from just before exit_notify() to right after.
Signed-off-by: Guillaume Morin <guillaume@morinfr.org>
Cc: matt.helsley@gmail.com
---
diff --git a/kernel/exit.c b/kernel/exit.c
index 1e77fc6..9b0ac8c 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -804,7 +804,6 @@ void do_exit(long code)
module_put(task_thread_info(tsk)->exec_domain->module);
- proc_exit_connector(tsk);
/*
* FIXME: do that only when needed, using sched_exit tracepoint
@@ -812,6 +811,7 @@ void do_exit(long code)
flush_ptrace_hw_breakpoint(tsk);
exit_notify(tsk, group_dead);
+ proc_exit_connector(tsk);
#ifdef CONFIG_NUMA
task_lock(tsk);
mpol_put(tsk->mempolicy);
--
Guillaume Morin <guillaume@morinfr.org>
next reply other threads:[~2014-02-24 19:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-24 19:27 Guillaume Morin [this message]
2014-03-15 18:22 ` [PATCH] exit.c: call proc_exit_connector() after exit_state is set Linus Torvalds
2014-03-15 19:12 ` Oleg Nesterov
2014-03-15 19:22 ` Linus Torvalds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140224192734.GA15573@bender.morinfr.org \
--to=guillaume@morinfr.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.helsley@gmail.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.