Re: Deleting the current directory, V2.1.54

Ricky Beam (root@defiant.interpath.net)
Sat, 13 Sep 1997 14:23:32 -0400 (EDT)


Letting the chips fall where they may, I quote Rogier Wolff:
>consider
> something < tempfile > tempfile
>This program simply uses its stdin/out file descriptors to access one
>single tempfile.

One bit of clarification, the _shell_ creates stdin/stdout as fd's to
the same file (possibly destroying/truncating the file.)

>Now consider
> something < tempfile > tempfile
> rm temfile
> something < tempfile > tempfile
>Now there are also two copies of "tempfile", both with the same name.
>This will work on any Unix.

Except for the fact that the shell has to open the fd's before it forks
off the process... so, there is only one file. '< tempfile' opens for
read... that's fine. '> tempfile' opens for write truncating the file...
that's fine. Both fd's are now pointing to the same point within the
same file which is now zero bytes in size. The shell does not unlink
tempfile before opening it for writing. If it did, then it would work
just file:
Eg: cat foo | ( rm -f foo ; cat > foo )
[tty3]dominion:/tmp/[2:01pm]:ls -l foo
-rw-r--r-- 1 cramer root 809476 Sep 13 14:01 foo
[tty3]dominion:/tmp/[2:07pm]:cat foo | ( rm -f foo ; cat > foo )
[tty3]dominion:/tmp/[2:07pm]:ls -l foo
-rw-r--r-- 1 cramer root 809476 Sep 13 14:07 foo

>> I have looked in the old AT&T Unix reference manual and cannot find
>> any prohibition against removing the default directory, however my
>> Sun doesn't allow such an operation. Sun's rmdir responds with
>> "Can't remove . or ..".
>
>Right. This is an implementation problem that used to be valid for
>ALL unices, but this restriction has been removed for Linux last
>month.

That was a "safety feature" of the command to prevent root from accidentally
unlinking a full directory -or- recursively deleting _up_ the directory tree.
(and yes, I've done both. [not under Linux tho'])

>> If this new behavior is okay, it could result in some problems for
>> new-bee Linux users. They could get "lost" as programs running in
>> certain default directories could have their file operations fail
>> for no apparent reason as some other task removed that directory
>> and then recreated it.
>
>New bees (:-) won't likely hit this. If they do it is a nice
>way to introduce them to the real semantics of Unix.

Pardon me, but they deleted the directory they are setting in??? Under
non-Linux UNIX, '.' and '..' are then _gone_!!! They _must_ use a full
path to get out of it. Under Linux the directory is not completely gone
yet:
[tty3]dominion:/tmp/[2:07pm]:mkdir test
[tty3]dominion:/tmp/[2:12pm]:cd test
[tty3]dominion:/tmp/test/[2:12pm]:ls -al
total 6
drwxr-xr-x 0 cramer root 1024 Sep 13 14:12 ./
drwxrwxrwt 3 root root 5120 Sep 13 14:12 ../
[tty3]dominion:/tmp/test/[2:12pm]:rmdir .
[tty3]dominion:/tmp/test/[2:12pm]:ls -al
total 6
drwxr-xr-x 0 cramer root 1024 Sep 13 14:12 ./
drwxrwxrwt 3 root root 5120 Sep 13 14:12 ../
[tty3]dominion:/tmp/test/[2:12pm]:touch foo
touch: foo: Operation not permitted
[tty3]dominion:/tmp/test/[2:12pm]:touch ../test/foo
touch: ../test/foo: No such file or directory
[tty3]dominion:/tmp/test/[2:12pm]:mkdir ../test
[tty3]dominion:/tmp/test/[2:12pm]:touch ../test/foo
[tty3]dominion:/tmp/test/[2:12pm]:ls -al
total 6
drwxr-xr-x 0 cramer root 1024 Sep 13 14:12 ./
drwxrwxrwt 4 root root 5120 Sep 13 14:12 ../
[tty3]dominion:/tmp/test/[2:15pm]:ls -al ../test/
total 6
drwxr-xr-x 2 cramer root 1024 Sep 13 14:12 ./
drwxrwxrwt 4 root root 5120 Sep 13 14:12 ../
-rw-r--r-- 1 cramer root 0 Sep 13 14:12 foo

>By the way, it is bad practise to Email as "root". For one, it shows
>you're a newby. (newby's like to brag "look, look, I'm root on my own
>machine!")

Nah, it just means you're too lazy to make and use an account. It's a DOS
thing I guess...

--Ricky

"This business is like the tobacco business. I wouldn't smoke for love or money
but by god I'll sell the shit outa it..." -- Virgil Wall