Skip to content

Commit

Permalink
exit: reparent: cleanup the changing of ->parent
Browse files Browse the repository at this point in the history
1. Cosmetic, but "if (t->parent == father)" looks a bit confusing.
   We need to change t->parent if and only if t is not traced.

2. If we actually want this BUG_ON() to ensure that parent/ptrace
   match each other, then we should also take ptrace_reparented()
   case into account too.

3. Change this code to use for_each_thread() instead of deprecated
   while_each_thread().

[dan.carpenter@oracle.com: silence a bogus static checker warning]
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Aaron Tomlin <atomlin@redhat.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Cc: Sterling Alexander <stalexan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Roland McGrath <roland@hack.frob.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Dec 11, 2014
1 parent dc2fd4b commit 57a0591
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ static void reparent_leader(struct task_struct *father, struct task_struct *p,

static void forget_original_parent(struct task_struct *father)
{
struct task_struct *p, *n, *reaper;
struct task_struct *p, *t, *n, *reaper;
LIST_HEAD(dead_children);

write_lock_irq(&tasklist_lock);
Expand All @@ -569,18 +569,15 @@ static void forget_original_parent(struct task_struct *father)
reaper = find_new_reaper(father);

list_for_each_entry_safe(p, n, &father->children, sibling) {
struct task_struct *t = p;

do {
for_each_thread(p, t) {
t->real_parent = reaper;
if (t->parent == father) {
BUG_ON(t->ptrace);
BUG_ON((!t->ptrace) != (t->parent == father));
if (likely(!t->ptrace))
t->parent = t->real_parent;
}
if (t->pdeath_signal)
group_send_sig_info(t->pdeath_signal,
SEND_SIG_NOINFO, t);
} while_each_thread(p, t);
}
reparent_leader(father, p, &dead_children);
}
write_unlock_irq(&tasklist_lock);
Expand Down

0 comments on commit 57a0591

Please sign in to comment.