From 8fc279fe65c87e0dc01de2ba8fb70edab154da8c Mon Sep 17 00:00:00 2001 From: Hector Palacios Date: Mon, 15 Apr 2019 10:59:35 +0200 Subject: [PATCH] libdigiapix: add rule for PWM channels to be owned by digiapix group The exported PWM channels now report the channel name under udev EXPORT parameter. Add the 'change' udev action type to the udev rules and use that parameter to change the group ownership of the PWM channels to digiapix group, so they can be used by non-root user. Signed-off-by: Hector Palacios --- .../libdigiapix/libdigiapix-git/99-digiapix.rules | 2 +- .../recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules index 04ec742bb..f48d744cb 100644 --- a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules +++ b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/99-digiapix.rules @@ -19,4 +19,4 @@ SUBSYSTEM=="spidev", GROUP="digiapix", MODE="0660" SUBSYSTEM=="gpio", KERNEL=="gpiochip0", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" SUBSYSTEM=="gpio", KERNEL!="gpiochip*", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" -SUBSYSTEM=="pwm", ACTION=="add", RUN="/etc/udev/scripts/digiapix.sh" +SUBSYSTEM=="pwm", ACTION=="add|change", RUN="/etc/udev/scripts/digiapix.sh" diff --git a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh index bc3897c85..8a9bdd26e 100644 --- a/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh +++ b/meta-digi-dey/recipes-digi/libdigiapix/libdigiapix-git/digiapix.sh @@ -19,13 +19,17 @@ if basename "${DEVPATH}" | grep -qs "gpiochip0$"; then # Use 'gpiochip0' event to set group and mode for 'export/unexport' files chown root:digiapix /sys/class/gpio/export /sys/class/gpio/unexport chmod g+w /sys/class/gpio/export /sys/class/gpio/unexport -elif basename "${DEVPATH}" | grep -qs "pwmchip[0-9]\+$"; then +elif basename "${DEVPATH}" | grep -qs "pwmchip[0-9]\+$" && [ "${ACTION}" = "add" ] ; then # Set group and mode for pwmchip's 'export/unexport' files chown root:digiapix /sys${DEVPATH}/export /sys${DEVPATH}/unexport chmod g+w /sys${DEVPATH}/export /sys${DEVPATH}/unexport +elif basename "${DEVPATH}" | grep -qs "pwmchip[0-9]\+$" && [ "${ACTION}" = "change" ] ; then + # Set group and mode for 'pwmX' channel and all files inside it... + chown root:digiapix /sys${DEVPATH}/${EXPORT} /sys${DEVPATH}/${EXPORT}/* + chmod g+w /sys${DEVPATH}/${EXPORT}/* else # Change group and mode of the sysfs files created whenever a 'gpioX' - # or 'pwmX' is exported + # is exported chown -h root:digiapix /sys${DEVPATH}/* chmod g+w /sys${DEVPATH}/* fi