Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
14 25 sysfs permissions #26
base: master
Are you sure you want to change the base?
14 25 sysfs permissions #26
Changes from 2 commits
168a874
20653fa
f9991c3
84789ac
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what flush was supposed to do.
If this is happening, then a sleep here will only make this flaky -- there will still be cases where failure happens, they just won't show up in tests as often (which is probably even worse).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be, however it can also run into a race condition if another process deletes it before we see it. It's definitely better than a sleep though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it turns out the value file was being created immediately on my system. But it is initially created owned by root:root. If you are running as root, then this is why you didn't get errors here. Unfortunately, running as root is not an option in my environment. I believe udev comes along and changes the file to root:gpio (on stock Raspberry Pi OS), but this change takes a few ms. The latest commit watches for this change and is able to continue after a 30ms delay on my Pi 4. The half second timeout should prevent deadlock on race condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that helps explain it.
I'm not sure how best to support this. I'm pretty sure that a sleep is not the right approach :D
What we want: a boolean flag which loops, waiting for the right condition. That condition would wait until...the file ownership changes?
But that likely won't work for everyone. Which owner should we wait for? The default of "current user" should work most of the time, but will it always work?
We could allow you to pass in a function... which we call at the right moment. But that's extremely messy as well.
I think probably we messed up on the API a bit. The constructor should not be performing logic. If we had a
staticmethod
constructor for the default case and customized constructors for more specialized cases, then we could break up this logic more easily.However, it's all up to @Gadgetoid as I am no longer the lead maintainer, and that would be a breaking change. Just some thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9991c3 waits for the group owner to change, matching that of the /sys/class/gpio/ directory. This should work for everyone. Since it gives up waiting after 0.5 seconds, there should be no breaking change here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I can't believe how far behind the curve I am with this. I've been working on getting libgpiod up to scratch, among other things.
This PR needs split up into two individual pulls. One to fix the file modes, which are a very imminent and clear cut problem (well certainly as of a year ago, sigh) and one to address the ownership.
IMO it's my preference simply to duck-type ownership - rather than checking the group we should just try to open the device, catch the error and re-try a number of times before raising an exception to the user.
I'm not averse to changing the API if we need to. I'd rather have a good library than worry about people having to make downstream code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree with auto-retry -- that is something for a client (with a retry library) to do, not us.
I'd be okay with having a paramater or default retry function to help folks have an a simple and easy path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I agree there- if it’s common behaviour for the system to be slow to assign relevant permissions to a file node we’re explicitly expecting to be writable, then that’s an implementation detail and not something to be surfaced to the user. Particularly as opening a pin - which necessarily requires an export - already has side-effects that could leave the gpio in an unexpected state.
You could argue for a change of API that requires the user to set up the initial value and direction outside the constructor, but that’s kicking the can down the road somewhat- if the user has to care about implementation details and minor per platform caveats, what’s the library even for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can see the point of keeping things simple and slow. Sorry, I deal with lots of "async" design paths in my work and was probably over-applying the best practices.