aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2009-04-02 19:58:19 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-04-02 22:05:00 -0400
commit5dfc80be73dd0c212d2e6dd8dbf5afa07e680bbe (patch)
treeac173fb3fcfe2970781591f620f22d30f4ce090c /kernel/exit.c
parent39c626ae47c469abdfd30c6e42eff884931380d6 (diff)
forget_original_parent: do not abuse child->ptrace_entry
By discussion with Roland. - Use ->sibling instead of ->ptrace_entry to chain the need to be release_task'd childs. Nobody else can use ->sibling, this task is EXIT_DEAD and nobody can find it on its own list. - rename ptrace_dead to dead_childs. - Now that we don't have the "parallel" untrace code, change back reparent_thread() to return void, pass dead_childs as an argument. Actually, I don't understand why do we notify /sbin/init when we reparent a zombie, probably it is better to reap it unconditionally. [akpm@linux-foundation.org: s/childs/children/] Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: "Metzger, Markus T" <markus.t.metzger@intel.com> Cc: Roland McGrath <roland@redhat.com> 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.c87
1 files changed, 41 insertions, 46 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 506693dfdd4e..029415d9f82e 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -726,46 +726,6 @@ static void exit_mm(struct task_struct * tsk)
726 mmput(mm); 726 mmput(mm);
727} 727}
728 728
729/* Returns nonzero if the child should be released. */
730static int reparent_thread(struct task_struct *p, struct task_struct *father)
731{
732 int dead;
733
734 if (p->pdeath_signal)
735 /* We already hold the tasklist_lock here. */
736 group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
737
738 list_move_tail(&p->sibling, &p->real_parent->children);
739
740 if (task_detached(p))
741 return 0;
742 /* If this is a threaded reparent there is no need to
743 * notify anyone anything has happened.
744 */
745 if (same_thread_group(p->real_parent, father))
746 return 0;
747
748 /* We don't want people slaying init. */
749 p->exit_signal = SIGCHLD;
750
751 /* If we'd notified the old parent about this child's death,
752 * also notify the new parent.
753 */
754 dead = 0;
755 if (!p->ptrace &&
756 p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
757 do_notify_parent(p, p->exit_signal);
758 if (task_detached(p)) {
759 p->exit_state = EXIT_DEAD;
760 dead = 1;
761 }
762 }
763
764 kill_orphaned_pgrp(p, father);
765
766 return dead;
767}
768
769/* 729/*
770 * When we die, we re-parent all our children. 730 * When we die, we re-parent all our children.
771 * Try to give them to another thread in our thread 731 * Try to give them to another thread in our thread
@@ -805,10 +765,46 @@ static struct task_struct *find_new_reaper(struct task_struct *father)
805 return pid_ns->child_reaper; 765 return pid_ns->child_reaper;
806} 766}
807 767
768/*
769* Any that need to be release_task'd are put on the @dead list.
770 */
771static void reparent_thread(struct task_struct *father, struct task_struct *p,
772 struct list_head *dead)
773{
774 if (p->pdeath_signal)
775 group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
776
777 list_move_tail(&p->sibling, &p->real_parent->children);
778
779 if (task_detached(p))
780 return;
781 /*
782 * If this is a threaded reparent there is no need to
783 * notify anyone anything has happened.
784 */
785 if (same_thread_group(p->real_parent, father))
786 return;
787
788 /* We don't want people slaying init. */
789 p->exit_signal = SIGCHLD;
790
791 /* If it has exited notify the new parent about this child's death. */
792 if (!p->ptrace &&
793 p->exit_state == EXIT_ZOMBIE && thread_group_empty(p)) {
794 do_notify_parent(p, p->exit_signal);
795 if (task_detached(p)) {
796 p->exit_state = EXIT_DEAD;
797 list_move_tail(&p->sibling, dead);
798 }
799 }
800
801 kill_orphaned_pgrp(p, father);
802}
803
808static void forget_original_parent(struct task_struct *father) 804static void forget_original_parent(struct task_struct *father)
809{ 805{
810 struct task_struct *p, *n, *reaper; 806 struct task_struct *p, *n, *reaper;
811 LIST_HEAD(ptrace_dead); 807 LIST_HEAD(dead_children);
812 808
813 exit_ptrace(father); 809 exit_ptrace(father);
814 810
@@ -821,15 +817,14 @@ static void forget_original_parent(struct task_struct *father)
821 BUG_ON(p->ptrace); 817 BUG_ON(p->ptrace);
822 p->parent = p->real_parent; 818 p->parent = p->real_parent;
823 } 819 }
824 if (reparent_thread(p, father)) 820 reparent_thread(father, p, &dead_children);
825 list_add(&p->ptrace_entry, &ptrace_dead);;
826 } 821 }
827
828 write_unlock_irq(&tasklist_lock); 822 write_unlock_irq(&tasklist_lock);
823
829 BUG_ON(!list_empty(&father->children)); 824 BUG_ON(!list_empty(&father->children));
830 825
831 list_for_each_entry_safe(p, n, &ptrace_dead, ptrace_entry) { 826 list_for_each_entry_safe(p, n, &dead_children, sibling) {
832 list_del_init(&p->ptrace_entry); 827 list_del_init(&p->sibling);
833 release_task(p); 828 release_task(p);
834 } 829 }
835} 830}