ln(1) and System V

David Harrison harrison at utfyzx.uucp
Tue Nov 1 05:17:01 AEST 1988


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).

There certainly are lock problems under SV:  the print spooler will
croak if it is fed a large number of jobs nearly simultaneously; a
number of users changing their passwords nearly simultaneously can
leave you without an /etc/passwd file; etc.  Both of these have happened
to me and the fix I use is to write a SV IPC onionskin around these 
commands with semaphores to implement real kernel-level locks.

I have some questions and one comment on this situation.

First the questions:  if one re-writes ln (as Geoff has done) to
reproduce the old behaviour and replaces the SV `ln' in /bin
with this version what will break?   People have been using the 
old `ln' behaviour for some years, but are people now relying on 
the new behaviour too?  If so, how?  Will implementing such a change
make passwd and lp more reliable with lots of users?  What does
POSIX say?

Finally the comment:  if one adheres to traditional UNIX philosophy 
the System V `ln' is correct.  It now behaves just like its cousins 
`cp' and `mv':  tell it to do something and it will.  If one wishes 
to test for the existence of file "new" this philosophy says that
one should use a tool for that, not some behaviour of a program that 
is supposed to make links.  I know one problem with the above 
statement; 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.  What is needed is a proper lock mechanism, and System V provides 
it with its IPC facilities in the kernel where they belong.
-- 
David Harrison, Dept. of Physics, Univ. of Toronto |  "Why do 3 notes make a
UUCP: {utgpu,sq,oscvax}!utfyzx!harrison            | triad and not a triangle?"
BITNET: HARRISON at UTORPHYS                          |         - Ernst Mach



More information about the Comp.unix.questions mailing list