By default, lockf(1) opens its lock file O_RDONLY|O_EXLOCK. On NFS, if the
file already exists, this is split into opening the file read-only and then
requesting an exclusive lock -- and the second step fails because NFS does
not permit exclusive locking on files which are opened read-only.
The new -w option changes the open flags to O_WRONLY|O_EXLOCK, allowing it
to work on NFS -- at the cost of not working if the file cannot be opened
for writing.
(Whether the traditional BSD behaviour of allowing exclusive locks to be
obtained on a file which cannot be opened for writing is a good idea is
perhaps questionable since it may allow less-privileged users to perform
a local denial of service; however this behaviour has been present for a
long time and changing it now seems like it would cause problems.)
Reviewed by: rmacklem
Differential Revision: https://reviews.freebsd.org/D26005
* Add pretty small EXAMPLES section
* While here, fix a warning in line 98 (new sentence in new line)
Approved by: bcr@
Differential Revision: https://reviews.freebsd.org/D25205
Although groff_mdoc(7) gives another impression, this is the ordering
most widely used and also required by mdocml/mandoc.
Reviewed by: ru
Approved by: philip, ed (mentors)
This is easy to confuse with the actual exit status of the program.
Instead exit with EX_SOFTWARE if the command doesn't exit normally.
MFC after: 1 month
lock experienced contention a number of processes would race to acquire
lock when it was released. This problem resulted in a lot of CPU
load as well as locks being picked up out of order.
Unfortunately, a regression snuck in which allowed multiple threads
to pickup the same lock when -k was not used. This could occur when
multiple processes open a file descriptor to inode X (one process
will be blocked) and the file is unlinked on unlock (thereby removing
the directory entry allow another process to create a new directory
entry for the same file name and lock it).
This changes restores the old algorithm of: wait for the lock, then
acquire lock when we want to unlink the file on exit (specifically
when -k is not used) and keeps the new algorithm for when -k is used,
which yields fairness and improved performance.
Also, update the man page to inform users that if lockf(1) is being
used to facilitate concurrency between a number of processes, it
is recommended that -k be used to reduce CPU load and yeld
fairness with regard to lock ordering.
Collaborated with: jdp
PR: bin/114341
PR: bin/116543
PR: bin/111101
MFC after: 1 week
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.
Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.
return EX_TEMPFAIL if the file was already locked. This makes it easier
to distinguish between lock collisions and failures within the command
being executed.
Also, don't complain if the unlink() fails in the cleanup handler. It
doesn't matter anyway, and it obscured the exit status returned from
the command that was executed.