From nobody Fri Mar 17 21:01:28 2023 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 4Pdc4T2xf6z3yqsR; Fri, 17 Mar 2023 21:01:29 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pdc4S5sdNz3py8; Fri, 17 Mar 2023 21:01:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086888; 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=9WEjex8I5tpI4Yyl2DkZvlgR/c8od9wZ+NhvHqHF0bc=; b=oI2uhhMb8uDC+MaRgRX5rCkI29oi2rwzbLOBHAbEBozba0u9uaQwLhIPY3LORccgxQYbem saDvdgBmFYKvGpDVIpkJ/Y49QysTq8S8vVfwChZGp4ln0p2SiU3LL4Ikhr27e1NA3Cm3Jk xdoBrlZUCigxNJtl2LYRd0UmpIQsxUt30vvdu0mLnjbd/ikbrfHo7gl8V4YoPan1PfM4Hm BG98KFCmz2rpIkTc/fTed0euzCtatnKo3be4y8SIHm6yoUFtEu54InzDENQNYjOPE/z2Sy Q9eN4mFAIq33yu6XHhnBtbOrDfmTM41LmxOxFAKpe9yN8x2CObfwdDfwgPrAHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086888; 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=9WEjex8I5tpI4Yyl2DkZvlgR/c8od9wZ+NhvHqHF0bc=; b=e0cMCYeh9bNRcJ5VvHAZSO/za7LtFiYF7KtGaKnEfDJooz39Bcg0b4tBEZQ76B2sT0za7q DK0GUbhTmeRlflWQrtBJYBidaYxYZWa1ausHg2p7c5gxkS36nvnRBDKFFq8I1nrRHdwf+h +yVCopp6oIDLbjgMBzpMxLtT9vbmimdIvAGWDt3m+Ih+A8Ga9Jzot6b9/fnXCAdR3WJdPf Tgg/5ELfIPyBWWLaKzijwtAdDN9biXRPREi9vTGw1GmVOGda8uabLCLNgA2hGWHMMs66yM qUICIYTEX3cXBRwwd7PBMz9NOhdYy8ex5uD92ZYaM/mb6q/8afVAnx/rc4NS8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679086888; a=rsa-sha256; cv=none; b=aMS4qCg1YZ2aVKpNCs7gWqKUNefxi+Ahh+jt02FZeJwlxXw4DXnYCywMbSALkn9lf2K6xy AjDR2QZ9aozZfAX0XUOJIkaZtJibc6mT/3LENA8KaRx+9Xobzq2WqQco31U89URpOINwf3 ioSCAlRxiOX2B1dI2bdgTmKsEOO805kLw4FoSKrri1M8523VjkBae869g6buyMD9QC+3ik m+8AjDitAfmb/oXECOg82iPsx0lbdQIhxAqyE+VZiD1C7LBVGouCbj+653u8tpTmuuEj3n m7UGxuAkzx+3+r4v8WsaS3jVS8hihn4bwi/1jo3nFwvWDrohe/rgUxBUH/7Vsg== 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 4Pdc4S4ztdzgrv; Fri, 17 Mar 2023 21:01:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32HL1SkJ015055; Fri, 17 Mar 2023 21:01:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HL1SAD015054; Fri, 17 Mar 2023 21:01:28 GMT (envelope-from git) Date: Fri, 17 Mar 2023 21:01:28 GMT Message-Id: <202303172101.32HL1SAD015054@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 6f71a684560f - stable/13 - daemon: add supervision_enabled var 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 6f71a684560f77086932cfd1403528b212969ddd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=6f71a684560f77086932cfd1403528b212969ddd commit 6f71a684560f77086932cfd1403528b212969ddd Author: Ihor Antonov AuthorDate: 2023-03-02 03:00:42 +0000 Commit: Kyle Evans CommitDate: 2023-03-17 21:01:01 +0000 daemon: add supervision_enabled var explicitly name a bunch of boolean checks that enable supervison mode and improve comments Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/669 (cherry picked from commit 203df05b692b5e2b92c990d8971f5797e3a7a139) --- usr.sbin/daemon/daemon.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index 0925d16a27a0..f15a3f567a8c 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -141,6 +142,7 @@ usage(int exitcode) int main(int argc, char *argv[]) { + bool supervision_enabled = false; char *p = NULL; const char *pidfile = NULL; const char *logtag = "daemon"; @@ -275,18 +277,31 @@ main(int argc, char *argv[]) } /* Write out parent pidfile if needed. */ pidfile_write(ppfh); + /* - * If the pidfile or restart option is specified the daemon - * executes the command in a forked process and wait on child - * exit to remove the pidfile or restart the command. Normally - * we don't want the monitoring daemon to be terminated - * leaving the running process and the stale pidfile, so we - * catch SIGTERM and forward it to the children expecting to - * get SIGCHLD eventually. We also must fork() to obtain a - * readable pipe with the child for writing to a log file - * and syslog. + * Supervision mode is enabled if one of the following options are used: + * --child-pidfile -p + * --supervisor-pidfile -P + * --restart -r / --restart-delay -R + * --syslog -S + * --syslog-facility -l + * --syslog-priority -s + * --syslog-tag -T + * + * In supervision mode daemon executes the command in a forked process + * and observes the child by waiting for SIGCHILD. In supervision mode + * daemon must never exit before the child, this is necessary to prevent + * orphaning the child and leaving a stale pid file. + * To achieve this daemon catches SIGTERM and + * forwards it to the child, expecting to get SIGCHLD eventually. */ - if (pidfile || ppidfile || restart || outfd != -1 || dosyslog) { + supervision_enabled = pidfile != NULL || + ppidfile != NULL || + restart != 0 || + outfd != -1 || + dosyslog != 0; + + if (supervision_enabled) { struct sigaction act_term = { 0 }; struct sigaction act_chld = { 0 }; struct sigaction act_hup = { 0 };