This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: posix/tst-waitid.c possible race condition on Linux
- From: Rich Felker <dalias at aerifal dot cx>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: Olivier Langlois <olivier at trillion01 dot com>, libc-alpha at sourceware dot org
- Date: Wed, 12 Jun 2013 20:10:40 -0400
- Subject: Re: posix/tst-waitid.c possible race condition on Linux
- References: <1371011970 dot 749 dot 30 dot camel at Wailaba2> <20130613000330 dot 2D1732C07F at topped-with-meat dot com>
On Wed, Jun 12, 2013 at 05:03:30PM -0700, Roland McGrath wrote:
> I think the test was racy. A change that will probably fix it is on the
> branch roland/tst-waitid and the patch is below, but I haven't been able to
> test it yet.
> [...]
> +
> + /* Give the child a chance to stop. The waitpid call below will block
> + until it has stopped, but if we are real quick and enter the waitpid
> + system call before the SIGCHLD has been generated, then it will be
> + discarded and never delivered. */
> + sleep (3);
> +
> pid_t wpid = waitpid (pid, &fail, WUNTRACED);
Wouldn't it make more sense to use sigtimedwait or sigwaitinfo to get
the signal? This would avoid the race condition without adding a long
sleep.
Rich