Re: rmdir of a busy directory

Martin Tessun (martin.tessun@class.de)
Mon, 15 Feb 1999 08:36:16 +0100


Alexander Viro wrote:
>
> On Fri, 12 Feb 1999, Ralf Corsepius wrote:
>
> > This might also be consequence of the same problem:
> >
> > mkdir <somedir>
> > cd <somedir>
> > rmdir .
> >
> > Under all OSes I tried, the rmdir . command above returns an error. On linux >
> > 2.1.124 (the version I first noticed to be affected) this silently succeeds.
>
> You never tried 4.4BSD, right?
>
> > BTW, this behaviour breaks building egcs/gcc/fixincludes for cross-compilers
> > under linux, because fixincludes (egcs-1.1b and egcs-1.1.1) contain a fragment
> > which rely on "rmdir ." failing.
>
> Then egcs/gcc is broken. Period. POSIX doesn't mandate failure on
> such operation. All *BSD do the same as Linux. And this behaviour is
> consistent with unlink(). Notice that it may be even fs-dependent. Out of
> curiosity - how does this fragment look like?
>
> Final word belongs Linus, indeed, but IMO reverting to -EBUSY on
> rmdir() is *wrong*.

Well in Solaris e.g. it isn't -EBUSY either. Have a look at the trace:

rmdir(".") Err#22 EINVAL
^^^^^^
rmdirwrite(2, " r m d i r", 5) = 5
: directory "write(2, " : d i r e c t o r y ".., 13) = 13
.": write(2, " . " : ", 4) = 4
Can't remove current directory or ..write(2, " C a n ' t r e m o v
e".., 36) = 36

write(2, "\n", 1) = 1
lseek(0, 0, SEEK_CUR) = 9628
_exit(2)

So perhaps this isn't POSIX (I don't really know POSIX that much), but I
think this is the correct behaviour. You normally don't cut the tree you
are sitting on.

So IMHO you may discuss the error-code, but it really should be a error,
as this is so in (as I think) all OSs. (Even in SunOS 4.x a BSD-Unix it
returned an Error.)

But rmdir really works (under Solaris) if you do the following:

mkdir x
cd x
cmdtool & # or any other process, but with the working directory on x
cd ..
rmdir x

So it is in fact only a problem if the process invoking the rmdir is in
the direcory which should be removed.
BTW: If you do a pwd in the new cmdtool you get a "Cannot determine
current working directory". So it really is in the removed directory.

Bye
Martin

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/