aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/exit.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@tv-sign.ru>2007-10-17 02:26:49 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:51 -0400
commit84eb646b6eabcd82ec563f30d2d9d40c2054a9c9 (patch)
tree96219c5844c80c40cbc9814a13a9a72de7430fc7 /kernel/exit.c
parent8e9073ed027771bcdee4033eb900a3c09ac90a19 (diff)
handle the multi-threaded init's exit() properly
With or without this patch, multi-threaded init's are not fully supported, but do_exit() is completely wrong. This becomes a real problem when we support pid namespaces. 1. do_exit() panics when the main thread of /sbin/init exits. It should not until the whole thread group exits. Move the code below, under the "if (group_dead)" check. Note: this means that forget_original_parent() can use an already dead child_reaper()'s task_struct. This is OK for /sbin/init because - do_wait() from alive sub-thread still can reap a zombie, we iterate over all sub-thread's ->children lists - do_notify_parent() will wakeup some alive sub-thread because it sends the group-wide signal However, we should remove choose_new_parent()->BUG_ON(reaper->exit_state) for this. 2. We are playing games with ->nsproxy->pid_ns. This code is bogus today, and it has to be changed anyway when we really support pid namespaces, just remove it. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Roland McGrath <roland@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com> Cc: Serge Hallyn <serue@us.ibm.com> Cc: Cedric Le Goater <clg@fr.ibm.com> Cc: 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.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 3b8dfffd9329..8b64c0371ae9 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -592,17 +592,6 @@ static void exit_mm(struct task_struct * tsk)
592 mmput(mm); 592 mmput(mm);
593} 593}
594 594
595static inline void
596choose_new_parent(struct task_struct *p, struct task_struct *reaper)
597{
598 /*
599 * Make sure we're not reparenting to ourselves and that
600 * the parent is not a zombie.
601 */
602 BUG_ON(p == reaper || reaper->exit_state);
603 p->real_parent = reaper;
604}
605
606static void 595static void
607reparent_thread(struct task_struct *p, struct task_struct *father, int traced) 596reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
608{ 597{
@@ -710,7 +699,7 @@ forget_original_parent(struct task_struct *father, struct list_head *to_release)
710 699
711 if (father == p->real_parent) { 700 if (father == p->real_parent) {
712 /* reparent with a reaper, real father it's us */ 701 /* reparent with a reaper, real father it's us */
713 choose_new_parent(p, reaper); 702 p->real_parent = reaper;
714 reparent_thread(p, father, 0); 703 reparent_thread(p, father, 0);
715 } else { 704 } else {
716 /* reparent ptraced task to its real parent */ 705 /* reparent ptraced task to its real parent */
@@ -731,7 +720,7 @@ forget_original_parent(struct task_struct *father, struct list_head *to_release)
731 } 720 }
732 list_for_each_safe(_p, _n, &father->ptrace_children) { 721 list_for_each_safe(_p, _n, &father->ptrace_children) {
733 p = list_entry(_p, struct task_struct, ptrace_list); 722 p = list_entry(_p, struct task_struct, ptrace_list);
734 choose_new_parent(p, reaper); 723 p->real_parent = reaper;
735 reparent_thread(p, father, 1); 724 reparent_thread(p, father, 1);
736 } 725 }
737} 726}
@@ -882,6 +871,14 @@ static void check_stack_usage(void)
882static inline void check_stack_usage(void) {} 871static inline void check_stack_usage(void) {}
883#endif 872#endif
884 873
874static inline void exit_child_reaper(struct task_struct *tsk)
875{
876 if (likely(tsk->group_leader != child_reaper(tsk)))
877 return;
878
879 panic("Attempted to kill init!");
880}
881
885fastcall NORET_TYPE void do_exit(long code) 882fastcall NORET_TYPE void do_exit(long code)
886{ 883{
887 struct task_struct *tsk = current; 884 struct task_struct *tsk = current;
@@ -895,13 +892,6 @@ fastcall NORET_TYPE void do_exit(long code)
895 panic("Aiee, killing interrupt handler!"); 892 panic("Aiee, killing interrupt handler!");
896 if (unlikely(!tsk->pid)) 893 if (unlikely(!tsk->pid))
897 panic("Attempted to kill the idle task!"); 894 panic("Attempted to kill the idle task!");
898 if (unlikely(tsk == child_reaper(tsk))) {
899 if (tsk->nsproxy->pid_ns != &init_pid_ns)
900 tsk->nsproxy->pid_ns->child_reaper = init_pid_ns.child_reaper;
901 else
902 panic("Attempted to kill init!");
903 }
904
905 895
906 if (unlikely(current->ptrace & PT_TRACE_EXIT)) { 896 if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
907 current->ptrace_message = code; 897 current->ptrace_message = code;
@@ -951,6 +941,7 @@ fastcall NORET_TYPE void do_exit(long code)
951 } 941 }
952 group_dead = atomic_dec_and_test(&tsk->signal->live); 942 group_dead = atomic_dec_and_test(&tsk->signal->live);
953 if (group_dead) { 943 if (group_dead) {
944 exit_child_reaper(tsk);
954 hrtimer_cancel(&tsk->signal->real_timer); 945 hrtimer_cancel(&tsk->signal->real_timer);
955 exit_itimers(tsk->signal); 946 exit_itimers(tsk->signal);
956 } 947 }