Re: [PATCH] do_wait fix for 2.6.10-rc1

From: Dinakar Guniguntala
Date: Wed Nov 10 2004 - 09:45:00 EST


On Tue, Nov 09, 2004 at 08:11:41AM -0800, Linus Torvalds wrote:
>
> I think I have a potentially better approach: make the rules for "flag" a
> bit more explicit, and make it have structure. We use "flag" for two
> things: we use it to determine if we should return -ECHILD (no children),
> and for whether we should wait for something that might become available
> later. So just split up "flag" into these two meanings, instead of just
> trying to use a single bit:
>
> - one bit that says "we found a child that _will_ wake us up when it's
> ready". In other words, that's a child that is ours, and is not yet a
> zombie.
>
> - one bit that says "we found a child that is ours".
>
> Make "eligible_child()" follow these rules, and then instead of just
> setting "flag = 1", we'd set "flag |= ret".
>
> Now, with these rules, we know just what to do: we only do the wait if the
> "we have children that will wake us up" bit is set. But we return ECHILD
> only if flag is totally clear.
>
> Does that sound like it would fix the problem?
>

How about if we set the flag only in the cases when the exit state is not
either TASK_DEAD or TASK_ZOMBIE.
Patch attached below. I confirmed that this fixes the problem and I also ran
some LTP tests

Signed-off-by: Dinakar Guniguntala <dino@xxxxxxxxxx>
Signed-off-by: Sripathi Kodi <sripathik@xxxxxxxxxx>


diff -Naurp linux-2.6.10-rc1.orig/kernel/exit.c linux-2.6.10-rc1/kernel/exit.c
--- linux-2.6.10-rc1.orig/kernel/exit.c 2004-10-23 03:10:06.000000000 +0530
+++ linux-2.6.10-rc1/kernel/exit.c 2004-11-10 17:18:20.818103584 +0530
@@ -1325,14 +1325,15 @@ repeat:
ret = eligible_child(pid, options, p);
if (!ret)
continue;
- flag = 1;

switch (p->state) {
case TASK_TRACED:
+ flag = 1;
if (!my_ptrace_child(p))
continue;
/*FALLTHROUGH*/
case TASK_STOPPED:
+ flag = 1;
if (!(options & WUNTRACED) &&
!my_ptrace_child(p))
continue;
@@ -1365,6 +1366,7 @@ repeat:
goto end;
break;
}
+ flag = 1;
check_continued:
if (!unlikely(options & WCONTINUED))
continue;