From owner-svn-src-all@freebsd.org Tue Jan 15 15:52:25 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E819D148E5CF; Tue, 15 Jan 2019 15:52:24 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8744F8C3DE; Tue, 15 Jan 2019 15:52:24 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6B1731D054; Tue, 15 Jan 2019 15:52:24 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x0FFqOjH030618; Tue, 15 Jan 2019 15:52:24 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x0FFqOHi030617; Tue, 15 Jan 2019 15:52:24 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201901151552.x0FFqOHi030617@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 15 Jan 2019 15:52:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r343045 - in stable/12: libexec/rc share/man/man8 X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12: libexec/rc share/man/man8 X-SVN-Commit-Revision: 343045 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8744F8C3DE X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-0.999,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2019 15:52:25 -0000 Author: kevans Date: Tue Jan 15 15:52:23 2019 New Revision: 343045 URL: https://svnweb.freebsd.org/changeset/base/343045 Log: MFC r342792, r342805: Provide rc_service variable for rc service scripts r342792: rc.subr: Provide rc_service variable for service scripts Some rc scripts in ports (e.g. uwsgi, apache, openvpn) allow for 'application profiles' that usually require the rc script to be invoked again for each active profile. Because there's no consistent way to determine the path because it differs between manual/service(8) invocations and /etc/rc invocations, this leads to patterns like these: - www/uwsgi hardcodes the script path - security/openvpn guesses either $_file or $0 based on $0 = /etc/rc Instead of forcing rc scripts to guess, provide an rc_service variable to the scripts that gets set appropriately both for direct execution or when a script is being executed via run_rc_script (e.g. /etc/rc). This is our analog of an OpenRC variable with the same name, different case (RC_SERVICE). r342805: rc.subr: Fix typo Originally intended as 'in case in needs to be re-invoked', but it was later decided (by myself) that 're-invoke itself' makes it more clear that the script is expected to use this in a way. PR: 234614 Modified: stable/12/libexec/rc/rc.subr stable/12/share/man/man8/rc.subr.8 Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rc/rc.subr ============================================================================== --- stable/12/libexec/rc/rc.subr Tue Jan 15 15:47:01 2019 (r343044) +++ stable/12/libexec/rc/rc.subr Tue Jan 15 15:52:23 2019 (r343045) @@ -52,6 +52,14 @@ ID="/usr/bin/id" IDCMD="if [ -x $ID ]; then $ID -un; fi" PS="/bin/ps -ww" JID=0 +# rc_service provides the path to the service script that we are executing. +# This is not being set here in an execution context, necessarily, so it's +# really just a reasonable guess, and it will get overwritten later if +# we are executing from some other means than direct execution by service(8) +# or manual invocation of the service script. The prime example of this is +# during system startup, all rc scripts will be invoked via /etc/rc, so +# run_rc_script will overwrite rc_service with the file being sourced. +rc_service="$0" # # functions @@ -867,6 +875,9 @@ check_startmsgs() # by $flags from the environment. # This variable may be changed by the precmd method. # +# rc_service Path to the service being executed, in case the service +# needs to re-invoke itself. +# # rc_pid PID of command (if appropriate) # # rc_fast Not empty if "fast" was provided (q.v.) @@ -1370,6 +1381,7 @@ run_rc_script() required_vars eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd + rc_service="$_file" case "$_file" in /etc/rc.d/*.sh) # no longer allowed in the base warn "Ignoring old-style startup script $_file" Modified: stable/12/share/man/man8/rc.subr.8 ============================================================================== --- stable/12/share/man/man8/rc.subr.8 Tue Jan 15 15:47:01 2019 (r343044) +++ stable/12/share/man/man8/rc.subr.8 Tue Jan 15 15:52:23 2019 (r343045) @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 19, 2018 +.Dd January 15, 2019 .Dt RC.SUBR 8 .Os .Sh NAME @@ -763,7 +763,7 @@ The following variables are available to the methods as well as after .Ic run_rc_command has completed: -.Bl -tag -width ".Va rc_flags" -offset indent +.Bl -tag -width ".Va rc_service" -offset indent .It Va rc_arg Argument provided to .Ic run_rc_command , @@ -777,6 +777,8 @@ unless overridden by the environment variable This variable may be changed by the .Ar argument Ns Va _precmd method. +.It Va rc_service +Path to the service script being executed, in case it needs to re-invoke itself. .It Va rc_pid PID of .Va command