From nobody Thu Mar 2 03:01:04 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 4PRwpn28qgz3vjpR; Thu, 2 Mar 2023 03:01:05 +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 4PRwpm4g4Tz44VJ; Thu, 2 Mar 2023 03:01:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677726064; 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=Nt7Ayo2Z/wDQOx/m7wT6vWC18nApKzChSPnXZsAFJX4=; b=UywZ3PHPFxBiQSXEEmn/hjW+5nidAO2jk1Um0U+9g1ianG7egpPB7dRdlEMAQcISD9HTZb nOLS4B2dHpHtEOWLgi/prAffEtdcyjEs2msw9J7CjRYxG0ZIH4by0yCaIGmbrOytkVumSv 7MlUpf/A83DmfioKm0FY2lqq+IpkbaAsD7R7xhGhPqNzwRTGRjY1ODxUp823tn2aHMB25j gxCj6REZUZOSYKOsKRED16S6H5fGBrlBnqVLbCY9NCdZoer5r4AtEaAtw+PGy2O2cS5gKU mvNqAkMCFe627zK6M0dAa5auOb24GRQuhu8o63gnQkzl77Z/YFdpSqIzNZFPVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677726064; 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=Nt7Ayo2Z/wDQOx/m7wT6vWC18nApKzChSPnXZsAFJX4=; b=Y1k0xieMcI8IZs4xB8ymesuYRWFncgOeEMs1I3z5EWFpFgI8TfRkinE4B06Mu7SqgvreN6 vZ9EoVlMjt+AzrXww5zeOhurJiSp5a8fp5yMBwQ0kZ9z0lsB/MbnI+JSriGkU1FgvkYk6G dwMxuOD8JuESvm2jHMq8Nej6GiH4zKeZUDvK+M1r7VB93u8n/KKScEp9EJF0s0iZAd5Eu5 PSJKIP9hP9KinKNKjBJXLOLUE8Y7MdEsFBD7PmX0NboDErrkdA/3Wc3bziHpYLjBayiUo1 R4sfozYniujK6WkkCq4QVSILuNPfGMHsP2oZVabzp1TkIA4Fc7MtrVNdtkmUIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677726064; a=rsa-sha256; cv=none; b=MHNNGzfkSdMIGwHbnnbCoQlNFVHjLQsucPcbnTrvO/luQ3XZTdmrCNIZm3i8/NbCdFpT1b wimKzLB4yLOw9vo92yQ4XSlASGj2OF+SrjC/j/+aWbuKHJvC2DC+K+ighaxvw1EwCJaHal 7fV8F51lEWU0+4SE6ag8Zu8pzvRQTfiqBQ3w00bOCVucliXPwtaSSH3qxLWxE4NGSkJwi7 5C5WJsgv0quoPaUKdgn11UoTIxpOTb8rvDOanB942Q5SEQB60cgECOkP0llDShm1c22zoh PNZvIaWe7/EkhnpcLmexbE7qVlTdEkwx0o+3EUfRcXpTgZLFDPE7X501DWIFxA== 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 4PRwpm3m48zyxl; Thu, 2 Mar 2023 03:01:04 +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 322314WJ034079; Thu, 2 Mar 2023 03:01:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 322314IV034078; Thu, 2 Mar 2023 03:01:04 GMT (envelope-from git) Date: Thu, 2 Mar 2023 03:01:04 GMT Message-Id: <202303020301.322314IV034078@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: 203df05b692b - main - 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/main X-Git-Reftype: branch X-Git-Commit: 203df05b692b5e2b92c990d8971f5797e3a7a139 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=203df05b692b5e2b92c990d8971f5797e3a7a139 commit 203df05b692b5e2b92c990d8971f5797e3a7a139 Author: Ihor Antonov AuthorDate: 2023-03-02 03:00:42 +0000 Commit: Kyle Evans CommitDate: 2023-03-02 03:00:42 +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 --- 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 };