summaryrefslogtreecommitdiff
path: root/src/signals.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/signals.c')
-rw-r--r--src/signals.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/signals.c b/src/signals.c
index b3e118a..058b8c9 100644
--- a/src/signals.c
+++ b/src/signals.c
@@ -1,6 +1,6 @@
/* signals.c
-Copyright (C) 2010 by Daniel Friesel
+Copyright (C) 2010-2023 by Birte Kristina Friesel
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
@@ -24,20 +24,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "feh.h"
+#include "filelist.h"
#include "winwidget.h"
+#include "options.h"
void feh_handle_signal(int);
+volatile int sig_received = 0;
+volatile int sig_exit = 0;
-void setup_signal_handlers()
+void setup_signal_handlers(void)
{
struct sigaction feh_sh;
sigset_t feh_ss;
if (
(sigemptyset(&feh_ss) == -1) ||
(sigaddset(&feh_ss, SIGUSR1) == -1) ||
- (sigaddset(&feh_ss, SIGUSR2) == -1))
+ (sigaddset(&feh_ss, SIGUSR2) == -1) ||
+ (sigaddset(&feh_ss, SIGALRM) == -1) ||
+ (sigaddset(&feh_ss, SIGTERM) == -1) ||
+ (sigaddset(&feh_ss, SIGQUIT) == -1) ||
+ (sigaddset(&feh_ss, SIGINT) == -1) ||
+ (sigaddset(&feh_ss, SIGTTIN) == -1))
{
- weprintf("Failed to set up signal mask, SIGUSR1/2 won't work");
+ weprintf("Failed to set up signal masks");
return;
}
@@ -47,9 +56,14 @@ void setup_signal_handlers()
if (
(sigaction(SIGUSR1, &feh_sh, NULL) == -1) ||
- (sigaction(SIGUSR2, &feh_sh, NULL) == -1))
+ (sigaction(SIGUSR2, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGALRM, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGTERM, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGQUIT, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGINT, &feh_sh, NULL) == -1) ||
+ (sigaction(SIGTTIN, &feh_sh, NULL) == -1))
{
- weprintf("Failed to set up signal handler, SIGUSR1/2 won't work");
+ weprintf("Failed to set up signal handler");
return;
}
@@ -58,15 +72,23 @@ void setup_signal_handlers()
void feh_handle_signal(int signo)
{
- winwidget winwid
- = winwidget_get_first_window_of_type(WIN_TYPE_SLIDESHOW);
-
- if (winwid) {
- if (signo == SIGUSR1)
- slideshow_change_image(winwid, SLIDE_NEXT);
- else if (signo == SIGUSR2)
- slideshow_change_image(winwid, SLIDE_PREV);
+ switch (signo) {
+ case SIGALRM:
+ if (childpid)
+ killpg(childpid, SIGINT);
+ return;
+ case SIGTTIN:
+ // we were probably backgrounded while we were running
+ control_via_stdin = 0;
+ return;
+ case SIGINT:
+ case SIGTERM:
+ case SIGQUIT:
+ if (childpid)
+ killpg(childpid, SIGINT);
+ sig_exit = 128 + signo;
+ return;
}
- return;
+ sig_received = signo;
}