Commit b1b4c679 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()

No functional changes, preparation for the next patch.

Move the "should we release this child" logic into the separate handler,
__ptrace_detach().
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Jerome Marchand <jmarchan@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6d69cb87
...@@ -744,48 +744,52 @@ static int ignoring_children(struct sighand_struct *sigh) ...@@ -744,48 +744,52 @@ static int ignoring_children(struct sighand_struct *sigh)
return ret; return ret;
} }
/* /* Returns nonzero if the tracee should be released. */
* Detach all tasks we were using ptrace on. int __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
* Any that need to be release_task'd are put on the @dead list.
*
* Called with write_lock(&tasklist_lock) held.
*/
static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
{ {
struct task_struct *p, *n;
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
__ptrace_unlink(p); __ptrace_unlink(p);
if (p->exit_state != EXIT_ZOMBIE) if (p->exit_state != EXIT_ZOMBIE)
continue; return 0;
/* /*
* If it's a zombie, our attachedness prevented normal * If it's a zombie, our attachedness prevented normal
* parent notification or self-reaping. Do notification * parent notification or self-reaping. Do notification
* now if it would have happened earlier. If it should * now if it would have happened earlier. If it should
* reap itself, add it to the @dead list. We can't call * reap itself we return true.
* release_task() here because we already hold tasklist_lock.
* *
* If it's our own child, there is no notification to do. * If it's our own child, there is no notification to do.
* But if our normal children self-reap, then this child * But if our normal children self-reap, then this child
* was prevented by ptrace and we must reap it now. * was prevented by ptrace and we must reap it now.
*/ */
if (!task_detached(p) && thread_group_empty(p)) { if (!task_detached(p) && thread_group_empty(p)) {
if (!same_thread_group(p->real_parent, parent)) if (!same_thread_group(p->real_parent, tracer))
do_notify_parent(p, p->exit_signal); do_notify_parent(p, p->exit_signal);
else if (ignoring_children(parent->sighand)) else if (ignoring_children(tracer->sighand))
p->exit_signal = -1; p->exit_signal = -1;
} }
if (task_detached(p)) { if (!task_detached(p))
/* return 0;
* Mark it as in the process of being reaped.
*/ /* Mark it as in the process of being reaped. */
p->exit_state = EXIT_DEAD; p->exit_state = EXIT_DEAD;
return 1;
}
/*
* Detach all tasks we were using ptrace on.
* Any that need to be release_task'd are put on the @dead list.
*
* Called with write_lock(&tasklist_lock) held.
*/
static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
{
struct task_struct *p, *n;
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
if (__ptrace_detach(parent, p))
list_add(&p->ptrace_entry, dead); list_add(&p->ptrace_entry, dead);
} }
}
} }
/* /*
......
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