diff --git a/gui-common/txrx-vchan.c b/gui-common/txrx-vchan.c index 669d48f6..8d88b8fd 100644 --- a/gui-common/txrx-vchan.c +++ b/gui-common/txrx-vchan.c @@ -31,7 +31,6 @@ #include "../include/txrx.h" void (*vchan_at_eof)(void) = NULL; -int vchan_is_closed = 0; /* double buffered in gui-daemon to deal with deadlock * during send large clipboard content @@ -70,6 +69,13 @@ static int write_data_exact(libvchan_t *vchan, char *buf, int size) return size; } +int real_write_message(libvchan_t *vchan, char *hdr, int size, char *data, int datasize) +{ + write_data(vchan, hdr, size); + write_data(vchan, data, datasize); + return 0; +} + int write_data(libvchan_t *vchan, char *buf, int size) { int count; @@ -86,26 +92,17 @@ int write_data(libvchan_t *vchan, char *buf, int size) return size; } -int real_write_message(libvchan_t *vchan, char *hdr, int size, char *data, int datasize) -{ - write_data(vchan, hdr, size); - write_data(vchan, data, datasize); - return 0; -} - int read_data(libvchan_t *vchan, char *buf, int size) { int written = 0; int ret; while (written < size) { - while (!libvchan_data_ready(vchan)) - wait_for_vchan_or_argfd_once(vchan, -1); ret = libvchan_read(vchan, buf + written, size - written); if (ret <= 0) handle_vchan_error(vchan, "read data"); written += ret; } -// fprintf(stderr, "read %d bytes\n", size); + // fprintf(stderr, "read %d bytes\n", size); return size; } diff --git a/screen-layout-handler/watch-screen-layout-changes.c b/screen-layout-handler/watch-screen-layout-changes.c index 3b96b9ec..58d89179 100644 --- a/screen-layout-handler/watch-screen-layout-changes.c +++ b/screen-layout-handler/watch-screen-layout-changes.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,8 @@ int main(int argc, char **argv) { signal(SIGCHLD, SIG_IGN); sigemptyset(&sigmask); sigaddset(&sigmask, SIGTERM); + sigaddset(&sigmask, SIGINT); + sigaddset(&sigmask, SIGHUP); if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) err(1, "Couldn't block signals for graceful signal recovery"); @@ -52,19 +55,17 @@ int main(int argc, char **argv) { for (;;) { int layout_changed; XEvent ev; - fd_set in_fds; - assert(sigfd >= 0 && sigfd < FD_SETSIZE && "sigfd too large"); - assert(x11_fd >= 0 && x11_fd < FD_SETSIZE && "x11_fd too large"); - FD_ZERO(&in_fds); - FD_SET(sigfd, &in_fds); - FD_SET(x11_fd, &in_fds); - - if (select(FD_SETSIZE, &in_fds, NULL, NULL, NULL) == -1) { + struct pollfd fds[2] = { + { .fd = sigfd, .events = POLLIN | POLLHUP, .revents = 0 }, + { .fd = x11_fd, .events = POLLIN | POLLHUP, .revents = 0 }, + }; + + if (poll(fds, 2, -1) == -1) { XCloseDisplay(d); - err(1, "select"); + err(1, "poll"); } - if (FD_ISSET(sigfd, &in_fds)) { + if (fds[0].revents) { /* This must be SIGTERM as we are not listening on anything else */ break; }