Add code to find luprex root directory

This commit is contained in:
2023-05-10 15:24:47 -04:00
parent 9e74e67277
commit 64b4fc465d
9 changed files with 68 additions and 19 deletions

View File

@@ -12,6 +12,7 @@
#include <vector>
#include <string>
#include <filesystem>
#include <fstream>
#include <poll.h>
#include <sys/time.h>
@@ -33,6 +34,11 @@ const int INVALID_SOCKET = -1;
struct termios orig_termios;
std::filesystem::path get_exe_path() {
char result[ PATH_MAX ];
ssize_t count = readlink( "/proc/self/exe", result, PATH_MAX );
return std::filesystem::path(std::string( result, (count > 0) ? count : 0 ));
}
void set_nonblocking(int fd) {
int flags = fcntl(fd, F_GETFL, 0);
@@ -219,11 +225,12 @@ static int console_read(char *bytes, int nbytes) {
return read(0, bytes, nbytes);
}
static void call_init_engine_wrapper(EngineWrapper *w) {
static void call_init_engine_wrapper(const std::filesystem::path &luprexroot, EngineWrapper *w) {
using InitFn = void (*)(EngineWrapper *);
InitFn initfn = (InitFn)dlsym(nullptr, "init_engine_wrapper");
if (initfn == nullptr) {
void *dll_handle = dlopen("./luprexlib.so", RTLD_NOW | RTLD_LOCAL);
std::string path = luprexroot / "build/linux/luprexlib.so";
void *dll_handle = dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL);
assert(dll_handle != nullptr);
initfn = (InitFn)dlsym(dll_handle, "init_engine_wrapper");
}