diff options
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | doc/coopgammad.1 | 7 | ||||
-rw-r--r-- | src/coopgammad.c | 44 | ||||
-rw-r--r-- | src/server.c | 19 |
5 files changed, 73 insertions, 7 deletions
@@ -78,6 +78,14 @@ SIGNALS SIGUSR1 Reexecute the process to an updated version. + SIGRTMIN+0 + Disconnect from the display server or + graphics card. + + SIGRTMIN+1 + Reconnect to the display server or graphics + card. + RATIONALE After reading the description section, the need for this should be obvious. @@ -1,2 +0,0 @@ -SIGRTMIN+0 Disconnect from the site -SIGRTMIN+1 Connect to the site diff --git a/doc/coopgammad.1 b/doc/coopgammad.1 index 5e83331..54ca6f6 100644 --- a/doc/coopgammad.1 +++ b/doc/coopgammad.1 @@ -92,6 +92,13 @@ for local display 0 when using .TP .B SIGUSR1 Reexecute the process to an updated version. +.TP +.B SIGRTMIN+0 +Disconnect from the display server or graphics +card. +.TP +.B SIGRTMIN+1 +Reconnect to the display server or graphics card. .SH "RATIONALE" After reading the description section, the need for this should be obvious. 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)); |