From 8710b6d63ddd91a2a6f03b918e13bb349563df37 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 16 Apr 2022 19:54:53 +0200 Subject: [PATCH] Add one last Hail Mary search to the chainloader --- src/chainloader/utils.cpp | 33 +++++++++++++++++++++++++++++---- src/chainloader/utils.h | 2 ++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/chainloader/utils.cpp b/src/chainloader/utils.cpp index e2cec39b..72505c53 100644 --- a/src/chainloader/utils.cpp +++ b/src/chainloader/utils.cpp @@ -52,7 +52,30 @@ void* find_plugin_library(const std::string& name) { } } - return dlopen(name.c_str(), RTLD_LAZY | RTLD_LOCAL); + if (void* handle = dlopen(name.c_str(), RTLD_LAZY | RTLD_LOCAL)) { + return handle; + } + + // One last Hail Mary, in case ldconfig was not set up correctly. This + // might be relevant for some of the `/usr/local/*` locations (although + // you really, really shouldn't install yabridge there, please, thank + // you). Yabridgectl searches through these same directories. + for (const auto& lib_dir : { + "/usr/lib", + "/usr/lib/x86_64-linux-gnu", + "/usr/lib64", + "/usr/local/lib", + "/usr/local/lib/x86_64-linux-gnu", + "/usr/local/lib64", + }) { + const fs::path candidate = fs::path(lib_dir) / name; + if (void* handle = + dlopen(candidate.c_str(), RTLD_LAZY | RTLD_LOCAL)) { + return handle; + } + } + + return nullptr; }; void* handle = impl(); @@ -62,9 +85,11 @@ void* find_plugin_library(const std::string& name) { Logger logger = Logger::create_exception_logger(); logger.log(""); - logger.log("Could not find '" + name + "'."); - logger.log("Make sure you followed the installation instructions from"); - logger.log("yabridge's readme"); + logger.log("Could not find '" + name + "'"); + logger.log(""); + logger.log( + "Make sure you followed the installation instructions from " + "yabridge's readme."); logger.log(""); logger.log("Source: '" + this_plugin_path.string() + "'"); logger.log(""); diff --git a/src/chainloader/utils.h b/src/chainloader/utils.h index 48be7826..0bd2c769 100644 --- a/src/chainloader/utils.h +++ b/src/chainloader/utils.h @@ -33,5 +33,7 @@ * process for `yabridge-host-32.exe`. * - When those don't exist, we'll try to `dlopen()` the file directly. This * will use the correct path for the system. + * - If we still can't find the file, we'll do one last scan through common lib + * directories in case `ldconfig` was not set up correctly. */ void* find_plugin_library(const std::string& name);