From f0ec3247bc1b9cd857d3bb00cf8f85d965342f23 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Tue, 26 Jan 2016 19:14:08 +0100
Subject: Support SIGUSR1 in daemon mode

In commit 7f62fb1 (Let SIGUSR1 trigger a reload, 2014-10-10), we added
support for reloading the data files by sending SIGUSR1 to an
interactive calcurse process. Add the same functionality to the daemon
mode.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/dmon.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/dmon.c b/src/dmon.c
index a9c4ed8..913b9f9 100644
--- a/src/dmon.c
+++ b/src/dmon.c
@@ -66,6 +66,11 @@ static unsigned data_loaded;
 
 static void dmon_sigs_hdlr(int sig)
 {
+	if (sig == SIGUSR1) {
+		want_reload = 1;
+		return;
+	}
+
 	if (data_loaded)
 		free_user_data();
 
@@ -138,6 +143,7 @@ static unsigned daemonize(int status)
 	    || !sigs_set_hdlr(SIGTERM, dmon_sigs_hdlr)
 	    || !sigs_set_hdlr(SIGALRM, dmon_sigs_hdlr)
 	    || !sigs_set_hdlr(SIGQUIT, dmon_sigs_hdlr)
+	    || !sigs_set_hdlr(SIGUSR1, dmon_sigs_hdlr)
 	    || !sigs_set_hdlr(SIGCHLD, SIG_IGN))
 		return 0;
 
@@ -172,6 +178,12 @@ void dmon_start(int parent_exit_status)
 	for (;;) {
 		int left;
 
+		if (want_reload) {
+			want_reload = 0;
+			io_reload_data();
+			notify_check_next_app(1);
+		}
+
 		if (!notify_get_next_bkgd())
 			DMON_ABRT(_("error loading next appointment\n"));
 
-- 
cgit v1.2.3-70-g09d2