From e091ee7220efa89d3e9566db12279a771fba17a2 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 6 Sep 2026 14:16:37 +0000 Subject: dhcp: T9278: define logmsg() for the DHCPv6 client script dhcp6c-script.j2 calls logmsg() six times but runs standalone under dhcp6c. It never sources dhclient-enter-hooks.d/01-vyos-logging, which is only pulled into the dhclient-script shell, and defines no logmsg() itself, so every call failed with "logmsg: not found" while adding shell errors to the journal. Carry a POSIX sh copy using the same tag, priorities and /tmp/vyos.dhclient.debug gate as the DHCPv4 hooks. The two messages announcing an internal step log at debug; the nameserver and search domain updates stay at info. --- data/templates/dhcp-client/dhcp6c-script.j2 | 32 +++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'data') diff --git a/data/templates/dhcp-client/dhcp6c-script.j2 b/data/templates/dhcp-client/dhcp6c-script.j2 index 14fb25cf6..1df690a5a 100644 --- a/data/templates/dhcp-client/dhcp6c-script.j2 +++ b/data/templates/dhcp-client/dhcp6c-script.j2 @@ -2,6 +2,34 @@ # Update DNS information for DHCPv6 clients # should be used only if vyos-hostsd is running +# This script is executed standalone by dhcp6c and can not source the dhclient +# hook /etc/dhcp/dhclient-enter-hooks.d/01-vyos-logging, which is only pulled +# into the dhclient-script shell. It therefore carries its own logmsg() - keep +# the tag, the priorities and the debug flag file in sync with that file. +LOG_TAG="dhclient-script-vyos" +LOG_DEBUG_ENABLE="/tmp/vyos.dhclient.debug" + +logmsg () { + log_level=$1 + shift + + case ${log_level} in + debug) + # Do not even build the message when debugging is not requested + [ -f "${LOG_DEBUG_ENABLE}" ] || return 0 + log_prio="daemon.debug" ;; + info) log_prio="daemon.info" ;; + warn) log_prio="daemon.warning" ;; + error) log_prio="daemon.err" ;; + *) + # Unknown level - do not lose the message, it was never a level + log_prio="daemon.info" + set -- "${log_level}" "$@" ;; + esac + + /usr/bin/logger -e --id=$$ -p ${log_prio} -t ${LOG_TAG} "$@" +} + if /usr/bin/systemctl -q is-active vyos-hostsd; then hostsd_client="/usr/bin/vyos-hostsd-client" hostsd_changes= @@ -23,9 +51,9 @@ if /usr/bin/systemctl -q is-active vyos-hostsd; then fi if [ $hostsd_changes ]; then - logmsg info "Applying changes via vyos-hostsd-client" + logmsg debug "Applying changes via vyos-hostsd-client" $hostsd_client --apply else - logmsg info "No changes to apply via vyos-hostsd-client" + logmsg debug "No changes to apply via vyos-hostsd-client" fi fi -- cgit v1.2.3