[client] clipboard/wayland: ignore SIGPIPE from clients that hang up

Otherwise, a badly-behaving client causes Looking Glass to receive a
SIGPIPE during Wayland copy operations. Handle EPIPE at call-sites
instead.

Co-authored-by: Quantum <quantum2048@gmail.com>
This commit is contained in:
Tudor Brindus 2021-01-09 19:46:41 -05:00 committed by Geoffrey McRae
parent 48941cb9c4
commit 2627381021
2 changed files with 9 additions and 1 deletions

View File

@ -410,6 +410,7 @@ static bool wayland_cb_init(
this->dataFn = dataFn;
this->display = wminfo->info.wl.display;
this->registry = wl_display_get_registry(this->display);
this->stashed_type = LG_CLIPBOARD_DATA_NONE;
// Wait for the initial set of globals to appear.
wl_registry_add_listener(this->registry, &registry_listener, NULL);
@ -451,6 +452,7 @@ static void data_source_handle_send(void * data, struct wl_data_source * source,
ssize_t written = write(fd, transfer->data + pos, transfer->size - pos);
if (written < 0)
{
if (errno != EPIPE)
DEBUG_ERROR("Failed to write clipboard data: %s", strerror(errno));
goto error;
}

View File

@ -1861,6 +1861,12 @@ static int lg_run()
signal(SIGINT , int_handler);
signal(SIGTERM, int_handler);
// Request to receive EPIPE instead of SIGPIPE when one end of a pipe
// disconnects while a write is pending. This is useful to the Wayland
// clipboard backend, where an arbitrary application is on the other end of
// that pipe.
signal(SIGPIPE, SIG_IGN);
// try map the shared memory
if (!ivshmemOpen(&g_state.shm))
{