ln(1) and System V
Geoff Kuenning
geoff at desint.UUCP
Wed Nov 2 18:48:57 AEST 1988
In article <1988Oct31.141701.11055 at utfyzx.uucp> harrison at utfyzx.UUCP (David Harrison) writes:
> Recently Geoff Collyer (utstat!geoff) has pointed out that under System
> V the command:
> ln old new
> will destroy "new" if it already exists. Historically and under other
> UNIX versions the same command will complain and refuse to make the link.
> Geoff calls the System V behaviour "an unintuitive shock". It certainly
> breaks any program that relies on `ln' refusing to link to "new" as a way
> of doing locks (including parts of Cnews).
...
> code like:
> if [ !exists new ] # new command `exists'
> then
> ln old new
> fi
> leaves a terrible window of vulnerability between the test and the
> link.
After seeing this, I checked on my system, since several of my important
scripts use 'ln' to implement locks. However, I found that all of these
scripts use the following sequence to make the lock:
trap "" 1 2 15
touch lock
ln lock lock1 || exit 1
trap "rm -f lock lock1; exit 1" 1 2 15
This *will* work, because ln will fail complaining the "lock" and "lock1"
are identical.
On the other hand, if your scripts use the following sequence, they will
fail to lock on System V:
touch lock.$$
ln lock.$$ lock || exit 1
--
Geoff Kuenning geoff at ITcorp.com uunet!desint!geoff
More information about the Comp.unix.wizards
mailing list