1.7.7: rm -rf sometimes fails - race condition?

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Dec 13 15:41:00 GMT 2010

On Dec 12 17:55, Matthias Andree wrote:
> Am 12.12.2010 16:46, schrieb Corinna Vinschen:
> > Probably the file-in-use stuff is not really your problem.  There's
> > another problem which is this:  If the directory you want to remove is
> > the CWD of a Windows process, then removing the dir fails.  The reason
> > is that the CWD handle of a Windows process is opened without the
> > FILE_SHARE_DELETE sahring mode set.  So, any try to rename or remove
> > that dir will fail.
> > 
> > For Cygwin 1.7.7, this is also true for Cygwin processes.  There was
> > that handle problem with Cygwin's CWD handling on Vista and later which
> > has been discussed on this list between August and October.  Since we
> > had no way to fix this problem at this point, Cygwin 1.7.7 reverted to
> > the old Cygwin 1.5 behaviour to use the Win32 function SetCurrentDirectory
> > to set the CWD.  With obvious results.
> > 
> > In the meantime John Carey was so kind to dive into the OS and found a
> > solution to replicate Vista's CWD handling so that Cygwin 1.7.8 will
> > again be able to remove directories which are the CWD of any Cygwin
> > process.  The problem with native, non-Cygwin processes holding a
> > CWD handle to this directory will of course persist.
> Ah, that might possibly account for races, depending on how fast we leave the
> directory alone in 1.7.7.

Some tools or scripts expect to be able to do this:

  mkdir foo
  cd foo
  rmdir ../foo     ("rmdir ." returns EINVAL per POSIX)

> > So, here's the question:  Did you try a recent Cygwin snapshot from
> > http://cygwin.com/snapshots/?  Perhaps it fixes your problem.
> Not yet, but can do. Does that entail reinstalling cyglsa since 1.7.7 (just
> planning to keep the number of reboots down :-))?

Just replacing the Cygwin DLL will do.


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

More information about the Cygwin mailing list