Skip to content

nut: hotplug script includes leading zeroes in PRODUCT case, leading to undetected hw #6966

@tofurky

Description

@tofurky

Maintainer: @cshoredaniel
Environment: ath79, ubnt,routerstation-pro, r8011+2-6bbb220255

'nut' package was compiled from latest commit as of 9/7/18 (2e624f9)

Description:

/etc/hotplug.d/usb/30-libhid-ups has a case statement like so:

[ -n "$PRODUCT" ] && case "$PRODUCT" in
3f0/0001/* | \
3f0/1f01/* | \
3f0/1f02/* | \
3f0/1f06/* | \
...
50d/0900/* | \
50d/0910/* | \
...
"")
	[ -d /var/run/nut ] && [ ! -f /var/run/nut/disable-hotplug ] && \
		/etc/init.d/nut-server enabled &&  perform_libhid_action
	;;
esac

however, adding "env >> /tmp/debug" to the script showed that PRODUCT does not include the leading 0 for my ups:

pvendid=50d pprodid=910
USER=root
ACTION=bind
...
PRODUCT=50d/910/6
INTERFACE=3/0/0
PWD=/
DEVTYPE=usb_interface

so the case doesn't match and the hotplug script doesn't set permissions, etc. leading to brokenness when not running upsd and /lib/nut/usbhid-ups as root.

the fix seems obvious, remove the leading zeroes. however i'm unsure if all leading zeroes should be removed, or just the first. in my case of PRODUCT=50d/910/6, changing the relevant case line to 50d/910/* | \ fixed the issue and allowed the hotplug script to run as intended.

also, i'll throw this out there as well - /etc/init.d/nut-server seems to unconditionally set local RUNAS=nut in start_driver_instance(), but for some reason still has this later on:

	if [ -n "$RUNAS" ]; then
		chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
		chown $RUNAS:$(id -gn $RUNAS) "$(dirname "$UPS_C")"
	fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions