git: 93449dfa01a5 - main - dns/dnsmasq*: add a checkconfig option to rcfile

From: Matthias Andree <mandree_at_FreeBSD.org>
Date: Sat, 20 Jul 2024 09:03:24 UTC
The branch main has been updated by mandree:

URL: https://cgit.FreeBSD.org/ports/commit/?id=93449dfa01a515bf3b2c7d6e6c08d7e56e0aabf6

commit 93449dfa01a515bf3b2c7d6e6c08d7e56e0aabf6
Author:     Dmitry Selivanov <dseliv@gmail.com>
AuthorDate: 2024-07-20 08:59:57 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2024-07-20 09:03:06 +0000

    dns/dnsmasq*: add a checkconfig option to rcfile
    
    and automatically invoke it before restart or stop.
    Under the hood, this runs dnsmasq --test.
    
    Bump PORTREVISION of dnsmasq only, the -devel port is not
    built regularly.
    
    [commit message by Matthias Andree <mandree@FreeBSD.org>]
---
 dns/dnsmasq-devel/files/dnsmasq.in | 16 ++++++++++++++--
 dns/dnsmasq/Makefile               |  2 +-
 dns/dnsmasq/files/dnsmasq.in       | 16 ++++++++++++++--
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/dns/dnsmasq-devel/files/dnsmasq.in b/dns/dnsmasq-devel/files/dnsmasq.in
index bd62247f6694..1311df694b69 100644
--- a/dns/dnsmasq-devel/files/dnsmasq.in
+++ b/dns/dnsmasq-devel/files/dnsmasq.in
@@ -59,13 +59,15 @@ load_rc_config "${name}"
 command_args="-x $pidfile -C $dnsmasq_conf"
 
 required_files="${dnsmasq_conf}"
-extra_commands="reload logstats"
+extra_commands="reload logstats checkconfig"
 
 reload_precmd="reload_pre"
 reload_postcmd="reload_post"
+restart_precmd="checkconfig"
 start_postcmd="timestampconf"
-stop_precmd="rmtimestamp"
+stop_precmd="stop_pre"
 logstats_cmd="logstats"
+checkconfig_cmd="checkconfig"
 
 reload_pre() {
         if [ "$dnsmasq_conf" -nt "${timestamp}" ] ; then
@@ -94,4 +96,14 @@ rmtimestamp() {
         rm -f "${timestamp}"
 }
 
+stop_pre() {
+        checkconfig || return
+        rmtimestamp
+}
+
+checkconfig() {
+        echo "Performing sanity check on ${name} configuration."
+        ${command} ${command_args} --test
+}
+
 run_rc_command "$1"
diff --git a/dns/dnsmasq/Makefile b/dns/dnsmasq/Makefile
index 89589552e859..522c420f55a5 100644
--- a/dns/dnsmasq/Makefile
+++ b/dns/dnsmasq/Makefile
@@ -1,7 +1,7 @@
 PORTNAME=	dnsmasq
 DISTVERSION=	2.90
 # Leave the PORTREVISION in even if 0 to avoid accidental PORTEPOCH bumps:
-PORTREVISION=	1
+PORTREVISION=	2
 PORTEPOCH=	1
 CATEGORIES=	dns
 MASTER_SITES=	https://www.thekelleys.org.uk/dnsmasq/ \
diff --git a/dns/dnsmasq/files/dnsmasq.in b/dns/dnsmasq/files/dnsmasq.in
index bd62247f6694..1311df694b69 100644
--- a/dns/dnsmasq/files/dnsmasq.in
+++ b/dns/dnsmasq/files/dnsmasq.in
@@ -59,13 +59,15 @@ load_rc_config "${name}"
 command_args="-x $pidfile -C $dnsmasq_conf"
 
 required_files="${dnsmasq_conf}"
-extra_commands="reload logstats"
+extra_commands="reload logstats checkconfig"
 
 reload_precmd="reload_pre"
 reload_postcmd="reload_post"
+restart_precmd="checkconfig"
 start_postcmd="timestampconf"
-stop_precmd="rmtimestamp"
+stop_precmd="stop_pre"
 logstats_cmd="logstats"
+checkconfig_cmd="checkconfig"
 
 reload_pre() {
         if [ "$dnsmasq_conf" -nt "${timestamp}" ] ; then
@@ -94,4 +96,14 @@ rmtimestamp() {
         rm -f "${timestamp}"
 }
 
+stop_pre() {
+        checkconfig || return
+        rmtimestamp
+}
+
+checkconfig() {
+        echo "Performing sanity check on ${name} configuration."
+        ${command} ${command_args} --test
+}
+
 run_rc_command "$1"