Ros::ok() return true with dead roscore in node started as root
Hello,
I am trying to kill my node started as root.
In my case, my node need to be started as root to access some hardware (gpio).
So I added sudo -E
as a launch-prefix to my node.
When I ctrl+c my launchfile, the roscore died but node my node (probably due to the fact that the signal SIGTERM is not forwarded to program started as root). But I was expecting ros::ok()
to return false or even ros::isShuttingDown()
to return true, but no.
In this case as a normal user or as root rosnode list
return ERROR: Unable to communicate with master!
, so the master is dead but my node doesn't know about this.
<launch>
<node name="test_node" pkg="test_pkg" type="test_node" launch-prefix="sudo -E" />
</launch>
and a simple node to test it:
#include <ros/ros.h>
int main(int argc, char** argv) {
ros::init(argc, argv, "test_node");
ros::NodeHandle nh;
ros::NodeHandle nh_p("~");
ros::Rate rate(10);
while (ros::ok()) {
ros::spinOnce();
// do stuff
rate.sleep();
std::cerr<<"ros is ok"<<std::endl;
if(ros::isShuttingDown())
std::cerr<<"shutdown is called"<<std::endl;
}
std::cerr<<"program exit properly"<<std::endl;
//free acess to hardware
return 0;
Maybe this way is not the good one to kill a node started as root, I am open to any suggestion. Thanks for your help.
my suggestion would be to allow non-root users to acces the GPIOs. What platform are you using? You can do this either via udev, by adding yourself to a specific group (e.g. dialout) or by making the GPIO world-read-writeable. So I'd suggest one or two. About your problem, I cannot help there.
ros::ok()
returns whether the process local ROS objects are in an OK (enough) state. Not whether the master is still up.isShuttingDown()
returns whether the local node has been requested .... to stop (using
rosnode kill ..
fi, or by aroslaunch
server instance afterctrl+c
).The problem here is that a regular user cannot ask processes from other users to terminate using signals, as it doesn't have the right permissions.
Does the node shutdown if you use
rosnode kill
?@mgruhler I am using a raspberry pi 3 (Ubuntu ARM) and pigpio. And I haven't found any way to use pigpio without root.
@gvdhoorn thanks for the explaination I didn't knew about this. rosnode kill return
ERROR: Unable to communicate with master!
as normal user or as root. The only way I found to kill the process was to send a SIGTERM signal as root. Maybe I could check if the master is still alive.@GuillaumeB there are many questions about GPIO and RPi on this site. Check out #q278090 and the link therein, or #q229435
did you do this after you
ctrl+c
-ed everything already? If so, that would make sense.Yes, after the
ctrl+c
. I just tried the other way around and it worked. I can userosnode kill
before thectr+c