From 83af57a9b31fd04a66c49d7ceab046066dde4792 Mon Sep 17 00:00:00 2001 From: Alessandro Toia Date: Mon, 4 Mar 2024 18:03:32 -0800 Subject: [PATCH] wayland_hook: make sure wl_handle is not null and lib is loaded --- src/wayland_hook.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/wayland_hook.cpp b/src/wayland_hook.cpp index c29e47a6..b6c05e9c 100644 --- a/src/wayland_hook.cpp +++ b/src/wayland_hook.cpp @@ -18,42 +18,46 @@ struct wl_display* wl_display_ptr = nullptr; EXPORT_C_(struct wl_display*) wl_display_connect(const char *name) { - struct wl_display *ret = NULL; + struct wl_display *ret = nullptr; - if(!wl_handle) - { + if (!wl_handle) { wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY); - wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect"); - wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd"); } - ret = wl_display_connect_ptr(name); + if (wl_handle) { + wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect"); + wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd"); - if(!wl_display_ptr) - wl_display_ptr = ret; + ret = wl_display_connect_ptr(name); - init_wayland_data(); + if (!wl_display_ptr) { + wl_display_ptr = ret; + init_wayland_data(); + } + } return ret; } EXPORT_C_(struct wl_display*) wl_display_connect_to_fd(int fd) { - struct wl_display *ret = NULL; + struct wl_display *ret = nullptr; - if(!wl_handle) - { + if (!wl_handle) { wl_handle = real_dlopen("libwayland-client.so", RTLD_LAZY); - wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd"); - wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect"); } - ret = wl_display_connect_to_fd_ptr(fd); + if (wl_handle) { + wl_display_connect_to_fd_ptr = (pwl_display_connect_to_fd)real_dlsym(wl_handle, "wl_display_connect_to_fd"); + wl_display_connect_ptr = (pwl_display_connect)real_dlsym(wl_handle, "wl_display_connect"); - if(!wl_display_ptr) - wl_display_ptr = ret; + ret = wl_display_connect_to_fd_ptr(fd); - init_wayland_data(); + if (!wl_display_ptr) { + wl_display_ptr = ret; + init_wayland_data(); + } + } return ret; }