Fix #213: Merge branch 'pull-213'

This commit is contained in:
Jon Lund Steffensen
2015-12-28 11:35:53 -05:00
4 changed files with 149 additions and 69 deletions
+1
View File
@@ -10,6 +10,7 @@ bin_PROGRAMS = redshift
redshift_SOURCES = \
redshift.c redshift.h \
signals.c signals.h \
colorramp.c colorramp.h \
config-ini.c config-ini.h \
location-manual.c location-manual.h \
+3 -69
View File
@@ -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"));
}
+107
View File
@@ -0,0 +1,107 @@
/* signals.c -- Signal processing source
This file is part of Redshift.
Redshift is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Redshift is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2009-2015 Jon Lund Steffensen <jonlst@gmail.com>
Copyright (c) 2015 Mattias Andrée <maandree@member.fsf.org>
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__)
# include <signal.h>
#endif
#include "signals.h"
#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__)
volatile sig_atomic_t exiting = 0;
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;
}
#endif /* ! HAVE_SIGNAL_H || __WIN32__ */
int
signals_install_handlers(void)
{
#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__)
struct sigaction sigact;
sigset_t sigset;
int r;
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);
if (r < 0) {
perror("sigaction");
return -1;
}
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__ */
return 0;
}
+38
View File
@@ -0,0 +1,38 @@
/* signals.h -- Signal processing header
This file is part of Redshift.
Redshift is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Redshift is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2009-2015 Jon Lund Steffensen <jonlst@gmail.com>
Copyright (c) 2015 Mattias Andrée <maandree@member.fsf.org>
*/
#ifndef REDSHIFT_SIGNALS_H
#define REDSHIFT_SIGNALS_H
#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__)
extern volatile sig_atomic_t exiting;
extern volatile sig_atomic_t disable;
#else /* ! HAVE_SIGNAL_H || __WIN32__ */
# define exiting 0
# define disable 0
#endif /* ! HAVE_SIGNAL_H || __WIN32__ */
int signals_install_handlers(void);
#endif /* REDSHIFT_SIGNALS_H */