Re: wait4() WNOHANG ignored when tracing under 2.0.28

Matthias Urlichs (smurf@work.smurf.noris.de)
4 Feb 1997 07:57:40 +0100


In linux.dev.kernel, article <5d47qc$kte$1@work.smurf.noris.de>,
smurf@work.smurf.noris.de (Matthias Urlichs) writes:
>
> # strace -f foo
> [...]
> personality(PER_LINUX) = 0
> fork() = 21389
> [pid 21388] wait4(-1, <unfinished ...>
> [pid 21389] nanosleep(0xbffff8f8, 0xbffff8f8, 0x40091770, 0x1, 0x80485ac) = 0
> [pid 21389] _exit(0) = ?
> <... wait4 resumed> 0xbffff90c, WNOHANG, NULL) = 0
> _exit(0) = ?
>
> The main program returns immediately when I'm not tracing.
>
Graah. This is a bug of the strace program. I hate when that happens.

A process table dump shows, and strace'ing strace verifies, that the beast
fails to restart the parent process because it doesn't take the WNOHANG
flag into account when deciding that a parent process should be suspended
because it's waiting for children. :-( Usually, this suspension is a
Good Thing because the child processes are temporarily children of strace.

free sibling
task PC stack pid father child younger older
[...]
strace 123 S 00000000 4 29553 1765 29555 29544
foo 124 T 00000000 4 29554 29553 29555
foo 125 S 01D53EA3 396 29555 29553 29554

Here's the (rather trivial) patch:

RCS file: /usr/src/cvs/misc/strace/process.c,v
diff -u -r1.2 process.c
--- process.c 1996/07/30 07:36:06 1.2
+++ process.c 1997/02/04 06:41:27
@@ -818,7 +818,7 @@
struct tcb *tcp;
{
if (entering(tcp)) {
- if (tcp->nchildren > 0) {
+ if (!(tcp->u_arg[2] & WNOHANG) && tcp->nchildren > 0) {
/* There are traced children */
tcp->flags |= TCB_SUSPENDED;
tcp->waitpid = tcp->u_arg[0];

-- 
The greatest of fools is he who imposes on himself, and in greatest
concern thinks certainly he knows that which he has least studied, and
of which he is profoundly ignorant.
                                -- Shaftesbury
-- 
Matthias Urlichs         \  noris network GmbH  /  Xlink-POP Nürnberg 
Schleiermacherstraße 12   \   Linux+Internet   /   EMail: urlichs@noris.de
90491 Nürnberg (Germany)   \    Consulting+Programming+Networking+etc'ing
   PGP: 1024/4F578875   1B 89 E2 1C 43 EA 80 44  15 D2 29 CF C6 C7 E0 DE
       Click <A HREF="http://info.noris.de/~smurf/finger">here</A>.    42