Skip to content

Commit

Permalink
Merge pull request #80 from MEitelwein/master
Browse files Browse the repository at this point in the history
add 1s delay in set_direction to allow udev to set permissions
  • Loading branch information
xtacocorex authored Nov 12, 2017
2 parents c87b0ca + 00cd5c0 commit 906beb0
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 906beb0

Please sign in to comment.