p: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4a6c4f0265ac7234cf31a3c4494e3354caf629d3 Auto-Submitted: auto-generated Date: Wed, 06 May 2026 05:38:09 +0000 Message-Id: <69fad3c1.386bd.12ff8fd0@gitrepo.freebsd.org> The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=4a6c4f0265ac7234cf31a3c4494e3354caf629d3 commit 4a6c4f0265ac7234cf31a3c4494e3354caf629d3 Author: Christian Ullrich AuthorDate: 2026-05-03 15:35:10 +0000 Commit: Dag-Erling Smørgrav 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);