diff options
author | 2010-12-24 10:37:24 +0000 | |
---|---|---|
committer | 2010-12-24 10:37:24 +0000 | |
commit | b644115bf63f6712aa271a13a71cdbca9a986643 (patch) | |
tree | 1bc51264442dde8398b729be076b2f048d08d9d7 | |
parent | now that pkg_create checks more stuff, we have to ask for it to create (diff) | |
download | wireguard-openbsd-b644115bf63f6712aa271a13a71cdbca9a986643.tar.xz wireguard-openbsd-b644115bf63f6712aa271a13a71cdbca9a986643.zip |
Fix a flaw in the rc.subr framework reported by stephan@ where
local_rcconf would get overwritten by flags from the rc script itself.
Based on an original idea and diff from robert@, create an rc_conf
function that we add in the rc_script after the defaults daemon*
variables.
This way we can use defaults variables names in other part of the script
(when defining a specific pexp for instance).
While here, simplify setting up the default daemon variables so that we
don't need to do any substitution in rc_start.
rc scripts must include daemon variables before calling rc_conf. All
other locally modified variables (pexp, rc_reload, local additions...)
must come after.
feedback from and works for sthen@
ok robert@
-rw-r--r-- | etc/rc.d/rc.subr | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index c98bb2ae178..cab274d6406 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.14 2010/12/13 16:06:45 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.15 2010/12/24 10:37:24 ajacoutot Exp $ [ -z "${local_rcconf}" ] && . /etc/rc.conf @@ -9,8 +9,8 @@ rc_err() { rc_start() { type rc_pre >/dev/null && rc_pre - su -l -c ${daemon_class:-daemon} -s ${daemon_shell:-/bin/sh} \ - ${daemon_user:-root} -c "${daemon} ${daemon_flags}" >/dev/null + su -l -c ${daemon_class} -s ${daemon_shell} ${daemon_user} \ + -c "${daemon} ${daemon_flags}" >/dev/null } rc_check() { @@ -26,26 +26,35 @@ rc_stop() { type rc_post >/dev/null && rc_post || return 0 } -rc_cmd() { - _name=`basename $0` +rc_conf() { + [ -n "${daemon}" ] || rc_err "$0: daemon is not set" - eval _enotsup=\${rc_${1}} + _name=`basename $0` eval _rcflags=\${${_name}_flags} eval _rcuser=\${${_name}_user} eval _rcclass=\${${_name}_class} eval _rcshell=\${${_name}_shell} - [ X"${_enotsup}" != X"NO" ] || rc_err "$0: $1 is not supported" - [ `id -u` -eq 0 -o X"$1" = "Xcheck" ] || \ - rc_err "$0: need root privileges" - [ -n "${daemon}" ] || rc_err "$0: daemon is not set" + [ -z "${daemon_class}" ] && daemon_class=daemon + [ -z "${daemon_shell}" ] && daemon_shell=/bin/sh + [ -z "${daemon_user}" ] && daemon_user=root + [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} - [ -n "${_rcflags}" ] && daemon_flags=`echo ${_rcflags} | tr -s "[:space:]"` [ -n "${_rcuser}" ] && daemon_user=${_rcuser} [ -n "${_rcclass}" ] && daemon_class=${_rcclass} [ -n "${_rcshell}" ] && daemon_shell=${_rcshell} - [ -n "${pexp}" ] || \ - pexp="${daemon}${daemon_flags:+ ${daemon_flags}}" + + daemon_flags=`echo ${daemon_flags} | tr -s "[:space:]"` + + pexp="${daemon}${daemon_flags:+ ${daemon_flags}}" +} + +rc_cmd() { + [ `id -u` -eq 0 -o X"$1" = "Xcheck" ] || \ + rc_err "$0: need root privileges" + + eval _enotsup=\${rc_${1}} + [ X"${_enotsup}" != X"NO" ] || rc_err "$0: $1 is not supported" case "$1" in check) |