aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
authorGuillaume Morin <guillaume@morinfr.org>2014-04-07 18:38:31 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-07 19:36:04 -0400
commitef9823939e5acd5d323ff61fbc427ef998dd203e (patch)
tree84685216b295fa81ea71af435889f040af3fcf1f /kernel/exit.c
parent4bcb8232cf4eb061b086c10f56b6808adcdb5a93 (diff)
kernel/exit.c: call proc_exit_connector() after exit_state is set
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. Oleg said: : Even with this patch the code above is still "racy" if the child is : multi-threaded. Plus it should obviously filter-out subthreads. And : afaics there is no way to make it reliable, even if you change the code : above so that waitpid() is called only after the last thread exits WNOHANG : still can fail. Signed-off-by: Guillaume Morin <guillaume@morinfr.org> Cc: Matt Helsley <matt.helsley@gmail.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/exit.c')
-rw-r--r--kernel/exit.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 171c9a9d7b00..decf648574f6 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -802,13 +802,13 @@ void do_exit(long code)
802 802
803 module_put(task_thread_info(tsk)->exec_domain->module); 803 module_put(task_thread_info(tsk)->exec_domain->module);
804 804
805 proc_exit_connector(tsk);
806 /* 805 /*
807 * FIXME: do that only when needed, using sched_exit tracepoint 806 * FIXME: do that only when needed, using sched_exit tracepoint
808 */ 807 */
809 flush_ptrace_hw_breakpoint(tsk); 808 flush_ptrace_hw_breakpoint(tsk);
810 809
811 exit_notify(tsk, group_dead); 810 exit_notify(tsk, group_dead);
811 proc_exit_connector(tsk);
812#ifdef CONFIG_NUMA 812#ifdef CONFIG_NUMA
813 task_lock(tsk); 813 task_lock(tsk);
814 mpol_put(tsk->mempolicy); 814 mpol_put(tsk->mempolicy);