aboutsummaryrefslogtreecommitdiffstats
path: root/src/signals.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-03-21 23:46:04 +0100
committerMattias Andrée <m@maandree.se>2025-03-21 23:46:04 +0100
commita091370e612b79452ac882e299d0e85154a64b59 (patch)
treee3af7375e90955609424ebe19442ddb3d53d6e09 /src/signals.c
parentRemove dependency on libsimple since it's not portable (diff)
downloadredshift-ng-a091370e612b79452ac882e299d0e85154a64b59.tar.gz
redshift-ng-a091370e612b79452ac882e299d0e85154a64b59.tar.bz2
redshift-ng-a091370e612b79452ac882e299d0e85154a64b59.tar.xz
misc stuff
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'src/signals.c')
-rw-r--r--src/signals.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/src/signals.c b/src/signals.c
index 3487d23..390d684 100644
--- a/src/signals.c
+++ b/src/signals.c
@@ -25,8 +25,8 @@ volatile sig_atomic_t disable = 0;
/**
- * Signal handlar for exit signals (SIGINT, SIGTERM, SIGQUIT)
- *
+ * Signal handler for exit signals (SIGINT, SIGTERM, SIGQUIT)
+ *
* @param signo The received signal
*/
static void
@@ -41,8 +41,8 @@ sigexit(int signo)
/**
- * Signal handlar for disable signal (SIGUSR1)
- *
+ * Signal handler for disable signal (SIGUSR1)
+ *
* @param signo The received signal
*/
#ifndef WINDOWS
@@ -55,6 +55,24 @@ sigdisable(int signo)
#endif
+/**
+ * Signal handler for forceful exiting; installed by
+ * `install_forceful_exit_signal_handlers`
+ *
+ * @param signo The received signal
+ */
+#ifndef WINDOWS
+static void
+sigalrm(int signo)
+{
+ if (exiting || signo == SIGALRM)
+ exit(0);
+ exiting = 1;
+ alarm(1U);
+}
+#endif
+
+
void
install_signal_handlers(void)
{
@@ -90,3 +108,28 @@ install_signal_handlers(void)
eprintf("sigaction SIGCHLD &{.sa_handler=SIG_IGN, .sa_mask={}, .sa_flags=0} NULL:");
#endif
}
+
+
+#ifndef WINDOWS
+void
+install_forceful_exit_signal_handlers(void)
+{
+ struct sigaction sigact;
+ sigset_t sigset;
+
+ exiting = 0;
+ memset(&sigact, 0, sizeof(sigact));
+ sigemptyset(&sigset);
+ sigact.sa_mask = sigset;
+ sigact.sa_flags = 0;
+ sigact.sa_handler = &sigalrm;
+ if (sigaction(SIGINT, &sigact, NULL))
+ eprintf("sigaction SIGINT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:");
+ if (sigaction(SIGTERM, &sigact, NULL))
+ eprintf("sigaction SIGTERM &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:");
+ if (sigaction(SIGQUIT, &sigact, NULL))
+ eprintf("sigaction SIGQUIT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:");
+ if (sigaction(SIGALRM, &sigact, NULL))
+ eprintf("sigaction SIGALRM &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:");
+}
+#endif