before running rc_rcexec.
Based on an proposal from openbsd.tech at aisha.cc
ok robert@ abieber@
#!/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
daemon_flags="${daemon_flags} $(print -rn -- $(< ${amd_master}))"
}
-rc_start() {
- rc_exec "cd /etc/amd; ${daemon} ${daemon_flags}"
-}
-
rc_cmd $1
-# $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>
#
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
[ -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
}
[ "${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() {
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}
[ -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}
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}})"
-.\" $OpenBSD: rc.d.8,v 1.37 2021/11/09 11:43:47 kn Exp $
+.\" $OpenBSD: rc.d.8,v 1.38 2022/05/26 11:27:03 ajacoutot Exp $
.\"
.\" Copyright (c) 2021 Antoine Jacoutot
.\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: November 9 2021 $
+.Dd $Mdocdate: May 26 2022 $
.Dt RC.D 8
.Os
.Sh NAME
The following can be overridden by site-specific values provided in
.Xr rc.conf.local 8 :
.Bl -tag -width daemon_timeout -offset indent
+.It Ar daemon Ns _execdir
+Run daemon from the specified directory.
.It Ar daemon Ns _flags
Additional arguments to call the daemon with.
These will be appended to any mandatory arguments already contained in the
-.\" $OpenBSD: rc.subr.8,v 1.43 2022/05/21 14:11:39 ajacoutot Exp $
+.\" $OpenBSD: rc.subr.8,v 1.44 2022/05/26 11:27:03 ajacoutot Exp $
.\"
.\" Copyright (c) 2021 Antoine Jacoutot
.\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 21 2022 $
+.Dd $Mdocdate: May 26 2022 $
.Dt RC.SUBR 8
.Os
.Sh NAME
.Ic rc_reload .
.El
.It Ic rc_exec
-Execute process using
+Execute argument using
.Xr su 1
according to
.Va daemon_class ,
+.Va daemon_execdir ,
.Va daemon_user ,
.Va daemon_rtable
and
If no such login class exists then
.Dq daemon
will be used.
+.It Va daemon_execdir
+Change to this directory before running
+.Ic rc_exec .
.It Va daemon_flags
Arguments to call the daemon with.
.It Ar daemon Ns _logger
script, if the
.Cm check
action needs root privileges.
+.El
.Pp
All
.Va daemon_*
.Nm :
.Bd -literal -offset indent
daemon_class=daemon
+daemon_execdir=
daemon_flags=
daemon_logger=
daemon_rtable=0
site-specific values provided in
.Xr rc.conf.local 8
for
+.Va daemon_execdir ,
.Va daemon_flags ,
.Va daemon_logger ,
.Va daemon_rtable ,
.Va daemon_user
will override those defaults.
.El
-.El
.Sh FILES
.Bl -tag -width Ds
.It Pa /etc/rc.d/
-.\" $OpenBSD: rcctl.8,v 1.39 2022/04/01 10:13:35 ajacoutot Exp $
+.\" $OpenBSD: rcctl.8,v 1.40 2022/05/26 11:27:03 ajacoutot Exp $
.\"
.\" Copyright (c) 2014 Antoine Jacoutot <ajacoutot@openbsd.org>
.\"
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: April 1 2022 $
+.Dd $Mdocdate: May 26 2022 $
.Dt RCCTL 8
.Os
.Sh NAME
.Ar variable
can be one of
.Cm class ,
+.Cm execdir ,
.Cm flags ,
.Cm logger ,
.Cm rtable ,
# rcctl set apmd flags -A
# rcctl get apmd
apmd_class=daemon
-apmd_flags=-A
+apmd_execdir=
+apmd_flags=NO
apmd_logger=
apmd_rtable=0
apmd_timeout=30
#!/bin/ksh
#
-# $OpenBSD: rcctl.sh,v 1.112 2022/02/10 16:57:33 robert Exp $
+# $OpenBSD: rcctl.sh,v 1.113 2022/05/26 11:27:03 ajacoutot Exp $
#
-# Copyright (c) 2014, 2015-2021 Antoine Jacoutot <ajacoutot@openbsd.org>
+# Copyright (c) 2014, 2015-2022 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
[ -n "${_svc}" ] || return
local _status=0 _val _var=$2
- local daemon_class daemon_flags daemon_logger daemon_rtable
- local daemon_timeout daemon_user
+ local daemon_class daemon_execdir daemon_flags daemon_logger
+ local daemon_rtable daemon_timeout daemon_user
if svc_is_special ${_svc}; then
daemon_flags="$(eval echo \${${_svc}})"
[ -z "${daemon_class}" ] && \
daemon_class="$(svc_getdef ${_svc} class)"
fi
+ if [ -z "${_var}" -o "${_var}" = "execdir" ]; then
+ [ -z "${daemon_execdir}" ] && \
+ daemon_execdir="$(eval echo \"\${${_svc}_execdir}\")"
+ [ -z "${daemon_execdir}" ] && \
+ daemon_execdir="$(svc_getdef ${_svc} execdir)"
+ fi
if [[ -z ${_var} || ${_var} == @(flags|status) ]]; then
[ -z "${daemon_flags}" ] && \
daemon_flags="$(eval echo \"\${${_svc}_flags}\")"
echo "${_svc}=${daemon_flags}"
else
echo "${_svc}_class=${daemon_class}"
+ echo "${_svc}_execdir=${daemon_execdir}"
echo "${_svc}_flags=${daemon_flags}"
echo "${_svc}_logger=${daemon_logger}"
echo "${_svc}_rtable=${daemon_rtable}"
[ -n "${_svc}" ] || return
local _status=0 _val _var=$2
- local daemon_class daemon_flags daemon_logger daemon_rtable
- local daemon_timeout daemon_user
+ local daemon_class daemon_execdir daemon_flags daemon_logger
+ local daemon_rtable daemon_timeout daemon_user
if svc_is_special ${_svc}; then
# unconditionally parse: we always output flags and/or status
echo "${_svc}=${daemon_flags}"
else
echo "${_svc}_class=${daemon_class}"
+ echo "${_svc}_execdir=${daemon_execdir}"
echo "${_svc}_flags=${daemon_flags}"
echo "${_svc}_logger=${daemon_logger}"
echo "${_svc}_rtable=${daemon_rtable}"
( svc_getdef ${_svc} status ) && \
echo "${_svc}=NO" >>${_TMP_RCCONF}
else
- grep -Ev "^${_svc}_(flags|logger|rtable|timeout|user).*=" \
+ grep -Ev "^${_svc}_(execdir|flags|logger|rtable|timeout|user).*=" \
/etc/rc.conf.local >${_TMP_RCCONF}
( svc_getdef ${_svc} status ) && \
echo "${_svc}_flags=NO" >>${_TMP_RCCONF}
fi
if [ -n "${_args}" ]; then
+ if [ "${_var}" = "execdir" ]; then
+ [[ ${_args%${_args#?}} == / ]] ||
+ rcctl_err "\"${_args}\" must be an absolute path"
+ fi
if [ "${_var}" = "logger" ]; then
logger -p "${_args}" </dev/null >/dev/null 2>&1 ||
rcctl_err "unknown priority name: \"${_args}\""
rcctl_err "service ${svc} does not exist" 2
if [ -n "${var}" ]; then
[ "${svc}" = "all" ] && usage
- [[ ${var} != @(class|flags|logger|rtable|status|timeout|user) ]] && usage
+ [[ ${var} != @(class|execdir|flags|logger|rtable|status|timeout|user) ]] && usage
if svc_is_meta ${svc}; then
[ "${var}" != "status" ] && \
rcctl_err "/etc/rc.d/${svc} is a meta script, cannot \"${action} ${var}\""
fi
if svc_is_special ${svc}; then
- [[ ${var} == @(class|logger|rtable|timeout|user) ]] && \
+ [[ ${var} == @(class|execdir|logger|rtable|timeout|user) ]] && \
rcctl_err "\"${svc}\" is a special variable, cannot \"${action} ${var}\""
fi
fi
svc_is_avail ${svc} || \
rcctl_err "service ${svc} does not exist" 2
fi
- [[ ${var} != @(class|flags|logger|rtable|status|timeout|user) ]] && usage
+ [[ ${var} != @(class|execdir|flags|logger|rtable|status|timeout|user) ]] && usage
svc_is_meta ${svc} && [ "${var}" != "status" ] && \
rcctl_err "/etc/rc.d/${svc} is a meta script, cannot \"${action} ${var}\""
[[ ${var} = flags && ${args} = NO ]] && \