lkml.org 
[lkml]   [2011]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 09/11] job control: reorganize wait_task_stopped()
Hello,

On Thu, May 12, 2011 at 07:25:06PM +0200, Oleg Nesterov wrote:
> > WNOHANG disables that mechanism.
>
> Yes, this is clear. WNOHANG can "race" with the transitions above.
> But we do not care, this is like reading the word which can be
> changed by another thread, no?
>
> But this bug is different. Say, the parent does wait(WNOWAIT) and
> gets CLD_STOPPED. After that it has all rights to assume that
> wait(WNOHANG) must report either STOPPED or CONTINUED.

They aren't that different. Please consider the following program.

#define PTRACE_SEIZE 0x4206
#define PTRACE_INTERRUPT 0x4207

#define PTRACE_SEIZE_DEVEL 0x80000000

static const struct timespec ts1ms = { .tv_nsec = 1000000 };

int main(int argc, char **argv)
{
pid_t child, control;

child = fork();
if (!child)
while (1)
pause();

kill(child, SIGSTOP);
waitid(P_PID, child, NULL, WSTOPPED | WNOWAIT);

control = fork();
if (!control) {
while (1) {
kill(child, SIGCONT);
nanosleep(&ts1ms, NULL);
kill(child, SIGSTOP);
nanosleep(&ts1ms, NULL);
}
}

while (1) {
siginfo_t si = {};

waitid(P_PID, child, &si,
WSTOPPED | WCONTINUED | WNOWAIT | WNOHANG);
if (!si.si_pid)
break;
}

kill(control, SIGKILL);
kill(child, SIGKILL);
return 0;
}

waitid(2) should always succeed as it's never consuming wait state,
but it does, with or without the patch. All transitions need to be
made water tight to remove the bug.

Thanks.

--
tejun


\
 
 \ /
  Last update: 2011-05-12 19:35    [W:1.212 / U:0.428 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site