public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] exit: Clarify choice of new parent in forget_original_parent()
@ 2015-06-16  9:49 Kirill Tkhai
  2015-06-16 19:27 ` Oleg Nesterov
  0 siblings, 1 reply; 5+ messages in thread
From: Kirill Tkhai @ 2015-06-16  9:49 UTC (permalink / raw)
  To: linux-kernel; +Cc: Oleg Nesterov, Andrew Morton

Second parameter of find_new_reaper() and the similarity of its name
and find_child_reaper()'s name confuse a reader.

Rename find_child_reaper() for better conformity of its name and its
function. Also delete the second parameter of find_new_reaper().

These both improve modularity.

Signed-off-by: Kirill Tkhai <ktkhai@odin.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 kernel/exit.c |   24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/kernel/exit.c b/kernel/exit.c
index 22fcc05..ae60a4d 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -450,7 +450,7 @@ static struct task_struct *find_alive_thread(struct task_struct *p)
 	return NULL;
 }
 
-static struct task_struct *find_child_reaper(struct task_struct *father)
+static void exit_pidns_child_reaper(struct task_struct *father)
 	__releases(&tasklist_lock)
 	__acquires(&tasklist_lock)
 {
@@ -458,12 +458,12 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
 	struct task_struct *reaper = pid_ns->child_reaper;
 
 	if (likely(reaper != father))
-		return reaper;
+		return;
 
 	reaper = find_alive_thread(father);
 	if (reaper) {
 		pid_ns->child_reaper = reaper;
-		return reaper;
+		return;
 	}
 
 	write_unlock_irq(&tasklist_lock);
@@ -473,8 +473,6 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
 	}
 	zap_pid_ns_processes(pid_ns);
 	write_lock_irq(&tasklist_lock);
-
-	return father;
 }
 
 /*
@@ -484,15 +482,21 @@ static struct task_struct *find_child_reaper(struct task_struct *father)
  *    child_subreaper for its children (like a service manager)
  * 3. give it to the init process (PID 1) in our pid namespace
  */
-static struct task_struct *find_new_reaper(struct task_struct *father,
-					   struct task_struct *child_reaper)
+static struct task_struct *find_new_reaper(struct task_struct *father)
 {
-	struct task_struct *thread, *reaper;
+	struct task_struct *thread, *reaper, *child_reaper;
 
 	thread = find_alive_thread(father);
 	if (thread)
 		return thread;
 
+	child_reaper = task_active_pid_ns(father)->child_reaper;
+	/*
+	 * child_reaper doesn't have children after zap_pid_ns_processes(),
+	 * therefore it can't enter this function.
+	 */
+	BUG_ON(child_reaper == father);
+
 	if (father->signal->has_child_subreaper) {
 		/*
 		 * Find the first ->is_child_subreaper ancestor in our pid_ns.
@@ -557,11 +561,11 @@ static void forget_original_parent(struct task_struct *father,
 		exit_ptrace(father, dead);
 
 	/* Can drop and reacquire tasklist_lock */
-	reaper = find_child_reaper(father);
+	exit_pidns_child_reaper(father);
 	if (list_empty(&father->children))
 		return;
 
-	reaper = find_new_reaper(father, reaper);
+	reaper = find_new_reaper(father);
 	list_for_each_entry(p, &father->children, sibling) {
 		for_each_thread(p, t) {
 			t->real_parent = reaper;




^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-17 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-16  9:49 [PATCH] exit: Clarify choice of new parent in forget_original_parent() Kirill Tkhai
2015-06-16 19:27 ` Oleg Nesterov
2015-06-16 20:03   ` Oleg Nesterov
2015-06-17 17:24     ` Kirill Tkhai
2015-06-17 17:23   ` Kirill Tkhai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox