summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
authorAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2022-08-29 19:14:03 +0000
committerAntoine Jacoutot <ajacoutot@cvs.openbsd.org>2022-08-29 19:14:03 +0000
commit9338abe157eda7cb842acfc98b6677fc9ff01a3a (patch)
tree25172e45471cea68bd618020999c4aad9fde14b4 /etc
parent035767cb71d5a19879432c16b9faf5197e56f167 (diff)
Introduce the rc_configtest() function.
By default it just returns "0" but can be overriden by rc.d scripts to check that the daemon configuration is valid when running "start", "reload" and "restart".
Diffstat (limited to 'etc')
-rw-r--r--etc/rc.d/rc.subr12
1 files changed, 11 insertions, 1 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr
index ef2b6d6f49b..c1e5a1728de 100644
--- a/etc/rc.d/rc.subr
+++ b/etc/rc.d/rc.subr
@@ -1,4 +1,4 @@
-# $OpenBSD: rc.subr,v 1.154 2022/05/26 11:27:03 ajacoutot Exp $
+# $OpenBSD: rc.subr,v 1.155 2022/08/29 19:14:02 ajacoutot Exp $
#
# Copyright (c) 2010, 2011, 2014-2022 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -162,6 +162,10 @@ _rc_wait_for_start() {
return
}
+rc_configtest() {
+ return 0
+}
+
rc_exec() {
local _rcexec="su -fl -c ${daemon_class} -s /bin/sh ${daemon_user} -c"
[ "${daemon_rtable}" -eq "$(id -R)" ] ||
@@ -222,6 +226,10 @@ rc_cmd() {
[ -z "${INRC}" ] && _rc_do rc_check && exit 0
echo $_n "${INRC:+ }${_name}"
while true; do # no real loop, only needed to break
+ # mostly useful for daemons whose child will not return
+ # a config parsing error to the parent during startup
+ # e.g. bgpd, httpd...
+ _rc_do rc_configtest || break
if type rc_pre >/dev/null; then
_rc_do rc_pre || break
fi
@@ -276,6 +284,7 @@ rc_cmd() {
reload)
echo $_n "${INRC:+ }${_name}"
_rc_do rc_check || _rc_exit failed
+ _rc_do rc_configtest || _rc_exit failed
_rc_do rc_reload & _timer=$!
while ((SECONDS < daemon_timeout)); do
pkill -0 -P "$$" 2>/dev/null || break
@@ -289,6 +298,7 @@ rc_cmd() {
_rc_exit ${_exit:=ok}
;;
restart)
+ _rc_do rc_configtest || _rc_exit failed
$0 ${_RC_DEBUG} ${_RC_FORCE} stop &&
$0 ${_RC_DEBUG} ${_RC_FORCE} start
;;