From fbc1f08371266a4459b7c70d3612aba21b62cd3540ab3f89b24efafa916db73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= Date: Fri, 4 Apr 2014 20:08:15 +0000 Subject: [PATCH] - Parse /proc/1/cmdline to detect systemd 0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch OBS-URL: https://build.opensuse.org/package/show/systemsmanagement/cfengine?expand=0&rev=87 --- ...proc-1-cmdline-and-check-for-systemd.patch | 96 +++++++++++++++++++ cfengine.changes | 3 + cfengine.spec | 4 + 3 files changed, 103 insertions(+) create mode 100644 0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch diff --git a/0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch b/0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch new file mode 100644 index 0000000..9565f49 --- /dev/null +++ b/0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch @@ -0,0 +1,96 @@ +From 66cfed74c4a14d89c9c7078c7ce1c16d26af5d1e Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= +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 + diff --git a/cfengine.changes b/cfengine.changes index 9ed5331..112d665 100644 --- a/cfengine.changes +++ b/cfengine.changes @@ -9,6 +9,9 @@ Fri Apr 4 19:30:04 UTC 2014 - kkaempf@suse.com - Parse /etc/os-release for product and version Add patch 0001-Check-etc-os-release-for-distribution-information.patch +- Parse /proc/1/cmdline to detect systemd + 0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch + ------------------------------------------------------------------- Thu Apr 3 13:10:56 UTC 2014 - kkaempf@suse.com diff --git a/cfengine.spec b/cfengine.spec index 245f65a..2085972 100644 --- a/cfengine.spec +++ b/cfengine.spec @@ -78,6 +78,9 @@ Patch3: drop-revision.patch # parse /etc/os-release for product and version information, kkaempf@suse.de Patch4: 0001-Check-etc-os-release-for-distribution-information.patch +# parse /proc/1/cmdline to detect systemd +Patch5: 0001-Evaluate-proc-1-cmdline-and-check-for-systemd.patch + BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: bison BuildRequires: db-devel @@ -203,6 +206,7 @@ This package contains the files of the cfengine server. %endif %patch3 -p1 %patch4 -p1 +%patch5 -p1 ##### rpmlint #### wrong-file-end-of-line-encoding