From ff30fda45ac8ba77a3d377d44ac712f97385c017 Mon Sep 17 00:00:00 2001 From: ajacoutot Date: Fri, 2 Sep 2022 22:11:57 +0000 Subject: [PATCH] Make rc_configtest behave like rc_pre and rc_post; i.e. don't define a default function (each rc.d script is supposed to define its own if wanted). This way, we can filter out the "configtest" action depending on whether the function exists or not. Adapt documentation. tweak/ok kn@ --- etc/rc.d/rc.subr | 27 ++++++++++++++++----------- share/man/man8/rc.d.8 | 9 ++------- share/man/man8/rc.subr.8 | 22 ++++++++++++++++------ 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index 5be38a4b55d..4d8ed2c969a 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.157 2022/09/01 07:25:32 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.158 2022/09/02 22:11:57 ajacoutot Exp $ # # Copyright (c) 2010, 2011, 2014-2022 Antoine Jacoutot # Copyright (c) 2010, 2011 Ingo Schwarze @@ -93,6 +93,9 @@ _rc_quirks() { _rc_not_supported() { local _a _enotsup _what=${1} for _a in ${_rc_actions}; do + [ "${_what}" == "configtest" ] && + ! typeset -f rc_configtest >/dev/null && _enotsup=NO && + break [ "${_what}" == "restart" ] && _what="stop" if [ "${_what}" == "${_a}" ]; then eval _enotsup=\${rc_${_what}} @@ -162,10 +165,6 @@ _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)" ] || @@ -233,8 +232,10 @@ rc_cmd() { # running during start is 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 + if typeset -f rc_configtest >/dev/null; then + _rc_do rc_configtest || break + fi + if typeset -f rc_pre >/dev/null; then _rc_do rc_pre || break fi # prevent hanging the boot sequence @@ -255,7 +256,7 @@ rc_cmd() { done # handle failure _rc_do _rc_rm_runfile - type rc_post >/dev/null && _rc_do rc_post + typeset -f rc_post >/dev/null && _rc_do rc_post _rc_exit failed ;; stop) @@ -280,7 +281,7 @@ rc_cmd() { # KILL the process _rc_do rc_check && _rc_do _rc_sendsig KILL && _exit="killed" _rc_do _rc_rm_runfile - if type rc_post >/dev/null; then + if typeset -f rc_post >/dev/null; then _rc_do rc_post || _exit=failed fi _rc_exit ${_exit:=ok} @@ -288,7 +289,9 @@ rc_cmd() { reload) echo $_n "${INRC:+ }${_name}" _rc_do rc_check || _rc_exit failed - _rc_do rc_configtest || _rc_exit failed + if typeset -f rc_configtest >/dev/null; then + _rc_do rc_configtest || _rc_exit failed + fi _rc_do rc_reload & _timer=$! while ((SECONDS < daemon_timeout)); do pkill -0 -P "$$" 2>/dev/null || break @@ -302,7 +305,9 @@ rc_cmd() { _rc_exit ${_exit:=ok} ;; restart) - _rc_do rc_configtest || _rc_exit failed + if typeset -f rc_configtest >/dev/null; then + _rc_do rc_configtest || _rc_exit failed + fi $0 ${_RC_DEBUG} ${_RC_FORCE} stop && $0 ${_RC_DEBUG} ${_RC_FORCE} start ;; diff --git a/share/man/man8/rc.d.8 b/share/man/man8/rc.d.8 index 3810fe0f1c2..edd928ca24b 100644 --- a/share/man/man8/rc.d.8 +++ b/share/man/man8/rc.d.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rc.d.8,v 1.39 2022/09/01 07:25:32 ajacoutot Exp $ +.\" $OpenBSD: rc.d.8,v 1.40 2022/09/02 22:11:57 ajacoutot Exp $ .\" .\" Copyright (c) 2021 Antoine Jacoutot .\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze @@ -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: September 1 2022 $ +.Dd $Mdocdate: September 2 2022 $ .Dt RC.D 8 .Os .Sh NAME @@ -96,11 +96,6 @@ Perform a stop, then a start. Return 0 if the daemon is running or 1 if it is not. .It Cm configtest Check that the daemon configuration is valid. -Only useful if the -.Nm rc.d -script provides an -.Ic rc_configtest -function. .El .Sh ENVIRONMENT Daemon control scripts use a fixed number of diff --git a/share/man/man8/rc.subr.8 b/share/man/man8/rc.subr.8 index 88173b481e0..f03327ba392 100644 --- a/share/man/man8/rc.subr.8 +++ b/share/man/man8/rc.subr.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rc.subr.8,v 1.47 2022/08/30 05:40:28 jmc Exp $ +.\" $OpenBSD: rc.subr.8,v 1.48 2022/09/02 22:11:57 ajacoutot Exp $ .\" .\" Copyright (c) 2021, 2022 Antoine Jacoutot .\" Copyright (c) 2011 Robert Nagy, Antoine Jacoutot, Ingo Schwarze @@ -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: August 30 2022 $ +.Dd $Mdocdate: September 2 2022 $ .Dt RC.SUBR 8 .Os .Sh NAME @@ -193,10 +193,8 @@ Check daemon configuration before running .Cm start , .Cm reload and -.Cm restart . -Defaults to -.Sq return 0 -but can be overridden by the +.Cm restart +if implemented by the .Xr rc.d 8 script. .It Ic rc_exec @@ -210,6 +208,18 @@ according to and .Va daemon_logger values. +.It Ic rc_post +This function is run after +.Cm stop +if implemented by the +.Xr rc.d 8 +script. +.It Ic rc_pre +This function is run before +.Cm start +if implemented by the +.Xr rc.d 8 +script. .It Ic rc_reload Send the .Va rc_reload_signal -- 2.20.1