mirror of
https://github.com/openwrt/packages.git
synced 2026-04-15 19:02:09 +00:00
When a USB UPS is first configured, the permissions on the device under `/dev/bus/usb` have not yet been set to allow the nut user access. This resulted in errors such as: Fri Feb 13 23:39:01 2026 daemon.debug upsd[3504]: [D1] mainloop: UPS [eco550ups] is not currently connected, trying to reconnect Fri Feb 13 23:39:01 2026 daemon.debug upsd[3504]: [D1] mainloop: UPS [eco550ups] is still not connected (FD -1) Fri Feb 13 23:39:03 2026 daemon.debug upsd[3504]: [D1] mainloop: UPS [eco550ups] is not currently connected, trying to reconnect Fri Feb 13 23:39:03 2026 daemon.debug upsd[3504]: [D1] mainloop: UPS [eco550ups] is still not connected (FD -1) or Fri Feb 13 23:38:44 2026 daemon.err usbhid-ups[3083]: No matching HID UPS found Fri Feb 13 23:38:49 2026 daemon.warn procd: failed adding instance cgroup for nut-server: No error information Fri Feb 13 23:38:49 2026 daemon.err usbhid-ups[3115]: libusb1: Could not open any HID devices: insufficient permissions on everything Fri Feb 13 23:38:49 2026 daemon.err usbhid-ups[3115]: No matching HID UPS found Fri Feb 13 23:38:54 2026 daemon.warn procd: failed adding instance cgroup for nut-server: No error information and upsd would enter a procd crashloop. We fix that by looking in `sysfs` (under `/sys/devices`) to find the correct USB device and set its ownership and permissions to allow acces to the user the driver is running under. Copilot complained about a few things * nut-server.init had potential word-splitting issues in various spots. * it also had some commands missing an argument * improved documentation was required to clarify a dependency * an incorrect sed could mangle names as well as remove the intended name Additionally, while fixing those issues the author noticed that the case of multiple UPS devices with the same vendorid:productid were not correctly handled. A check of the serial number, if provided, was added along with a fallback to allowing NUT communications with all UPS devices with a given vendorid:productid, if no serial number was given. Improve efficiency and decrease McCabe complexity of ensure_usb_ups_access, while also fixing Copilot complaints. $@ in case is a problem, and we only handle the first parameter in any event, so change $@ to "$1" Copilot caught a missing 2>&1 and we silence some shellcheck false positives Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>