Open wujiang opened 8 years ago
The open /sys/class/gpio/gpio21/direction: permission denied
error when running as a non-root user is due to a race with raspian's udev rules (/etc/udev/rules.d/99-com.rules
) for gpio group access:
Using the changes to in #61 to allow the use of pre-exported gpio pins, we can use a helper script to export the gpio pins and wait for udev to settle:
#!/bin/sh
#
# raspbian uses udev to assign /sys/class/gpio group write permissions, but this is racy between gpio export and writing to .../direction:
# http://raspberrypi.stackexchange.com/questions/23162/gpio-value-file-appears-with-wrong-permissions-momentarily
# export beforehand and wait for udev before running
for gpio in "$@"; do
[ -e /sys/class/gpio/gpio$gpio ] || echo $gpio > /sys/class/gpio/export
done
echo "$0: Waiting for gpio devices to settle..." >&2
udevadm settle
IMO this is the best way to deal with the timing race in #52 and #53.
It looks like Raspberry pi needs some time after
export
to link the digital pin properly.Without the sleep, the output is
-rw-r--r--
. With the sleep, the output is-rwxrwx---
which is correct.This affects
SetDirection
directly.