diff --git a/eplansys_demo/src/corridor_actions.cpp b/eplansys_demo/src/corridor_actions.cpp index 5fcbd831..98ba0f4b 100644 --- a/eplansys_demo/src/corridor_actions.cpp +++ b/eplansys_demo/src/corridor_actions.cpp @@ -31,6 +31,8 @@ #include "rclcpp/rclcpp.hpp" +#include "leave.hpp" + namespace eplansys_demo { @@ -130,6 +132,5 @@ int main(int argc, char ** argv) } executor.spin(); - rclcpp::shutdown(); - return 0; + eplansys_demo::leave(0); } diff --git a/eplansys_demo/src/leave.hpp b/eplansys_demo/src/leave.hpp new file mode 100644 index 00000000..07b4eb08 --- /dev/null +++ b/eplansys_demo/src/leave.hpp @@ -0,0 +1,47 @@ +// Copyright 2026 Intelligent Robotics Lab +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef LEAVE_HPP_ +#define LEAVE_HPP_ + +#include + +#include + +#include "rclcpp/rclcpp.hpp" + +namespace eplansys_demo +{ + +/// End the process once its work is done, without destroying the performers. +/// +/// A performer interrupted by the launch file at the end of a mission +/// segfaulted in about one run in five, after every action had finished. The +/// fault is in the performer's destructor, run from main after +/// rclcpp::shutdown(), while CascadeLifecycleNode frees its activators_state_ +/// map through a pointer that is no longer valid; no thread of this process was +/// using the node by then. Nothing is left to do at that point, so the process +/// leaves through _exit and skips the teardown, as plansys2_tests does for its +/// own exit-time fault. +[[noreturn]] inline void leave(int status) +{ + rclcpp::shutdown(); + std::fflush(stdout); + std::fflush(stderr); + _exit(status); +} + +} // namespace eplansys_demo + +#endif // LEAVE_HPP_ diff --git a/eplansys_demo/src/survey_actions.cpp b/eplansys_demo/src/survey_actions.cpp index 83132c6a..e9636ef9 100644 --- a/eplansys_demo/src/survey_actions.cpp +++ b/eplansys_demo/src/survey_actions.cpp @@ -31,6 +31,8 @@ #include "rclcpp/rclcpp.hpp" +#include "leave.hpp" + namespace eplansys_demo { @@ -133,6 +135,5 @@ int main(int argc, char ** argv) } executor.spin(); - rclcpp::shutdown(); - return 0; + eplansys_demo::leave(0); } diff --git a/eplansys_demo/src/survey_sites_actions.cpp b/eplansys_demo/src/survey_sites_actions.cpp index c835db42..e113809e 100644 --- a/eplansys_demo/src/survey_sites_actions.cpp +++ b/eplansys_demo/src/survey_sites_actions.cpp @@ -31,6 +31,8 @@ #include "lifecycle_msgs/msg/transition.hpp" #include "rclcpp/rclcpp.hpp" +#include "leave.hpp" + namespace eplansys_demo { @@ -136,6 +138,5 @@ int main(int argc, char ** argv) } executor.spin(); - rclcpp::shutdown(); - return 0; + eplansys_demo::leave(0); }