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

The big sudo challenge: how can we fix the need to run PiGpio provider applications as sudo? #212

Closed
FDelporte opened this issue Apr 18, 2022 · 16 comments
Assignees
Labels
enhancement New feature or request

Comments

@FDelporte
Copy link
Member

FDelporte commented Apr 18, 2022

As the native PiGpio integration requires sudo-privileges, a lot of users have problems or don't know if this requirement although it is mentioned in the documentation.

Relateded issues

@FDelporte FDelporte self-assigned this Apr 18, 2022
@FDelporte FDelporte added the enhancement New feature or request label Apr 18, 2022
@sgparry
Copy link

sgparry commented Apr 25, 2022

This is not just a documentation issue. This is a real deal-breaker and makes using Pi4J utterly unusable in any program that requires network listeners or similar permission sensitive services. Node and python both have ways of doing GPIO and SPI without sudo privileges and appear to do so without yet another daemon and yet another slow socket interface. Are there any supported alternatives to pigpio please?

@savageautomate
Copy link
Member

savageautomate commented Apr 25, 2022

The sudo requirement can be mitigated for select functions including GPIO, I2C, SPI, SERIAL with the implementation of Linux file system I/O providers opposed to the PiGpio implementation. This is on my list of things TODO.

Accessing GPIO via the Linux (user) file system drivers does add some latency but likely not as much as a socket daemon.

I'm not sure if PWM functions or other supported I/O capabilities have been exposed via the Linux FS yet or not.

Additional details when this was implemented in the previous generation of Pi4J are included here:
http://www.savagehomeautomation.com/pi4j-nonprivileged

REF: #117

@FDelporte
Copy link
Member Author

Hi @savageautomate, would be great if you could get me started on this LinuxFS or if we could work together on it...
See #117

@hackerjimbo
Copy link

An interesting (and faster) alternative is to consider using /dev/gpiomem. It's there for exactly this purpose.

@FDelporte
Copy link
Member Author

@hackerjimbo sounds promising :-)
you have some more info or example implementations of this approach?

@hackerjimbo
Copy link

The GPIO library used by the v1 version used it.

@hackerjimbo
Copy link

Essentially it's like /dev/mem but limited to the GPIO area.

@sgparry
Copy link

sgparry commented Apr 25, 2022

So why did later versions switch to things like Wiring and now pigpio, which themselves both seem to have very limited / sporadic support?

@hackerjimbo
Copy link

Because the original one wasn't maintained.

@FDelporte
Copy link
Member Author

indeed WiringPi got deprecated in 2019. That's why Pi4J V2 switched to PiGpio. These native libraries are the "gateway" between Java and the GPIOs.

@sgparry
Copy link

sgparry commented Apr 26, 2022

Problem seems to be that these gateways all to often become unhinged. pigpio not only requires root privileges but also seems to block other programs from accessing unrelated gpio pins and does not release that control even when you terminate the daemon.

@savageautomate
Copy link
Member

@sgparry

I have been working on the LinuxFS implementation of a GPIO provider based on the older Linux Filesystem GPIO driver via the /sys/class/gpio file. You user account must have the gpio group assigned to it to use this without sudo.

You can see this changes and build from this branch if you would like to test them out.
https://github.com/Pi4J/pi4j-v2/commits/issues/%23117

Here are some basic examples I used to test with for Linux FS Digital Input, Digital Output, and PWM:
https://github.com/savageautomate/pi4j-remote-test/tree/main/src/main/java/com/pi4j/remote

Note, I did not get PWM working on my system without sudo; however, this may just be a configuration or overlay issue. I need to update to the latest OS version and try again.

@savageautomate
Copy link
Member

savageautomate commented May 4, 2022

@hackerjimbo

An interesting (and faster) alternative is to consider using /dev/gpiomem. It's there for exactly this purpose.

Yes, that would be something we could look into. However, to start with I'm trying to target the generic Linux kernel defined GPIO APIs so that the implementation may potentially be useful for other SoCs in the future.

If we implement any RaspberryPi specific code, we would do that in the RaspberryPi I/O providers (which are currently just stubs and not implemented.).

Currently, I'm prototyping the native code to allow Pi4J to use the newer /dev/gpiochip* character Linux device driver opposed to the older proc FS (/sys/class/gpio) driver which apparently is getting deprecated. (More info: https://elixir.bootlin.com/linux/v5.15/source/include/uapi/linux/gpio.h). If I target the 5.15 kernel in the latest Raspbian OS release we may be able to include things like PULL UP/DOWN bias which was not previously supported via the Linux filesystem drivers. I still need to test this out and see if it works but I have been able to get the basic input and output working in native code. This still may not be as efficient as the /dev/gpiomem approach but it would at least adhere to the generic Linux APIs for GPIO access.

@eitch
Copy link
Member

eitch commented Sep 17, 2024

We now have a new gpiod implementation, and this doesn't require sudo anymore. So this issue is resolved, check out the new provider: https://www.pi4j.com/documentation/providers/gpiod/

@eitch eitch closed this as completed Sep 17, 2024
@amanteaux
Copy link

Thank you a lot for this release!
To be completely sure, does this release still require sudo for PWM access?

@taartspi
Copy link
Collaborator

taartspi commented Oct 8, 2024

The pigpio provider still requires sudo

https://www.pi4j.com/documentation/providers/.
The linuxfs pwm provider operates without sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants