git: 2052d09b7a5f - stable/13 - lockf: Avoid spinning when operating on an fd
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 06 May 2026 05:38:14 UTC
The branch stable/13 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=2052d09b7a5f55447b5106489731e229f93d8bda
commit 2052d09b7a5f55447b5106489731e229f93d8bda
Author: Christian Ullrich <chris@chrullrich.net>
AuthorDate: 2026-05-03 15:35:10 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-05-06 05:37:46 +0000
lockf: Avoid spinning when operating on an fd
When operating on a file descriptor, acquire_lock() would ignore the
flags argument and always operate in non-blocking mode, resulting in
unnecessary busy-looping.
PR: 294832
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D56722
(cherry picked from commit d90513ea85693da0ca5955173609f4e81e38ae16)
---
usr.bin/lockf/lockf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c
index f459b54060aa..a1711aaa8b6a 100644
--- a/usr.bin/lockf/lockf.c
+++ b/usr.bin/lockf/lockf.c
@@ -267,10 +267,14 @@ acquire_lock(union lock_subject *subj, int flags, int silent)
int fd;
if (fdlock) {
+ int lflags = LOCK_EX;
+
assert(subj->subj_fd >= 0 && subj->subj_fd <= INT_MAX);
fd = (int)subj->subj_fd;
- if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
+ if ((flags & O_NONBLOCK) == O_NONBLOCK)
+ lflags |= LOCK_NB;
+ if (flock(fd, lflags) == -1) {
if (errno == EAGAIN || errno == EINTR)
return (-1);
err(EX_CANTCREAT, "cannot lock fd %d", fd);