Skip to content

Commit

Permalink
sleep to avoid udev race condition #185
Browse files Browse the repository at this point in the history
sleep 100 ms after export to avoid race condition as udev
needs the opportunity to set group ownership and permission

Test instructions:
==================
reboot, log back in, wait for udev to set group ownership and permission:

$ ls -la /sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip6/export
-rw-rw---- 1 root pwm 4096 Nov  2 04:02 /sys/devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip6/export

run test program:

python ~/issue185.py

contents of test program:

import Adafruit_BBIO.PWM as PWM
PWM.start("P8_13", 50, 1000, 0)
PWM.stop("P8_13")
PWM.cleanup()
  • Loading branch information
pdp7 committed Nov 2, 2017
1 parent 657d1fb commit b65cbf8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/c_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
}
fprintf(f, "%d", p->index);
fclose(f);
/* sleep to avoid race condition as udev needs the
opportunity to set group ownership and permission */
syslog(LOG_DEBUG, "Adafruit_BBIO: pwm_start: sleep 100 ms after export to avoid udev race condition");
usleep(100 * 1000); /* 100 ms */
} else {
syslog(LOG_ERR, "Adafruit_BBIO: pwm_setup: %s couldn't stat %s: %i-%s",
key, pwm_path, errno, strerror(errno));
Expand Down

0 comments on commit b65cbf8

Please sign in to comment.