Commit Graph

15 Commits

Author SHA1 Message Date
Christian S.J. Peron
cc2a9f52a7 Finish off style(9) fixes which I started two revisions ago. This basically
changes the indentation style from 4 spaces to 8 spaces which we expect to
see in other FreeBSD source files.
2005-10-09 04:45:41 +00:00
Christian S.J. Peron
45edbdccd7 Do not ignore ENOENT
Pointed out by:	Amir Shalem
2005-10-07 11:49:27 +00:00
Christian S.J. Peron
4ccbe0c50d Un-break handling of -t 0 which was broken in my previous commit.
Add a flags argument to wait_for_lock so that O_NONBLOCK can be
passed to open if a user doesn't want the open to sleep until the
lock becomes available.

Submitted by:	Amir Shalem (partially modified)
2005-10-05 22:02:07 +00:00
Christian S.J. Peron
031469eb27 Fix long standing race condition associated with how lockf uses open(2)
for mutual exclusion:

A brief description of the problem:

	1) Proc A picks up non-blocking lock on file X
	2) Proc B attempts to pickup lock, fails then waits
	3) Proc C attempts to pickup lock, fails then waits
	4) Proc A releases lock
	5) Proc B acquires lock, release it to pickup a non-blocking version
	6) Proc C acquires lock, release it to pickup a non-blocking version
	7) Both process B and C race each other to pickup lock again

This occurs mainly because the processes do not keep the lock after they have
been waiting on it. They drop it, attempt to re-acquire it. (They use the wait
to notify when the lock has become available then race to pick it up). This
results in additional CPU utilization during the race, and can also result
in processes picking locks up out of order.

This change attempts to correct this problem by eliminating the test/acquire
race and having the operating system handle it.

Reported by:	kris
Tested by:	kris
MFC after:	1 week
2005-10-05 17:39:15 +00:00
Tim J. Robbins
208f2fd1ed Use warn() instead of perror(). 2004-07-15 04:51:21 +00:00
David E. O'Brien
e026a48c34 Consistently use FBSDID 2002-06-30 05:25:07 +00:00
David Malone
9ff5e898db Warns cleanups. 2001-12-03 21:07:23 +00:00
Peter Wemm
c3aac50f28 $Id$ -> $FreeBSD$ 1999-08-28 01:08:13 +00:00
John Polstra
2f278eac1f Add a "-k" option, to specify that the lock file should be kept
rather than removed.

Submitted by:	Nick Barnes <Nick.Barnes@pobox.com>
1998-07-08 05:29:05 +00:00
Philippe Charnier
3ec665d482 lockf: usage : lockf -> usage: lockf by using fprintf instead of errx. 1997-07-22 07:32:23 +00:00
Warner Losh
1c8af87873 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-29 04:34:07 +00:00
Peter Wemm
c115df18cd Revert $FreeBSD$ to $Id$ 1997-02-22 19:58:13 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
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.
1997-01-14 07:20:47 +00:00
John Polstra
ae06cb4d32 On failure, return various exit codes from <sysexits.h>. In particular,
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.
1997-01-09 19:53:21 +00:00
John Polstra
c8929a4926 Initial import of the lockf utility. It executes an arbitrary command
while holding an exclusive lock on a file.
1997-01-08 20:12:59 +00:00