aboutsummaryrefslogtreecommitdiff
path: root/comp3331/server/src/shared/shared.cc
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
commit98cef5e9a772602d42acfcf233838c760424db9a (patch)
tree5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp3331/server/src/shared/shared.cc
initial commit
Diffstat (limited to 'comp3331/server/src/shared/shared.cc')
-rw-r--r--comp3331/server/src/shared/shared.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/comp3331/server/src/shared/shared.cc b/comp3331/server/src/shared/shared.cc
new file mode 100644
index 0000000..3a13b47
--- /dev/null
+++ b/comp3331/server/src/shared/shared.cc
@@ -0,0 +1,25 @@
+#include "shared/shared.hh"
+
+namespace shared {
+
+bool should_exit = false;
+
+static void set_signal(const decltype(SIGINT) signal,
+ void (*const callback)(const int)) {
+ struct sigaction sa {};
+ sa.sa_handler = callback;
+ if (sigaction(signal, &sa, nullptr) == -1) {
+ throw std::runtime_error("failed to set signal handler!");
+ }
+}
+
+void set_exit_handler() {
+ set_signal(SIGPIPE, SIG_IGN);
+ set_signal(SIGINT, [](const int) {
+ std::cout << " interrupt signal received\n";
+ should_exit = true;
+ });
+}
+
+} // namespace shared
+