Skip to content

Commit 7e8b204

Browse files
committed
InitSystem: resolve real path of exe path
1 parent e8dc500 commit 7e8b204

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/detection/initsystem/initsystem_linux.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
66
const char* error = ffProcessGetBasicInfoLinux((int) result->pid, &result->name, NULL, NULL);
77
if (error) return error;
88

9-
const char* exeName;
10-
11-
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &exeName, NULL);
9+
const char* _;
10+
// In linux /proc/1/exe is not readable
11+
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL);
12+
if (result->exe.chars[0] == '/')
13+
{
14+
// In some old system, /sbin/init is a symlink
15+
char buf[PATH_MAX];
16+
if (realpath(result->exe.chars, buf))
17+
ffStrbufSetS(&result->exe, buf);
18+
}
1219

1320
if (ffStrbufEqualS(&result->name, "systemd"))
1421
{
1522
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
16-
"systemctl",
23+
result->exe.chars, // use exe path in case users have another systemd installed
1724
"--version",
1825
NULL,
1926
}) == NULL && result->version.length)
@@ -25,22 +32,12 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
2532
ffStrbufSubstrBefore(&result->version, iEnd);
2633
ffStrbufSubstrAfter(&result->version, iStart);
2734
}
28-
else
29-
{
30-
iStart = ffStrbufFirstIndexC(&result->version, ' ');
31-
if (iStart < result->version.length)
32-
{
33-
uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ' ');
34-
ffStrbufSubstrBefore(&result->version, iEnd);
35-
ffStrbufSubstrAfter(&result->version, iStart);
36-
}
37-
}
3835
}
3936
}
4037
else if (ffStrbufEqualS(&result->name, "launchd"))
4138
{
4239
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
43-
"launchctl",
40+
"/bin/launchctl",
4441
"version",
4542
NULL,
4643
}) == NULL && result->version.length)

0 commit comments

Comments
 (0)