Bug 262738 - usr.bin/lockf: Add support for locking file descriptors
Summary: usr.bin/lockf: Add support for locking file descriptors
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Kyle Evans
URL: https://reviews.freebsd.org/D42718
Keywords: easy, feature, needs-qa
Depends on:
Blocks:
 
Reported: 2022-03-23 12:20 UTC by Daniel O'Connor
Modified: 2023-12-15 18:58 UTC (History)
3 users (show)

See Also:
kevans: mfc-stable14+
kevans: mfc-stable13+
kevans: mfc-stable12-


Attachments
Add support for locking FDs to lockf (4.51 KB, patch)
2022-03-23 12:20 UTC, Daniel O'Connor
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel O'Connor 2022-03-23 12:20:57 UTC
Created attachment 232656 [details]
Add support for locking FDs to lockf

Inspired by flock on Linux, teach lockf the trick of locking an already open FD so sections of shell scripts can be locked (or just avoid having to wrap a shell script in a lockf or shell instance).
Comment 1 commit-hook freebsd_committer freebsd_triage 2023-11-26 04:16:09 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=09a7fe0a5523d53ff6c26ddef9a947f293e18c22

commit 09a7fe0a5523d53ff6c26ddef9a947f293e18c22
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-11-22 07:46:14 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-11-26 04:15:05 +0000

    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

 usr.bin/lockf/lockf.1             |  63 ++++++++++++++++++-
 usr.bin/lockf/lockf.c             | 128 +++++++++++++++++++++++++++++++++-----
 usr.bin/lockf/tests/lockf_test.sh |  91 +++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 16 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-12-15 16:51:27 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=63b86eb6fa935ecf94b9a0f1842b56a223f151be

commit 63b86eb6fa935ecf94b9a0f1842b56a223f151be
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-11-22 07:46:14 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-12-15 00:58:29 +0000

    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.

    (cherry picked from commit 09a7fe0a5523d53ff6c26ddef9a947f293e18c22)

 usr.bin/lockf/lockf.1             |  63 ++++++++++++++++++-
 usr.bin/lockf/lockf.c             | 128 +++++++++++++++++++++++++++++++++-----
 usr.bin/lockf/tests/lockf_test.sh |  91 +++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 16 deletions(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-12-15 18:57:47 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=663424957d8079d514d127ac8c2fb65b247960be

commit 663424957d8079d514d127ac8c2fb65b247960be
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-11-22 07:46:14 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-12-15 00:59:25 +0000

    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.

    (cherry picked from commit 09a7fe0a5523d53ff6c26ddef9a947f293e18c22)

 usr.bin/lockf/lockf.1             |  63 ++++++++++++++++++-
 usr.bin/lockf/lockf.c             | 128 +++++++++++++++++++++++++++++++++-----
 usr.bin/lockf/tests/lockf_test.sh |  91 +++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 16 deletions(-)
Comment 4 Kyle Evans freebsd_committer freebsd_triage 2023-12-15 18:58:47 UTC
Thanks for the patch!