[PATCH] Fix reparenting to the same thread group. (take 2)

This patch fixes the case when we reparent to a different thread in the
same thread group. This modifies the code so that we do not send
signals and do not change the signal to send to SIGCHLD unless we have
change the thread group of our parents. It also suppresses sending
pdeath_sig in this cas as well since the result of geppid doesn't
change.

Thanks to Oleg for spotting my bug of only fixing this for non-ptraced
tasks.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Albert Cahalan <acahalan@gmail.com>
Cc: Andrew Morton <akpm@osdl.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Coywolf Qi Hunt <qiyong@fc-cn.com>
Acked-by: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Eric W. Biederman and committed by
Linus Torvalds
b2b2cbc4 ef129412

+22 -15
+22 -15
kernel/exit.c
··· 597 597 static void 598 598 reparent_thread(struct task_struct *p, struct task_struct *father, int traced) 599 599 { 600 - /* We don't want people slaying init. */ 601 - if (p->exit_signal != -1) 602 - p->exit_signal = SIGCHLD; 603 - 604 - if (p->pdeath_signal) 605 - /* We already hold the tasklist_lock here. */ 606 - group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p); 607 - 608 600 /* Move the child from its dying parent to the new one. */ 609 601 if (unlikely(traced)) { 610 602 /* Preserve ptrace links if someone else is tracing this child. */ ··· 612 620 p->parent = p->real_parent; 613 621 add_parent(p); 614 622 615 - /* If we'd notified the old parent about this child's death, 616 - * also notify the new parent. 617 - */ 618 - if (p->exit_state == EXIT_ZOMBIE && p->exit_signal != -1 && 619 - thread_group_empty(p)) 620 - do_notify_parent(p, p->exit_signal); 621 - else if (p->state == TASK_TRACED) { 623 + if (p->state == TASK_TRACED) { 622 624 /* 623 625 * If it was at a trace stop, turn it into 624 626 * a normal stop since it's no longer being ··· 621 635 ptrace_untrace(p); 622 636 } 623 637 } 638 + 639 + /* If this is a threaded reparent there is no need to 640 + * notify anyone anything has happened. 641 + */ 642 + if (p->real_parent->group_leader == father->group_leader) 643 + return; 644 + 645 + /* We don't want people slaying init. */ 646 + if (p->exit_signal != -1) 647 + p->exit_signal = SIGCHLD; 648 + 649 + if (p->pdeath_signal) 650 + /* We already hold the tasklist_lock here. */ 651 + group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p); 652 + 653 + /* If we'd notified the old parent about this child's death, 654 + * also notify the new parent. 655 + */ 656 + if (!traced && p->exit_state == EXIT_ZOMBIE && 657 + p->exit_signal != -1 && thread_group_empty(p)) 658 + do_notify_parent(p, p->exit_signal); 624 659 625 660 /* 626 661 * process group orphan check