InitSystem: resolve real path of exe path

This commit is contained in:
李通洲
2024-05-29 19:12:43 +08:00
parent e8dc500f24
commit 7e8b204644
+12 -15
View File
@@ -6,14 +6,21 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
const char* error = ffProcessGetBasicInfoLinux((int) result->pid, &result->name, NULL, NULL);
if (error) return error;
const char* exeName;
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &exeName, NULL);
const char* _;
// In linux /proc/1/exe is not readable
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL);
if (result->exe.chars[0] == '/')
{
// In some old system, /sbin/init is a symlink
char buf[PATH_MAX];
if (realpath(result->exe.chars, buf))
ffStrbufSetS(&result->exe, buf);
}
if (ffStrbufEqualS(&result->name, "systemd"))
{
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
"systemctl",
result->exe.chars, // use exe path in case users have another systemd installed
"--version",
NULL,
}) == NULL && result->version.length)
@@ -25,22 +32,12 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
ffStrbufSubstrBefore(&result->version, iEnd);
ffStrbufSubstrAfter(&result->version, iStart);
}
else
{
iStart = ffStrbufFirstIndexC(&result->version, ' ');
if (iStart < result->version.length)
{
uint32_t iEnd = ffStrbufNextIndexC(&result->version, iStart + 1, ' ');
ffStrbufSubstrBefore(&result->version, iEnd);
ffStrbufSubstrAfter(&result->version, iStart);
}
}
}
}
else if (ffStrbufEqualS(&result->name, "launchd"))
{
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
"launchctl",
"/bin/launchctl",
"version",
NULL,
}) == NULL && result->version.length)