* [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
@ 2009-01-29 4:29 Oleg Nesterov
2009-02-05 1:23 ` Roland McGrath
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2009-01-29 4:29 UTC (permalink / raw)
To: Andrew Morton
Cc: Jerome Marchand, Roland McGrath, Denys Vlasenko, linux-kernel
No functional changes, preparation for the next patch.
Move the "should we release this child" logic into the separate handler,
__ptrace_detach().
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
--- 6.29-rc3/kernel/exit.c~3_REINTRODUCE_DETACH 2009-01-29 02:46:42.000000000 +0100
+++ 6.29-rc3/kernel/exit.c 2009-01-29 04:09:40.000000000 +0100
@@ -737,6 +737,39 @@ static int ignoring_children(struct sigh
sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT;
}
+/* Returns nonzero if the tracee should be released. */
+int __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
+{
+ __ptrace_unlink(p);
+
+ if (p->exit_state != EXIT_ZOMBIE)
+ return 0;
+ /*
+ * If it's a zombie, our attachedness prevented normal
+ * parent notification or self-reaping. Do notification
+ * now if it would have happened earlier. If it should
+ * reap itself, add it to the @dead list. We can't call
+ * release_task() here because we already hold tasklist_lock.
+ *
+ * If it's our own child, there is no notification to do.
+ * But if our normal children self-reap, then this child
+ * was prevented by ptrace and we must reap it now.
+ */
+ if (!task_detached(p) && thread_group_empty(p)) {
+ if (!same_thread_group(p->real_parent, tracer))
+ do_notify_parent(p, p->exit_signal);
+ else if (ignoring_children(tracer->sighand))
+ p->exit_signal = -1;
+ }
+
+ if (!task_detached(p))
+ return 0;
+
+ /* Mark it as in the process of being reaped. */
+ p->exit_state = EXIT_DEAD;
+ return 1;
+}
+
/*
* Detach all tasks we were using ptrace on.
* Any that need to be release_task'd are put on the @dead list.
@@ -748,36 +781,8 @@ static void ptrace_exit(struct task_stru
struct task_struct *p, *n;
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
- __ptrace_unlink(p);
-
- if (p->exit_state != EXIT_ZOMBIE)
- continue;
-
- /*
- * If it's a zombie, our attachedness prevented normal
- * parent notification or self-reaping. Do notification
- * now if it would have happened earlier. If it should
- * reap itself, add it to the @dead list. We can't call
- * release_task() here because we already hold tasklist_lock.
- *
- * If it's our own child, there is no notification to do.
- * But if our normal children self-reap, then this child
- * was prevented by ptrace and we must reap it now.
- */
- if (!task_detached(p) && thread_group_empty(p)) {
- if (!same_thread_group(p->real_parent, parent))
- do_notify_parent(p, p->exit_signal);
- else if (ignoring_children(parent->sighand))
- p->exit_signal = -1;
- }
-
- if (task_detached(p)) {
- /*
- * Mark it as in the process of being reaped.
- */
- p->exit_state = EXIT_DEAD;
+ if (__ptrace_detach(parent, p))
list_add(&p->ptrace_entry, dead);
- }
}
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
2009-01-29 4:29 [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit() Oleg Nesterov
@ 2009-02-05 1:23 ` Roland McGrath
2009-02-05 14:39 ` Oleg Nesterov
0 siblings, 1 reply; 6+ messages in thread
From: Roland McGrath @ 2009-02-05 1:23 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel
> No functional changes, preparation for the next patch.
>
> Move the "should we release this child" logic into the separate handler,
> __ptrace_detach().
My inclination is to use bool in new code for true/false return values,
but I don't really care.
Please canonicalize the comment formatting for your new comments.
The preserved comment no longer makes sense, there is no "dead list" in
that function. Make it a coherent comment at the top that explains the
return value.
Given its content, this function now better belongs in ptrace.c, I think.
Thanks,
Roland
=====
/*
* Called with tasklist_lock held for writing.
* Unlink a traced task, and clean it up if it was a traced zombie.
* Return true if it needs to be reaped with release_task().
* (We can't call release_task() here because we already hold tasklist_lock.)
*
* If it's a zombie, our attachedness prevented normal parent notification
* or self-reaping. Do notification now if it would have happened earlier.
* If it should reap itself, return true.
*
* If it's our own child, there is no notification to do.
* But if our normal children self-reap, then this child
* was prevented by ptrace and we must reap it now.
*/
bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p)
{
__ptrace_unlink(p);
if (p->exit_state == EXIT_ZOMBIE) {
if (!task_detached(p) && thread_group_empty(p)) {
if (!same_thread_group(p->real_parent, tracer))
do_notify_parent(p, p->exit_signal);
else if (ignoring_children(tracer->sighand))
p->exit_signal = -1;
}
if (task_detached(p)) {
/*
* Mark it as in the process of being reaped.
*/
p->exit_state = EXIT_DEAD;
return true;
}
}
return false;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
2009-02-05 1:23 ` Roland McGrath
@ 2009-02-05 14:39 ` Oleg Nesterov
2009-02-05 20:37 ` Roland McGrath
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2009-02-05 14:39 UTC (permalink / raw)
To: Roland McGrath
Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel
On 02/04, Roland McGrath wrote:
>
> > No functional changes, preparation for the next patch.
> >
> > Move the "should we release this child" logic into the separate handler,
> > __ptrace_detach().
>
> My inclination is to use bool in new code for true/false return values,
> but I don't really care.
>
> Please canonicalize the comment formatting for your new comments.
>
> The preserved comment no longer makes sense, there is no "dead list" in
> that function. Make it a coherent comment at the top that explains the
> return value.
OK, I'll send the cleanup patch.
> Given its content, this function now better belongs in ptrace.c, I think.
I don't completely agree... This helper imho has nothing to do with
ptracing, except it does __ptrace_unlink(). But OK, I will move it
if you prefer. In that case we should export task_detached().
Oleg.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
2009-02-05 14:39 ` Oleg Nesterov
@ 2009-02-05 20:37 ` Roland McGrath
2009-02-05 22:06 ` Oleg Nesterov
0 siblings, 1 reply; 6+ messages in thread
From: Roland McGrath @ 2009-02-05 20:37 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel
> > Given its content, this function now better belongs in ptrace.c, I think.
>
> I don't completely agree... This helper imho has nothing to do with
> ptracing, except it does __ptrace_unlink(). But OK, I will move it
> if you prefer.
Obviously where it goes is not a big deal. But I think it's clear that it
has everything to do with ptrace and nothing to do with anything else.
It resolves a situation that can only arise because of ptrace magic.
> In that case we should export task_detached().
Or just recognize that this trivial wrapper around == -1 has little
value two lines away from a place where = -1 is done explicitly.
Really, the "abstraction" is more confusing than not in this function, IMHO.
Thanks,
Roland
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
2009-02-05 20:37 ` Roland McGrath
@ 2009-02-05 22:06 ` Oleg Nesterov
2009-02-09 2:14 ` Roland McGrath
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2009-02-05 22:06 UTC (permalink / raw)
To: Roland McGrath
Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel
On 02/05, Roland McGrath wrote:
>
> > > Given its content, this function now better belongs in ptrace.c, I think.
> >
> > I don't completely agree... This helper imho has nothing to do with
> > ptracing, except it does __ptrace_unlink(). But OK, I will move it
> > if you prefer.
>
> Obviously where it goes is not a big deal. But I think it's clear that it
> has everything to do with ptrace and nothing to do with anything else.
> It resolves a situation that can only arise because of ptrace magic.
OK, OK, I will move it.
> > In that case we should export task_detached().
>
> Or just recognize that this trivial wrapper around == -1 has little
> value two lines away from a place where = -1 is done explicitly.
> Really, the "abstraction" is more confusing than not in this function, IMHO.
Well, yes. The only problem it is not easy to grep for this check
without a helper.
(And I still hope we can change the rules sometimes, I think there
is no good reason to have task_detached() or EXIT_DEAD tasks on
->children list. But this is offtopic.)
Oleg.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit()
2009-02-05 22:06 ` Oleg Nesterov
@ 2009-02-09 2:14 ` Roland McGrath
0 siblings, 0 replies; 6+ messages in thread
From: Roland McGrath @ 2009-02-09 2:14 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Jerome Marchand, Denys Vlasenko, linux-kernel
> (And I still hope we can change the rules sometimes, I think there
> is no good reason to have task_detached() or EXIT_DEAD tasks on
> ->children list. But this is offtopic.)
Agreed on both counts. :-)
Thanks,
Roland
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-02-09 2:14 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-29 4:29 [PATCH 3/4] ptrace: reintroduce __ptrace_detach() as a callee of ptrace_exit() Oleg Nesterov
2009-02-05 1:23 ` Roland McGrath
2009-02-05 14:39 ` Oleg Nesterov
2009-02-05 20:37 ` Roland McGrath
2009-02-05 22:06 ` Oleg Nesterov
2009-02-09 2:14 ` Roland McGrath
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox