-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Library segfaults when not running as root on Raspberry Pi #424
Comments
Maybe someone with more knowledge could help on this. Debugging the library (non root user) I saw something that it is does not looks good. This is a backtrace of the failing function ....
At the first two function calls the paddr is 0xffffffff which does not seems to be right. Even if there is no alternative to find if the SPI or the bcm can access the hardware, it can easily detected from paddr. |
While digging...
From the code we see
So either check after |
As the bcm2835 could not initialize the spi0 because of privileges we could make a check if we actually have root access. The best place to put the check is
We can easily detect root access there with something like :
|
I'm going to create a PR for that! |
I assume this affects other Linux distros besides Raspbian on the Pi, but I haven't tested it as I don't have a Linux device with GPIO/SPI handy. This was encountered on the latest version of Raspbian on the Pi 3.
The library (including all of its examples) does not work on the Pi unless you're running as root/su, which may be common knowledge, but it is not mentioned in the RPi documentation page. It is subtly shown to use sudo on the Linux documentation page but I did not discover this until after I found the solution to the problem. Also I was not the only one that had this problem.
The result of running it as non-root on the Raspberry Pi is a segfault, which is extremely user-unfriendly. Ideally, the library should detect if SPI is unavailable and throw a meaningful exception.
It appears from the code comments here that this should be as simple as checking the return value for zero here. I am not a C++ expert but I think I can try my hand at submitting a PR for this, I just wanted to go ahead and get an issue logged in case someone had a better solution in the meantime. Also, the RPi documentation should probably be updated with this requirement.
The text was updated successfully, but these errors were encountered: