From nobody Fri Mar 17 21:01:42 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 4Pdc4k3wSSz3yqrl; Fri, 17 Mar 2023 21:01:42 +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 4Pdc4k36CDz3qcJ; Fri, 17 Mar 2023 21:01:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086902; 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=fX2RsK0sdXN8orOy04SJ2IhxRmwyBeCcEtKPAg5aNuw=; b=EPX+14EeMRAtm6zoVLq+pX0fAwYOBUV0m74LJsndkH0/O4Y+VQpYgYWZ+MX3pSHRIxdTmA EAvp04dzfJgKwtyLP9n6ypn1VqhSDFsFl8/JE09Lmf+On/o6ZXYo4cyBeiDMzc69CLUpIn llURS3JnQS2xbvWTqgIYmwS2KuGU1+ssh6qHVQP32HYxz/Q1jbEj+IjhYzrBQhiUOmVjZz rXq5w0flh/GxspF8VgL7/LUuc8R1NtifcIY0SAgbQgPl9jLEdU1s2c7ymBZW4mEjUWyVyU +zdKrzO6WB2LaGGP/CFULzMh5ItPIiFnS47P5UF/Ms46flu1w0SeWt3Oc/paJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679086902; 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=fX2RsK0sdXN8orOy04SJ2IhxRmwyBeCcEtKPAg5aNuw=; b=mhvew+FNwOJdozGoY8a7btOCa+iDRWuVRYF0+naeHNtxaoBj2jR78HzfK2AKNT9i6oOTJI gXaDsxYgopZwC/EPODBteL/DCljD4NMiC/HnMFXLZ7YHIO3p51VnYo/j8KOx0jGDESpKxS QllgCoWUiOmnB5+SgnTfYsEzUFh9eCgUYxJItfJAe+rRDf3rXaM3dkOBYwfBff6b1YPYpd F2XcG/9E/6jGkufUay33lL+GsB1ytyaWQ2PPuY88ZKV18QqhkCnUvYffvU7MW6cmRHc+Wx /dR6k/2qXqMyrJ6eHoaIjMXRjz2+9tjSRHUxYxvCqEfhMHK/XxpX9aJdOZmkMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679086902; a=rsa-sha256; cv=none; b=J/1GHsxD0eqjQTag15XtnGrOVitLuJ5f6Pu5DIE7/HUwpJ/eN986UAzFvz++vYRa1U7nqu MXoYhJ8zU71uLcfcPbcUOSotTzmvgkU/Cj9M0ZJlW3xftMiHnlmDAWfAFboSTbUnYTZMuu vxqFZsiT/ZI/N4lsC8iBTnU+gmvVUpNLrca3XHMwGnhXD//pBEvG81dDqlMw10t9vq4TPQ EfT7foegA54mHUGE/NOR63qvm8Z33esk6+LEx8RoFLnqdNkRHfCjHt3BImDiRfLh+ZtuiR l6NBcycHNjwd552o+/xYrGkrWmANKCTpW24LZdTsT6JO5YqjOZd79mtKSCoY7w== 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 4Pdc4k2CKfzgcy; Fri, 17 Mar 2023 21:01:42 +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 32HL1gUH015309; Fri, 17 Mar 2023 21:01:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32HL1gd0015308; Fri, 17 Mar 2023 21:01:42 GMT (envelope-from git) Date: Fri, 17 Mar 2023 21:01:42 GMT Message-Id: <202303172101.32HL1gd0015308@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: 799d67ec407f - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 799d67ec407f6d93b00b7d8a364a3284aeb5d07f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=799d67ec407f6d93b00b7d8a364a3284aeb5d07f commit 799d67ec407f6d93b00b7d8a364a3284aeb5d07f Author: Ihor Antonov AuthorDate: 2023-03-03 05:17:02 +0000 Commit: Kyle Evans CommitDate: 2023-03-17 21:01:03 +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 (cherry picked from commit f907027b49d93170ed2e92cf0d183cd643b1f70e) --- 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 };