Hi.
This diff allows to configure an directory from which we run rc.d commands.
This can be useful for daemons that must cd into a specific directory prio
launching.
Here's an example for the automounter.
Some rc.d scripts in ports can benefit from this as well (so we can remove
handcrafted rc_start function and use the default).
Comments / OK?
Index: amd
===================================================================
RCS file: /cvs/src/etc/rc.d/amd,v
retrieving revision 1.9
diff -u -p -r1.9 amd
--- amd 11 Jan 2018 21:09:26 -0000 1.9
+++ amd 21 May 2022 14:52:07 -0000
@@ -7,16 +7,13 @@ daemon="/usr/sbin/amd"
. /etc/rc.d/rc.subr
pexp="${daemon}.*"
+rc_execdir=/etc/amd
rc_reload=NO
rc_stop=NO
rc_pre() {
[[ -e ${amd_master} ]] || return 1
daemon_flags="${daemon_flags} $(print -rn -- $(< ${amd_master}))"
-}
-
-rc_start() {
- ${rcexec} "cd /etc/amd; ${daemon} ${daemon_flags}"
}
rc_cmd $1
Index: etc/rc.d/rc.subr
===================================================================
RCS file: /cvs/src/etc/rc.d/rc.subr,v
retrieving revision 1.153
diff -u -p -r1.153 rc.subr
--- etc/rc.d/rc.subr 21 May 2022 10:50:09 -0000 1.153
+++ etc/rc.d/rc.subr 21 May 2022 14:49:17 -0000
@@ -164,8 +164,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; } \
+ ${rc_execdir:+cd ${rc_execdir} && } \
+ $@ \
+ ${daemon_logger:+ 2>&1 |
+ logger -ip ${daemon_logger} -t ${_name}}"
}
rc_start() {
Index: share/man/man8/rc.subr.8
===================================================================
RCS file: /cvs/src/share/man/man8/rc.subr.8,v
retrieving revision 1.43
diff -u -p -r1.43 rc.subr.8
--- share/man/man8/rc.subr.8 21 May 2022 14:11:39 -0000 1.43
+++ share/man/man8/rc.subr.8 21 May 2022 14:49:17 -0000
@@ -194,9 +194,10 @@ Execute process using
according to
.Va daemon_class ,
.Va daemon_user ,
-.Va daemon_rtable
-and
+.Va daemon_rtable ,
.Va daemon_logger
+and
+.Va rc_execdir
values.
.It Ic rc_reload
Send the
@@ -305,6 +306,9 @@ in an
.Nm rc.d
script to force starting the daemon in background when using the default
.Ic rc_start .
+.It Va rc_execdir
+Change to this directory before running
+.Ic rc_exec .
.It Va rc_reload
Can be set to
.Dq NO
--
Antoine