fbc1f08371
0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=87
97 lines
2.7 KiB
Diff
97 lines
2.7 KiB
Diff
From 66cfed74c4a14d89c9c7078c7ce1c16d26af5d1e Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@suse.de>
|
|
Date: Fri, 4 Apr 2014 22:03:29 +0200
|
|
Subject: [PATCH] Evaluate /proc/1/cmdline and check for systemd
|
|
|
|
Set 'systemd' class eventually.
|
|
---
|
|
libenv/sysinfo.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
|
|
1 file changed, 50 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/libenv/sysinfo.c b/libenv/sysinfo.c
|
|
index 901791220855..64ca0aa5a880 100644
|
|
--- a/libenv/sysinfo.c
|
|
+++ b/libenv/sysinfo.c
|
|
@@ -114,6 +114,7 @@ static time_t GetBootTimeFromUptimeCommand(time_t); // Last resort
|
|
void CalculateDomainName(const char *nodename, const char *dnsname, char *fqname, char *uqname, char *domain);
|
|
|
|
#ifdef __linux__
|
|
+static void Linux_Systemd(EvalContext *ctx);
|
|
static int Linux_Os_Release(EvalContext *ctx);
|
|
static int Linux_Fedora_Version(EvalContext *ctx);
|
|
static int Linux_Redhat_Version(EvalContext *ctx);
|
|
@@ -929,14 +930,17 @@ static void OSClasses(EvalContext *ctx)
|
|
#ifdef __linux__
|
|
struct stat statbuf;
|
|
|
|
-/* Mandrake/Mandriva, Fedora and Oracle VM Server supply /etc/redhat-release, so
|
|
- we test for those distributions first */
|
|
+ /* check for systemd init process */
|
|
+ Linux_Systemd(ctx);
|
|
|
|
if (stat("/etc/os-release", &statbuf) != -1)
|
|
{
|
|
Linux_Os_Release(ctx);
|
|
}
|
|
|
|
+/* Mandrake/Mandriva, Fedora and Oracle VM Server supply /etc/redhat-release, so
|
|
+ we test for those distributions first */
|
|
+
|
|
if (stat("/etc/mandriva-release", &statbuf) != -1)
|
|
{
|
|
Linux_Mandriva_Version(ctx);
|
|
@@ -1220,6 +1224,50 @@ static void OSClasses(EvalContext *ctx)
|
|
|
|
#ifdef __linux__
|
|
|
|
+static void Linux_Systemd(EvalContext *ctx)
|
|
+{
|
|
+ char proc1[CF_MAXVARSIZE];
|
|
+ struct stat statbuf;
|
|
+ char *slash;
|
|
+
|
|
+ if (!ReadLine("/proc/1/cmdline", proc1, sizeof(proc1)))
|
|
+ {
|
|
+ UnexpectedError("Failed to read /proc/1/cmdline");
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (lstat(proc1, &statbuf) != 0)
|
|
+ {
|
|
+ UnexpectedError("Failed to stat %s", proc1);
|
|
+ return;
|
|
+ }
|
|
+ if (S_ISLNK(statbuf.st_mode))
|
|
+ {
|
|
+ int len;
|
|
+ len = readlink(proc1, proc1, sizeof(proc1));
|
|
+ if (len <= 0)
|
|
+ {
|
|
+ UnexpectedError("Failed to readlink %s", proc1);
|
|
+ return;
|
|
+ }
|
|
+ *(proc1 + len) = '\0';
|
|
+ }
|
|
+ Log(LOG_LEVEL_VERBOSE, "Init process: %s", proc1);
|
|
+ slash = strrchr(proc1, '/');
|
|
+ if (slash == NULL)
|
|
+ {
|
|
+ slash = proc1;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ slash++;
|
|
+ }
|
|
+ if (strcmp(slash, "systemd") == 0)
|
|
+ {
|
|
+ EvalContextClassPutHard(ctx, slash, "inventory,attribute_name=none,source=agent");
|
|
+ }
|
|
+}
|
|
+
|
|
static int Linux_Os_Release(EvalContext *ctx)
|
|
{
|
|
#define OS_REL_FILENAME "/etc/os-release"
|
|
--
|
|
1.8.4.5
|
|
|