isapego commented on code in PR #1272:
URL: https://github.com/apache/ignite-3/pull/1272#discussion_r1010553669
##########
modules/platforms/cpp/tests/client-test/main.cpp:
##########
@@ -22,8 +22,41 @@
#include <gtest/gtest.h>
#include <chrono>
+#include <csignal>
#include <thread>
+namespace {
+/** Shutdown handler that cleans up resources. */
+std::function<void(int)> shutdown_handler;
+
+/**
+ * Receives OS signal and handles it.
+ *
+ * @param signum Signal value.
+ */
+void signal_handler(int signum) {
+ shutdown_handler(signum);
+
+ signal(signum, SIG_DFL);
+
+ raise(signum);
+}
+}
+
+/**
+ * Sets process abortion (SIGABRT, SIGINT, SIGSEGV signals) handler.
+ *
+ * @param handler Abortion handler.
+ */
+void set_process_abort_handler(std::function<void(int)> handler) {
+ // Install signal handlers to clean up resources on early exit.
+ signal(SIGABRT, signal_handler);
+ signal(SIGINT, signal_handler);
+ signal(SIGSEGV, signal_handler);
+
+ shutdown_handler = std::move(handler);
Review Comment:
Handler should be set prior to signal interceptors or we are going to get
unhandled exception while handling signal in some cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]