Created
October 3, 2023 22:50
-
-
Save vadz/722d0ff91ffc346093551715a2219025 to your computer and use it in GitHub Desktop.
LD-preloadable library preventing GTK from killing applications using it under Wayland
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Build with | |
$ cc -Wall -O2 -fPIC -shared -o libfix_wl_display_flush.so fix_wl_display_flush.c | |
Use as | |
$ LD_PRELOAD=libfix_wl_display_flush.so ./app | |
*/ | |
#define _GNU_SOURCE | |
#include <dlfcn.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <wayland-client-core.h> | |
typedef int (*wl_display_flush_t)(struct wl_display*); | |
int wl_display_flush(struct wl_display* d) | |
{ | |
static wl_display_flush_t orig_wl_display_flush = NULL; | |
if (!orig_wl_display_flush) { | |
orig_wl_display_flush = (wl_display_flush_t)dlsym(RTLD_NEXT, "wl_display_flush"); | |
if (!orig_wl_display_flush) { | |
fprintf(stderr, "Failed to get wl_display_flush(): %s\n", dlerror()); | |
exit(127); | |
} | |
} | |
int rc = orig_wl_display_flush(d); | |
if (rc < 0) { | |
if (errno == EAGAIN) { | |
usleep(100000); | |
rc = orig_wl_display_flush(d); | |
} | |
} | |
return rc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment