History log of /freebsd-current/usr.bin/lockf/lockf.c
Revision Date Author Comments
# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# e4967d4d 25-Nov-2023 Kyle Evans <kevans@FreeBSD.org>

lockf: switch to strtonum() for parsing timeout

Convert waitsec to a long long to be able to hold the full domain of
alarm(3) timeout on all platforms, and let strtonum(3) handle the input
validation. strtonum(3) also happens to provide a neater interface for
error handling, and it already includes our pre-existing empty input
check.

Sponsored by: Klara, Inc.


# 09a7fe0a 22-Nov-2023 Kyle Evans <kevans@FreeBSD.org>

lockf: allow locking file descriptors

This is most useful inside a shell script, allowing one to lock just
portions of a script rather than having to wrap the entire script in a
lock.

PR: 262738
Reviewed by: 0mp, allanjude (both previous versions)
Co-authored-by: Daniel O'Connor <darius@dons.net.au>
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D42718


# 18425c19 21-Nov-2023 Alexander Melkov <melkov@comptek.ru>

lockf: don't hold stdin/stdout/stderr open

None of these are essential in the lockf monitor (parent post-fork), so
close them to maintain the illusion that lockf hasn't been inserted into
the pipeline. This ensures that the correct effects happen on other
programs in the pipeline if the locked command closes or redirects these
elsewhere.

The original patch used -s to close stdout/stderr rather than closing
them unconditionally, but it's not clear that we really care that much.
kevans dropped that part when taking the patch, patch is otherwise by
listed author.

PR: 112379
Reviewed by: 0mp, allanjude (both earlier version), kevans
Feedback from: des
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D42713


# 35095fd2 21-Nov-2023 Kyle Evans <kevans@FreeBSD.org>

lockf: correct omission in the usage statement

The -w flag was added without being noted in the usage statement; fix
that now.

While we're here, re-sort the getopt() string.

Reviewed by: 0mp, allanjude, des
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D42712


# 3041e695 21-Nov-2023 Kyle Evans <kevans@FreeBSD.org>

lockf: hide unavailable error with -n -s

The error message is expected, allow -s to suppress just that one since
it would loosely fall under the definition of "failure to acquire the
lock" described in the manpage for the -s option.

Reviewed by: 0mp, allanjude
Feedback from: des
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D42711


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# a1b6427a 07-Jul-2023 Alfonso Gregory <gfunni234@gmail.com>

Mark usage function as __dead2 in programs where it does not return

In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 437bab48 26-Aug-2020 Colin Percival <cperciva@FreeBSD.org>

Add -w option to lockf(1).

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


# d614ded6 20-Mar-2019 Andriy Voskoboinyk <avos@FreeBSD.org>

lockf(1): return EX_UNAVAILABLE if -n is used and the lock file does not
exist

Apply EX_UNAVAILABLE patch part from PR 170775 to match the documentation.

Checked with a command from PR 210770:
lockf -n /tmp/doesnotexist echo; echo $?

PR: 210770
MFC after: 1 week


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# 90e81864 15-Apr-2015 Bryan Drewery <bdrewery@FreeBSD.org>

Remove extra flags from r250462.

MFC after: 1 week


# b5be420a 10-May-2013 Eitan Adler <eadler@FreeBSD.org>

Add option to lockf to avoid creating a file if it does not exist.

PR: bin/170775
Submitted by: Matthew Story <matthewstory@gmail.com>
Reviewed by: scottl
MFC after: 1 week


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 7f15c32d 21-Aug-2008 David Malone <dwmalone@FreeBSD.org>

Lockf was exiting with status 1 if the command did not exit normally.
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


# 6a53f0a5 12-Oct-2007 Christian S.J. Peron <csjp@FreeBSD.org>

Revision 1.12 of lockf.c fixed a "thundering herd" scenario when the
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


# cc2a9f52 08-Oct-2005 Christian S.J. Peron <csjp@FreeBSD.org>

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.


# 45edbdcc 07-Oct-2005 Christian S.J. Peron <csjp@FreeBSD.org>

Do not ignore ENOENT

Pointed out by: Amir Shalem


# 4ccbe0c5 05-Oct-2005 Christian S.J. Peron <csjp@FreeBSD.org>

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)


# 031469eb 05-Oct-2005 Christian S.J. Peron <csjp@FreeBSD.org>

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


# 208f2fd1 14-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Use warn() instead of perror().


# e026a48c 29-Jun-2002 David E. O'Brien <obrien@FreeBSD.org>

Consistently use FBSDID


# 9ff5e898 03-Dec-2001 David Malone <dwmalone@FreeBSD.org>

Warns cleanups.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 2f278eac 07-Jul-1998 John Polstra <jdp@FreeBSD.org>

Add a "-k" option, to specify that the lock file should be kept
rather than removed.

Submitted by: Nick Barnes <Nick.Barnes@pobox.com>


# 3ec665d4 22-Jul-1997 Philippe Charnier <charnier@FreeBSD.org>

lockf: usage : lockf -> usage: lockf by using fprintf instead of errx.


# 1c8af878 28-Mar-1997 Warner Losh <imp@FreeBSD.org>

compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.


# c115df18 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

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.


# ae06cb4d 09-Jan-1997 John Polstra <jdp@FreeBSD.org>

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.


# c8929a49 08-Jan-1997 John Polstra <jdp@FreeBSD.org>

Initial import of the lockf utility. It executes an arbitrary command
while holding an exclusive lock on a file.