diff options
Diffstat (limited to 'kernel/exit.c')
-rw-r--r-- | kernel/exit.c | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 506a957b665a..53872bf993fa 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -214,20 +214,19 @@ struct pid *session_of_pgrp(struct pid *pgrp) | |||
214 | static int will_become_orphaned_pgrp(struct pid *pgrp, struct task_struct *ignored_task) | 214 | static int will_become_orphaned_pgrp(struct pid *pgrp, struct task_struct *ignored_task) |
215 | { | 215 | { |
216 | struct task_struct *p; | 216 | struct task_struct *p; |
217 | int ret = 1; | ||
218 | 217 | ||
219 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { | 218 | do_each_pid_task(pgrp, PIDTYPE_PGID, p) { |
220 | if (p == ignored_task | 219 | if ((p == ignored_task) || |
221 | || p->exit_state | 220 | (p->exit_state && thread_group_empty(p)) || |
222 | || is_global_init(p->real_parent)) | 221 | is_global_init(p->real_parent)) |
223 | continue; | 222 | continue; |
223 | |||
224 | if (task_pgrp(p->real_parent) != pgrp && | 224 | if (task_pgrp(p->real_parent) != pgrp && |
225 | task_session(p->real_parent) == task_session(p)) { | 225 | task_session(p->real_parent) == task_session(p)) |
226 | ret = 0; | 226 | return 0; |
227 | break; | ||
228 | } | ||
229 | } while_each_pid_task(pgrp, PIDTYPE_PGID, p); | 227 | } while_each_pid_task(pgrp, PIDTYPE_PGID, p); |
230 | return ret; /* (sighing) "Often!" */ | 228 | |
229 | return 1; | ||
231 | } | 230 | } |
232 | 231 | ||
233 | int is_current_pgrp_orphaned(void) | 232 | int is_current_pgrp_orphaned(void) |
@@ -255,6 +254,37 @@ static int has_stopped_jobs(struct pid *pgrp) | |||
255 | return retval; | 254 | return retval; |
256 | } | 255 | } |
257 | 256 | ||
257 | /* | ||
258 | * Check to see if any process groups have become orphaned as | ||
259 | * a result of our exiting, and if they have any stopped jobs, | ||
260 | * send them a SIGHUP and then a SIGCONT. (POSIX 3.2.2.2) | ||
261 | */ | ||
262 | static void | ||
263 | kill_orphaned_pgrp(struct task_struct *tsk, struct task_struct *parent) | ||
264 | { | ||
265 | struct pid *pgrp = task_pgrp(tsk); | ||
266 | struct task_struct *ignored_task = tsk; | ||
267 | |||
268 | if (!parent) | ||
269 | /* exit: our father is in a different pgrp than | ||
270 | * we are and we were the only connection outside. | ||
271 | */ | ||
272 | parent = tsk->real_parent; | ||
273 | else | ||
274 | /* reparent: our child is in a different pgrp than | ||
275 | * we are, and it was the only connection outside. | ||
276 | */ | ||
277 | ignored_task = NULL; | ||
278 | |||
279 | if (task_pgrp(parent) != pgrp && | ||
280 | task_session(parent) == task_session(tsk) && | ||
281 | will_become_orphaned_pgrp(pgrp, ignored_task) && | ||
282 | has_stopped_jobs(pgrp)) { | ||
283 | __kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp); | ||
284 | __kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp); | ||
285 | } | ||
286 | } | ||
287 | |||
258 | /** | 288 | /** |
259 | * reparent_to_kthreadd - Reparent the calling kernel thread to kthreadd | 289 | * reparent_to_kthreadd - Reparent the calling kernel thread to kthreadd |
260 | * | 290 | * |
@@ -635,22 +665,7 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced) | |||
635 | p->exit_signal != -1 && thread_group_empty(p)) | 665 | p->exit_signal != -1 && thread_group_empty(p)) |
636 | do_notify_parent(p, p->exit_signal); | 666 | do_notify_parent(p, p->exit_signal); |
637 | 667 | ||
638 | /* | 668 | kill_orphaned_pgrp(p, father); |
639 | * process group orphan check | ||
640 | * Case ii: Our child is in a different pgrp | ||
641 | * than we are, and it was the only connection | ||
642 | * outside, so the child pgrp is now orphaned. | ||
643 | */ | ||
644 | if ((task_pgrp(p) != task_pgrp(father)) && | ||
645 | (task_session(p) == task_session(father))) { | ||
646 | struct pid *pgrp = task_pgrp(p); | ||
647 | |||
648 | if (will_become_orphaned_pgrp(pgrp, NULL) && | ||
649 | has_stopped_jobs(pgrp)) { | ||
650 | __kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp); | ||
651 | __kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp); | ||
652 | } | ||
653 | } | ||
654 | } | 669 | } |
655 | 670 | ||
656 | /* | 671 | /* |
@@ -735,11 +750,9 @@ static void forget_original_parent(struct task_struct *father) | |||
735 | * Send signals to all our closest relatives so that they know | 750 | * Send signals to all our closest relatives so that they know |
736 | * to properly mourn us.. | 751 | * to properly mourn us.. |
737 | */ | 752 | */ |
738 | static void exit_notify(struct task_struct *tsk) | 753 | static void exit_notify(struct task_struct *tsk, int group_dead) |
739 | { | 754 | { |
740 | int state; | 755 | int state; |
741 | struct task_struct *t; | ||
742 | struct pid *pgrp; | ||
743 | 756 | ||
744 | /* | 757 | /* |
745 | * This does two things: | 758 | * This does two things: |
@@ -753,25 +766,8 @@ static void exit_notify(struct task_struct *tsk) | |||
753 | exit_task_namespaces(tsk); | 766 | exit_task_namespaces(tsk); |
754 | 767 | ||
755 | write_lock_irq(&tasklist_lock); | 768 | write_lock_irq(&tasklist_lock); |
756 | /* | 769 | if (group_dead) |
757 | * Check to see if any process groups have become orphaned | 770 | kill_orphaned_pgrp(tsk->group_leader, NULL); |
758 | * as a result of our exiting, and if they have any stopped | ||
759 | * jobs, send them a SIGHUP and then a SIGCONT. (POSIX 3.2.2.2) | ||
760 | * | ||
761 | * Case i: Our father is in a different pgrp than we are | ||
762 | * and we were the only connection outside, so our pgrp | ||
763 | * is about to become orphaned. | ||
764 | */ | ||
765 | t = tsk->real_parent; | ||
766 | |||
767 | pgrp = task_pgrp(tsk); | ||
768 | if ((task_pgrp(t) != pgrp) && | ||
769 | (task_session(t) == task_session(tsk)) && | ||
770 | will_become_orphaned_pgrp(pgrp, tsk) && | ||
771 | has_stopped_jobs(pgrp)) { | ||
772 | __kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp); | ||
773 | __kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp); | ||
774 | } | ||
775 | 771 | ||
776 | /* Let father know we died | 772 | /* Let father know we died |
777 | * | 773 | * |
@@ -788,8 +784,8 @@ static void exit_notify(struct task_struct *tsk) | |||
788 | * the same after a fork. | 784 | * the same after a fork. |
789 | */ | 785 | */ |
790 | if (tsk->exit_signal != SIGCHLD && tsk->exit_signal != -1 && | 786 | if (tsk->exit_signal != SIGCHLD && tsk->exit_signal != -1 && |
791 | ( tsk->parent_exec_id != t->self_exec_id || | 787 | (tsk->parent_exec_id != tsk->real_parent->self_exec_id || |
792 | tsk->self_exec_id != tsk->parent_exec_id) | 788 | tsk->self_exec_id != tsk->parent_exec_id) |
793 | && !capable(CAP_KILL)) | 789 | && !capable(CAP_KILL)) |
794 | tsk->exit_signal = SIGCHLD; | 790 | tsk->exit_signal = SIGCHLD; |
795 | 791 | ||
@@ -986,7 +982,7 @@ NORET_TYPE void do_exit(long code) | |||
986 | module_put(tsk->binfmt->module); | 982 | module_put(tsk->binfmt->module); |
987 | 983 | ||
988 | proc_exit_connector(tsk); | 984 | proc_exit_connector(tsk); |
989 | exit_notify(tsk); | 985 | exit_notify(tsk, group_dead); |
990 | #ifdef CONFIG_NUMA | 986 | #ifdef CONFIG_NUMA |
991 | mpol_free(tsk->mempolicy); | 987 | mpol_free(tsk->mempolicy); |
992 | tsk->mempolicy = NULL; | 988 | tsk->mempolicy = NULL; |
@@ -1382,7 +1378,7 @@ unlock_sig: | |||
1382 | if (!retval && infop) | 1378 | if (!retval && infop) |
1383 | retval = put_user(0, &infop->si_errno); | 1379 | retval = put_user(0, &infop->si_errno); |
1384 | if (!retval && infop) | 1380 | if (!retval && infop) |
1385 | retval = put_user(why, &infop->si_code); | 1381 | retval = put_user((short)why, &infop->si_code); |
1386 | if (!retval && infop) | 1382 | if (!retval && infop) |
1387 | retval = put_user(exit_code, &infop->si_status); | 1383 | retval = put_user(exit_code, &infop->si_status); |
1388 | if (!retval && infop) | 1384 | if (!retval && infop) |