-
-
Notifications
You must be signed in to change notification settings - Fork 581
Initsystem (Linux): Detect version of shepherd. #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#include "util/stringUtils.h" | ||
|
||
#include <libgen.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
FF_MAYBE_UNUSED static bool extractSystemdVersion(const char* str, uint32_t len, void* userdata) | ||
|
@@ -37,6 +38,20 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) | |
ffProcessGetInfoLinux((int) result->pid, &result->name, &result->exe, &_, NULL); | ||
if (result->exe.chars[0] == '/') | ||
{ | ||
if (ffStrbufEqualS(&result->name, "shepherd") || | ||
ffStrbufEqualS(&result->name, "guile")) | ||
{ | ||
// guile --no-auto-compile shepherd | ||
// find the shepherd script in /proc/1/cmdline | ||
const char* tmp = result->exe.chars; | ||
while(!ffStrbufEndsWithS(&result->exe, "/shepherd")) | ||
{ | ||
tmp += result->exe.length + 1; | ||
memmove(result->exe.chars, tmp, strlen(tmp) + 1); | ||
ffStrbufRecalculateLength(&result->exe); | ||
} | ||
} | ||
|
||
// In some old system, /sbin/init is a symlink | ||
char buf[PATH_MAX]; | ||
if (realpath(result->exe.chars, buf)) | ||
|
@@ -84,16 +99,19 @@ const char* ffDetectInitSystem(FFInitSystemResult* result) | |
ffStrbufSubstrAfterLastC(&result->version, ' '); | ||
} | ||
} | ||
else if (ffStrbufEqualS(&result->name, "guile")) | ||
else if (ffStrbufEqualS(&result->name, "shepherd")) | ||
{ | ||
// TODO: guile is actually shepherd | ||
if (ffProcessAppendStdOut(&result->version, (char* const[]) { | ||
ffStrbufEndsWithS(&result->exe, "/guile") ? result->exe.chars : "guile", | ||
"--version", | ||
if (ffProcessAppendStdOut(&result->version, (char* const[]) { | ||
ffStrbufEndsWithS(&result->exe, "/shepherd") ? result->exe.chars : "shepherd", | ||
"--version", | ||
NULL, | ||
}) == NULL && result->version.length) | ||
{ | ||
// guile (GNU Guile) 3.0.9 | ||
// shepherd (GNU Shepherd) 1.0.6 | ||
// The first line in the output might not contain the version | ||
if (!ffStrbufStartsWithS(&result->version, "shepherd")) | ||
ffStrbufSubstrAfterFirstC(&result->version, '\n'); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This skips over the warning about missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If shepherd version always comes at the end, I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is some licensing information in the lines afterwards that I ommitted.
|
||
ffStrbufSubstrBeforeFirstC(&result->version, '\n'); | ||
ffStrbufSubstrAfterLastC(&result->version, ' '); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this iterates the args until it finds the one that points to the script.
Or what else did you mean by your previous comment?