diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e698be61..759d3782f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1148,7 +1148,7 @@ elseif(Haiku) src/detection/gtk_qt/gtk.c src/detection/host/host_windows.c src/detection/icons/icons_nosupport.c - src/detection/initsystem/initsystem_haiku.cpp + src/detection/initsystem/initsystem_haiku.c src/detection/keyboard/keyboard_haiku.cpp src/detection/libc/libc_nosupport.c src/detection/lm/lm_nosupport.c @@ -1184,6 +1184,7 @@ elseif(Haiku) src/detection/zpool/zpool_nosupport.c src/util/platform/FFPlatform_unix.c src/util/binary_linux.c + src/util/haiku/version.cpp ) endif() diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index e4a8f62d5..a26e53848 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -315,6 +315,25 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons #elif defined(__HAIKU__) + { + team_info info; + if (get_team_info(pid, &info) == B_OK) + { + // This is tricky. info.args is not encoded, so that we don't know if + // a whitespace in args is part of the file path or an argument separator + if (info.argc == 1) + ffStrbufSetS(exe, info.args); + else + { + int argc = info.argc; + for (const char* p = info.args; (p = strchr(p, ' ')); ++p) + --argc; + if (argc == 1) + ffStrbufSetS(exe, info.args); + } + } + } + if (exePath) { image_info info; diff --git a/src/detection/initsystem/initsystem_haiku.c b/src/detection/initsystem/initsystem_haiku.c new file mode 100644 index 000000000..7a18a8e25 --- /dev/null +++ b/src/detection/initsystem/initsystem_haiku.c @@ -0,0 +1,34 @@ +#include "initsystem.h" +#include "util/stringUtils.h" +#include "util/haiku/version.h" +#include "common/io/io.h" + +#include +#include + +const char* ffDetectInitSystem(FFInitSystemResult* result) +{ + // Since it runs first, registrar does not know about it, + // so we can't query be_roster for it. + const char* path = "/boot/system/servers/launch_daemon"; + if (!ffPathExists(path, FF_PATHTYPE_FILE)) + return "launch_daemon is not found"; + + ffStrbufSetStatic(&result->exe, path); + ffStrbufSetStatic(&result->name, "launch_daemon"); + + team_info teamInfo; + int32 cookie = 0; + while (get_next_team_info(&cookie, &teamInfo) == B_OK) + { + if (ffStrEquals(teamInfo.args, path)) + { + result->pid = (uint32_t) teamInfo.team; + break; + } + } + + ffGetFileVersion(path, &result->version); + + return NULL; +} diff --git a/src/detection/initsystem/initsystem_haiku.cpp b/src/detection/initsystem/initsystem_haiku.cpp deleted file mode 100644 index 7714133af..000000000 --- a/src/detection/initsystem/initsystem_haiku.cpp +++ /dev/null @@ -1,52 +0,0 @@ -extern "C" { -#include "initsystem.h" -#include "common/processing.h" -#include "util/binary.h" -#include "util/stringUtils.h" -}; - -#include -#include -#include -#include -#include -#include - -const char* ffDetectInitSystem(FFInitSystemResult* result) -{ - team_info teamInfo; - int32 cookie = 0; - - // Since it runs first, registrar does not know about it, - // so we can't query be_roster for it. - BPath path("/boot/system/servers/launch_daemon"); - if (path.InitCheck() != B_OK) - return NULL; - - ffStrbufSetS(&result->exe, path.Path()); - ffStrbufSetStatic(&result->name, "launch_daemon"); - - while (get_next_team_info(&cookie, &teamInfo) == B_OK) - { - if (strcmp(teamInfo.args, path.Path()) == 0) - { - result->pid = (int)teamInfo.team; - break; - } - } - - BFile f(path.Path(), B_READ_ONLY); - if (f.InitCheck() != B_OK) - return NULL; - BAppFileInfo fileInfo(&f); - if (f.InitCheck() != B_OK) - return NULL; - - version_info version; - if (fileInfo.GetVersionInfo(&version, B_SYSTEM_VERSION_KIND) != B_OK) - return NULL; - - ffStrbufSetF(&result->version, "%d.%d.%d", (int)version.major, (int)version.middle, (int)version.minor); - - return NULL; -} diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index fab4202b4..6d6f5b6b6 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -27,6 +27,8 @@ static bool getFileVersion(const FFstrbuf* exePath, FFstrbuf* version) if (len <= 0) return false; return ffGetFileVersion(exePathW, version); } +#elif __HAIKU__ + #include "util/haiku/version.h" #endif static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version) @@ -847,6 +849,11 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe if(ffStrbufStartsWithIgnCaseS(processName, "zed")) return getTerminalVersionZed(exe, version); + #if __HAIKU__ + if(ffStrbufEqualS(processName, "Terminal")) + return ffGetFileVersion(exe->chars, version); + #endif + const char* termProgramVersion = getenv("TERM_PROGRAM_VERSION"); if(termProgramVersion) { diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index a3bce4ca6..cd99c863f 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -233,7 +233,7 @@ static inline void ffStrbufInit(FFstrbuf* strbuf) strbuf->chars = CHAR_NULL_PTR; } -FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate() +FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate(void) { FFstrbuf strbuf; ffStrbufInit(&strbuf); diff --git a/src/util/haiku/version.cpp b/src/util/haiku/version.cpp new file mode 100644 index 000000000..8dcf672ee --- /dev/null +++ b/src/util/haiku/version.cpp @@ -0,0 +1,24 @@ +extern "C" { +#include "version.h" +} + +#include +#include + +bool ffGetFileVersion(const char* filePath, FFstrbuf* version) +{ + BFile f(filePath, B_READ_ONLY); + if (f.InitCheck() != B_OK) + return false; + + BAppFileInfo fileInfo(&f); + if (f.InitCheck() != B_OK) + return false; + + version_info info; + if (fileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) != B_OK) + return false; + + ffStrbufSetF(version, "%d.%d.%d", (int)info.major, (int)info.middle, (int)info.minor); + return true; +} diff --git a/src/util/haiku/version.h b/src/util/haiku/version.h new file mode 100644 index 000000000..829801a88 --- /dev/null +++ b/src/util/haiku/version.h @@ -0,0 +1,3 @@ +#include "util/FFstrbuf.h" + +bool ffGetFileVersion(const char* filePath, FFstrbuf* version);