From: Daniel F. Dickinson Date: Thu, 27 Aug 2026 23:56:40 +0000 (-0400) Subject: nut: fix setting RUNAS and STATEPATH in hotplug scripts X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ef7cb6819d8600009851e8003a32027d118bede7;p=openwrt-packages.git nut: fix setting RUNAS and STATEPATH in hotplug scripts 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 --- diff --git a/net/nut/files/libhid-ups.hotplug b/net/nut/files/libhid-ups.hotplug index 140ac5656..883f40de6 100644 --- a/net/nut/files/libhid-ups.hotplug +++ b/net/nut/files/libhid-ups.hotplug @@ -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 diff --git a/net/nut/files/nut-serial.hotplug b/net/nut/files/nut-serial.hotplug index 7a7988d8c..6cceb10dd 100644 --- a/net/nut/files/nut-serial.hotplug +++ b/net/nut/files/nut-serial.hotplug @@ -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. @@ -43,18 +46,11 @@ 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