]> git.99rst.org Git - openwrt-packages.git/commitdiff
nut: use common log functions instead of direct logger calls
authorDaniel F. Dickinson <redacted>
Sat, 18 Jul 2026 22:51:35 +0000 (18:51 -0400)
committerJosef Schlehofer <redacted>
Sun, 19 Jul 2026 09:23:51 +0000 (11:23 +0200)
Where possible prefer the log wrappers to direct logger calls.

Signed-off-by: Daniel F. Dickinson <redacted>
net/nut/files/libhid-ups.hotplug
net/nut/files/nut-cgi.init
net/nut/files/nut-serial.hotplug
net/nut/files/nut-server.init
net/nut/files/nut-service.sh.functions

index 0400b28b70129e4de5b75dd332680b6bb85f1595..babbff17ac586fe2ca2b512e8a25d007d0c3e7b3 100644 (file)
@@ -58,7 +58,7 @@ start_stop_driver() {
        add)
                # Skip hotplug if it is disabled or NUT is shutting down
                if ! allow_hotplug_restart; then
-                       logger -s -t nut-usb-hotplug "Hotplug restart disabled starting '$ups' when processing '$ACTION' for '$DEVNAME'"
+                       log_msg "Hotplug restart disabled starting '$ups' when processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug info
                        # This is a configuration not an error
                        return 0
                fi
