aboutsummaryrefslogtreecommitdiffstats
path: root/src/redshift.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/redshift.c')
-rw-r--r--src/redshift.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/redshift.c b/src/redshift.c
index 4f2304c..ddab891 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -304,11 +304,11 @@ run_continual_mode(void)
disable = 0;
}
if (exiting) {
- if (done) /* TODO also if already disabled (fade complete) */
- break; /* On second signal stop the ongoing fade */
- done = 1;
disabled = 1;
exiting = 0;
+ if (done || (disabled && !fade_length))
+ break; /* On second signal stop the ongoing fade */
+ done = 1;
}
if (verbose && disabled != prev_disabled)
printf(_("Status: %s\n"), disabled ? _("Disabled") : _("Enabled"));
@@ -358,7 +358,7 @@ run_continual_mode(void)
prev_target_colour = target_colour;
/* Break loop when done and final fade is over */
- if (done && fade_length == 0)
+ if (done && !fade_length)
break;
/* Adjust temperature and sleep */
@@ -386,6 +386,9 @@ main(int argc, char *argv[])
double day_level;
enum period period;
struct colour_setting colour;
+#ifndef WINDOWS
+ int fd;
+#endif
argv0 = argv[0];
@@ -397,6 +400,21 @@ main(int argc, char *argv[])
textdomain(PACKAGE);
#endif
+ /* Ensure standard file descriptors exist */
+#ifndef WINDOWS
+ fd = open("/dev/null", O_RDWR);
+ while (fd < 2) {
+ if (fd < 0)
+ eprintf("open /dev/null O_RDWR:");
+ fd = dup(fd);
+ }
+ if (fd > 2)
+ close(fd);
+#endif
+
+ /* Set up interprocess communication */
+ install_signal_handlers();
+
/* Get configurations and configure */
load_settings(&settings, argc, argv);
if (scheme.type == SOLAR_SCHEME) {
@@ -409,9 +427,6 @@ main(int argc, char *argv[])
}
config_ini_free(&settings.config);
- /* Set up interprocess communication */
- install_signal_handlers();
-
/* Get location if required */
if (scheme.type == SOLAR_SCHEME) {
if (provider->get_fd(provider_state) >= 0)
@@ -441,10 +456,11 @@ main(int argc, char *argv[])
break;
case PROGRAM_MODE_ONE_SHOT:
+ case PROGRAM_MODE_UNTIL_DEATH:
case PROGRAM_MODE_RESET:
if (method->apply(method_state, &colour, preserve_gamma) < 0)
eprintf(_("Temperature adjustment failed."));
- if (method->autoreset) {
+ if (mode == PROGRAM_MODE_UNTIL_DEATH || method->autoreset) {
weprintf(_("Press ctrl-c to stop..."));
while (!exiting)
pause();
@@ -461,9 +477,9 @@ main(int argc, char *argv[])
#endif
}
- if (method_state)
- method->free(method_state);
if (provider_state)
provider->free(provider_state);
+ if (method_state)
+ method->free(method_state);
return 0;
}