|
4 | 4 | #include "util/stringUtils.h"
|
5 | 5 |
|
6 | 6 | #include <libgen.h>
|
| 7 | +#include <string.h> |
7 | 8 | #include <unistd.h>
|
8 | 9 |
|
9 | 10 | FF_MAYBE_UNUSED static bool extractSystemdVersion(const char* str, uint32_t len, void* userdata)
|
@@ -37,6 +38,20 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
|
37 | 38 | ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL);
|
38 | 39 | if (result->exe.chars[0] == '/')
|
39 | 40 | {
|
| 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 | + |
40 | 55 | // In some old system, /sbin/init is a symlink
|
41 | 56 | char buf[PATH_MAX];
|
42 | 57 | if (realpath(result->exe.chars, buf))
|
@@ -84,16 +99,19 @@ const char* ffDetectInitSystem(FFInitSystemResult* result)
|
84 | 99 | ffStrbufSubstrAfterLastC(&result->version, ' ');
|
85 | 100 | }
|
86 | 101 | }
|
87 |
| - else if (ffStrbufEqualS(&result->name, "guile")) |
| 102 | + else if (ffStrbufEqualS(&result->name, "shepherd")) |
88 | 103 | {
|
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", |
93 | 107 | NULL,
|
94 | 108 | }) == NULL && result->version.length)
|
95 | 109 | {
|
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 | + |
97 | 115 | ffStrbufSubstrBeforeFirstC(&result->version, '\n');
|
98 | 116 | ffStrbufSubstrAfterLastC(&result->version, ' ');
|
99 | 117 | }
|
|
0 commit comments