git: 4a6c4f0265ac - stable/14 - 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:09 UTC
The branch stable/14 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=4a6c4f0265ac7234cf31a3c4494e3354caf629d3
commit 4a6c4f0265ac7234cf31a3c4494e3354caf629d3
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:39 +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 dd02bf2a5417..cd4a1623fb71 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);