From 193bf42ab0721384570bb6913e5f38385a9105e7 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 21 Nov 2024 00:47:39 +0000 Subject: detect-virt: check the inode number of the pid namespace The indoe number of root pid namespace is hardcoded in the kernel to 0xEFFFFFFC since 3.8, so check the inode number of our pid namespace if all else fails. If it's not 0xEFFFFFFC then we are in a pid namespace, hence a container environment. Fixes https://github.com/systemd/systemd/issues/35249 [Reworked by Lennart, to make use of namespace_is_init()] --- test/units/TEST-74-AUX-UTILS.detect-virt.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') 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 -- cgit v1.2.3