Skip to content

Commit b65cbf8

Browse files
committed
sleep to avoid udev race condition #185
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()
1 parent 657d1fb commit b65cbf8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

source/c_pwm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
412412
}
413413
fprintf(f, "%d", p->index);
414414
fclose(f);
415+
/* sleep to avoid race condition as udev needs the
416+
opportunity to set group ownership and permission */
417+
syslog(LOG_DEBUG, "Adafruit_BBIO: pwm_start: sleep 100 ms after export to avoid udev race condition");
418+
usleep(100 * 1000); /* 100 ms */
415419
} else {
416420
syslog(LOG_ERR, "Adafruit_BBIO: pwm_setup: %s couldn't stat %s: %i-%s",
417421
key, pwm_path, errno, strerror(errno));

0 commit comments

Comments
 (0)