diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2022-05-26 11:27:04 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2022-05-26 11:27:04 +0000 |
commit | 93f186935230f0ed853871a30a3246fdb8227464 (patch) | |
tree | fb05b46e24079a221657cb3c9ae1f9e3c0a53ae5 /etc/rc.d | |
parent | 2162d4812fc64d9f6e4de1933f0653465af7329a (diff) |
Introduce a new daemon_execdir variable for changing to a specified directory
before running rc_rcexec.
Based on an proposal from openbsd.tech at aisha.cc
ok robert@ abieber@
Diffstat (limited to 'etc/rc.d')
-rw-r--r-- | etc/rc.d/amd | 7 | ||||
-rw-r--r-- | etc/rc.d/rc.subr | 20 |
2 files changed, 16 insertions, 11 deletions
diff --git a/etc/rc.d/amd b/etc/rc.d/amd index dbfb3d92503..39df91c26dd 100644 --- a/etc/rc.d/amd +++ b/etc/rc.d/amd @@ -1,8 +1,9 @@ #!/bin/ksh # -# $OpenBSD: amd,v 1.10 2022/05/21 12:42:21 ajacoutot Exp $ +# $OpenBSD: amd,v 1.11 2022/05/26 11:27:03 ajacoutot Exp $ daemon="/usr/sbin/amd" +daemon_execdir="/etc/amd" . /etc/rc.d/rc.subr @@ -15,8 +16,4 @@ rc_pre() { daemon_flags="${daemon_flags} $(print -rn -- $(< ${amd_master}))" } -rc_start() { - rc_exec "cd /etc/amd; ${daemon} ${daemon_flags}" -} - rc_cmd $1 diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index 3ad058c56cd..ef2b6d6f49b 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -1,6 +1,6 @@ -# $OpenBSD: rc.subr,v 1.153 2022/05/21 10:50:09 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.154 2022/05/26 11:27:03 ajacoutot Exp $ # -# Copyright (c) 2010, 2011, 2014-2021 Antoine Jacoutot <ajacoutot@openbsd.org> +# Copyright (c) 2010, 2011, 2014-2022 Antoine Jacoutot <ajacoutot@openbsd.org> # Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> # Copyright (c) 2010, 2011, 2014 Robert Nagy <robert@openbsd.org> # @@ -49,7 +49,7 @@ _rc_parse_conf() { while IFS=' ' read -r _l; do [[ $_l == [!#=]*=* ]] || continue _key=${_l%%*([[:blank:]])=*} - [[ $_key == *_@(flags|logger|rtable|timeout|user) ]] || + [[ $_key == *_@(execdir|flags|logger|rtable|timeout|user) ]] || [[ " ${_allowed_keys[*]} " == *" $_key "* ]] || continue [[ $_key == "" ]] && continue @@ -114,14 +114,17 @@ _rc_write_runfile() { [ -d ${_RC_RUNDIR} ] || mkdir -p ${_RC_RUNDIR} && cat >${_RC_RUNFILE} <<EOF daemon_class=${daemon_class} +daemon_execdir=${daemon_execdir} daemon_flags=${daemon_flags} daemon_logger=${daemon_logger} daemon_rtable=${daemon_rtable} daemon_timeout=${daemon_timeout} daemon_user=${daemon_user} pexp=${pexp} +rc_reload=${rc_reload} rc_reload_signal=${rc_reload_signal} rc_stop_signal=${rc_stop_signal} +rc_usercheck=${rc_usercheck} EOF } @@ -164,8 +167,11 @@ rc_exec() { [ "${daemon_rtable}" -eq "$(id -R)" ] || _rcexec="route -T ${daemon_rtable} exec ${_rcexec}" - ${_rcexec} "${daemon_logger:+set -o pipefail; }$@${daemon_logger:+ 2>&1 | - logger -ip ${daemon_logger} -t ${_name}}" + ${_rcexec} "${daemon_logger:+set -o pipefail; } \ + ${daemon_execdir:+cd ${daemon_execdir} && } \ + $@ \ + ${daemon_logger:+ 2>&1 | + logger -ip ${daemon_logger} -t ${_name}}" } rc_start() { @@ -317,6 +323,7 @@ _rc_do _rc_parse_conf rc_reload_signal=${rc_reload_signal:=HUP} rc_stop_signal=${rc_stop_signal:=TERM} +eval _rcexecdir=\${${_name}_execdir} eval _rcflags=\${${_name}_flags} eval _rclogger=\${${_name}_logger} eval _rcrtable=\${${_name}_rtable} @@ -334,6 +341,7 @@ getcap -f /etc/login.conf.d/${_name}:/etc/login.conf ${_name} 1>/dev/null 2>&1 & [ -n "${_RC_FORCE}" -o "$1" != "start" ] && [ X"${_rcflags}" = X"NO" ] && unset _rcflags +[ -n "${_rcexecdir}" ] && daemon_execdir=${_rcexecdir} [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} [ -n "${_rclogger}" ] && daemon_logger=${_rclogger} [ -n "${_rcrtable}" ] && daemon_rtable=${_rcrtable} @@ -347,7 +355,7 @@ if [ -n "${_RC_DEBUG}" ]; then fi readonly daemon_class -unset _rcflags _rclogger _rcrtable _rctimeout _rcuser +unset _rcexecdir _rcflags _rclogger _rcrtable _rctimeout _rcuser # the shell will strip the quotes from daemon_flags when starting a daemon; # make sure pexp matches the process (i.e. doesn't include the quotes) pexp="$(eval echo ${daemon}${daemon_flags:+ ${daemon_flags}})" |