diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-05-07 17:25:16 +0200 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2015-12-28 11:31:42 -0500 |
commit | e0a617fcada616a8112f7d9df51ac10bd58130af (patch) | |
tree | fe18266b82a9d3979c0524e985c897c5ae703d1a /src/redshift.c | |
parent | Merge pull request #197 from forivall/clamp-fix (diff) | |
download | redshift-ng-e0a617fcada616a8112f7d9df51ac10bd58130af.tar.gz redshift-ng-e0a617fcada616a8112f7d9df51ac10bd58130af.tar.bz2 redshift-ng-e0a617fcada616a8112f7d9df51ac10bd58130af.tar.xz |
Move signal processing functions and sigaction calls to signals from redshift.c
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/redshift.c')
-rw-r--r-- | src/redshift.c | 78 |
1 files changed, 6 insertions, 72 deletions
diff --git a/src/redshift.c b/src/redshift.c index defd0a1..bf741bb 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -48,6 +48,7 @@ #include "solar.h" #include "systemtime.h" #include "hooks.h" +#include "signals.h" /* pause() is not defined on windows platform but is not needed either. Use a noop macro instead. */ @@ -319,32 +320,6 @@ static const char *period_names[] = { N_("Transition") }; -#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__) - -static volatile sig_atomic_t exiting = 0; -static volatile sig_atomic_t disable = 0; - -/* Signal handler for exit signals */ -static void -sigexit(int signo) -{ - exiting = 1; -} - -/* Signal handler for disable signal */ -static void -sigdisable(int signo) -{ - disable = 1; -} - -#else /* ! HAVE_SIGNAL_H || __WIN32__ */ - -static int exiting = 0; -static int disable = 0; - -#endif /* ! HAVE_SIGNAL_H || __WIN32__ */ - /* Determine which period we are currently in. */ static period_t @@ -817,52 +792,11 @@ run_continual_mode(const location_t *loc, will be exactly 6500K. */ double adjustment_alpha = 1.0; -#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__) - struct sigaction sigact; - sigset_t sigset; - sigemptyset(&sigset); - - /* Install signal handler for INT and TERM signals */ - sigact.sa_handler = sigexit; - sigact.sa_mask = sigset; - sigact.sa_flags = 0; - - r = sigaction(SIGINT, &sigact, NULL); + r = signals_install_handlers(); if (r < 0) { - perror("sigaction"); - return -1; + return r; } - r = sigaction(SIGTERM, &sigact, NULL); - if (r < 0) { - perror("sigaction"); - return -1; - } - - /* Install signal handler for USR1 signal */ - sigact.sa_handler = sigdisable; - sigact.sa_mask = sigset; - sigact.sa_flags = 0; - - r = sigaction(SIGUSR1, &sigact, NULL); - if (r < 0) { - perror("sigaction"); - return -1; - } - - /* Ignore CHLD signal. This causes child processes - (hooks) to be reaped automatically. */ - sigact.sa_handler = SIG_IGN; - sigact.sa_mask = sigset; - sigact.sa_flags = 0; - - r = sigaction(SIGCHLD, &sigact, NULL); - if (r < 0) { - perror("sigaction"); - return -1; - } -#endif /* HAVE_SIGNAL_H && ! __WIN32__ */ - if (verbose) { printf(_("Status: %s\n"), _("Enabled")); } @@ -1447,9 +1381,9 @@ main(int argc, char *argv[]) stderr); exit(EXIT_FAILURE); } - + provider->free(&location_state); - + if (verbose) { print_location(&loc); @@ -1470,7 +1404,7 @@ main(int argc, char *argv[]) MIN_LAT, MAX_LAT); exit(EXIT_FAILURE); } - + /* Longitude */ if (loc.lon < MIN_LON || loc.lon > MAX_LON) { /* TRANSLATORS: Append degree symbols if possible. */ |