Skip to content

Commit 68bd10f

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

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/detection/initsystem/initsystem_linux.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "util/stringUtils.h"
55

66
#include <libgen.h>
7+
#include <string.h>
78
#include <unistd.h>
89

910
FF_MAYBE_UNUSED static bool extractSystemdVersion(const char* str, uint32_t len, void* userdata)
@@ -37,6 +38,20 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
3738
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL);
3839
if (result->exe.chars[0] == '/')
3940
{
41+
if (ffStrbufEqualS(&result->name, "shepherd") ||
42+
ffStrbufEqualS(&result->name, "guile"))
43+
{
44+
// guile --no-auto-compile shepherd
45+
// find the shepherd script in /proc/1/cmdline
46+
const char* tmp = result->exe.chars;
47+
while(!ffStrbufEndsWithS(&result->exe, "/shepherd"))
48+
{
49+
tmp += result->exe.length + 1;
50+
memmove(result->exe.chars, tmp, strlen(tmp) + 1);
51+
ffStrbufRecalculateLength(&result->exe);
52+
}
53+
}
54+
4055
// In some old system, /sbin/init is a symlink
4156
char buf[PATH_MAX];
4257
if (realpath(result->exe.chars, buf))
@@ -84,16 +99,19 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
8499
ffStrbufSubstrAfterLastC(&result->version, ' ');
85100
}
86101
}
87-
else if (ffStrbufEqualS(&result->name, "guile"))
102+
else if (ffStrbufEqualS(&result->name, "shepherd"))
88103
{
89-
// TODO: guile is actually shepherd
90-
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
91-
ffStrbufEndsWithS(&result->exe, "/guile") ? result->exe.chars : "guile",
92-
"--version",
104+
if (ffProcessAppendStdOut(&result->version, (char* const[]) {
105+
ffStrbufEndsWithS(&result->exe, "/shepherd") ? result->exe.chars : "shepherd",
106+
"--version",
93107
NULL,
94108
}) == NULL && result->version.length)
95109
{
96-
// guile (GNU Guile) 3.0.9
110+
// shepherd (GNU Shepherd) 1.0.6
111+
// The first line in the output might not contain the version
112+
if (!ffStrbufStartsWithS(&result->version, "shepherd"))
113+
ffStrbufSubstrAfterFirstC(&result->version, '\n');
114+
97115
ffStrbufSubstrBeforeFirstC(&result->version, '\n');
98116
ffStrbufSubstrAfterLastC(&result->version, ' ');
99117
}

0 commit comments

Comments
 (0)