aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-12-10 18:55:14 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-10 20:41:17 -0500
commitc9dc05bfdb3f7fd7c00f3cbd33816c99d2cb9029 (patch)
tree2b1f69634ca760afbb4585d5a6a37bc549cd5c7c
parent1109909c7df08f55ff9104276bb9db1ee2e6e53d (diff)
exit: reparent: introduce find_alive_thread()
Add the new simple helper to factor out the for_each_thread() code in find_child_reaper() and find_new_reaper(). It can also simplify the potential PF_EXITING -> exit_state change, plus perhaps we can change this code to take SIGNAL_GROUP_EXIT into account. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Aaron Tomlin <atomlin@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Cc: Lennart Poettering <lennart@poettering.net> Cc: Sterling Alexander <stalexan@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.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/kernel/exit.c b/kernel/exit.c
index 930fbe1b5ee2..b0f482f5daf9 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -459,6 +459,17 @@ static void exit_mm(struct task_struct *tsk)
459 clear_thread_flag(TIF_MEMDIE); 459 clear_thread_flag(TIF_MEMDIE);
460} 460}
461 461
462static struct task_struct *find_alive_thread(struct task_struct *p)
463{
464 struct task_struct *t;
465
466 for_each_thread(p, t) {
467 if (!(t->flags & PF_EXITING))
468 return t;
469 }
470 return NULL;
471}
472
462static struct task_struct *find_child_reaper(struct task_struct *father) 473static struct task_struct *find_child_reaper(struct task_struct *father)
463 __releases(&tasklist_lock) 474 __releases(&tasklist_lock)
464 __acquires(&tasklist_lock) 475 __acquires(&tasklist_lock)
@@ -469,9 +480,8 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
469 if (likely(reaper != father)) 480 if (likely(reaper != father))
470 return reaper; 481 return reaper;
471 482
472 for_each_thread(father, reaper) { 483 reaper = find_alive_thread(father);
473 if (reaper->flags & PF_EXITING) 484 if (reaper) {
474 continue;
475 pid_ns->child_reaper = reaper; 485 pid_ns->child_reaper = reaper;
476 return reaper; 486 return reaper;
477 } 487 }
@@ -497,16 +507,13 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
497static struct task_struct *find_new_reaper(struct task_struct *father, 507static struct task_struct *find_new_reaper(struct task_struct *father,
498 struct task_struct *child_reaper) 508 struct task_struct *child_reaper)
499{ 509{
500 struct task_struct *thread; 510 struct task_struct *thread, *reaper;
501 511
502 for_each_thread(father, thread) { 512 thread = find_alive_thread(father);
503 if (thread->flags & PF_EXITING) 513 if (thread)
504 continue;
505 return thread; 514 return thread;
506 }
507 515
508 if (father->signal->has_child_subreaper) { 516 if (father->signal->has_child_subreaper) {
509 struct task_struct *reaper;
510 /* 517 /*
511 * Find the first ->is_child_subreaper ancestor in our pid_ns. 518 * Find the first ->is_child_subreaper ancestor in our pid_ns.
512 * We start from father to ensure we can not look into another 519 * We start from father to ensure we can not look into another
@@ -520,10 +527,9 @@ static struct task_struct *find_new_reaper(struct task_struct *father,
520 break; 527 break;
521 if (!reaper->signal->is_child_subreaper) 528 if (!reaper->signal->is_child_subreaper)
522 continue; 529 continue;
523 for_each_thread(reaper, thread) { 530 thread = find_alive_thread(reaper);
524 if (!(thread->flags & PF_EXITING)) 531 if (thread)
525 return thread; 532 return thread;
526 }
527 } 533 }
528 } 534 }
529 535