diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index fb2f7d755..58e29f1f8 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -48,7 +48,7 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex if(length > 0) exe->length = (uint32_t)length; - #else + #elif defined(__FreeBSD__) size_t size = exe->allocated; if(!sysctl( diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c index a6e5d1b13..2fa403ca6 100644 --- a/src/util/platform/FFPlatform_unix.c +++ b/src/util/platform/FFPlatform_unix.c @@ -5,8 +5,15 @@ #include #include +#include #include +#ifdef __APPLE__ + #include +#elif defined(__FreeBSD__) + #include +#endif + static void platformPathAddEnv(FFlist* dirs, const char* env) { const char* envValue = getenv(env); @@ -82,7 +89,31 @@ static void getDataDirs(FFPlatform* platform) platformPathAddEnv(&platform->dataDirs, "XDG_DATA_HOME"); ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/"); - #if defined(__APPLE__) + // Add ${currentExePath}/../share + FF_STRBUF_AUTO_DESTROY exePath = ffStrbufCreateA(PATH_MAX); + #ifdef __linux__ + ssize_t exePathLen = readlink("/proc/self/exe", exePath.chars, exePath.allocated); + #elif defined(__APPLE__) + int exePathLen = proc_pidpath((int) getpid(), exePath.chars, exePath.allocated); + #elif defined(__FreeBSD__) + size_t exePathLen = exePath.allocated; + if(sysctl( + (int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4, + exePath.chars, &exePathLen, + NULL, 0 + )) + exePathLen = 0; + #endif + if (exePathLen > 0) + { + exePath.length = (uint32_t) exePathLen; + ffStrbufSubstrBeforeLastC(&exePath, '/'); + ffStrbufSubstrBeforeLastC(&exePath, '/'); + ffStrbufAppendS(&exePath, "/share"); + ffPlatformPathAddAbsolute(&platform->dataDirs, exePath.chars); + } + + #ifdef __APPLE__ ffPlatformPathAddHome(&platform->dataDirs, platform, "Library/Application Support/"); #endif