aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/signal.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/signal.c')
-rw-r--r--src/signal.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/signal.c b/src/signal.c
index b5c27ec..d721f67 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -6,12 +6,55 @@
*/
#include "signal.h"
+#include "compiler.h"
#include "log.h"
#include <signal.h>
+#include <string.h>
volatile sig_atomic_t global_stop_flag = 0;
+static void set_global_stop_flag(UNUSED int signum)
+{
+ global_stop_flag = 1;
+}
+
+static int my_sigaction(int signo, const struct sigaction *act)
+{
+ int ret = 0;
+
+ ret = sigaction(signo, act, NULL);
+ if (ret < 0) {
+ log_errno("sigaction");
+ return ret;
+ }
+
+ return ret;
+}
+
+int signal_install_global_handler()
+{
+ int ret = 0;
+
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = set_global_stop_flag;
+
+ /* Don't care about proper cleanup here; we exit the program if this
+ * fails anyway. */
+ ret = my_sigaction(SIGINT, &sa);
+ if (ret < 0)
+ return ret;
+ ret = my_sigaction(SIGQUIT, &sa);
+ if (ret < 0)
+ return ret;
+ ret = my_sigaction(SIGTERM, &sa);
+ if (ret < 0)
+ return ret;
+
+ return ret;
+}
+
int signal_set(const sigset_t *new, sigset_t *old)
{
int ret = 0;