From: ajacoutot Date: Mon, 29 Aug 2022 19:14:02 +0000 (+0000) Subject: Introduce the rc_configtest() function. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=51617a979418e09a2cb520a6086b186fe800f682;p=openbsd 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". --- 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 # Copyright (c) 2010, 2011 Ingo Schwarze @@ -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 ;; diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 8428537e5fe..77561515adc 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -1,6 +1,6 @@ -.\" $OpenBSD: rc.subr.8,v 1.45 2022/05/27 12:27:39 ajacoutot Exp $ +.\" $OpenBSD: rc.subr.8,v 1.46 2022/08/29 19:14:02 ajacoutot Exp $ .\" -.\" Copyright (c) 2021 Antoine Jacoutot +.\" Copyright (c) 2021, 2022 Antoine Jacoutot .\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze .\" All rights reserved. .\" @@ -25,7 +25,7 @@ .\" (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 27 2022 $ +.Dd $Mdocdate: August 29 2022 $ .Dt RC.SUBR 8 .Os .Sh NAME @@ -188,6 +188,17 @@ If it is running, call .Ic rc_reload . .El +.It Ic rc_configtest +Check daemon configuration before running +.Cm start , +.Cm reload +and +.Cm restart . +Defaults to +.Sq return 0 +but can be overriden by the +.Xr rc.d 8 +script. .It Ic rc_exec Execute argument using .Xr su 1 @@ -323,7 +334,7 @@ Signal sent to the daemon process by the default .Fn rc_reload function. -Default to +Defaults to .Em HUP . .It Va rc_stop_signal Signal sent to the daemon process