mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-26 13:48:49 +08:00
sysfs: address race condition from udev rules when exporting GPIO pins
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
9fc46368a4
commit
62ebd67dea
@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -96,7 +97,18 @@ func (d *digitalPin) Export() error {
|
||||
d.direction.Close()
|
||||
}
|
||||
|
||||
d.direction, err = fs.OpenFile(fmt.Sprintf("%v/%v/direction", GPIOPATH, d.label), os.O_RDWR, 0644)
|
||||
attempt := 0
|
||||
for {
|
||||
attempt++
|
||||
d.direction, err = fs.OpenFile(fmt.Sprintf("%v/%v/direction", GPIOPATH, d.label), os.O_RDWR, 0644)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if attempt > 10 {
|
||||
return err
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
if d.value != nil {
|
||||
d.value.Close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user