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 2 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,20 +194,26 @@ 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;
}
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

auto close_session = rcpputils::make_scope_exit(
CihatAltiparmak marked this conversation as resolved.
Show resolved Hide resolved
[&session]() {
z_close(z_move(session));
});

KeyboardReader keyreader;

char c = 0;
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;
}