Can you elaborate? Do they need to start from a specific directory or from a directory they have write access to? Because we could cd /tmp unconditionally
— Antoine > On 6 May 2022, at 00:43, Aaron Bieber <[email protected]> wrote: > > > >> On Thu, May 5, 2022, at 3:24 PM, Antoine Jacoutot wrote: >> Not a fan adding a knob for this. >> I don’t remember why amd needs to start from /etc/amd. >> >> — >> Antoine > > There are a number of ports that would benefit from this as well. > >> >>>> On 5 May 2022, at 23:12, aisha <[email protected]> wrote: >>> >>> Hi, >>> I've attached a patch which allows setting the daemon start directory using >>> the variable `daemon_startdir`. >>> I think this is useful in the cases where it is desirable to change the >>> start directory before running the daemon, e.g. with /etc/rc.d/amd . >>> A major benefit of this is that this allows setting the start directory >>> manually while also allowing the use of daemon_logger, which gets lost in >>> case someone writes their own rc_start (again, amd is an example). >>> >>> This is not always possible using the rcexec which uses `su -l` as the >>> daemon might be running as root (or if user has home directory to >>> /nonexistent). >>> >>> Thanks, >>> Aisha >>> >>> diff --git a/etc/rc.d/amd b/etc/rc.d/amd >>> index 3bfe9dc555e..5c1b8a897ed 100644 >>> --- a/etc/rc.d/amd >>> +++ b/etc/rc.d/amd >>> @@ -3,6 +3,7 @@ >>> # $OpenBSD: amd,v 1.9 2018/01/11 21:09:26 rpe Exp $ >>> >>> daemon="/usr/sbin/amd" >>> +daemon_startdir="/etc/amd" >>> >>> . /etc/rc.d/rc.subr >>> >>> @@ -15,8 +16,4 @@ rc_pre() { >>> daemon_flags="${daemon_flags} $(print -rn -- $(< ${amd_master}))" >>> } >>> >>> -rc_start() { >>> - ${rcexec} "cd /etc/amd; ${daemon} ${daemon_flags}" >>> -} >>> - >>> rc_cmd $1 >>> diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr >>> index ed2adb6515e..035f8d9b172 100644 >>> --- a/etc/rc.d/rc.subr >>> +++ b/etc/rc.d/rc.subr >>> @@ -117,6 +117,7 @@ daemon_class=${daemon_class} >>> daemon_flags=${daemon_flags} >>> daemon_logger=${daemon_logger} >>> daemon_rtable=${daemon_rtable} >>> +daemon_startdir=${daemon_startdir} >>> daemon_timeout=${daemon_timeout} >>> daemon_user=${daemon_user} >>> pexp=${pexp} >>> @@ -160,7 +161,7 @@ _rc_wait_for_start() { >>> } >>> >>> rc_start() { >>> - ${rcexec} "${daemon_logger:+set -o pipefail; }${daemon} >>> ${daemon_flags}${daemon_logger:+ 2>&1 | >>> + ${rcexec} "${daemon_logger:+set -o pipefail; }${daemon_startdir:+cd >>> ${daemon_startdir}; }${daemon} ${daemon_flags}${daemon_logger:+ 2>&1 | >>> logger -ip ${daemon_logger} -t ${_name}}" >>> } >>> >>> @@ -312,6 +313,7 @@ rc_stop_signal=${rc_stop_signal:=TERM} >>> eval _rcflags=\${${_name}_flags} >>> eval _rclogger=\${${_name}_logger} >>> eval _rcrtable=\${${_name}_rtable} >>> +eval _rcstartdir=\${${_name}_startdir} >>> eval _rctimeout=\${${_name}_timeout} >>> eval _rcuser=\${${_name}_user} >>> >>> @@ -329,6 +331,7 @@ getcap -f /etc/login.conf.d/${_name}:/etc/login.conf >>> ${_name} 1>/dev/null 2>&1 & >>> [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} >>> [ -n "${_rclogger}" ] && daemon_logger=${_rclogger} >>> [ -n "${_rcrtable}" ] && daemon_rtable=${_rcrtable} >>> +[ -n "${_rcstartdir}" ] && daemon_startdir=${_rcstartdir} >>> [ -n "${_rctimeout}" ] && daemon_timeout=${_rctimeout} >>> [ -n "${_rcuser}" ] && daemon_user=${_rcuser} >>> >>> >
