If systemd is installed, but not the init system,
systemd-machined fails with an unhelpful error message:
Launch helper exited with unknown return code 1
Fall back to manual cgroup creation if systemd is installed,
but it's not PID 1.
[1]
https://bugs.freedesktop.org/show_bug.cgi?id=69962
---
(Yes, Gentoo.)
src/util/virsystemd.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 8adf209..0404a63 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -30,6 +30,7 @@
#include "virstring.h"
#include "viralloc.h"
#include "virutil.h"
+#include "virfile.h"
#include "virlog.h"
#include "virerror.h"
@@ -142,6 +143,28 @@ cleanup:
return machinename;
}
+/*
+ * Returns 0 if systemd is the init, -2 if not
+ * -1 on fatal error
+ */
+static int
+virSystemdIsInit(void)
+{
+ char *buf = NULL;
+ int ret = -2;
+
+ if (virFileReadAll("/proc/1/comm", sizeof("systemd\n "),
&buf) < 0)
+ return -1;
+
+ if (STREQ(buf, "systemd\n"))
+ ret = 0;
+ else
+ VIR_DEBUG("systemd is not the init");
+
+ VIR_FREE(buf);
+ return ret;
+}
+
/**
* virSystemdCreateMachine:
* @name: driver unique name of the machine
@@ -173,6 +196,9 @@ int virSystemdCreateMachine(const char *name,
if (ret < 0)
return ret;
+ if ((ret = virSystemdIsInit()) < 0)
+ return ret;
+
if (!(conn = virDBusGetSystemBus()))
return -1;
--
1.8.3.2