diff options
Diffstat (limited to '')
-rw-r--r-- | src/coopgammad.c | 44 | ||||
-rw-r--r-- | src/server.c | 19 |
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)); |