Running a node that needs root privileges
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
Running ROS nodes as
root
is really not a good idea, but try withsudo -E
as alaunch-prefix
. That should preventsudo
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 evensudo -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.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.
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 usinglibcap
, setting device permissions withudev
, and running your node as a user that is in thekmem
group.Yes. What @Geoff wrote (which is a better version of what I wanted to get across).
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.
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.