Messages in this thread | | | Date | Fri, 30 Mar 2012 19:14:30 +0200 | From | Oleg Nesterov <> | Subject | Re: Is prctl(PR_SET_CHILD_SUBREAPER) going to break my code which checks getppid == 1? |
| |
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.
| |