mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
InitSystem: resolve real path of exe path
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user