Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions gui-common/txrx-vchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
21 changes: 11 additions & 10 deletions screen-layout-handler/watch-screen-layout-changes.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poll.h>

#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
Expand All @@ -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");

Expand All @@ -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;
}
Expand Down