Skip to content

Running as root #62

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

Closed
matzeema opened this issue Jun 9, 2020 · 4 comments
Closed

Running as root #62

matzeema opened this issue Jun 9, 2020 · 4 comments

Comments

@matzeema
Copy link

matzeema commented Jun 9, 2020

I'm currently trying to build a own library to communicate with the GPIOs to use UART and PWM. I am using the wiringPi library because it supports both interfaces. The problem is that wiringPi needs root permission to initialize PWM. I already searched for other solutions to run wiringPi without root but didn't find a lot.

So I just came to the point to run flutter-pi as root which doesn't seem to work.

pi@raspberrypi:~/projects/kart_project $ sudo flutter-pi .
sudo: flutter-pi: command not found

I was extra confused when I read this in README.md at the Fixing the GPU permissions part:

Otherwise, you'll need to run flutter-pi with sudo.

So is this a problem of flutter-pi or is there something wrong with my machine?

@DisDis
Copy link
Contributor

DisDis commented Jun 9, 2020

use:
sudo ./flutter-pi .

@DisDis
Copy link
Contributor

DisDis commented Jun 9, 2020

But you should exec (one time)
sudo usermod -a -G render pi
afte that we can exec just (without sudo):
./flutter-pi .

@ardera
Copy link
Owner

ardera commented Jun 9, 2020

So is this a problem of flutter-pi or is there something wrong with my machine?

Neither, it's a user error 😄

You need to remember sudo is interpreting the argument you give it as a completely different user, namely root. root has it's own user directory (/root), similiar to the pi user, which has /home/pi as its user directory.

So everything you put into /home/pi/.bashrc, /home/pi/.profile or /home/pi/bin (et al.) will not work when using sudo. (Because the shell looks for these file in /root instead). So in your case, you probably put the path to flutter-pi into your PATH variable inside /home/pi/.bashrc, or you created a symlink in /home/pi/bin to point to the flutter-pi executable, so you don't have to invoke flutter-pi with the path every time. But this does not work when running using sudo.

You need to use the path of the flutter-pi executable when running using sudo. So for example, sudo ./flutter-pi or sudo /home/pi/devel/flutter-pi. Or you modify the .bashrc or similiar of the root user, but that may be a security hazard.

@matzeema
Copy link
Author

matzeema commented Jun 9, 2020

Oh thank you! I am quite new to Linux so thanks for the explanation. Works fine :)

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

No branches or pull requests

3 participants