ptrace: simplify ptrace_exit()->ignoring_children() path
ignoring_children() takes parent->sighand->siglock and checks k_sigaction[SIGCHLD] atomically. But this buys nothing, we can't get the "really" wrong result even if we race with sigaction(SIGCHLD). If we read the "stale" sa_handler/sa_flags we can pretend it was changed right after the check. Remove spin_lock(->siglock), and kill "int ign" which caches the result of ignoring_children() which becomes rather trivial. Perhaps it makes sense to export this helper, do_notify_parent() can use it too. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Jerome Marchand <jmarchan@redhat.com> Cc: Roland McGrath <roland@redhat.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
95c3eb76dc
Коммит
6d69cb87f0
|
@ -732,19 +732,15 @@ static void exit_mm(struct task_struct * tsk)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return nonzero if @parent's children should reap themselves.
|
* Called with irqs disabled, returns true if childs should reap themselves.
|
||||||
*
|
|
||||||
* Called with write_lock_irq(&tasklist_lock) held.
|
|
||||||
*/
|
*/
|
||||||
static int ignoring_children(struct task_struct *parent)
|
static int ignoring_children(struct sighand_struct *sigh)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct sighand_struct *psig = parent->sighand;
|
spin_lock(&sigh->siglock);
|
||||||
unsigned long flags;
|
ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) ||
|
||||||
spin_lock_irqsave(&psig->siglock, flags);
|
(sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT);
|
||||||
ret = (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN ||
|
spin_unlock(&sigh->siglock);
|
||||||
(psig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT));
|
|
||||||
spin_unlock_irqrestore(&psig->siglock, flags);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -757,7 +753,6 @@ static int ignoring_children(struct task_struct *parent)
|
||||||
static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
|
static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
|
||||||
{
|
{
|
||||||
struct task_struct *p, *n;
|
struct task_struct *p, *n;
|
||||||
int ign = -1;
|
|
||||||
|
|
||||||
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
|
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
|
||||||
__ptrace_unlink(p);
|
__ptrace_unlink(p);
|
||||||
|
@ -779,12 +774,8 @@ static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
|
||||||
if (!task_detached(p) && thread_group_empty(p)) {
|
if (!task_detached(p) && thread_group_empty(p)) {
|
||||||
if (!same_thread_group(p->real_parent, parent))
|
if (!same_thread_group(p->real_parent, parent))
|
||||||
do_notify_parent(p, p->exit_signal);
|
do_notify_parent(p, p->exit_signal);
|
||||||
else {
|
else if (ignoring_children(parent->sighand))
|
||||||
if (ign < 0)
|
p->exit_signal = -1;
|
||||||
ign = ignoring_children(parent);
|
|
||||||
if (ign)
|
|
||||||
p->exit_signal = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task_detached(p)) {
|
if (task_detached(p)) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче