Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SIGTERM handler for linux and closed session when reading error is caught #252

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions rmw_zenoh_cpp/src/zenohd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "rmw/error_handling.h"

#include "rcpputils/scope_exit.hpp"

static bool running = true;

class KeyboardReader final
Expand Down Expand Up @@ -192,18 +194,24 @@ int main(int argc, char ** argv)
return 1;
}

z_owned_session_t s = z_open(z_move(config));
if (!z_check(s)) {
z_owned_session_t session = z_open(z_move(config));
if (!z_check(session)) {
printf("Unable to open router session!\n");
return 1;
}
auto always_close_session = rcpputils::make_scope_exit(
[&session]() {
z_close(z_move(session));
});

printf(
"Started Zenoh router with id %s.\n",
rmw_zenoh_cpp::liveliness::zid_to_str(z_info_zid(z_session_loan(&s))).c_str());
rmw_zenoh_cpp::liveliness::zid_to_str(z_info_zid(z_session_loan(&session))).c_str());
#ifdef _WIN32
SetConsoleCtrlHandler(quit, TRUE);
#else
signal(SIGINT, quit);
signal(SIGTERM, quit);
#endif

KeyboardReader keyreader;
Expand All @@ -227,7 +235,5 @@ int main(int argc, char ** argv)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

z_close(z_move(s));

return 0;
}