diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 6688438360f9..c1f0469ba114 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -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 @@ -879,6 +887,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 it needs to +# re-invoked. +# # rc_pid PID of command (if appropriate) # # rc_fast Not empty if "fast" was provided (q.v.) @@ -1382,6 +1393,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" diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 09a9ed6d4871..e039d148744d 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -29,7 +29,7 @@ .\" .\" $FreeBSD$ .\" -.Dd November 7, 2018 +.Dd January 5, 2019 .Dt RC.SUBR 8 .Os .Sh NAME @@ -771,7 +771,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 , @@ -785,6 +785,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