summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/basic/virt.c19
-rwxr-xr-xtest/units/TEST-74-AUX-UTILS.detect-virt.sh4
2 files changed, 23 insertions, 0 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c
index fd0c353791..7792d64f16 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -645,6 +645,16 @@ static int running_in_cgroupns(void) {
}
}
+static int running_in_pidns(void) {
+ int r;
+
+ r = namespace_is_init(NAMESPACE_PID);
+ if (r < 0)
+ return log_debug_errno(r, "Failed to test if in root PID namespace, ignoring: %m");
+
+ return !r;
+}
+
static Virtualization detect_container_files(void) {
static const struct {
const char *file_path;
@@ -790,12 +800,21 @@ check_files:
r = running_in_cgroupns();
if (r > 0) {
+ log_debug("Running in a cgroup namespace, assuming unknown container manager.");
v = VIRTUALIZATION_CONTAINER_OTHER;
goto finish;
}
if (r < 0)
log_debug_errno(r, "Failed to detect cgroup namespace: %m");
+ /* Finally, the root pid namespace has an hardcoded inode number of 0xEFFFFFFC since kernel 3.8, so
+ * if all else fails we can check the inode number of our pid namespace and compare it. */
+ if (running_in_pidns() > 0) {
+ log_debug("Running in a pid namespace, assuming unknown container manager.");
+ v = VIRTUALIZATION_CONTAINER_OTHER;
+ goto finish;
+ }
+
/* If none of that worked, give up, assume no container manager. */
v = VIRTUALIZATION_NONE;
goto finish;
diff --git a/test/units/TEST-74-AUX-UTILS.detect-virt.sh b/test/units/TEST-74-AUX-UTILS.detect-virt.sh
index fe1db4d2aa..a1539d9b44 100755
--- a/test/units/TEST-74-AUX-UTILS.detect-virt.sh
+++ b/test/units/TEST-74-AUX-UTILS.detect-virt.sh
@@ -5,3 +5,7 @@ set -o pipefail
SYSTEMD_IN_CHROOT=1 systemd-detect-virt --chroot
(! SYSTEMD_IN_CHROOT=0 systemd-detect-virt --chroot)
+
+if ! systemd-detect-virt -c; then
+ unshare --mount-proc --fork --user --pid systemd-detect-virt --container
+fi