public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 4/4] forget_original_parent: cleanup ptrace pathes
@ 2009-01-29  8:06 Oleg Nesterov
  2009-02-05  2:40 ` Roland McGrath
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2009-01-29  8:06 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Eric W. Biederman, Roland McGrath, linux-kernel

No functional changes.

- Fold ptrace_exit() into forget_original_parent(), it is trivial
  now. More importantly, this makes the code more symmetrical with
  reparent_thread().

- The same for ptrace_exit_finish(), and "ptrace_" is not correct
  any longer.

- "ptrace_dead" doesn't match the reality, rename to "dead_list".

- swap the reparent_thread()'s arguments, just to make it more
  symmetrical with __ptrace_detach().

Signed-off-by: Oleg Nesterov <oleg@redhat.com>

--- 6.29-rc3/kernel/exit.c~8_CLEANUP	2009-01-29 08:03:18.000000000 +0100
+++ 6.29-rc3/kernel/exit.c	2009-01-29 08:54:14.000000000 +0100
@@ -770,42 +770,8 @@ int __ptrace_detach(struct task_struct *
 	return 1;
 }
 
-/*
- * Detach all tasks we were using ptrace on.
- * Any that need to be release_task'd are put on the @dead list.
- *
- * Called with write_lock(&tasklist_lock) held.
- */
-static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
-{
-	struct task_struct *p, *n;
-
-	list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
-		if (__ptrace_detach(parent, p))
-			list_add(&p->ptrace_entry, dead);
-	}
-}
-
-/*
- * Finish up exit-time ptrace cleanup.
- *
- * Called without locks.
- */
-static void ptrace_exit_finish(struct task_struct *parent,
-			       struct list_head *dead)
-{
-	struct task_struct *p, *n;
-
-	BUG_ON(!list_empty(&parent->ptraced));
-
-	list_for_each_entry_safe(p, n, dead, ptrace_entry) {
-		list_del_init(&p->ptrace_entry);
-		release_task(p);
-	}
-}
-
 /* Returns nonzero if the child should be released. */
-static int reparent_thread(struct task_struct *p, struct task_struct *father)
+static int reparent_thread(struct task_struct *father, struct task_struct *p)
 {
 	int dead;
 
@@ -886,14 +852,17 @@ static struct task_struct *find_new_reap
 static void forget_original_parent(struct task_struct *father)
 {
 	struct task_struct *p, *n, *reaper;
-	LIST_HEAD(ptrace_dead);
+	LIST_HEAD(dead_list);
 
 	write_lock_irq(&tasklist_lock);
 	reaper = find_new_reaper(father);
 	/*
 	 * First clean up ptrace if we were using it.
 	 */
-	ptrace_exit(father, &ptrace_dead);
+	list_for_each_entry_safe(p, n, &father->ptraced, ptrace_entry) {
+		if (__ptrace_detach(father, p))
+			list_add(&p->ptrace_entry, &dead_list);
+	}
 
 	list_for_each_entry_safe(p, n, &father->children, sibling) {
 		p->real_parent = reaper;
@@ -901,14 +870,18 @@ static void forget_original_parent(struc
 			BUG_ON(p->ptrace);
 			p->parent = p->real_parent;
 		}
-		if (reparent_thread(p, father))
-			list_add(&p->ptrace_entry, &ptrace_dead);;
+		if (reparent_thread(father, p))
+			list_add(&p->ptrace_entry, &dead_list);;
 	}
-
 	write_unlock_irq(&tasklist_lock);
+
 	BUG_ON(!list_empty(&father->children));
+	BUG_ON(!list_empty(&father->ptraced));
 
-	ptrace_exit_finish(father, &ptrace_dead);
+	list_for_each_entry_safe(p, n, &dead_list, ptrace_entry) {
+		list_del_init(&p->ptrace_entry);
+		release_task(p);
+	}
 }
 
 /*


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

end of thread, other threads:[~2009-02-10 23:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-29  8:06 [PATCH 4/4] forget_original_parent: cleanup ptrace pathes Oleg Nesterov
2009-02-05  2:40 ` Roland McGrath
2009-02-05 15:33   ` Oleg Nesterov
2009-02-09  2:36     ` Roland McGrath
2009-02-10 22:47       ` Oleg Nesterov
2009-02-10 23:23         ` Roland McGrath
2009-02-10 23:40           ` Oleg Nesterov
2009-02-10 23:53             ` Roland McGrath

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