[uw.mfcf.software] /usr/source/.xlsource/mfcf/misc/flock/flock.c

rjwhite@watmath.waterloo.edu (09/09/89)

From: RJ White <rjwhite>

flock(2) sorta doesnt work on Mips machines.
Ive beat on the flock (1) user command  to work there.
source updated on math, not installed anywhere.  Not really sure where
its supposed to be.

The main problems with flock(2) on Mips are that for exclusive locks,
the file has be be opened for write, and flocks are not inherited
by children.  And the return error message is dumb: No permission.
So in flock(1), the flock has to be done in the child, after opening
the file RDWR, then pass the process-id of itself back to the parent
who can print it out and then exit so you can still do stuff like:
	pid=`flock file`
in scripts.  If the flock fails for ANY reason, it writes out the
...Operation would block... message on Mips to be consistent with the
other machines in case anybody actually checks the return message in scripts.

The Mips docu claims that fcntl's and flock's dont work together.
I found that they did when trying two differnt versions of flock(1)
using both fcntl and flock(2), so I used the flock(2) so it was the least
amount of changes.