aboutsummaryrefslogtreecommitdiffstats
path: root/src/gammad.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-11 17:22:39 +0200
committerMattias Andrée <maandree@kth.se>2016-07-11 17:22:39 +0200
commit2794356649d7d40839cabffbeeee27bbadcc8b7a (patch)
tree43fbce49cfba0a2653d22d61d3b55e45db77d8a4 /src/gammad.c
parentDetect kernel automatically (diff)
downloadcoopgammad-2794356649d7d40839cabffbeeee27bbadcc8b7a.tar.gz
coopgammad-2794356649d7d40839cabffbeeee27bbadcc8b7a.tar.bz2
coopgammad-2794356649d7d40839cabffbeeee27bbadcc8b7a.tar.xz
Add signal handlers
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/gammad.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/gammad.c b/src/gammad.c
index 92fbf4d..7e981ad 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -56,6 +56,44 @@ size_t outputs_n = 0;
*/
int socketfd = -1;
+/**
+ * Has the process receive a signal
+ * telling it to re-execute?
+ */
+volatile sig_atomic_t reexec = 0;
+
+/**
+ * Has the process receive a signal
+ * telling it to terminate?
+ */
+volatile sig_atomic_t terminate = 0;
+
+
+
+/**
+ * Called when the process receives
+ * a signal telling it to re-execute
+ *
+ * @param signo The received signal
+ */
+static void sig_reexec(int signo)
+{
+ reexec = 1;
+ (void) signo;
+}
+
+
+/**
+ * Called when the process receives
+ * a signal telling it to terminate
+ *
+ * @param signo The received signal
+ */
+static void sig_terminate(int signo)
+{
+ terminate = 1;
+ (void) signo;
+}
/**
@@ -311,6 +349,9 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
/**
* Create PID file
*
+ * @signal SIGUSR1 Re-execute to updated process image
+ * @signal SIGTERM Terminate the process gracefully
+ *
* @param pidfile The pathname of the PID file
* @return Zero on success, -1 on error,
* -2 if the service is already running
@@ -635,10 +676,16 @@ int main(int argc, char** argv)
goto fail;
}
- /* Change directory to / to avoid blocking umounting. */
+ /* Change directory to / to avoid blocking umounting */
if (chdir("/") < 0)
perror(argv0);
+ /* Set up signal handlers */
+ if (signal(SIGUSR1, sig_reexec) == SIG_ERR)
+ goto fail;
+ if (signal(SIGTERM, sig_terminate) == SIG_ERR)
+ goto fail;
+
/* Place in the background unless -f */
if (foreground == 0)
{