mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
Feat: add Linux libloader entry point
- libloader: add platform/linux/Entry.cpp that starts the loader from a constructor - libloader: read the config path from JuiceAgent_ConfigPath, falling back to $HOME/.juiceagent - libloader: default JuiceAgentNativeLibraryPath to libagent.so on non-Windows - injector: print a notice that the Linux injector is not open source yet
This commit is contained in:
1 parent
59e705510e
commit
6eb1925ec3
3 files changed
+73
-1
No files matched your search
@@ -1,4 +1,10 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// TODO: Implement Linux injector
|
||||
// Due to certain reasons, the Injector for Linux is not open source.
|
||||
// Please wait a moment for the next update.
|
||||
printf("Due to certain reasons, the Injector for Linux is not open source. Please wait a moment for the next update.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -92,7 +92,14 @@ void JuiceAgent::Loader::initialize(const char* runtime_dir, JNIEnv* env, jvmtiE
|
||||
|
||||
JuiceAgent::Utils::Serializer ser;
|
||||
ser.add_kv("Version", cfg.get<int>("JuiceAgent.Version", -1));
|
||||
ser.add_kv("JuiceAgentNativeLibraryPath", cfg.getPath("JuiceAgent.JuiceAgentNativeLibraryPath", (cfg.getRuntimeDir()/"libagent.dll").string()));
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string default_libagent_path = (cfg.getRuntimeDir()/"libagent.dll").string();
|
||||
#else
|
||||
std::string default_libagent_path = (cfg.getRuntimeDir()/"libagent.so").string();
|
||||
#endif
|
||||
|
||||
ser.add_kv("JuiceAgentNativeLibraryPath", cfg.getPath("JuiceAgent.JuiceAgentNativeLibraryPath", default_libagent_path));
|
||||
ser.add_kv("RuntimeDir", cfg.getRuntimeDir().string());
|
||||
|
||||
std::string args = ser.serialize();
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "JuiceAgent/Logger.hpp"
|
||||
#include "Loader.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <thread>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static void run_loader() {
|
||||
const char* env = std::getenv("JuiceAgent_ConfigPath");
|
||||
std::string current_path;
|
||||
|
||||
if (env != nullptr && env[0] != '\0') {
|
||||
// Use the environment variable if it exists and is not empty.
|
||||
current_path = env;
|
||||
} else {
|
||||
spdlog::trace("[libloader] JuiceAgent_ConfigPath is not set");
|
||||
|
||||
const char* home = std::getenv("HOME");
|
||||
if (home == nullptr || home[0] == '\0') {
|
||||
spdlog::error("[libloader] HOME environment variable is not set");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to $HOME/.juiceagent.
|
||||
fs::path config_dir = fs::path(home) / ".juiceagent";
|
||||
|
||||
std::error_code ec;
|
||||
fs::create_directories(config_dir, ec);
|
||||
|
||||
if (ec) {
|
||||
spdlog::error(
|
||||
"[libloader] Failed to create config directory: {}",
|
||||
ec.message()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
current_path = config_dir.string();
|
||||
}
|
||||
|
||||
spdlog::info("[libloader] current path: {}", current_path);
|
||||
|
||||
JuiceAgent::Loader::entrypoint(current_path.c_str());
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void entry() {
|
||||
Logger::init();
|
||||
|
||||
spdlog::info("[libloader] loaded!");
|
||||
|
||||
std::thread([] {
|
||||
run_loader();
|
||||
}).detach();
|
||||
}
|
||||
Reference in new issue
Block a user