Subject: Re: bug#10470: MSYS: race in directory access?

From: Eric Blake <[email-masked]>
Date: Tue, 10 Jan 2012 06:02:11 -0700

On 01/10/2012 05:44 AM, Stefano Lattarini wrote:
> On 01/10/2012 12:35 PM, Peter Rosin wrote:
>> Peter Rosin skrev 2012-01-10 11:12:
>>> Stefano Lattarini skrev 2012-01-10 10:50:
>>>> [2] Now that I think of it, my knee-jerk guess is that the "( sleep 1 ) &"
>>>>     put in configure by AM_SANITY_CHECK is the likely culprit.

It IS the culprit.  Use of a directory as the cwd _IS_ what prevents
removal of said directory.

> Thanks for tracking this down.  So the question now becomes: why doesn't
> the trick with background processes work on MSYS?  Does maybe MSYS lack
> proper emulation of POSIX-ish PIDs?  If that is the case, can we easily
> work around that in our situation?

Background processes _do_ work, the problem here is that you cannot
rmdir an in-use directory.  So as long as the background process still
exists, the directory is still in use.

But that analysis points out what should be a valid workaround: instead
of doing '(sleep 1)&', do '(cd somewhere/safe; sleep 1)&'.  Then the cwd
of the sleep process is no longer tied to a directory that you plan on
removing, so you no longer have to wait for that sleep process to exit.
 As for what somewhere/safe should be, $(abs_builddir) is probably
reasonable.

> As a last resort, we might enable this suboptimal-but-safer behaviour
> only when the build system is recognized to be MinGW/MSYS...

Nah, doing a cd to somewhere safe before sleeping in the background
should be non-invasive and appropriate for all platforms.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org