From nobody Sun Jun 02 19:29:41 2024 X-Original-To: dev-commits-src-main@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 4Vsn4564wfz5Jp3S; Sun, 02 Jun 2024 19:29:41 +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 4Vsn455ZWVz4bJB; Sun, 2 Jun 2024 19:29:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717356581; 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=hP2LvK3/7QUNy9/RZWvInAxF5AfyiDRnHENddPBTBwE=; b=IUGUbdGnkFjelIJ9mm5WD1/PJkuPCwvb1CDTnK+todh0BeiKMg9YLYwzmXEhkLxkBFcxOP kBzVW3aeDzm4rZOwWqWVbSQSb/YRIFduTqa9huaMIDo6AzlVnFF3/botn6XH4HUz3YuqkK uqHkLU6vnHCzM/Hn6TAZ2xNRERpyjBmRmeF13pyRQKBCmeJ6hAdcPvFGMYSCMT7DCt7kPU mOh5h/YGc5UiIdtb3q4NT70A6JK4kvfPJIgjGGsjGCd9Uvt8QHLxbzhSsSu8KWRIlJA87o UiBYfTStydO24ChL75SmenoaP6RvWrT9+8pbEGqvRWqwr2ein58IXiW4zqTNUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717356581; a=rsa-sha256; cv=none; b=jJ0cZcv+hVQ7/JbtWdPYWoXrr0QoR2yhcxHD7XZtbxp+wXi3qaPPIIjbD9gH4d4MOzYU5z zUMIMOruAdnVClUB2pVkJB5ujKOxMVb4filb1pzjdaNdO8wo1LxXbTtZXr6/C6a7YuvdWg RrkXlB+JP2Y2g1VFHgxBLMN2+tbGIPO3oeBIVxD9ZllCFiN/ZeV8OqsXXyAShqjm6gFOuw keLYgBKKdbp0qLg1ZABShbVFzZl/7ImkuIxeW2ykS0u89TYFwic4sbXfKr2Z/t+KnA8toi wSP3T2wUZir2gL198ueW6Vh/vS2qMH9JsnHwrWrPRf2Ub+gWKYVQ5VKvvSqsNQ== 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=1717356581; 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=hP2LvK3/7QUNy9/RZWvInAxF5AfyiDRnHENddPBTBwE=; b=ttazMhzTJBN7SXhPdXJJVaqWooGTQDYVmeRrP0EEPMpi862NDVdPAk+BYckQBymGS5JFmA MbIPasaObWpuqvd2WvrHkD6uNgXEPuD9I/k9YprKm3d98lwJs/ERTlUzaEm76JNzs3dWHr RDq6arTNh9lr35EldETPofjcbf7ai3DyPWNOVfWl5ofLn6oCLTeaJnqcJWCTDS/u3qrw6l fpfaU2373j2xkY4LBEGfww9oK/pXQSVfij4s4JvGecTqi6k5k/NvIQW6m2HSO01+1ayr3A Do91jxdD5DDQJ2pVMht4DfPAag4lvPo/pOHHq3+UKs3gzTaoqdq/x9Jf2wvtGA== 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 4Vsn455B5bz143M; Sun, 2 Jun 2024 19:29:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 452JTfcI015754; Sun, 2 Jun 2024 19:29:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 452JTfce015751; Sun, 2 Jun 2024 19:29:41 GMT (envelope-from git) Date: Sun, 2 Jun 2024 19:29:41 GMT Message-Id: <202406021929.452JTfce015751@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eugene Grosbein Subject: git: 32a579e4fc69 - main - rc.subr(8): introduce ${name}_offcmd List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 32a579e4fc69a65e8901111ad5f65ec56a97dfab Auto-Submitted: auto-generated The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=32a579e4fc69a65e8901111ad5f65ec56a97dfab commit 32a579e4fc69a65e8901111ad5f65ec56a97dfab Author: Eugene Grosbein AuthorDate: 2024-06-02 19:13:42 +0000 Commit: Eugene Grosbein CommitDate: 2024-06-02 19:29:22 +0000 rc.subr(8): introduce ${name}_offcmd New variable ${name}_offcmd may be used to supply commands executed if named service is not enabled. Previously start_precmd could be used for such a task but now rc.subr(8) does not call it if a service is not enabled. Fix devd startup script to use it instead of start_precmd. PR: 279198 MFC after: 2 weeks Reported by: Dmitry S. Lukhtionov Tested by: Dmitry S. Lukhtionov --- libexec/rc/rc.d/devd | 7 +++---- libexec/rc/rc.subr | 25 +++++++++++++++++++++---- share/man/man8/rc.subr.8 | 4 +++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/libexec/rc/rc.d/devd b/libexec/rc/rc.d/devd index 47326662339c..98f2068c2075 100755 --- a/libexec/rc/rc.d/devd +++ b/libexec/rc/rc.d/devd @@ -14,7 +14,8 @@ desc="Device state change daemon" rcvar="devd_enable" command="/sbin/${name}" -start_precmd=${name}_prestart +devd_offcmd=devd_off +start_precmd=find_pidfile stop_precmd=find_pidfile find_pidfile() @@ -26,10 +27,8 @@ find_pidfile() fi } -devd_prestart() +devd_off() { - find_pidfile - # If devd is disabled, turn it off in the kernel to avoid unnecessary # memory usage. if ! checkyesno ${rcvar}; then diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 2fd4796b569f..9eead30790e2 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -982,6 +982,8 @@ startmsg() # # ${name}_limits n limits(1) to apply to ${command}. # +# ${name}_offcmd n If set, run if a service is not enabled. +# # ${rc_arg}_cmd n If set, use this as the method when invoked; # Otherwise, use default command (see below) # @@ -1270,13 +1272,13 @@ run_rc_command() -a "$rc_arg" != "describe" -a "$rc_arg" != "status" ] || [ -n "${rcvar}" -a "$rc_arg" = "stop" -a -z "${rc_pid}" ]; then if ! checkyesno ${rcvar}; then - if [ -n "${rc_quiet}" ]; then - return 0 - fi + [ "$rc_arg" = "start" ] && _run_rc_offcmd + if [ -z "${rc_quiet}" ]; then echo -n "Cannot '${rc_arg}' $name. Set ${rcvar} to " echo -n "YES in /etc/rc.conf or use 'one${rc_arg}' " echo "instead of '${rc_arg}'." - return 0 + fi + return 0 fi fi @@ -1643,11 +1645,26 @@ $_cpusetcmd $command $rc_flags $command_args" # # name R/W # ------------------ +# _offcmd R # _precmd R # _postcmd R # _return W # _setup R # +_run_rc_offcmd() +{ + eval _offcmd=\$${name}_offcmd + if [ -n "$_offcmd" ]; then + if [ -n "$_env" ]; then + eval "export -- $_env" + fi + debug "run_rc_command: ${rc_arg}_offcmd: $_offcmd $rc_extra_args" + eval "$_offcmd $rc_extra_args" + _return=$? + fi + return 0 +} + _run_rc_precmd() { check_required_before "$rc_arg" || return 1 diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 8f7b72e96dc5..4e3fa6771bf4 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 28, 2024 +.Dd June 2, 2024 .Dt RC.SUBR 8 .Os .Sh NAME @@ -773,6 +773,8 @@ Login class to use with .Va ${name}_limits . Defaults to .Dq Li daemon . +.It Va ${name}_offcmd +Shell commands to run if a service is not enabled. .It Va ${name}_oomprotect .Xr protect 1 .Va command