Skip to content

Commit 2124f43

Browse files
committed
fix segfault when running xvfb
1 parent b0ec08c commit 2124f43

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

addons/js-interposer/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ sdltest: build fake-devices
4040
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so ./sdl_joystick_reader
4141

4242
winetest: build build32 fake-devices
43-
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so wine control
43+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so wine control
44+
45+
xvfbtest: build
46+
LD_PRELOAD=$(PWD)/selkies_joystick_interposer.so Xvfb

addons/js-interposer/joystick_interposer.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ static void interposer_log(const char *level, const char *msg, ...)
9494
}
9595

9696
// Function that takes the address of a function pointer and uses dlsym to load the system function into it
97-
static void load_real_func(void (**target)(void), const char *name)
97+
static int load_real_func(void (**target)(void), const char *name)
9898
{
99+
if (*target != NULL) return 0;
99100
*target = dlsym(RTLD_NEXT, name);
100101
if (target == NULL)
101102
{
102103
interposer_log(LOG_ERROR, "Error getting original '%s' function: %s", name, dlerror());
104+
return -1;
103105
}
106+
return 0;
104107
}
105108

106109
// Function pointers to original calls
@@ -313,6 +316,7 @@ int interposer_open_socket(js_interposer_t *interposer)
313316
// Interpose epoll_ctl to make joystck socket fd non-blocking.
314317
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
315318
{
319+
if (load_real_func((void *)&real_epoll_ctl, "epoll_ctl") < 0) return -1;
316320
if (op == EPOLL_CTL_ADD)
317321
{
318322
// Find matching device in interposer list
@@ -336,6 +340,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
336340
// Interposer function for open syscall
337341
int open(const char *pathname, int flags, ...)
338342
{
343+
if (load_real_func((void *)&real_open, "open") < 0) return -1;
339344
// Find matching device in interposer list
340345
js_interposer_t *interposer = NULL;
341346
for (size_t i = 0; i < NUM_INTERPOSERS(); i++)
@@ -369,6 +374,7 @@ int open(const char *pathname, int flags, ...)
369374
// Interposer function for open64
370375
int open64(const char *pathname, int flags, ...)
371376
{
377+
if (load_real_func((void *)&real_open64, "open64") < 0) return -1;
372378
// Find matching device in interposer list
373379
js_interposer_t *interposer = NULL;
374380
for (size_t i = 0; i < NUM_INTERPOSERS(); i++)
@@ -618,6 +624,7 @@ int intercept_ev_ioctl(js_interposer_t *interposer, int fd, unsigned long reques
618624
// Interposer function for ioctl syscall
619625
int ioctl(int fd, unsigned long request, ...)
620626
{
627+
if (load_real_func((void *)&real_ioctl, "ioctl") < 0) return -1;
621628
va_list args;
622629
va_start(args, request);
623630
void *arg = va_arg(args, void *);

0 commit comments

Comments
 (0)