From nobody Sat Aug 22 21:14:48 2026 X-Original-To: dev-commits-src-all@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 4hS9142zlgz6pBQL for ; Sat, 22 Aug 2026 21:14:48 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hS91424Llz483d for ; Sat, 22 Aug 2026 21:14:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787433288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AaHR3+87ZQgnR3uflPHOJio2rLUdwd1cHZAAutXRBXE=; b=RdsJz/ZLxAtbT53X3/Iz8Hh6kAn8JMeZpZTvsxQWUGvrFd8kHP8w38ynZqlm4RGFY3eEzI Vy0Y1e3FvUvlum9cOIguHHrkXsQaf8itrrzU7BhVCgxBRa3/aIGqKa1z/zwsiTclKmpX/i FaK8uKu+qcDAnrj4i5wrE6c1Zm/5bxGpDb+1b6HckdD1elTB+DBzBjYjW4lCH+sErH+/f8 jnLoslgw2OuloWMD/q+P9/MDieA8+GK0fto1nfkC/dw0f8Q000Tgdp9hxDkKFWRwESas0c vFdSC8WN6GKZ/3qHq7rGBdneDRQCedec4cxJ5hsOBP9hS2kr/5iJWgIyhCGpCg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787433288; a=rsa-sha256; cv=none; b=RwuxzxPcgsRiby8/KgPEuJFMz4mKOojoww27pu0vnQ40/TgoRQZ6tyy1K4rlAR7bG/OuRh jkRGnnHqCRlMtHoz2RE94QG2AClz/2MYzXdx8huFa9WfiApmOcdcZGM2G/rHY0+FR4PDAc kyJKJs6lOCfUr/X/rfKywFMhiiUMTnRngvBUjWYHrAX9MBsOGEJIw1txoIPdGjwlTo+ABn mkYM/3ou7lkePmNHABRCk2p5OSwzGLP8clykKG7M0YNhA7JZo+HlxqlJs/SZ9iG5jCpHSN HqYOa/RGMK1YsNdp4cLyLQDUuswzg3fjPkkaf19726a89GiwuufJzDD99b4NNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787433288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AaHR3+87ZQgnR3uflPHOJio2rLUdwd1cHZAAutXRBXE=; b=g88NOjRGtmqbYkIocuqR99xkN/SDxO/3EwSWYfBYYPYtbXK0i7pf3XeF1G+LQJWeIWszcZ Wt+/I9m/+wv5aHLyf4Lat86CjacLBxkwPjFUf0X5tdyKvXf+Y19GcmZUvO/fglUKBLaAp9 S+alv2ht7wBDmXnzQwPKua9B3N9wcR9pKMxBntm1wpwdaJC31ZQ/ipaQNj6ukd4aNrMRvE qziNr9y1ZcEbjYdhaZSJHqKMVBlcfNmgypvXzBXn9CQ3dQXVhl8L9NrJdpVb3yjKc7n+LX Ux7NIm3jlR8cUwG71GiGaeuXLfsYCdqJqC2AlwmSgxY3MA1ESOF/xsjW4Vl9vA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hS9140mPVz13yM for ; Sat, 22 Aug 2026 21:14:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 42083 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 22 Aug 2026 21:14:48 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Andre Albsmeier From: Michael Osipov Subject: git: 21f5c8438851 - stable/14 - daemon(8): Add option to write pidfile w/o supervising it List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: 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: michaelo X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 21f5c8438851ed2a8ac9251a42648999f8b36439 Auto-Submitted: auto-generated Date: Sat, 22 Aug 2026 21:14:48 +0000 Message-Id: <6a8a1148.42083.478c8c4f@gitrepo.freebsd.org> The branch stable/14 has been updated by michaelo: URL: https://cgit.FreeBSD.org/src/commit/?id=21f5c8438851ed2a8ac9251a42648999f8b36439 commit 21f5c8438851ed2a8ac9251a42648999f8b36439 Author: Andre Albsmeier AuthorDate: 2024-08-17 09:20:00 +0000 Commit: Michael Osipov CommitDate: 2026-08-22 21:13:51 +0000 daemon(8): Add option to write pidfile w/o supervising it Co-authored-by: Michael Osipov PR: 280487 Reviewed by: kevans, michaelo MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D46313 (cherry picked from commit fe06e383cc64fce8b604d21f8526b91fa6aecc39) --- usr.sbin/daemon/daemon.8 | 19 ++++++++++++++++--- usr.sbin/daemon/daemon.c | 27 +++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/usr.sbin/daemon/daemon.8 b/usr.sbin/daemon/daemon.8 index a1a56de03d4a..c81a733e1bc0 100644 --- a/usr.sbin/daemon/daemon.8 +++ b/usr.sbin/daemon/daemon.8 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 28, 2026 +.Dd August 13, 2026 .Dt DAEMON 8 .Os .Sh NAME @@ -32,7 +32,7 @@ .Nd run detached from the controlling terminal .Sh SYNOPSIS .Nm -.Op Fl cfHrS +.Op Fl cfHrSx .Op Fl p Ar child_pidfile .Op Fl P Ar supervisor_pidfile .Op Fl t Ar title @@ -195,10 +195,23 @@ and .Ev SHELL are set accordingly. Requires adequate superuser privileges. +.It Fl x , Fl -execute-only +Do not supervise the child process when using +.Fl p . +This option is useful to run the given program as another user when +.Xr su 1 +can't be used but a file holding the pid is needed. +The +.Ar child_pidfile +will not be locked and the contents may be silently truncated by +a concurrent daemon(8) invocation. .El .Pp If any of the options -.Fl -child-pidfile , +.Fl -child-pidfile +(without +.Fl -execute-only +), .Fl -output-mask , .Fl -restart , .Fl -restart-delay , diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index 2aa51b539805..da194d526145 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -110,13 +110,14 @@ static int daemon_setup_kqueue(void); static int pidfile_truncate(struct pidfh *); -static const char shortopts[] = "+cfHSp:P:ru:o:M:s:l:t:m:R:T:h"; +static const char shortopts[] = "+cfHSxp:P:ru:o:M:s:l:t:m:R:T:h"; static const struct option longopts[] = { { "change-dir", no_argument, NULL, 'c' }, { "close-fds", no_argument, NULL, 'f' }, { "sighup", no_argument, NULL, 'H' }, { "syslog", no_argument, NULL, 'S' }, + { "execute-only", no_argument, NULL, 'x' }, { "output-file", required_argument, NULL, 'o' }, { "output-file-mode", required_argument, NULL, 'M' }, { "output-mask", required_argument, NULL, 'm' }, @@ -137,7 +138,7 @@ static _Noreturn void usage(int exitcode) { (void)fprintf(stderr, - "usage: daemon [-cfHrS] [-p child_pidfile] [-P supervisor_pidfile]\n" + "usage: daemon [-cfHrSx] [-p child_pidfile] [-P supervisor_pidfile]\n" " [-u user] [-o output_file] [-M output_file_mode] [-t title]\n" " [-l syslog_facility] [-s syslog_priority]\n" " [-T syslog_tag] [-m output_mask] [-R restart_delay_secs]\n" @@ -148,6 +149,7 @@ usage(int exitcode) " --close-fds -f Set stdin, stdout, stderr to /dev/null\n" " --sighup -H Close and re-open output file on SIGHUP\n" " --syslog -S Send output to syslog\n" + " --execute-only -x Do not supervise child process when using -p\n" " --output-file -o Append output of the child process to file\n" " --output-file-mode -M Output file mode of the child process\n" " --output-mask -m What to send to syslog/file\n" @@ -173,6 +175,7 @@ main(int argc, char *argv[]) int ch = 0; mode_t *set = NULL; struct daemon_state state; + bool opt_x = false; daemon_state_init(&state); @@ -183,7 +186,7 @@ main(int argc, char *argv[]) /* * Supervision mode is enabled if one of the following options are used: * --output-file -o - * --child-pidfile -p + * --child-pidfile -p (if --execute-only -x is not given) * --supervisor-pidfile -P * --restart -r / --restart-delay -R * --syslog -S @@ -243,9 +246,14 @@ main(int argc, char *argv[]) free(set); set = NULL; break; + case 'x': + opt_x = true; + break; case 'p': state.child_pidfile = optarg; - state.mode = MODE_SUPERVISE; + /* + * Enable supervision later if no -x was given + */ break; case 'P': state.parent_pidfile = optarg; @@ -302,6 +310,17 @@ main(int argc, char *argv[]) usage(1); } + /* + * Enable supervision for -p if -x was not given + */ + if (state.child_pidfile != NULL) { + if (!opt_x) { + state.mode = MODE_SUPERVISE; + } + } else if (opt_x) { + errx(6, "-x is not allowed without -p"); + } + if (!state.title) { state.title = argv[0]; }