]> git.99rst.org Git - openwrt-packages.git/commitdiff
nut: fix setting RUNAS and STATEPATH in hotplug scripts
authorDaniel F. Dickinson <redacted>
Thu, 27 Aug 2026 23:56:40 +0000 (19:56 -0400)
committerJosef Schlehofer <redacted>
Thu, 10 Sep 2026 08:22:36 +0000 (10:22 +0200)
A previous PR missed updating the hotplug scripts for the
new find_runas and find_statepath functions which emit
the value on stdout instead of setting a variable in the
caller's scope. Update that usage and handle error conditions.

Also ensure we fully handle finding the group of the RUNAS user for
the serial usb hotplug case, and handle error conditions for that.

Signed-off-by: Daniel F. Dickinson <redacted>
net/nut/files/libhid-ups.hotplug
net/nut/files/nut-serial.hotplug

index 140ac5656c41bd95e0eb0d6f1b3433b20e2411aa..883f40de6bf7a2a6df75f2c3323c1edf0789e708 100644 (file)
@@ -229,16 +229,25 @@ perform_libhid_action() {
        local pvendid pprodid
 
        # Only find statepath and runas once per event
-       # defines STATEPATH
-       find_statepath "upsd" "nut_server" || {
+       STATEPATH="$(find_statepath "upsd" "nut_server")" || {
                log_error "Failed to set STATEPATH" "libhid-ups" nut-usb-hotplug
                return 1
        }
-       # sets RUNAS
-       find_runas "upsd" "nut_server" || {
+       [ -n "$STATEPATH" ] || {
+               log_error "Failed to set STATEPATH" "libhid-ups" nut-usb-hotplug
+               return 1
+       }
+       export STATEPATH
+
+       RUNAS="$(find_runas "upsd" "nut_server")" || {
+               log_error "Failed to set RUNAS" "libhid-ups" nut-usb-hotplug
+               return 1
+       }
+       [ -n "$RUNAS" ] || {
                log_error "Failed to set RUNAS" "libhid-ups" nut-usb-hotplug
                return 1
        }
+       export RUNAS
 
        # PRODUCT comes from the calling hotplug event, and
        # is of the form vendorid/productid/other
index 7a7988d8c97c5c1c3e3d737c842438f41267219f..6cceb10dd38623009fc04d77e3a20e94eb763f20 100644 (file)
@@ -36,6 +36,9 @@
        exit 1
 }
 
+# Group of RUNAS user; used to allow access to the USB serial device
+DEVICE_GROUP=""
+
 # 'shellcheck' does not understand config_foreach and therefore treats
 # functions and variables referenced only from config_foreach as not reachable,
 # or never invoked.
 nut_set_serial_port_permissions() {
        local devname="$1" # Must be full path (e.g. /dev/...)
        local ups="$2"
-       local device_group
-
-       # Get group of RUNAS user, to set the group of the hotplugged device node
-       # If RUNAS user does not exist, exit with an error.
-       device_group="$(id -gn "${RUNAS:-nut}")" || {
-               log_error "Unable to find group for '$RUNAS'. Skipping ups '$ups'" nut-serial nut-serial-hotplug
-               return 1
-       }
 
        # Guard against disappearing device (e.g. due to 'bouncing' device)
        if [ -e "$devname" ]; then
-               if ! chgrp "$device_group" "$devname"; then
+               # Allow RUNAS user (which is user of driver process) to access device
+               if ! chgrp "$DEVICE_GROUP" "$devname"; then
                        log_error "Unable to set group on '$devname'" nut-serial nut-serial-hotplug
                        return 1
                fi
@@ -124,11 +120,22 @@ nut_on_hotplug_add() {
                exit 1
        }
 
-       # Only find statepath and runas once per event
-       # sets RUNAS
-       find_runas "upsd" "nut_server" || {
+       # Only find runas once per event
+       RUNAS="$(find_runas "upsd" "nut_server")" || {
                log_error_exit "Failed to set RUNAS" nut-serial nut-serial-hotplug
        }
+       [ -n "$RUNAS" ] || {
+               log_error_exit "Failed to set RUNAS" nut-serial nut-serial-hotplug
+       }
+       export RUNAS
+
+       # Get group of RUNAS user, to set the group of the hotplugged device node
+       # If RUNAS user does not exist, exit with an error.
+       DEVICE_GROUP="$(id -gn "${RUNAS}")" || {
+               log_error "Unable to find group for RUNAS user '$RUNAS'. Skipping serial usb hotplug." nut-serial nut-serial-hotplug
+               return 1
+       }
+       export DEVICE_GROUP
 
        # Check if serial USB UPS for each NUT driver instance (UPS), and if so
        # configure permissions to allow NUT to access the port
git clone https://git.99rst.org/PROJECT