Date: Wed, 06 May 2026 05:38:14 +0000 From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Christian Ullrich <chris@chrullrich.net> Subject: git: 2052d09b7a5f - stable/13 - lockf: Avoid spinning when operating on an fd Message-ID: <69fad3c6.384c7.4f190967@gitrepo.freebsd.org>
index | next in thread | raw e-mail
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);home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69fad3c6.384c7.4f190967>
