89 std::lock_guard<std::mutex> lock(
mutex_);
93 RCLCPP_INFO(
getLogger(),
"CpMicroRosAgent: already launched, skipping");
100 if (pipe(pipefd) == -1)
103 getLogger(),
"CpMicroRosAgent: pipe() failed: %s",
104 std::system_category().message(errno).c_str());
110 if (pipe2(lifefd, O_CLOEXEC) == -1)
113 getLogger(),
"CpMicroRosAgent: pipe2() failed: %s",
114 std::system_category().message(errno).c_str());
126 dup2(pipefd[1], STDOUT_FILENO);
127 dup2(pipefd[1], STDERR_FILENO);
129 close_range(3, ~0U, 0);
131 execl(
"/bin/sh",
"/bin/sh",
"-c",
command_.c_str(),
nullptr);
155 getLogger(),
"CpMicroRosAgent: no watchdog, fork() failed: %s",
156 std::system_category().message(errno).c_str());
161 int flags = fcntl(
pipeFd_, F_GETFL, 0);
162 fcntl(
pipeFd_, F_SETFL, flags | O_NONBLOCK);
172 ssize_t n = read(
pipeFd_, buf,
sizeof(buf) - 1);
176 RCLCPP_DEBUG(
getLogger(),
"[micro_ros_agent] %s", buf);
180 std::this_thread::sleep_for(std::chrono::milliseconds(100));
191 getLogger(),
"CpMicroRosAgent: fork() failed: %s",
192 std::system_category().message(errno).c_str());