@@ -66,7 +66,7 @@ start_stop_driver() {
                # Set permissions to allow the UPS device to start
                # In some cases this may be enough for the UPS to start working
                if ! ensure_usb_ups_access "$ups" "$known_devname"; then
-                       logger -s -t nut-usb-hotplug "Unable to enable access to '$ups' when processing '$ACTION' for '$DEVNAME'"
+                       log_error "Unable to enable access to '$ups' when processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug
                        return 0
                fi
 
@@ -77,11 +77,11 @@ start_stop_driver() {
                # our last check.
                if /etc/init.d/nut-server enabled; then
                        if ! /etc/init.d/nut-server start "$ups"; then
-                               logger -s -t nut-usb-hotplug "Failed to start '$ups' processing '$ACTION' for '$DEVNAME'"
+                               log_error "Failed to start '$ups' processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug
                                return 0
                        fi
                else
-                       logger -s -t nut-usb-hotplug "Hotplug became disabled while processing '$ACTION' for '$DEVNAME'."
+                       log_error "Hotplug became disabled while processing '$ACTION' for '$DEVNAME'." "libhid-ups" nut-usb-hotplug
                        return 0
                fi
                ;;
@@ -90,7 +90,7 @@ start_stop_driver() {
                # We stop only the removed UPS as we want the NUT service and other
                # UPS (if any) to remain up.
                /etc/init.d/nut-server stop "$ups" || {
-                       logger -s -t nut-usb-hotplug "Failed to stop nut-driver instance (UPS) '$ups'."
+                       log_error "Failed to stop nut-driver instance (UPS) '$ups'." "libhid-ups" nut-usb-hotplug
                        return 0
                }
                ;;
@@ -116,7 +116,7 @@ nut_driver_config() {
        # we keep going as we will restart this UPS with no match.
        config_get cfg_vendorid "$ups" vendorid
        if [ -n "$cfg_vendorid" ] && ! check_valid_hex_number "${cfg_vendorid/0x/}"; then
-               logger -s -t nut-usb-hotplug "Configured vendorid for '$ups' is not valid"
+               log_error "Configured vendorid for '$ups' is not valid" "libhid-ups" nut-usb-hotplug
                nd_driver_config_error=true
                return 0
        fi
@@ -138,7 +138,7 @@ nut_driver_config() {
        # we keep going as we will restart this UPS with no match.
        config_get cfg_productid "$ups" productid
        if [ -n "$cfg_productid" ] && ! check_valid_hex_number "${cfg_productid/0x/}"; then
-               logger -s -t nut-usb-hotplug "Configured productid for '$ups' is not valid"
+               log_error "Configured productid for '$ups' is not valid" "libhid-ups" nut-usb-hotplug
                nd_driver_config_error=true
                return 0
        fi
@@ -163,7 +163,7 @@ nut_driver_config() {
        if [ "$try_match" = "no" ]; then
                if [ "$ACTION" = "add" ]; then
                        if ! allow_hotplug_restart; then
-                               logger -s -t nut-usb-hotplug "Hotplug restart disabled starting '$ups' when processing '$ACTION' for '$DEVNAME'"
+                               log_msg "Hotplug restart disabled starting '$ups' when processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug notice
                                return 0
                        fi
                        # We check enabled again here, in case of a race condition since
@@ -173,14 +173,14 @@ nut_driver_config() {
                                # than restart of '$ups'. The nut-server initscript will do a
                                # start if the reload fails.
                                /etc/init.d/nut-server reload "$ups" || {
-                                       log_error "Failed to reload unmatched driver instance (UPS) '$ups' in nut_driver_config" libhid-ups nut-usb-hotplug
+                                       log_msg "Failed to reload unmatched driver instance (UPS) '$ups' in nut_driver_config" libhid-ups nut-usb-hotplug notice
                                        nd_driver_config_error=true
                                        return 0
                                }
                        else
                                # Initscript should have its own logging, and we do not exit with
                                # error as that would abort processing other devices
-                               logger -s -t nut-usb-hotplug "NUT server disabled when processing '$ACTION' for '$DEVNAME'."
+                               log_msg "NUT server disabled when processing '$ACTION' for '$DEVNAME'." "libhid-ups" nut-usb-hotplug notice
                                return 0
                        fi
                else
@@ -192,12 +192,12 @@ nut_driver_config() {
                fi
        elif [ -n "$cfg_vendorid" ] && [ -n "$cfg_productid" ] && [ -n "$pvendid" ] && [ -n "$pprodid" ]; then
                if ! check_valid_hex_number "$pvendid"; then
-                       logger -s -t nut-usb-hotplug "Hotplug vendor id for '$ups' is not valid"
+                       log_error "Hotplug vendor id for '$ups' is not valid" "libhid-ups" nut-usb-hotplug
                        nd_driver_config_error=true
                        return 0
                fi
                if ! check_valid_hex_number "$pprodid"; then
-                       logger -s -t nut-usb-hotplug "Hotplug product id for '$ups' is not valid"
+                       log_error "Hotplug product id for '$ups' is not valid" "libhid-ups" nut-usb-hotplug
                        nd_driver_config_error=true
                        return 0
                fi
@@ -230,12 +230,12 @@ perform_libhid_action() {
        # Only find statepath and runas once per event
        # defines STATEPATH
        find_statepath "upsd" "nut_server" || {
-               logger -s -t nut-usb-hotplug "Failed to set STATEPATH"
+               log_error "Failed to set STATEPATH" "libhid-ups" nut-usb-hotplug
                return 1
        }
        # sets RUNAS
        find_runas "upsd" "nut_server" || {
-               logger -s -t nut-usb-hotplug "Failed to set RUNAS"
+               log_error "Failed to set RUNAS" "libhid-ups" nut-usb-hotplug
                return 1
        }
 
@@ -284,7 +284,7 @@ perform_libhid_action() {
        # and not already stopped, will be stopped. This is preferable to doing
        # nothing on removals.
        if ! allow_hotplug_restart; then
-               logger -s -t nut-usb-hotplug "Hotplug restart disabled when processing '$ACTION' for '$DEVNAME'"
+               log_msg "Hotplug restart disabled when processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug notice
                return 0
        fi
        # We check enabled again here, in case of a race condition since
@@ -296,7 +296,7 @@ perform_libhid_action() {
                fi
                return 0
        else
-               logger -s -t nut-usb-hotplug "NUT server disabled when processing '$ACTION' for '$DEVNAME'."
+               log_msg "NUT server disabled when processing '$ACTION' for '$DEVNAME'." "libhid-ups" nut-usb-hotplug notice
                return 0
        fi
        # We do not return 0 here as it is unnecessary (all if branches have a
@@ -324,13 +324,13 @@ case "$PRODUCT" in
        # NUT_DISABLE_HOTPLUG_PATH is an external sentinel used to indicate NUT
        # hotplug is disabled.
        if ! allow_hotplug_restart; then
-               logger -s -t nut-usb-hotplug "Hotplug restart disabled when processing '$ACTION' for '$DEVNAME'"
+               log_msg "Hotplug restart disabled when processing '$ACTION' for '$DEVNAME'" "libhid-ups" nut-usb-hotplug notice
                exit 0
        fi
        # We check enabled again here, in case of a race condition since
        # our last check.
        if ! /etc/init.d/nut-server enabled; then
-               logger -s -t nut-usb-hotplug "NUT server disabled when processing '$ACTION' for '$DEVNAME'."
+               log_msg "NUT server disabled when processing '$ACTION' for '$DEVNAME'." "libhid-ups" nut-usb-hotplug notice
                exit 0
        fi
        if ! perform_libhid_action; then
index 9cd65089d6497d165a58acbf2611283669039a87..9aea83c94df9c38f4c515c690aa6de1fdc2c1958 100644 (file)
@@ -280,7 +280,7 @@ service_reload() {
                        return 1
                fi
                # Empty hosts is not necessarily an error, but we log for information
-               logger -s -t nut-cgi "No configured hosts"
+               log_msg "No configured hosts" nut-cgi nut-cgi info
        fi
 
        # NUT CGI host file configuration is independent of upsset configuration
index 9da375df8e7a096dca41058d1ef70d0bdfc4506c..d7e300525c98943d34edb6e9f2276a8183570fff 100644 (file)
@@ -139,7 +139,7 @@ nut_on_hotplug_add() {
        # attempt to reload the driver and/or server
        if [ "$did_set_perms" = "true" ]; then
                # Informational and not an error
-               logger -t nut-serial-hotplug "Successfully set permissions for serial device(s)"
+               log_msg "Successfully set permissions for serial device(s)" nut-serial nut-serial-hotplug info
                # We shouldn't get here if hotplug is disabled (race condition if we do), so log it as an error
                if ! allow_hotplug_restart; then
                        log_error "Did not restart NUT after setting permissions as hotplug restart is disabled" nut-serial nut-serial-hotplug
@@ -163,7 +163,7 @@ nut_on_hotplug_add() {
 # for information
 if ! allow_hotplug_restart; then
        # Informational and not an error
-       logger -t nut-serial-hotplug "Did not set permissions on serial port hotplug as NUT hotplug is disabled"
+       log_msg "Did not set permissions on serial port hotplug as NUT hotplug is disabled" nut-serial nut-serial-hotplug notice
        exit 0
 fi
 
index 8a80d2ede34e10c5cef4e2ddbc42014397e98a49..7293627f46dbd7a14826289baceb83f3035af339 100644 (file)
@@ -397,7 +397,7 @@ reload_ups_driver() {
 
 stop_service_if_no_instances() {
        if service_active_no_instances "nut-server"; then
-               logger -t "nut-server" "nut-server active with no instances"
+               log_msg "nut-server active with no instances" nut-server "nut-server" notice
                # If "nut-server" is active with no instances
                # We don't care about the exit code of procd_kill, and logging its
                # stderr can aid debugging.
index 54e138cdc26260af700556d114814ad6876b7229..b8a4ded76cec54d6a4cfdcf68c84301a0fdac3a7 100644 (file)
@@ -67,7 +67,7 @@ list_running_instances() {
        if [ -n "$running_instances" ]; then
                json_init
                json_load "$running_instances" || {
-                       logger -s -t nut-service "json_load failed in list_running_instances"
+                       log_error "json_load failed in list_running_instances" nut-service.sh nut-service
                        return 1
                }
                json_get_keys instance_names
@@ -139,7 +139,7 @@ signal_instance() {
        # We only want to issue secondary command if the primary command fails
        if [ "$ret" = "1" ] && [ -n "$secondary_command" ] && procd_running "$service_name" "$instance_name"; then
                # Informational log message, not error
-               logger -s -t "$service_name" "Performing '$secondary_command' $* for '$instance_name'"
+               log_msg "Performing '$secondary_command' $* for '$instance_name'" nut-service.sh "$service_name" info
                set -f
                "$secondary_command" "$@" 2>&1 | logger -t "$service_name"
                set +f
git clone https://git.99rst.org/PROJECT