diff options
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/exit.c | 78 | ||||
-rw-r--r-- | kernel/pid_namespace.c | 6 |
2 files changed, 34 insertions, 50 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 75c647387639..25ed2ad986df 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -831,26 +831,50 @@ static void reparent_thread(struct task_struct *p, struct task_struct *father) | |||
831 | * the child reaper process (ie "init") in our pid | 831 | * the child reaper process (ie "init") in our pid |
832 | * space. | 832 | * space. |
833 | */ | 833 | */ |
834 | static struct task_struct *find_new_reaper(struct task_struct *father) | ||
835 | { | ||
836 | struct pid_namespace *pid_ns = task_active_pid_ns(father); | ||
837 | struct task_struct *thread; | ||
838 | |||
839 | thread = father; | ||
840 | while_each_thread(father, thread) { | ||
841 | if (thread->flags & PF_EXITING) | ||
842 | continue; | ||
843 | if (unlikely(pid_ns->child_reaper == father)) | ||
844 | pid_ns->child_reaper = thread; | ||
845 | return thread; | ||
846 | } | ||
847 | |||
848 | if (unlikely(pid_ns->child_reaper == father)) { | ||
849 | write_unlock_irq(&tasklist_lock); | ||
850 | if (unlikely(pid_ns == &init_pid_ns)) | ||
851 | panic("Attempted to kill init!"); | ||
852 | |||
853 | zap_pid_ns_processes(pid_ns); | ||
854 | write_lock_irq(&tasklist_lock); | ||
855 | /* | ||
856 | * We can not clear ->child_reaper or leave it alone. | ||
857 | * There may by stealth EXIT_DEAD tasks on ->children, | ||
858 | * forget_original_parent() must move them somewhere. | ||
859 | */ | ||
860 | pid_ns->child_reaper = init_pid_ns.child_reaper; | ||
861 | } | ||
862 | |||
863 | return pid_ns->child_reaper; | ||
864 | } | ||
865 | |||
834 | static void forget_original_parent(struct task_struct *father) | 866 | static void forget_original_parent(struct task_struct *father) |
835 | { | 867 | { |
836 | struct task_struct *p, *n, *reaper = father; | 868 | struct task_struct *p, *n, *reaper; |
837 | LIST_HEAD(ptrace_dead); | 869 | LIST_HEAD(ptrace_dead); |
838 | 870 | ||
839 | write_lock_irq(&tasklist_lock); | 871 | write_lock_irq(&tasklist_lock); |
840 | 872 | reaper = find_new_reaper(father); | |
841 | /* | 873 | /* |
842 | * First clean up ptrace if we were using it. | 874 | * First clean up ptrace if we were using it. |
843 | */ | 875 | */ |
844 | ptrace_exit(father, &ptrace_dead); | 876 | ptrace_exit(father, &ptrace_dead); |
845 | 877 | ||
846 | do { | ||
847 | reaper = next_thread(reaper); | ||
848 | if (reaper == father) { | ||
849 | reaper = task_child_reaper(father); | ||
850 | break; | ||
851 | } | ||
852 | } while (reaper->flags & PF_EXITING); | ||
853 | |||
854 | list_for_each_entry_safe(p, n, &father->children, sibling) { | 878 | list_for_each_entry_safe(p, n, &father->children, sibling) { |
855 | p->real_parent = reaper; | 879 | p->real_parent = reaper; |
856 | if (p->parent == father) { | 880 | if (p->parent == father) { |
@@ -959,39 +983,6 @@ static void check_stack_usage(void) | |||
959 | static inline void check_stack_usage(void) {} | 983 | static inline void check_stack_usage(void) {} |
960 | #endif | 984 | #endif |
961 | 985 | ||
962 | static inline void exit_child_reaper(struct task_struct *tsk) | ||
963 | { | ||
964 | if (likely(tsk->group_leader != task_child_reaper(tsk))) | ||
965 | return; | ||
966 | |||
967 | if (tsk->nsproxy->pid_ns == &init_pid_ns) | ||
968 | panic("Attempted to kill init!"); | ||
969 | |||
970 | /* | ||
971 | * @tsk is the last thread in the 'cgroup-init' and is exiting. | ||
972 | * Terminate all remaining processes in the namespace and reap them | ||
973 | * before exiting @tsk. | ||
974 | * | ||
975 | * Note that @tsk (last thread of cgroup-init) may not necessarily | ||
976 | * be the child-reaper (i.e main thread of cgroup-init) of the | ||
977 | * namespace i.e the child_reaper may have already exited. | ||
978 | * | ||
979 | * Even after a child_reaper exits, we let it inherit orphaned children, | ||
980 | * because, pid_ns->child_reaper remains valid as long as there is | ||
981 | * at least one living sub-thread in the cgroup init. | ||
982 | |||
983 | * This living sub-thread of the cgroup-init will be notified when | ||
984 | * a child inherited by the 'child-reaper' exits (do_notify_parent() | ||
985 | * uses __group_send_sig_info()). Further, when reaping child processes, | ||
986 | * do_wait() iterates over children of all living sub threads. | ||
987 | |||
988 | * i.e even though 'child_reaper' thread is listed as the parent of the | ||
989 | * orphaned children, any living sub-thread in the cgroup-init can | ||
990 | * perform the role of the child_reaper. | ||
991 | */ | ||
992 | zap_pid_ns_processes(tsk->nsproxy->pid_ns); | ||
993 | } | ||
994 | |||
995 | NORET_TYPE void do_exit(long code) | 986 | NORET_TYPE void do_exit(long code) |
996 | { | 987 | { |
997 | struct task_struct *tsk = current; | 988 | struct task_struct *tsk = current; |
@@ -1051,7 +1042,6 @@ NORET_TYPE void do_exit(long code) | |||
1051 | } | 1042 | } |
1052 | group_dead = atomic_dec_and_test(&tsk->signal->live); | 1043 | group_dead = atomic_dec_and_test(&tsk->signal->live); |
1053 | if (group_dead) { | 1044 | if (group_dead) { |
1054 | exit_child_reaper(tsk); | ||
1055 | hrtimer_cancel(&tsk->signal->real_timer); | 1045 | hrtimer_cancel(&tsk->signal->real_timer); |
1056 | exit_itimers(tsk->signal); | 1046 | exit_itimers(tsk->signal); |
1057 | } | 1047 | } |
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 598f1eec9826..fab8ea86fac3 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c | |||
@@ -179,12 +179,6 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns) | |||
179 | rc = sys_wait4(-1, NULL, __WALL, NULL); | 179 | rc = sys_wait4(-1, NULL, __WALL, NULL); |
180 | } while (rc != -ECHILD); | 180 | } while (rc != -ECHILD); |
181 | 181 | ||
182 | /* | ||
183 | * We can not clear ->child_reaper or leave it alone. | ||
184 | * There may by stealth EXIT_DEAD tasks on ->children, | ||
185 | * forget_original_parent() must move them somewhere. | ||
186 | */ | ||
187 | pid_ns->child_reaper = init_pid_ns.child_reaper; | ||
188 | acct_exit_ns(pid_ns); | 182 | acct_exit_ns(pid_ns); |
189 | return; | 183 | return; |
190 | } | 184 | } |