aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2009-04-02 19:58:13 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-02 22:04:59 -0400
commitb1b4c6799fb59e710454bfe0ab477cb8523a8667 (patch)
tree1cdd19f00c584a8800ce0d3a5530b78d1cbd6e56
parent6d69cb87f05eef3b02370b2f7bae608ad2301a00 (diff)
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: Oleg 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--kernel/exit.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 7a8311422930..576eae233b53 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -744,6 +744,38 @@ static int ignoring_children(struct sighand_struct *sigh)
744 return ret; 744 return ret;
745} 745}
746 746
747/* Returns nonzero if the tracee should be released. */
748int __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
749{
750 __ptrace_unlink(p);
751
752 if (p->exit_state != EXIT_ZOMBIE)
753 return 0;
754 /*
755 * If it's a zombie, our attachedness prevented normal
756 * parent notification or self-reaping. Do notification
757 * now if it would have happened earlier. If it should
758 * reap itself we return true.
759 *
760 * If it's our own child, there is no notification to do.
761 * But if our normal children self-reap, then this child
762 * was prevented by ptrace and we must reap it now.
763 */
764 if (!task_detached(p) && thread_group_empty(p)) {
765 if (!same_thread_group(p->real_parent, tracer))
766 do_notify_parent(p, p->exit_signal);
767 else if (ignoring_children(tracer->sighand))
768 p->exit_signal = -1;
769 }
770
771 if (!task_detached(p))
772 return 0;
773
774 /* Mark it as in the process of being reaped. */
775 p->exit_state = EXIT_DEAD;
776 return 1;
777}
778
747/* 779/*
748 * Detach all tasks we were using ptrace on. 780 * Detach all tasks we were using ptrace on.
749 * Any that need to be release_task'd are put on the @dead list. 781 * Any that need to be release_task'd are put on the @dead list.
@@ -755,36 +787,8 @@ static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
755 struct task_struct *p, *n; 787 struct task_struct *p, *n;
756 788
757 list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) { 789 list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
758 __ptrace_unlink(p); 790 if (__ptrace_detach(parent, p))
759
760 if (p->exit_state != EXIT_ZOMBIE)
761 continue;
762
763 /*
764 * If it's a zombie, our attachedness prevented normal
765 * parent notification or self-reaping. Do notification
766 * now if it would have happened earlier. If it should
767 * reap itself, add it to the @dead list. We can't call
768 * release_task() here because we already hold tasklist_lock.
769 *
770 * If it's our own child, there is no notification to do.
771 * But if our normal children self-reap, then this child
772 * was prevented by ptrace and we must reap it now.
773 */
774 if (!task_detached(p) && thread_group_empty(p)) {
775 if (!same_thread_group(p->real_parent, parent))
776 do_notify_parent(p, p->exit_signal);
777 else if (ignoring_children(parent->sighand))
778 p->exit_signal = -1;
779 }
780
781 if (task_detached(p)) {
782 /*
783 * Mark it as in the process of being reaped.
784 */
785 p->exit_state = EXIT_DEAD;
786 list_add(&p->ptrace_entry, dead); 791 list_add(&p->ptrace_entry, dead);
787 }
788 } 792 }
789} 793}
790 794