From: Daniel F. Dickinson Date: Tue, 7 Jul 2026 02:08:01 +0000 (-0400) Subject: nut: split interface_triggers function X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=4638c42055946ac424d208f6e92aadc9eb8dd884;p=openwrt-packages.git nut: split interface_triggers function Using add_interface_triggers and check_interface_up is a better separation of concerns and the code has little in common (no duplication of code concerns). While we are at it make both nut-monitor and nut-server failure of add_interface_triggers non-fatal with a logged error message. Signed-off-by: Daniel F. Dickinson --- diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index 959448b8c..82e63088d 100644 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -92,7 +92,7 @@ service_preconditions() { fi build_config || return 1 - interface_triggers "check_interface_up" "upsmon" || return 1 + check_interface_up "upsmon" || return 1 return 0 ;; *) @@ -217,8 +217,8 @@ service_triggers() { # We do not pass a variadic instance name as the nut-monitor initscript does # not need an additional instance name argument, only the initscript name - interface_triggers "add_trigger" "upsmon" "$interface_reload_delay" "nut-monitor" || { - log_error_exit "Failed to add interface triggers" nut-monitor nut-monitor + add_interface_triggers "upsmon" "$interface_reload_delay" "nut-monitor" || { + log_error "Failed to add interface triggers" nut-monitor nut-monitor } procd_add_reload_trigger "nut_monitor" } diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 1354e90ab..1467bd516 100644 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -251,7 +251,7 @@ service_preconditions() { case $ret in 0) - interface_triggers "check_interface_up" "upsd" || should_start_srv=false + check_interface_up "upsd" || should_start_srv=false ;; *) should_start_srv=false @@ -264,7 +264,7 @@ service_preconditions() { case $ret in 0 | 2) - interface_triggers "check_interface_up" "upsd" || should_stop_srv=true + check_interface_up "upsd" || should_stop_srv=true ;; *) should_stop_srv=true @@ -561,6 +561,8 @@ service_triggers() { interface_reload_delay="$DEFAULT_PROCD_INTERFACE_RELOAD_DELAY" fi - interface_triggers "add_trigger" "upsd" "$interface_reload_delay" "nut-server" "upsd" + add_interface_triggers "upsd" "$interface_reload_delay" "nut-server" "upsd" || { + log_error "Failed to add interface triggers" nut-server nut-server + } procd_add_reload_trigger "nut_server" } diff --git a/net/nut/files/nut-service.sh.functions b/net/nut/files/nut-service.sh.functions index b750c3bcf..1e6ab927e 100644 --- a/net/nut/files/nut-service.sh.functions +++ b/net/nut/files/nut-service.sh.functions @@ -243,73 +243,73 @@ service_active_no_instances() { } # Setup triggers in procd for changes to specified network interfaces -# network_is_up depends on /lib/functions/network.sh having been sourced -interface_triggers() { - local action="$1" - local section="$2" - local interface_reload_delay="${3:-$DEFAULT_PROCD_INTERFACE_RELOAD_DELAY}" - local initscript="$4" - if [ $# -ge 4 ]; then - shift 4 +add_interface_triggers() { + local section="$1" + local interface_reload_delay="${2:-$DEFAULT_PROCD_INTERFACE_RELOAD_DELAY}" + local initscript="$3" + if [ $# -ge 3 ]; then + shift 3 fi - local interfaces interface - local have_up_interface - local trigger_failed + + local interfaces interface trigger_failed config_get interfaces "$section" triggerlist - # We list the actions we care about. Other actions are irrelevant. - # We do not need to log or otherwise 'notice' other actions - case "$action" in - add_trigger) - if [ -n "$interfaces" ] && [ "$interfaces" != "all" ]; then - set -f - trigger_failed="false" - # interfaces is deliberately unquoted so we get word-splitting for - # the for loop - for interface in $interfaces; do - # We use the variadic third and fourth parameters of procd_add_interface_trigger to - # restart instead of reload on interface up/down events. Additionally the variadic - # fifth and following parameters of procd_add_interface_trigger are passed through to - # the