aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2008-07-25 22:45:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-26 15:00:08 -0400
commitdae33574dcf5211e1f43c7e45fa29f73ba3e00cb (patch)
tree090eb4af17451836fb39cebf57fbee64a6bd23b5 /kernel/exit.c
parentdaded34be96b1975ff8539ff62ad8b158ce7d842 (diff)
tracehook: release_task
This moves the ptrace-related logic from release_task into tracehook.h and ptrace.h inlines. It provides clean hooks both before and after locking tasklist_lock, for future tracing logic to do more cleanup without the lock. This also changes release_task() itself in the rare "zap_leader" case to set the leader to EXIT_DEAD before iterating. This maintains the invariant that release_task() only ever handles a task in EXIT_DEAD. This is a common-sense invariant that is already always true except in this one arcane case of zombie leader whose parent ignores SIGCHLD. This change is harmless and only costs one store in this one rare case. It keeps the expected state more consisently sane, which is nicer when debugging weirdness in release_task(). It also lets some future code in the tracehook entry points rely on this invariant for bookkeeping. Signed-off-by: Roland McGrath <roland@redhat.com> Cc: Oleg Nesterov <oleg@tv-sign.ru> Reviewed-by: Ingo Molnar <mingo@elte.hu> 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.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index c3691cbc220a..da28745f7c38 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -163,27 +163,17 @@ static void delayed_put_task_struct(struct rcu_head *rhp)
163 put_task_struct(container_of(rhp, struct task_struct, rcu)); 163 put_task_struct(container_of(rhp, struct task_struct, rcu));
164} 164}
165 165
166/*
167 * Do final ptrace-related cleanup of a zombie being reaped.
168 *
169 * Called with write_lock(&tasklist_lock) held.
170 */
171static void ptrace_release_task(struct task_struct *p)
172{
173 BUG_ON(!list_empty(&p->ptraced));
174 ptrace_unlink(p);
175 BUG_ON(!list_empty(&p->ptrace_entry));
176}
177 166
178void release_task(struct task_struct * p) 167void release_task(struct task_struct * p)
179{ 168{
180 struct task_struct *leader; 169 struct task_struct *leader;
181 int zap_leader; 170 int zap_leader;
182repeat: 171repeat:
172 tracehook_prepare_release_task(p);
183 atomic_dec(&p->user->processes); 173 atomic_dec(&p->user->processes);
184 proc_flush_task(p); 174 proc_flush_task(p);
185 write_lock_irq(&tasklist_lock); 175 write_lock_irq(&tasklist_lock);
186 ptrace_release_task(p); 176 tracehook_finish_release_task(p);
187 __exit_signal(p); 177 __exit_signal(p);
188 178
189 /* 179 /*
@@ -205,6 +195,13 @@ repeat:
205 * that case. 195 * that case.
206 */ 196 */
207 zap_leader = task_detached(leader); 197 zap_leader = task_detached(leader);
198
199 /*
200 * This maintains the invariant that release_task()
201 * only runs on a task in EXIT_DEAD, just for sanity.
202 */
203 if (zap_leader)
204 leader->exit_state = EXIT_DEAD;
208 } 205 }
209 206
210 write_unlock_irq(&tasklist_lock); 207 write_unlock_irq(&tasklist_lock);