From nobody Fri Mar 3 05:17:29 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 4PSbnj4j1Qz3whPd; Fri, 3 Mar 2023 05:17: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 4PSbnj4CB2z3lnr; Fri, 3 Mar 2023 05:17:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677820649; 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=hmX03zDJ1nrlKla26gHvtNk/0YhIiGBm0skttQzxEW4=; b=ddJ2LRGhy+QiDcNWTZmsAR6zgyf1mNwE/V73VZOoD4b5W6B/dVthJUsfNaU3D65d3jxEUE hfgJH+XTdUoITwwVU2OkE1qxUZAUz5m0Gv0e8X2noNytW25tL4gfJ7mAiJgYYROWSDbB/k GuSFantEj/IRqAYu1eLuyjW7DevYwNdgemOr/NdzFNcYqpGwXFhlTVKfECKd55D0fN/Z00 a9X46l/Bb5SpbiczsDbjOJ6NBgwh1CFyAOG+SUfXTMuGsl/vBiAD8tVNvaWKWoe51TsSj4 yQ4a8BBnGduZbBFlevSJPQjUl95xKMkSns0h+uqT3sk72J2bSPkNanXb6n+hRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677820649; 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=hmX03zDJ1nrlKla26gHvtNk/0YhIiGBm0skttQzxEW4=; b=pqxC6ShPMsUYrwxMOS6cK+czw0ra3Qn3ftIU6TFh7GGFMAFfy7J6zPC0kAmexCRc4MLb1i k1VMSk8vsr1E21hmE9nuYsKo5A0Bi2oUUNBMj1HXEV+jj/xPyUyOZ8yblgO9gkSiiHe/tF dr8u56WFMcY0/ZufyWf00Z05PVznHJWzIVLiCAF1r4Xxg0EWqr5222VY77eSW2eW7PewbL 40yC0gEvCIyuXuFEGRzJxfcP18KtLFf78LXWwgRFPrEM/cgCYGDWgP/HSlUCKIc26pPZm/ bKBV9S/+z2g1vOnxzG7MJSuOznAAAYunb+8ESEWuWSuL6BAp1dzyzsmq9uqNDw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677820649; a=rsa-sha256; cv=none; b=QGhU2ggHhT4/V+MpE59/s2/itVZUjANUXeJIflhJoum/Fof9/c+loSkn0VXQDb6e9yWZV7 MWq9ion+L6vAoFfl3uS6yl9fvj8hZ/7yx3T5RShfYlzilB/GbkvptDlOr3/NrD1GJ9fmYj A2SRGAKpqj6TOLSsnjosKMgt3S4LGxDs9Ni6j4B7a4CR/cmJHBQSZrYTZp+qe18Z3v5Kuf lF8w4sBajTveDN/xQMBJ1MlqhhCCHGyGGinEukUpZvNaLVwre3XApBz8aNd8GjArz2E1RL uYwXAw8JHn/1Z8nre5ScKoPpVAvxBiZ887ATK4y0y/TEUn1qU0To+N8LVNodZg== 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 4PSbnj3FKtzlhY; Fri, 3 Mar 2023 05:17:29 +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 3235HThm019721; Fri, 3 Mar 2023 05:17:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3235HTWd019720; Fri, 3 Mar 2023 05:17:29 GMT (envelope-from git) Date: Fri, 3 Mar 2023 05:17:29 GMT Message-Id: <202303030517.3235HTWd019720@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: f907027b49d9 - main - daemon: set supervise_enabled during argument processing 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: f907027b49d93170ed2e92cf0d183cd643b1f70e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=f907027b49d93170ed2e92cf0d183cd643b1f70e commit f907027b49d93170ed2e92cf0d183cd643b1f70e Author: Ihor Antonov AuthorDate: 2023-03-03 05:17:02 +0000 Commit: Kyle Evans CommitDate: 2023-03-03 05:17:02 +0000 daemon: set supervise_enabled during argument processing Now when supervsion mode has it's own variable there is really no reason to set it separately from the rest of the variables. Move initialization of supervise_enabled var to the argument processing switch loop, where it belongs. Reviewed by: kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/672 --- usr.sbin/daemon/daemon.c | 54 +++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index 08ae5c74b8c2..3bbf092b500c 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -179,6 +179,23 @@ main(int argc, char *argv[]) sigemptyset(&mask_term); sigemptyset(&mask_orig); + /* + * 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. + */ while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (ch) { case 'c': @@ -197,6 +214,7 @@ main(int argc, char *argv[]) errx(5, "unrecognized syslog facility"); } logparams.syslog_enabled = true; + supervision_enabled = true; break; case 'm': stdmask = strtol(optarg, &p, 10); @@ -206,15 +224,25 @@ main(int argc, char *argv[]) break; case 'o': logparams.output_filename = optarg; + /* + * TODO: setting output filename doesn't have to turn + * the supervision mode on. For non-supervised mode + * daemon could open the specified file and set it's + * descriptor as both stderr and stout before execve() + */ + supervision_enabled = true; break; case 'p': child_pidfile = optarg; + supervision_enabled = true; break; case 'P': parent_pidfile = optarg; + supervision_enabled = true; break; case 'r': restart_enabled = true; + supervision_enabled = true; break; case 'R': restart_enabled = true; @@ -230,9 +258,11 @@ main(int argc, char *argv[]) errx(4, "unrecognized syslog priority"); } logparams.syslog_enabled = true; + supervision_enabled = true; break; case 'S': logparams.syslog_enabled = true; + supervision_enabled = true; break; case 't': title = optarg; @@ -240,6 +270,7 @@ main(int argc, char *argv[]) case 'T': logparams.syslog_tag = optarg; logparams.syslog_enabled = true; + supervision_enabled = true; break; case 'u': user = optarg; @@ -286,29 +317,6 @@ main(int argc, char *argv[]) /* Write out parent pidfile if needed. */ pidfile_write(parent_pidfh); - /* - * 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. - */ - supervision_enabled = child_pidfile != NULL || - parent_pidfile != NULL || - restart_enabled == true || - logparams.output_fd != -1 || - logparams.syslog_enabled == true; - if (supervision_enabled) { struct sigaction act_term = { 0 }; struct sigaction act_chld = { 0 };