summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--info/blueshift.texinfo5
-rwxr-xr-xsrc/__main__.py23
3 files changed, 27 insertions, 2 deletions
diff --git a/TODO b/TODO
index 1e169b5..7e122d3 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@ Medium priority:
Small examples
-r support in the comperhensive example
Store settings so that we can transition from them instead of from clean
- Signal USR1 for configuration reload
Low priority:
ICC profile support
diff --git a/info/blueshift.texinfo b/info/blueshift.texinfo
index fe0bcaf..3f7ac50 100644
--- a/info/blueshift.texinfo
+++ b/info/blueshift.texinfo
@@ -123,6 +123,9 @@ Blueshift does not check the user home, rather it
checks @env{HOME} which should be the user home, unless
you change it yourself.
+You update the configuration file you can send a
+SIGUSR1 signal to reload it.
+
@item -p @c the long name of option is inspired from openntpd
@itemx --panic-gate
@itemx --panicgate
@@ -530,6 +533,8 @@ may replace if you want to do something very special,
is invoked to run the continuous mode, it the program
shall run in continuous mode. Which is determined by
whether the function @code{periodically} is defined.
+Updates to @code{continuous_run} are ignored when
+SIGUSR1 signals are received.
You can also replace the function @code{signal_SIGTERM}.
@code{continuous_run} sets up the program to run it
diff --git a/src/__main__.py b/src/__main__.py
index 6aa0e2a..405bd76 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -31,7 +31,7 @@ PROGRAM_VERSION = '1.1'
## Set global variables
global DATADIR, i_size, o_size, r_curve, g_curve, b_curve, clip_result, reset, panicgate
global periodically, wait_period, fadein_time, fadeout_time, fadein_steps, fadeout_steps
-global monitor_controller, running, continuous_run, panic
+global monitor_controller, running, continuous_run, panic, _globals_
global signal_SIGTERM
@@ -153,6 +153,26 @@ def signal_SIGTERM(signum, frame):
running = False
+
+_globals_, _locals_ = globals(), dict(locals())
+for key in _locals_:
+ _globals_[key] = _locals_[key]
+def signal_SIGUSR1(signum, frame):
+ '''
+ Signal handler for SIGUSR1
+
+ @param signum The signal number, 0 if called from the program itself
+ @param frame Ignore, it will probably be `None`
+ '''
+ code = None
+ with open(config_file, 'rb') as script:
+ code = script.read()
+ code = code.decode('utf8', 'error') + '\n'
+ code = compile(code, config_file, 'exec')
+ exec(code, _globals_)
+
+
+
def continuous_run():
'''
Invoked to run continuously if `periodically` is not `None`
@@ -172,6 +192,7 @@ def continuous_run():
## Catch signals
signal.signal(signal.SIGTERM, signal_SIGTERM)
+ signal.signal(signal.SIGUSR1, signal_SIGUSR1)
## Fade in
early_exit = False