Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexport digital pins on Close(). #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wujiang
Copy link
Contributor

@wujiang wujiang commented Dec 29, 2015

Exported digital pins can be uninitialized.

How to reproduce the problem

package main

import (
        "fmt"

        "github.com/kidoman/embd"
        _ "github.com/wujiang/embd/host/rpi"
)

func main() {
        embd.InitGPIO()
        defer embd.CloseGPIO()
        fmt.Println(embd.SetDirection(12, embd.Out))
}
/tmp $ go build
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
write /sys/class/gpio/export: device or resource busy
/tmp $ ./tmp
write /sys/class/gpio/export: device or resource busy
/tmp $ ls /sys/class/gpio/
export  gpio12  gpiochip0  unexport

After the change:

/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied

Exported digital pins can be uninitialized.
@jpillora
Copy link

👍 Just ran into this issue

@tve
Copy link
Contributor

tve commented Sep 25, 2016

While I understand the problem, it seems to me that the unexporting should happen last after closing the exported files. So it seems that the Close() calls should be skipped on !initialized but the order of events shouldn't be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants