Re: POSIX feature or Bug?

Linus Torvalds (torvalds@cs.helsinki.fi)
Fri, 20 Sep 1996 09:56:14 +0300 (EET DST)


On Fri, 20 Sep 1996, Ulrich Windl wrote:
>
> In 2.0.20 I tried "cd /tmp; mkdir X; cd X; rmdir /tmp/X" with
> success. A subsequent "pwd" complains about the working directory...

"Don't do that then".

Actually, it's neither a bug nor a POSIX feature: it's just how things
work. Directories are just normal files, and you can think of having a
directory as your current working directory as having a file open.

What happens when you remove a file that you had open? The open file still
works, but you can't get at it though the filesystem name-space any more.
Similarly, when you remove a directory that you have as you cwd, the
directory still exists, but you can't get at it through the filesystem
name-space.

There is a special restriction here, and that's the fact that a removed
directory cannot have new files created in it. That's simply because the
kernel doesn't really like the idea of having a file with a non-existent
directory as the parent..

Anyway, I think most other UNIX'es will act the same way.

[ sounds of logging onto other systems.. ]

Solaris, HP-UX and Digital UNIX work the same way as Linux, but Solaris and
HP-UX try to be "clever" and notice that you're trying to remove the cwd. But
under both the "clever" OS's you can just open another window and removing
the cwd in _another_ process, no problem (so the check seems to be just some
silly one-liner check added by some Sun/HP/xxx engineer who though the check
would be a good idea for some strange reason, but it has no real meaning).

Linus