Skip to content

Commit 948a965

Browse files
committed
Terminal (Haiku): detect terminal version
1 parent a13935e commit 948a965

File tree

8 files changed

+90
-54
lines changed

8 files changed

+90
-54
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,7 @@ elseif(Haiku)
11481148
src/detection/gtk_qt/gtk.c
11491149
src/detection/host/host_windows.c
11501150
src/detection/icons/icons_nosupport.c
1151-
src/detection/initsystem/initsystem_haiku.cpp
1151+
src/detection/initsystem/initsystem_haiku.c
11521152
src/detection/keyboard/keyboard_haiku.cpp
11531153
src/detection/libc/libc_nosupport.c
11541154
src/detection/lm/lm_nosupport.c
@@ -1184,6 +1184,7 @@ elseif(Haiku)
11841184
src/detection/zpool/zpool_nosupport.c
11851185
src/util/platform/FFPlatform_unix.c
11861186
src/util/binary_linux.c
1187+
src/util/haiku/version.cpp
11871188
)
11881189
endif()
11891190

src/common/processing_linux.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
315315

316316
#elif defined(__HAIKU__)
317317

318+
{
319+
team_info info;
320+
if (get_team_info(pid, &info) == B_OK)
321+
{
322+
// This is tricky. info.args is not encoded, so that we don't know if
323+
// a whitespace in args is part of the file path or an argument separator
324+
if (info.argc == 1)
325+
ffStrbufSetS(exe, info.args);
326+
else
327+
{
328+
int argc = info.argc;
329+
for (const char* p = info.args; (p = strchr(p, ' ')); ++p)
330+
--argc;
331+
if (argc == 1)
332+
ffStrbufSetS(exe, info.args);
333+
}
334+
}
335+
}
336+
318337
if (exePath)
319338
{
320339
image_info info;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "initsystem.h"
2+
#include "util/stringUtils.h"
3+
#include "util/haiku/version.h"
4+
#include "common/io/io.h"
5+
6+
#include <OS.h>
7+
#include <unistd.h>
8+
9+
const char* ffDetectInitSystem(FFInitSystemResult* result)
10+
{
11+
// Since it runs first, registrar does not know about it,
12+
// so we can't query be_roster for it.
13+
const char* path = "/boot/system/servers/launch_daemon";
14+
if (!ffPathExists(path, FF_PATHTYPE_FILE))
15+
return "launch_daemon is not found";
16+
17+
ffStrbufSetStatic(&result->exe, path);
18+
ffStrbufSetStatic(&result->name, "launch_daemon");
19+
20+
team_info teamInfo;
21+
int32 cookie = 0;
22+
while (get_next_team_info(&cookie, &teamInfo) == B_OK)
23+
{
24+
if (ffStrEquals(teamInfo.args, path))
25+
{
26+
result->pid = (uint32_t) teamInfo.team;
27+
break;
28+
}
29+
}
30+
31+
ffGetFileVersion(path, &result->version);
32+
33+
return NULL;
34+
}

src/detection/initsystem/initsystem_haiku.cpp

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/detection/terminalshell/terminalshell.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ static bool getFileVersion(const FFstrbuf* exePath, FFstrbuf* version)
2727
if (len <= 0) return false;
2828
return ffGetFileVersion(exePathW, version);
2929
}
30+
#elif __HAIKU__
31+
#include "util/haiku/version.h"
3032
#endif
3133

3234
static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version)
@@ -847,6 +849,11 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
847849
if(ffStrbufStartsWithIgnCaseS(processName, "zed"))
848850
return getTerminalVersionZed(exe, version);
849851

852+
#if __HAIKU__
853+
if(ffStrbufEqualS(processName, "Terminal"))
854+
return ffGetFileVersion(exe->chars, version);
855+
#endif
856+
850857
const char* termProgramVersion = getenv("TERM_PROGRAM_VERSION");
851858
if(termProgramVersion)
852859
{

src/util/FFstrbuf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ static inline void ffStrbufInit(FFstrbuf* strbuf)
233233
strbuf->chars = CHAR_NULL_PTR;
234234
}
235235

236-
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate()
236+
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate(void)
237237
{
238238
FFstrbuf strbuf;
239239
ffStrbufInit(&strbuf);

src/util/haiku/version.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extern "C" {
2+
#include "version.h"
3+
}
4+
5+
#include <File.h>
6+
#include <AppFileInfo.h>
7+
8+
bool ffGetFileVersion(const char* filePath, FFstrbuf* version)
9+
{
10+
BFile f(filePath, B_READ_ONLY);
11+
if (f.InitCheck() != B_OK)
12+
return false;
13+
14+
BAppFileInfo fileInfo(&f);
15+
if (f.InitCheck() != B_OK)
16+
return false;
17+
18+
version_info info;
19+
if (fileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) != B_OK)
20+
return false;
21+
22+
ffStrbufSetF(version, "%d.%d.%d", (int)info.major, (int)info.middle, (int)info.minor);
23+
return true;
24+
}

src/util/haiku/version.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "util/FFstrbuf.h"
2+
3+
bool ffGetFileVersion(const char* filePath, FFstrbuf* version);

0 commit comments

Comments
 (0)