From cf3b92233edaa90a504b07625972ea746271e9bb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 20 Nov 2026 16:56:47 +0100 Subject: Terminate when display server terminates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- DEPENDENCIES | 4 ++-- LICENSE | 2 +- coopgammad.c | 1 + servers-coopgamma.c | 4 ++-- servers-crtc.c | 2 ++ servers-master.c | 26 ++++++++++++++++++++------ state.c | 5 +++++ state.h | 5 +++++ types-message.c | 2 +- 9 files changed, 39 insertions(+), 12 deletions(-) diff --git a/DEPENDENCIES b/DEPENDENCIES index ff47212..bb82716 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,13 +1,13 @@ RUNTIME DEPENDENCIES: libc - libgamma>=0.7.4 + libgamma>=0.9 BUILD DEPENDENCIES: libc - libgamma>=0.7.4 + libgamma>=0.9 libclut cc make diff --git a/LICENSE b/LICENSE index 83ceedf..09be60a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License -© 2016, 2019 Mattias Andrée +© 2016, 2019, 2026 Mattias Andrée Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/coopgammad.c b/coopgammad.c index 3f4eb78..7a85ea7 100644 --- a/coopgammad.c +++ b/coopgammad.c @@ -352,6 +352,7 @@ initialise(int foreground, int keep_stderr, int query) /* Get site */ if (initialise_site() < 0) goto fail; + displayfd = libgamma_get_fd(&site); /* Get PID file and socket pathname */ if (!(pidpath = get_pidfile_pathname()) || diff --git a/servers-coopgamma.c b/servers-coopgamma.c index 42cd783..36b942a 100644 --- a/servers-coopgamma.c +++ b/servers-coopgamma.c @@ -376,8 +376,8 @@ handle_set_gamma(size_t conn, const char *restrict message_id, const char *restr struct message *restrict msg = inbound + conn; struct output *restrict output = NULL; struct filter filter; - char *restrict p; - char *restrict q; + const char *restrict p; + const char *restrict q; int saved_errno; ssize_t r; diff --git a/servers-crtc.c b/servers-crtc.c index 9171586..7014e61 100644 --- a/servers-crtc.c +++ b/servers-crtc.c @@ -227,6 +227,7 @@ disconnect(void) if (!connected) return 0; connected = 0; + displayfd = -1; for (i = 0; i < outputs_n; i++) { outputs[i].crtc = NULL; @@ -269,6 +270,7 @@ reconnect(void) /* Get site */ if (initialise_site() < 0) goto fail; + displayfd = libgamma_get_fd(&site); /* Get partitions and CRTC:s */ if (initialise_crtcs() < 0) diff --git a/servers-master.c b/servers-master.c index f6ebfee..9b01c00 100644 --- a/servers-master.c +++ b/servers-master.c @@ -105,8 +105,8 @@ dispatch_message(size_t conn, struct message *restrict msg) * the server socket and all connections * * The file descriptor will be ordered as in - * the array `connections`, `socketfd` will - * be last. + * the array `connections`, followed by `socketfd` + * and the display-server file descriptor if available. * * @param fds Reference parameter for the array of file descriptors * @param fdn Output parameter for the number of file descriptors @@ -120,12 +120,12 @@ update_fdset(struct pollfd **restrict fds, nfds_t *restrict fdn, nfds_t *restric nfds_t j = 0; void *new; - if (connections_used + 1 > *fds_alloc) { - new = realloc(*fds, (connections_used + 1) * sizeof(**fds)); + if (connections_used + 1 + (displayfd >= 0) > *fds_alloc) { + new = realloc(*fds, (connections_used + 1 + (displayfd >= 0)) * sizeof(**fds)); if (!new) return -1; *fds = new; - *fds_alloc = connections_used + 1; + *fds_alloc = connections_used + 1 + (displayfd >= 0); } for (i = 0; i < connections_used; i++) { @@ -140,6 +140,12 @@ update_fdset(struct pollfd **restrict fds, nfds_t *restrict fdn, nfds_t *restric (*fds)[j].events = NON_WR_POLL_EVENTS; j++; + if (displayfd >= 0) { + (*fds)[j].fd = displayfd; + (*fds)[j].events = 0; + j++; + } + *fdn = j; return 0; } @@ -316,6 +322,8 @@ main_loop(void) goto fail; } connection = 0; + if (update_fdset(&fds, &fdn, &fds_alloc) < 0) + goto fail; } for (j = 0, i = 0; j < connections_used; j++) { @@ -328,6 +336,8 @@ main_loop(void) } } fds[i].revents = 0; + if (displayfd >= 0) + fds[fdn - 1].revents = 0; if (poll(fds, fdn, -1) < 0) { if (errno == EAGAIN) @@ -344,7 +354,11 @@ main_loop(void) if (!do_read && !do_write) continue; - if (fd == socketfd) { + if (fd == displayfd) { + if (connection != 1) + terminate = 1; + continue; + } else if (fd == socketfd) { r = handle_server(); } else { for (j = 0; connections[j] != fd; j++); diff --git a/state.c b/state.c index f3ddffa..1907812 100644 --- a/state.c +++ b/state.c @@ -34,6 +34,11 @@ size_t outputs_n = 0; */ int socketfd = -1; +/** + * The display server's file descriptor, -1 if unavailable or disconnected + */ +int displayfd = -1; /* do not marshal */ + /** * Has the process receive a signal * telling it to re-execute? diff --git a/state.h b/state.h index a76eee2..ca62e05 100644 --- a/state.h +++ b/state.h @@ -45,6 +45,11 @@ extern size_t outputs_n; */ extern int socketfd; +/** + * The display server's file descriptor, -1 if unavailable or disconnected + */ +extern int displayfd; + /** * Has the process receive a signal * telling it to re-execute? diff --git a/types-message.c b/types-message.c index de5644d..5c4cfcd 100644 --- a/types-message.c +++ b/types-message.c @@ -320,7 +320,7 @@ GCC_ONLY(__attribute__((__pure__, __nonnull__))) static int validate_header(const char *restrict header, size_t length) { - char *restrict p = memchr(header, ':', length * sizeof(char)); + const char *restrict p = memchr(header, ':', length * sizeof(char)); if (verify_utf8(header) < 0) { /* Either the string is not UTF-8, or your are under an UTF-8 attack, -- cgit v1.3.1