commit: 83a0e31f984a44b47f5bfc5979c03e96720bf1ff Author: Nicolas PARLANT <nicolas.parlant <AT> parhuet <DOT> fr> AuthorDate: Thu Feb 5 14:29:17 2026 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed Feb 25 16:11:08 2026 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=83a0e31f
net-dns/knot-resolver: add checkconfig for initd hardcode the pidfile owned by root Signed-off-by: Nicolas PARLANT <nicolas.parlant <AT> parhuet.fr> Part-of: https://github.com/gentoo/gentoo/pull/45638 Signed-off-by: Sam James <sam <AT> gentoo.org> net-dns/knot-resolver/files/knot-resolver.confd | 1 - net-dns/knot-resolver/files/knot-resolver.initd | 36 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/net-dns/knot-resolver/files/knot-resolver.confd b/net-dns/knot-resolver/files/knot-resolver.confd index 8c3c65cf5772..24f5ae8f5bdf 100644 --- a/net-dns/knot-resolver/files/knot-resolver.confd +++ b/net-dns/knot-resolver/files/knot-resolver.confd @@ -4,7 +4,6 @@ #KNOT_RESOLVER_USER=knot-resolver #KNOT_RESOLVER_GROUP=knot-resolver #KNOT_RESOLVER_CONFIG="/etc/knot-resolver/config.yaml" -#KNOT_RESOLVER_PIDFILE="/run/knot-resolver.pid" #LOG TARGET : syslog stdout stderr #KNOT_RESOLVER_LOG="syslog" diff --git a/net-dns/knot-resolver/files/knot-resolver.initd b/net-dns/knot-resolver/files/knot-resolver.initd index 33b54d634f91..72cc9b3f5cd2 100644 --- a/net-dns/knot-resolver/files/knot-resolver.initd +++ b/net-dns/knot-resolver/files/knot-resolver.initd @@ -5,7 +5,6 @@ : ${KNOT_RESOLVER_USER:=knot-resolver} : ${KNOT_RESOLVER_GROUP:=knot-resolver} : ${KNOT_RESOLVER_CONFIG:=/etc/knot-resolver/config.yaml} -: ${KNOT_RESOLVER_PIDFILE:=/run/knot-resolver.pid} : ${KNOT_RESOLVER_LOG:=syslog} export KRES_LOGGING_TARGET="${KNOT_RESOLVER_LOG}" @@ -13,7 +12,7 @@ export KRES_LOGGING_TARGET="${KNOT_RESOLVER_LOG}" command="/usr/bin/knot-resolver" command_args="-c ${KNOT_RESOLVER_CONFIG}" command_user="${KNOT_RESOLVER_USER}:${KNOT_RESOLVER_GROUP}" -pidfile="${KNOT_RESOLVER_PIDFILE}" +pidfile="/run/${RC_SVCNAME}.pid" command_background=true retry="TERM/60/KILL/5" @@ -30,8 +29,39 @@ depend() { provide dns } +checkconfig() { + # Filter the output to avoid a full traceback if the schema (JSON or YAML) is incorrect. Call 'su' to check permissions too. + errors=$(su ${KNOT_RESOLVER_USER} -s /bin/sh -c \ + "/usr/bin/kresctl validate --strict ${KNOT_RESOLVER_CONFIG} 2>&1" ) + [ -z "${errors}" ] && return 0 + + case "${errors}" in + *"Error:"*) + eerror "${KNOT_RESOLVER_CONFIG} can't be parsed!" + eerror "Please verify the schema (JSON or YAML)." + ;; + *) + eerror "${KNOT_RESOLVER_CONFIG} is invalid!" + eerror "${errors}" + ;; + esac + return 1 +} + +start_pre() { + if [ "${RC_CMD}" != "restart" ]; then + checkconfig || return 1 + fi +} + +stop_pre() { + if [ "${RC_CMD}" != "restart" ]; then + checkconfig || return 1 + fi +} + reload() { ebegin "Force-reloading ${SVCNAME}" - /usr/bin/kresctl --config=${KNOT_RESOLVER_CONFIG} reload --force + /usr/bin/kresctl --config="${KNOT_RESOLVER_CONFIG}" reload --force eend $? }
