49static std::atomic<bool> zmqzext_interrupted{
false};
50static bool handlers_stored{
false};
52static struct sigaction stored_sigint;
53static struct sigaction stored_sigterm;
55static void (*stored_sigint_handler)(int) =
nullptr;
56static void (*stored_sigterm_handler)(int) =
nullptr;
59void signal_handler(
int ) { zmqzext_interrupted.store(
true, std::memory_order_relaxed); }
62void store_signal_handlers() noexcept {
63 sigaction(SIGINT,
nullptr, &stored_sigint);
64 sigaction(SIGTERM,
nullptr, &stored_sigterm);
65 handlers_stored =
true;
68void setup_signal_handlers() noexcept {
69 struct sigaction action;
70 action.sa_handler = signal_handler;
72 sigemptyset(&action.sa_mask);
74 sigaction(SIGINT, &action,
nullptr);
75 sigaction(SIGTERM, &action,
nullptr);
84 if (!handlers_stored) {
85 store_signal_handlers();
87 setup_signal_handlers();
91 if (handlers_stored) {
92 sigaction(SIGINT, &stored_sigint,
nullptr);
93 sigaction(SIGTERM, &stored_sigterm,
nullptr);
94 handlers_stored =
false;
98void install_interrupt_handler() noexcept {
99 if (!handlers_stored) {
100 stored_sigint_handler = std::signal(SIGINT, signal_handler);
101 stored_sigterm_handler = std::signal(SIGTERM, signal_handler);
102 handlers_stored =
true;
104 std::signal(SIGINT, signal_handler);
105 std::signal(SIGTERM, signal_handler);
110 if (handlers_stored) {
111 std::signal(SIGINT, stored_sigint_handler);
112 std::signal(SIGTERM, stored_sigterm_handler);
113 handlers_stored =
false;
118bool is_interrupted() noexcept {
return zmqzext_interrupted.load(std::memory_order_relaxed); }
120void reset_interrupted() noexcept { zmqzext_interrupted.store(
false, std::memory_order_relaxed); }
Signal interrupt handling for graceful application shutdown.
CZZE_EXPORT bool is_interrupted() noexcept
Check if a program interrupt was received.
CZZE_EXPORT void restore_interrupt_handler() noexcept
Restore the previously stored signal handlers.
CZZE_EXPORT void install_interrupt_handler() noexcept
Install signal handlers for SIGINT and SIGTERM.
CZZE_EXPORT void reset_interrupted() noexcept
Reset the interrupt flag to false.
Signal definitions and utilities for actor inter-thread communication.