1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 04:43:21 +00:00

add 1s delay in set_direction to allow udev to set permissions

This commit is contained in:
Michael Eitelwein
2017-11-11 19:08:02 +00:00
parent c87b0ca72a
commit 00cd5c09ad

View File

@ -383,12 +383,19 @@ int gpio_set_direction(int gpio, unsigned int in_flag)
char filename[MAX_FILENAME]; filename[0] = '\0';
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/direction", gpio); BUF2SMALL(filename);
if ((fd = open(filename, O_WRONLY)) < 0) {
// if called as non-root, udev may need time to adjust file
// permissions after setting up gpio
sleep(1);
if ((fd = open(filename, O_WRONLY)) < 0) {
char err[256];
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s' (%s)", filename, strerror(errno));
add_error_msg(err);
return -1;
}
}
char direction[16];
if (in_flag) {