Messages in this thread Patch in this message | | | Date | Thu, 29 Jan 2009 09:06:03 +0100 | From | Oleg Nesterov <> | Subject | [PATCH 4/4] forget_original_parent: cleanup ptrace pathes |
| |
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); + } } /*
| |