From: ajacoutot Date: Thu, 1 Sep 2022 07:25:32 +0000 (+0000) Subject: Add a new action: "configtest", to check configuration syntax of the daemon. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a9970bb5dae573f58b0674bfde21aaf5c07ac5ff;p=openbsd Add a new action: "configtest", to check configuration syntax of the daemon. A few adjustments will be done in the next days (like disabling this action if there's no specific rc_configtest function defined). e.g. /etc/rc.d/sshd configtest rcctl configtest sshd idea from naddy@ --- diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index 542670c2c38..5be38a4b55d 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.156 2022/08/29 19:37:32 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.157 2022/09/01 07:25:32 ajacoutot Exp $ # # Copyright (c) 2010, 2011, 2014-2022 Antoine Jacoutot # Copyright (c) 2010, 2011 Ingo Schwarze @@ -16,7 +16,7 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -_rc_actions="start stop restart reload check" +_rc_actions="start stop restart reload check configtest" readonly _rc_actions _rc_check_name() { @@ -219,6 +219,10 @@ rc_cmd() { echo $_n "${INRC:+ }${_name}" _rc_do rc_check && _rc_exit ok || _rc_exit failed ;; + configtest) + echo $_n "${INRC:+ }${_name}" + _rc_do rc_configtest && _rc_exit ok || _rc_exit failed + ;; start) if [ X"${daemon_flags}" = X"NO" ]; then _rc_err "$0: need -f to force $1 since ${_name}_flags=NO" @@ -226,9 +230,9 @@ 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... + # 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 _rc_do rc_pre || break diff --git a/share/man/man8/rc.d.8 b/share/man/man8/rc.d.8 index 581743629b7..3810fe0f1c2 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.38 2022/05/26 11:27:03 ajacoutot Exp $ +.\" $OpenBSD: rc.d.8,v 1.39 2022/09/01 07:25:32 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: May 26 2022 $ +.Dd $Mdocdate: September 1 2022 $ .Dt RC.D 8 .Os .Sh NAME @@ -83,7 +83,7 @@ flags are specified. Each such script responds to the following .Ar actions : .Pp -.Bl -tag -width restart -offset indent -compact +.Bl -tag -width configtest -offset indent -compact .It Cm start Start the service, if not already running. .It Cm stop @@ -94,6 +94,13 @@ Tell the daemon to reload its configuration. Perform a stop, then a start. .It Cm check 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/usr.sbin/rcctl/rcctl.sh b/usr.sbin/rcctl/rcctl.sh index 9d72fa6944f..b2fb53aae12 100644 --- a/usr.sbin/rcctl/rcctl.sh +++ b/usr.sbin/rcctl/rcctl.sh @@ -1,6 +1,6 @@ #!/bin/ksh # -# $OpenBSD: rcctl.sh,v 1.113 2022/05/26 11:27:03 ajacoutot Exp $ +# $OpenBSD: rcctl.sh,v 1.114 2022/09/01 07:25:32 ajacoutot Exp $ # # Copyright (c) 2014, 2015-2022 Antoine Jacoutot # Copyright (c) 2014 Ingo Schwarze @@ -531,7 +531,7 @@ case ${action} in rcctl_err "service ${svc} does not exist" 2 done ;; - disable|enable|start|stop|restart|reload|check) + disable|enable|start|stop|restart|reload|check|configtest) shift 1 svcs="$*" [ -z "${svcs}" ] && usage @@ -632,7 +632,7 @@ case ${action} in needs_root ${action} svc_set ${svc} "${var}" "${args}" ;; - start|stop|restart|reload|check) + start|stop|restart|reload|check|configtest) for svc in ${svcs}; do if svc_is_special ${svc}; then rcctl_err "\"${svc}\" is a special variable, no rc.d(8) script"