From nobody Thu Jul 10 17:54:32 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bdMtK0td1z61L7l; Thu, 10 Jul 2025 17:54:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bdMtJ2TMRz3JcB; Thu, 10 Jul 2025 17:54:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752170072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i1OuLSm1Ekz7ue7G2QW84qHU3rhDtIgvH0yDtIfru9w=; b=cMbDR0SAELJCpODRdnZj/cZK3qOy6PgzlBGRYM2CkOYB19XJHK6+jWFdJpeLsCwMciFEOz SNYl/xurU9sYBt7KgP5EMBZsmr21CYMdrA8We0e4E8+8xcpTqHaIYZPu3wEH7Tw036q3TC DvXGzuAgbYKhV/ELmxqvn3CkpqdvZHq+NmI/xjm1K+SXo3ZHbtknJM3J2EQP8Yqk6NgayT /XKnRdbHH9hLELCi2++TnEQWh2xXOVn60qRWnZYk7KV5XBjJVo50n8p2O9677+xwB8PcKJ 6Wf7kOJtzEIGmk+TuRgmpVt7OVtVdoThYvb5Z8UK1/hbiRJNUJXMNtnW7LPcEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1752170072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i1OuLSm1Ekz7ue7G2QW84qHU3rhDtIgvH0yDtIfru9w=; b=I+5cbv1sSP+88wcoWR1rPgQCHhc1F33jfZtda+1xIhQh7nockTHpH96uzujC2xeI9jOHxl f37PiN5egzPpeSs8blTAMnH5GeAE7zeBNM7YL9J+/8r9Kdi71NQLirzOTxQDl5zOMA4OUF r4WTKjwtq0vFvRT0/GSOst0Wt6672t2rnzCw4NIJYmV+up5RbBLps8NwKo361BAz6xR5rq 96Bq8XLp0jntcpkuKZJQUfQEwTtuSgGUvlep2ib4vWb+Eg6ltfdTPW+k0/Ew0xUsRqgV2o wdGi3ipBPzxNPPbyLi8iUbIldBGES1P3cIHwTlsTfe2QvM4+ULgOjICHnBlauQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1752170072; a=rsa-sha256; cv=none; b=lHjL5Mei5A76cQSlgEpBviin28e6kM/9rxJjtnupTgOuq8MSgBpl+QXnGFNkdDUl1aDqhB m9MMXVpfHnlYAmhD0PjLNEoXK2q1la5rQqpTyGWX/8aN2lw3ICylFEQ480vZ0VJfL/8lRW wWjuH+YyD0/eJU9Lt0oYh9rxuX3n8IqkWKiNUudzqkr1Kf9grgcDdIq/AY2WzWtOX7l8JP y1H2jLbIySPIdS1S4EMPuhaiNhDflWxKkGosIgleyr1lh8SVfc1sS0/0KiGqk7Ez5KHtv+ 9fZ0cjA/2JsBrVQg/GD4QHY3a8pB6aa8zRtRtKvSjFXELKqdZ7vObm9fysIj3A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bdMtJ21rhz1GHK; Thu, 10 Jul 2025 17:54:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56AHsWIE072108; Thu, 10 Jul 2025 17:54:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56AHsWPR072105; Thu, 10 Jul 2025 17:54:32 GMT (envelope-from git) Date: Thu, 10 Jul 2025 17:54:32 GMT Message-Id: <202507101754.56AHsWPR072105@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 679f619495f6 - main - lockf: add a -T option to terminate the child upon early abort List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 679f619495f67eafc9fdb97d11381b14f2b49ccf Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=679f619495f67eafc9fdb97d11381b14f2b49ccf commit 679f619495f67eafc9fdb97d11381b14f2b49ccf Author: Kyle Evans AuthorDate: 2025-06-24 23:03:14 +0000 Commit: Kyle Evans CommitDate: 2025-07-10 17:54:20 +0000 lockf: add a -T option to terminate the child upon early abort This is useful to avoid having the command running twice in the face of the admin terminating the process. Notably, if the -p option is not in use (or can't be used, e.g., because we can't open the file for writing) then this provides a nice alternative where one simply needs to send a SIGTERM to the lockf(1) process associated with the lock file to clean it all up. Reviewed by: des Differential Revision: https://reviews.freebsd.org/D51025 --- usr.bin/lockf/lockf.1 | 18 +++++++++++++++++- usr.bin/lockf/lockf.c | 9 ++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/usr.bin/lockf/lockf.1 b/usr.bin/lockf/lockf.1 index 5832903246f1..40b4497bc80c 100644 --- a/usr.bin/lockf/lockf.1 +++ b/usr.bin/lockf/lockf.1 @@ -30,7 +30,7 @@ .Nd execute a command while holding a file lock .Sh SYNOPSIS .Nm -.Op Fl knpsw +.Op Fl knpsTw .Op Fl t Ar seconds .Ar file .Ar command @@ -136,6 +136,22 @@ This option will cause to open .Ar file for writing rather than reading. +.It Fl T +Upon receipt of a +.Dv SIGTERM , +forward a +.Dv SIGTERM +along to the +.Ar command +before cleaning up the +.Ar file +and exiting. +By default, +.Nm +effectively orphans the +.Ar command +after cleaning up the +.Ar file . .It Fl t Ar seconds Specifies a timeout for waiting for the lock. By default, diff --git a/usr.bin/lockf/lockf.c b/usr.bin/lockf/lockf.c index 19424418ed68..b0e16285998a 100644 --- a/usr.bin/lockf/lockf.c +++ b/usr.bin/lockf/lockf.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ static int lockfd = -1; static int keep; static int fdlock; static int status; +static bool termchild; static volatile sig_atomic_t timed_out; /* @@ -109,7 +111,7 @@ main(int argc, char **argv) silent = keep = writepid = 0; flags = O_CREAT | O_RDONLY; waitsec = -1; /* Infinite. */ - while ((ch = getopt(argc, argv, "knpst:w")) != -1) { + while ((ch = getopt(argc, argv, "knpsTt:w")) != -1) { switch (ch) { case 'k': keep = 1; @@ -120,6 +122,9 @@ main(int argc, char **argv) case 's': silent = 1; break; + case 'T': + termchild = true; + break; case 't': { const char *errstr; @@ -356,6 +361,8 @@ static void killed(int sig) { + if (termchild && child >= 0) + kill(child, sig); cleanup(); signal(sig, SIG_DFL); if (kill(getpid(), sig) == -1)