aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-12-10 15:55:14 -0800
committerMoyster <oysterized@gmail.com>2019-05-02 18:28:06 +0200
commitd3e67cf8262131e911ae069fb906663b52b9ecdb (patch)
tree5e4866e0f736623ca06be8ba080cbdd896cfdd48
parent4e7991910e3e5064129ae750442cc71cc8085503 (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. Change-Id: I76475039081a5ccc2d93a87b0674eee22447d773 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 ea1bde938..45466641e 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -462,6 +462,17 @@ static void exit_mm(struct task_struct *tsk)
clear_thread_flag(TIF_MEMDIE);
}
+static struct task_struct *find_alive_thread(struct task_struct *p)
+{
+ struct task_struct *t;
+
+ for_each_thread(p, t) {
+ if (!(t->flags & PF_EXITING))
+ return t;
+ }
+ return NULL;
+}
+
static struct task_struct *find_child_reaper(struct task_struct *father)
__releases(&tasklist_lock)
__acquires(&tasklist_lock)
@@ -472,9 +483,8 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
if (likely(reaper != father))
return reaper;
- for_each_thread(father, reaper) {
- if (reaper->flags & PF_EXITING)
- continue;
+ reaper = find_alive_thread(father);
+ if (reaper) {
pid_ns->child_reaper = reaper;
return reaper;
}
@@ -500,16 +510,13 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
static struct task_struct *find_new_reaper(struct task_struct *father,
struct task_struct *child_reaper)
{
- struct task_struct *thread;
+ struct task_struct *thread, *reaper;
- for_each_thread(father, thread) {
- if (thread->flags & PF_EXITING)
- continue;
+ thread = find_alive_thread(father);
+ if (thread)
return thread;
- }
if (father->signal->has_child_subreaper) {
- struct task_struct *reaper;
/*
* Find the first ->is_child_subreaper ancestor in our pid_ns.
* We start from father to ensure we can not look into another
@@ -523,10 +530,9 @@ static struct task_struct *find_new_reaper(struct task_struct *father,
break;
if (!reaper->signal->is_child_subreaper)
continue;
- for_each_thread(reaper, thread) {
- if (!(thread->flags & PF_EXITING))
- return thread;
- }
+ thread = find_alive_thread(reaper);
+ if (thread)
+ return thread;
}
}