From 4743ad5dc740ba3ca439979b7af6594806622028 Mon Sep 17 00:00:00 2001 From: Mateusz Piotrowski <0mp@FreeBSD.org> Date: Tue, 10 Nov 2020 10:19:55 +0000 Subject: [PATCH] MFC r351863: rc: Honor ${name}_env when a custom *_cmd is defined (e.g., start_cmd) A user may set ${name}_env variable in rc.conf(5) in order to set additional environment variables for a service command. Unfortunately, at the moment this variable is only honored when the command is specified via the command variable. Those additional environment variables coming from ${name}_env are never set if the service is started via the ${rc_arg}_cmd variable (for example start_cmd). PR: 239692 Reviewed by: bcr, jilles Approved by: src (jilles) Requested by: koobs --- libexec/rc/rc.subr | 3 +++ share/man/man8/rc.subr.8 | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 89bda1c1488..d2a980e94ab 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -1024,6 +1024,9 @@ run_rc_command() _postcmd=\$${rc_arg}_postcmd if [ -n "$_cmd" ]; then + if [ -n "$_env" ]; then + eval "export -- $_env" + fi _run_rc_precmd || return 1 _run_rc_doit "$_cmd $rc_extra_args" || return 1 _run_rc_postcmd diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index d3cfedf7dc0..e96341b3e3f 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -556,9 +556,19 @@ is mounted. A list of environment variables to run .Va command with. -This will be passed as arguments to the +Those variables will be passed as arguments to the .Xr env 1 -utility. +utility unless +.Ar argument Ns Va _cmd +is defined. +In that case the contents of +.Va ${name}_env +will be exported via the +.Xr export 1 +builtin of +.Xr sh 1 , +which puts some limitations on the names of variables +(e.g., a variable name may not start with a digit). .It Va ${name}_env_file A file to source for environmental variables to run .Va command -- 2.45.0