mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-08-24 07:06:32 +00:00
fix(linux): load librustdesk.so relative to the executable (#15719)
* fix(linux): load librustdesk.so relative to the executable The runner and the Dart FFI init loaded the core library by bare name, relying on the runner's $ORIGIN/lib RPATH. Repackaged installs (CachyOS repo, AUR) can lose that RPATH, making the app fail to start with "Failed to load librustdesk.so" unless users add the lib directory to ld.so.conf. Resolve lib/librustdesk.so next to the executable first, then fall back to the loader search path. https://github.com/rustdesk/rustdesk/discussions/14407 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(linux): harden bundled librustdesk.so resolution Address review: bail out when readlink() may have truncated the executable path, and widen the Dart try block so any failure probing the bundled library falls back to the loader search path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
5aeb4cf945
commit
006b9737e4
@@ -25,6 +25,23 @@ typedef F3 = Pointer<Uint8> Function(Pointer<Utf8>, int);
|
||||
typedef F3Dart = Pointer<Uint8> Function(Pointer<Utf8>, Int32);
|
||||
typedef HandleEvent = Future<void> Function(Map<String, dynamic> evt);
|
||||
|
||||
/// The Linux bundle keeps the core library at lib/librustdesk.so next to the
|
||||
/// executable. Prefer that copy, mirroring flutter/linux/main.cc: the plain
|
||||
/// name relies on the loader search path, which repackaged installs may not
|
||||
/// cover. https://github.com/rustdesk/rustdesk/discussions/14407
|
||||
DynamicLibrary _openLinuxCoreLib() {
|
||||
final bundled =
|
||||
'${File(Platform.resolvedExecutable).parent.path}/lib/librustdesk.so';
|
||||
try {
|
||||
if (File(bundled).existsSync()) {
|
||||
return DynamicLibrary.open(bundled);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint("Failed to load '$bundled': $e");
|
||||
}
|
||||
return DynamicLibrary.open('librustdesk.so');
|
||||
}
|
||||
|
||||
/// FFI wrapper around the native Rust core.
|
||||
/// Hides the platform differences.
|
||||
class PlatformFFI {
|
||||
@@ -120,7 +137,7 @@ class PlatformFFI {
|
||||
final dylib = isAndroid
|
||||
? DynamicLibrary.open('librustdesk.so')
|
||||
: isLinux
|
||||
? DynamicLibrary.open('librustdesk.so')
|
||||
? _openLinuxCoreLib()
|
||||
: isWindows
|
||||
? DynamicLibrary.open('librustdesk.dll')
|
||||
:
|
||||
|
||||
+33
-1
@@ -1,4 +1,8 @@
|
||||
#include <dlfcn.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "my_application.h"
|
||||
|
||||
#define RUSTDESK_LIB_PATH "librustdesk.so"
|
||||
@@ -7,8 +11,36 @@ bool gIsConnectionManager = false;
|
||||
|
||||
void print_help_install_pkg(const char* so);
|
||||
|
||||
// The bundle keeps the core library at lib/librustdesk.so next to the
|
||||
// executable. Resolve that path explicitly instead of relying on the
|
||||
// runner's RPATH, which repackaged installs may strip.
|
||||
// https://github.com/rustdesk/rustdesk/discussions/14407
|
||||
static void* dlopen_bundled_lib() {
|
||||
char exe_path[PATH_MAX];
|
||||
ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
|
||||
if (len <= 0 || len >= (ssize_t)(sizeof(exe_path) - 1)) return nullptr;
|
||||
exe_path[len] = '\0';
|
||||
char* last_slash = strrchr(exe_path, '/');
|
||||
if (last_slash == nullptr) return nullptr;
|
||||
*last_slash = '\0';
|
||||
char lib_path[PATH_MAX + sizeof("/lib/" RUSTDESK_LIB_PATH)];
|
||||
snprintf(lib_path, sizeof(lib_path), "%s/lib/%s", exe_path, RUSTDESK_LIB_PATH);
|
||||
if (access(lib_path, F_OK) != 0) return nullptr;
|
||||
void* librustdesk = dlopen(lib_path, RTLD_LAZY);
|
||||
if (!librustdesk) {
|
||||
char* error = dlerror();
|
||||
if (error != nullptr) {
|
||||
fprintf(stderr, "Failed to load \"%s\": %s\n", lib_path, error);
|
||||
}
|
||||
}
|
||||
return librustdesk;
|
||||
}
|
||||
|
||||
bool flutter_rustdesk_core_main() {
|
||||
void* librustdesk = dlopen(RUSTDESK_LIB_PATH, RTLD_LAZY);
|
||||
void* librustdesk = dlopen_bundled_lib();
|
||||
if (!librustdesk) {
|
||||
librustdesk = dlopen(RUSTDESK_LIB_PATH, RTLD_LAZY);
|
||||
}
|
||||
if (!librustdesk) {
|
||||
fprintf(stderr,"Failed to load \"librustdesk.so\"\n");
|
||||
char* error;
|
||||
|
||||
Reference in New Issue
Block a user