Commit 4ef892a0 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Report detached thread exit to the debugger

From: Daniel Jacobowitz <dan@debian.org>

Right now, CLONE_DETACHED threads silently vanish from GDB's sight when
they exit.  This patch lets the thread report its exit to the debugger, and
then be auto-reaped as soon as it is collected, instead of being reaped as
soon as it exits and not reported at all.

GDB works either way, but this is more correct and will be useful for some
later GDB patches.
parent a7fd6e5d
...@@ -651,6 +651,8 @@ static void exit_notify(struct task_struct *tsk) ...@@ -651,6 +651,8 @@ static void exit_notify(struct task_struct *tsk)
if (tsk->exit_signal != -1) { if (tsk->exit_signal != -1) {
int signal = tsk->parent == tsk->real_parent ? tsk->exit_signal : SIGCHLD; int signal = tsk->parent == tsk->real_parent ? tsk->exit_signal : SIGCHLD;
do_notify_parent(tsk, signal); do_notify_parent(tsk, signal);
} else if (tsk->ptrace) {
do_notify_parent(tsk, SIGCHLD);
} }
tsk->state = TASK_ZOMBIE; tsk->state = TASK_ZOMBIE;
...@@ -715,7 +717,7 @@ NORET_TYPE void do_exit(long code) ...@@ -715,7 +717,7 @@ NORET_TYPE void do_exit(long code)
tsk->exit_code = code; tsk->exit_code = code;
exit_notify(tsk); exit_notify(tsk);
if (tsk->exit_signal == -1) if (tsk->exit_signal == -1 && tsk->ptrace == 0)
release_task(tsk); release_task(tsk);
schedule(); schedule();
...@@ -859,7 +861,7 @@ static int wait_task_zombie(task_t *p, unsigned int *stat_addr, struct rusage *r ...@@ -859,7 +861,7 @@ static int wait_task_zombie(task_t *p, unsigned int *stat_addr, struct rusage *r
BUG_ON(state != TASK_DEAD); BUG_ON(state != TASK_DEAD);
return 0; return 0;
} }
if (unlikely(p->exit_signal == -1)) if (unlikely(p->exit_signal == -1 && p->ptrace == 0))
/* /*
* This can only happen in a race with a ptraced thread * This can only happen in a race with a ptraced thread
* dying on another processor. * dying on another processor.
...@@ -889,8 +891,12 @@ static int wait_task_zombie(task_t *p, unsigned int *stat_addr, struct rusage *r ...@@ -889,8 +891,12 @@ static int wait_task_zombie(task_t *p, unsigned int *stat_addr, struct rusage *r
/* Double-check with lock held. */ /* Double-check with lock held. */
if (p->real_parent != p->parent) { if (p->real_parent != p->parent) {
__ptrace_unlink(p); __ptrace_unlink(p);
do_notify_parent(p, p->exit_signal);
p->state = TASK_ZOMBIE; p->state = TASK_ZOMBIE;
/* If this is a detached thread, this is where it goes away. */
if (p->exit_signal == -1)
release_task (p);
else
do_notify_parent(p, p->exit_signal);
p = NULL; p = NULL;
} }
write_unlock_irq(&tasklist_lock); write_unlock_irq(&tasklist_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment