Running a node that needs root privileges

asked 2020-07-01 14:16:03 -0500

lortane gravatar image

updated 2020-07-01 14:22:07 -0500

gvdhoorn gravatar image

Hi all,

I've been trying to run a node that uses the bcm2835 library to access the GPIO in a Raspberry Pi 3B+. To access them, the node has to run as root. I've been trying to solve this issue with answers from other posts such as this one #q165246, but when I try to do that I get the following error.

error while loading shared libraries: libxmlrpcpp.so: cannot open shared object file: No such file or directory

I am running Ubuntu 20.04 LTS and ROS Noetic.

Does anybody have any suggestions on how to do this?

Thanks in advance

edit retag flag offensive close merge delete

Comments

Running ROS nodes as root is really not a good idea, but try with sudo -E as a launch-prefix. That should prevent sudo from sanatising the environment.

Whether it leaves LD_LIBRARY_PATH alone I'm not sure. It could be that Focal comes with security related changes which make even sudo -E not work.

I also remember there being libraries which allow access to GPIO on platforms like the RPi without requiring root priviliges. It would be good to try and find those and see whether you can use them.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-01 14:18:26 -0500 )edit

And please link to more than just a single Q&A you've already seen and tried. Otherwise we run the risk of suggesting things you've already tried. That would be a waste of everyone's time.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-01 14:21:55 -0500 )edit
2

Rather than running as root or using sudo, you should set up your device so that root privelages are not needed to access the hardware. The "Running as root" section on this page has (counter-intuitively) instructions on how to access the hardware while not running as root by using libcap, setting device permissions with udev, and running your node as a user that is in the kmem group.

Geoff gravatar image Geoff  ( 2020-07-01 20:00:11 -0500 )edit

Yes. What @Geoff wrote (which is a better version of what I wanted to get across).

gvdhoorn gravatar image gvdhoorn  ( 2020-07-02 02:48:27 -0500 )edit

Thank you for your answer @Geoff. I have tried your suggestion but I don't get it to work. Idk if it's okay to keep asking about this here as this has moved to a topic that's not related to ROS.

lortane gravatar image lortane  ( 2020-07-02 05:28:15 -0500 )edit

I recommend you first create a simple standalone program (not a ROS node) that accesses it, and get that working as a non-root user. Once you have that fixed, then turn it into a ROS node.

Geoff gravatar image Geoff  ( 2020-07-02 19:16:27 -0500 )edit