Re: Is prctl(PR_SET_CHILD_SUBREAPER) going to break my code whichchecks getppid == 1?

From: Oleg Nesterov
Date: Fri Mar 30 2012 - 13:22:10 EST


On 03/30, Karl Pickett wrote:
>
> On Mar 30, 2012, at 7:44 AM, Oleg Nesterov wrote:
>
> > Perhaps you can do something like
> >
> > ppid_for_child = getpid();
> >
> > if (!fork()) {
> > // Child
> > prctl(PR_SET_PDEATHSIG);
> > if (getppid() != ppid_for_child)
> > return;
> > ...
> > }
>
> There are two problems with that. 1., I don't think TCL/TK lets me access
> the parent pre-fork env like that - all I can change is the execed code.

Can't comment this, I do not know tcl/tk

> 2., That has a clear race with pid wrap around.

Not really. This ppid_for_child can be re-used, yes. But the new process
which gets this pid can't become the parent, getppid() can't return this
number.

Btw, PR_SET_PDEATHSIG + getppid() check is racy anyway (with or without
PR_SET_CHILD_SUBREAPER), it can race with reparenting. But the window is
tiny and the problem is purely theoretical I think.

> You really need a
> prctl(PR_DID_MY_REAL_PARENT_DIE) function to be safe.

Oh, I don't know. Sure, PR_SET_CHILD_SUBREAPER can confuse the child.
Just suppose it does daemonize() + assert(getppid() == 1). But this
is not the kernel problem.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/