aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-16 15:27:20 +0200
committerMattias Andrée <maandree@kth.se>2016-07-16 15:27:20 +0200
commitb9307ec82d59fd266b39bd7ec4302cee0ffea137 (patch)
treed561fd3b8a13040f6edabd03499e3a74e0e21270 /src
parentFix warnings (diff)
downloadcoopgammad-b9307ec82d59fd266b39bd7ec4302cee0ffea137.tar.gz
coopgammad-b9307ec82d59fd266b39bd7ec4302cee0ffea137.tar.bz2
coopgammad-b9307ec82d59fd266b39bd7ec4302cee0ffea137.tar.xz
The stuff around supportinf SIGRTMIN+0 and SIGRTMIN+1
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src')
-rw-r--r--src/coopgammad.c44
-rw-r--r--src/server.c19
2 files changed, 58 insertions, 5 deletions
diff --git a/src/coopgammad.c b/src/coopgammad.c
index a4ed5a7..9374dc9 100644
--- a/src/coopgammad.c
+++ b/src/coopgammad.c
@@ -45,7 +45,6 @@
-extern char* argv0;
extern char* argv0_real;
extern struct output* outputs;
extern size_t outputs_n;
@@ -60,6 +59,7 @@ extern libgamma_partition_state_t* partitions;
extern libgamma_crtc_state_t* crtcs;
extern volatile sig_atomic_t reexec;
extern volatile sig_atomic_t terminate;
+extern volatile sig_atomic_t connection;
@@ -141,13 +141,21 @@ volatile sig_atomic_t reexec = 0;
*/
volatile sig_atomic_t terminate = 0;
+/**
+ * Has the process receive a to
+ * disconnect from or reconnect to
+ * the site? 1 if disconnct, 2 if
+ * reconnect, 0 otherwise.
+ */
+volatile sig_atomic_t connection = 0;
+
/**
* Called when the process receives
* a signal telling it to re-execute
*
- * @param signo The received signal
+ * @param signo The received signal
*/
static void sig_reexec(int signo)
{
@@ -160,7 +168,7 @@ static void sig_reexec(int signo)
* Called when the process receives
* a signal telling it to terminate
*
- * @param signo The received signal
+ * @param signo The received signal
*/
static void sig_terminate(int signo)
{
@@ -170,6 +178,19 @@ static void sig_terminate(int signo)
/**
+ * Called when the process receives
+ * a signal telling it to disconnect
+ * from or reconnect to the site
+ *
+ * @param signo The received signal
+ */
+static void sig_connection(int signo)
+{
+ connection = signo - SIGRTMIN + 1;
+}
+
+
+/**
* Get the pathname of the runtime file
*
* @param suffix The suffix for the file
@@ -748,6 +769,10 @@ static int initialise(int full, int preserve, int foreground, int keep_stderr, i
goto fail;
if (signal(SIGTERM, sig_terminate) == SIG_ERR)
goto fail;
+ if (signal(SIGRTMIN + 0, sig_connection) == SIG_ERR)
+ goto fail;
+ if (signal(SIGRTMIN + 1, sig_connection) == SIG_ERR)
+ goto fail;
/* Place in the background unless -f */
if (full && (foreground == 0))
@@ -1002,6 +1027,10 @@ static size_t marshal(void* buf)
off += n;
}
+ if (bs != NULL)
+ *(sig_atomic_t*)(bs + off) = connection;
+ off += sizeof(sig_atomic_t);
+
return off;
}
@@ -1077,6 +1106,9 @@ static size_t unmarshal(void* buf)
else
off += sizeof(int);
+ connection = *(sig_atomic_t*)(bs + off);
+ off += sizeof(sig_atomic_t);
+
return off;
}
@@ -1285,8 +1317,10 @@ static void usage(void)
*
* The process closes stdout when the socket has been created
*
- * @signal SIGUSR1 Re-execute to updated process image
- * @signal SIGTERM Terminate the process gracefully
+ * @signal SIGUSR1 Re-execute to updated process image
+ * @signal SIGTERM Terminate the process gracefully
+ * @signal SIGRTMIN+0 Disconnect from the site
+ * @signal SiGRTMIN+1 Reconnect to the site
*
* @param argc The number of elements in `argv`
* @param argv Command line arguments. Recognised options:
diff --git a/src/server.c b/src/server.c
index 890c5a4..9544bad 100644
--- a/src/server.c
+++ b/src/server.c
@@ -94,6 +94,14 @@ extern volatile sig_atomic_t reexec;
extern volatile sig_atomic_t terminate;
/**
+ * Has the process receive a to
+ * disconnect from or reconnect to
+ * the site? 1 if disconnct, 2 if
+ * reconnect, 0 otherwise.
+ */
+extern volatile sig_atomic_t connection;
+
+/**
* Array of all outputs
*/
extern struct output* outputs;
@@ -1003,6 +1011,17 @@ int main_loop(void)
while (!reexec && !terminate)
{
+ if (connection == 1) /* disconnect */
+ {
+ connection = 0;
+ /* TODO */
+ }
+ else if (connection >= 2) /* reconnect */
+ {
+ connection = 0;
+ /* TODO */
+ }
+
memcpy(&fds_rd, &fds_orig, sizeof(fd_set));
memcpy(&fds_ex, &fds_orig, sizeof(fd_set));