GNU bug report logs - #9813
rm -rf calls rmdir() prior to close(), which can fail

Previous Next

Package: coreutils;

Reported by: Eric Blake <eblake <at> redhat.com>

Date: Thu, 20 Oct 2011 17:41:01 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Eric Blake <eblake <at> redhat.com>
Cc: bug-gnulib <at> gnu.org, 9813 <at> debbugs.gnu.org
Subject: bug#9813: rm -rf calls rmdir() prior to close(), which can fail
Date: Thu, 20 Oct 2011 12:47:28 -0700
On 10/20/11 10:38, Eric Blake wrote:
> POSIX is clear that attempts to rmdir() a directory that still has open descriptors may fail.

Hmm, that's news to me.  And on the contrary, the spec
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/rmdir.html>
explicitly talks about what rmdir() does when there are open descriptors:

 "If one or more processes have the directory open when the last link is removed,
  the dot and dot-dot entries, if present, shall be removed before rmdir() returns
  and no new entries may be created in the directory, but the directory shall not
  be removed until all references to the directory are closed."

which very much sounds like rmdir() is supposed to succeed in this case.

Also, there's no entry for this situation under the "may fail" section
of ERRORS.  And there's longstanding Unix tradition that you can unlink
a file that you have an open file descriptor to, which suggests that
rmdir() should do likewise.

So, if this is a problem under Cygwin, it's probably better to handle it
in the rmdir() wrapper that deals with Cygwin and file descriptors.




This bug report was last modified 13 years and 298 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.