Skip to content

Commit 7c62a53

Browse files
committed
Initsystem (Linux): Detect version of shepherd.
Followup to d553bc4
1 parent 7611d67 commit 7c62a53

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/detection/initsystem/initsystem_linux.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
3737
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL);
3838
if (result->exe.chars[0] == '/')
3939
{
40+
if (ffStrbufEqualS(&result->name, "shepherd") ||
41+
ffStrbufEqualS(&result->name, "guile"))
42+
{
43+
// guile --no-auto-compile shepherd
44+
// skip first 2 \0 characters to the shepherd path
45+
const char* tmp = result->exe.chars + result->exe.length + 1;
46+
ffStrbufSetS(&result->exe, tmp + strlen(tmp) + 1);
47+
}
48+
4049
// In some old system, /sbin/init is a symlink
4150
char buf[PATH_MAX];
4251
if (realpath(result->exe.chars, buf))
@@ -84,16 +93,19 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
8493
ffStrbufSubstrAfterLastC(&result->version, ' ');
8594
}
8695
}
87-
else if (ffStrbufEqualS(&result->name, "guile"))
96+
else if (ffStrbufEqualS(&result->name, "shepherd"))
8897
{
89-
// TODO: guile is actually shepherd
90-
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
91-
ffStrbufEndsWithS(&result->exe, "/guile") ? result->exe.chars : "guile",
92-
"--version",
98+
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
99+
ffStrbufEndsWithS(&result->exe, "/shepherd") ? result->exe.chars : "shepherd",
100+
"--version",
93101
NULL,
94102
}) == NULL && result->version.length)
95103
{
96-
// guile (GNU Guile) 3.0.9
104+
// shepherd (GNU Shepherd) 1.0.6
105+
// The first line in the output might not contain the version
106+
if (!ffStrbufStartsWithS(&result->version, "shepherd"))
107+
ffStrbufSubstrAfterFirstC(&result->version, '\n');
108+
97109
ffStrbufSubstrBeforeFirstC(&result->version, '\n');
98110
ffStrbufSubstrAfterLastC(&result->version, ' ');
99111
}

0 commit comments

Comments
 (0)