From c7a9db60f9aeed5770acb1559ec31b44dcf326e0 Mon Sep 17 00:00:00 2001 From: Vladimir Ermakov Date: Sat, 20 Dec 2025 11:00:12 +0100 Subject: [PATCH 1/2] watchcat: fix ping args Fix errors like that: > Could not reach "77.88.8.8 for 66. Rebooting after reaching 21600 Run with `sh -x`, i got: ``` + ping standard -I any -s 300 -c 1 '"77.88.8.8' ``` Which is caused by bad variable masking. Fix: https://github.com/openwrt/packages/issues/28100 Signed-off-by: Vladimir Ermakov --- utils/watchcat/Makefile | 2 +- utils/watchcat/files/watchcat.init | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/watchcat/Makefile b/utils/watchcat/Makefile index 7b011cf036e59..e93525f69e8e2 100644 --- a/utils/watchcat/Makefile +++ b/utils/watchcat/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=watchcat PKG_VERSION:=1 -PKG_RELEASE:=19 +PKG_RELEASE:=20 PKG_MAINTAINER:=Roger D PKG_LICENSE:=GPL-2.0 diff --git a/utils/watchcat/files/watchcat.init b/utils/watchcat/files/watchcat.init index da1cd0e77556e..9bfc68d0e3bab 100644 --- a/utils/watchcat/files/watchcat.init +++ b/utils/watchcat/files/watchcat.init @@ -104,19 +104,19 @@ config_watchcat() { ;; ping_reboot) procd_open_instance "watchcat_${1}" - procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" \"$pinghosts\" "$pingperiod" "$pingsize" "$addressfamily" "$interface" + procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" "$pinghosts" "$pingperiod" "$pingsize" "$addressfamily" "$interface" procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_close_instance ;; restart_iface) procd_open_instance "watchcat_${1}" - procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" \"$pinghosts\" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily" + procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily" procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_close_instance ;; run_script) procd_open_instance "watchcat_${1}" - procd_set_param command /usr/bin/watchcat.sh "run_script" "$period" \"$pinghosts\" "$pingperiod" "$pingsize" "$interface" "$addressfamily" "$script" + procd_set_param command /usr/bin/watchcat.sh "run_script" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$addressfamily" "$script" procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" procd_close_instance ;; From d3c3ee350441587e2bdb1b55d6044bed4e276393 Mon Sep 17 00:00:00 2001 From: Vladimir Ermakov Date: Sat, 20 Dec 2025 11:11:48 +0100 Subject: [PATCH 2/2] watchcat: add enabled option, connect stdio - A little refactor of init script. - Add enabled option - Report startup check error to stderr too. Signed-off-by: Vladimir Ermakov --- utils/watchcat/files/watchcat.init | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/utils/watchcat/files/watchcat.init b/utils/watchcat/files/watchcat.init index 9bfc68d0e3bab..91693390bc8aa 100644 --- a/utils/watchcat/files/watchcat.init +++ b/utils/watchcat/files/watchcat.init @@ -1,4 +1,5 @@ #!/bin/sh /etc/rc.common +# shellcheck shell=busybox USE_PROCD=1 @@ -17,7 +18,7 @@ append_string() { } time_to_seconds() { - time=$1 + time="$1" { [ "$time" -ge 1 ] 2> /dev/null && seconds="$time"; } || { [ "${time%s}" -ge 1 ] 2> /dev/null && seconds="${time%s}"; } || @@ -25,13 +26,15 @@ time_to_seconds() { { [ "${time%h}" -ge 1 ] 2> /dev/null && seconds=$((${time%h} * 3600)); } || { [ "${time%d}" -ge 1 ] 2> /dev/null && seconds=$((${time%d} * 86400)); } - echo $seconds + echo "$seconds" unset seconds unset time } config_watchcat() { # Read config + local enabled period mode pinghosts pingperiod forcedelay pingsize interface mmifacename unlockbands addressfamily script + config_get_bool enabled "$1" enabled 1 config_get period "$1" period "120" config_get mode "$1" mode "ping_reboot" config_get pinghosts "$1" pinghosts "8.8.8.8" @@ -44,11 +47,17 @@ config_watchcat() { config_get addressfamily "$1" addressfamily "any" config_get script "$1" script + # Skip disabled instances + [ "$enabled" = 1 ] || return + # Fix potential typo in mode and provide backward compatibility. [ "$mode" = "allways" ] && mode="periodic_reboot" [ "$mode" = "always" ] && mode="periodic_reboot" [ "$mode" = "ping" ] && mode="ping_reboot" + # forward declaration for append_string + export error warn + # Checks for settings common to all operation modes if [ "$mode" != "periodic_reboot" ] && [ "$mode" != "ping_reboot" ] && [ "$mode" != "restart_iface" ] && [ "$mode" != "run_script" ]; then append_string "error" "mode must be 'periodic_reboot' or 'ping_reboot' or 'restart_iface' or 'run_script'" "; " @@ -61,7 +70,7 @@ config_watchcat() { # ping_reboot mode and restart_iface mode specific checks if [ "$mode" = "ping_reboot" ] || [ "$mode" = "restart_iface" ] || [ "$mode" = "run_script" ]; then if [ -z "$error" ]; then - pingperiod_default="$((period / 5))" + local pingperiod_default="$((period / 5))" pingperiod="$(time_to_seconds "$pingperiod")" if [ "$pingperiod" -ge 0 ] && [ "$pingperiod" -ge "$period" ]; then @@ -90,40 +99,36 @@ config_watchcat() { [ -n "$warn" ] && logger -p user.warn -t "watchcat" "$1: $warn" [ -n "$error" ] && { - logger -p user.err -t "watchcat" "reboot program $1 not started - $error" + logger -s -p user.err -t "watchcat" "reboot program $1 not started - $error" return } + procd_open_instance "watchcat_${1}" + # Need to conditionally run mode functions because they have different signatures case "$mode" in periodic_reboot) - procd_open_instance "watchcat_${1}" procd_set_param command /usr/bin/watchcat.sh "periodic_reboot" "$period" "$forcedelay" - procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" - procd_close_instance ;; ping_reboot) - procd_open_instance "watchcat_${1}" procd_set_param command /usr/bin/watchcat.sh "ping_reboot" "$period" "$forcedelay" "$pinghosts" "$pingperiod" "$pingsize" "$addressfamily" "$interface" - procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" - procd_close_instance ;; restart_iface) - procd_open_instance "watchcat_${1}" procd_set_param command /usr/bin/watchcat.sh "restart_iface" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$mmifacename" "$unlockbands" "$addressfamily" - procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" - procd_close_instance ;; run_script) - procd_open_instance "watchcat_${1}" procd_set_param command /usr/bin/watchcat.sh "run_script" "$period" "$pinghosts" "$pingperiod" "$pingsize" "$interface" "$addressfamily" "$script" - procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" - procd_close_instance - ;; - *) - echo "Error starting Watchcat service. Invalid mode selection: $mode" ;; + # *) # impossible case: checked above + # echo "Error starting Watchcat service. Invalid mode selection: $mode" + # ;; esac + + procd_set_param respawn "${respawn_threshold:-3600}" "${respawn_timeout:-5}" "${respawn_retry:-5}" + # simplify debugging + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance } start_service() {