Skip to content

Commit

Permalink
add 1s delay in set_direction to allow udev to set permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
MEitelwein committed Nov 11, 2017
1 parent c87b0ca commit 00cd5c0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/event_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,18 @@ 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) {
char err[256];
snprintf(err, sizeof(err), "gpio_set_direction: could not open '%s' (%s)", filename, strerror(errno));
add_error_msg(err);
return -1;
// 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];
Expand Down

0 comments on commit 00cd5c0

Please sign in to comment.