detect-virt: check the inode number of the pid namespace
authorLuca Boccassi <luca.boccassi@gmail.com>
Thu, 21 Nov 2024 00:47:39 +0000 (00:47 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Nov 2024 23:14:20 +0000 (00:14 +0100)
commit193bf42ab0721384570bb6913e5f38385a9105e7
tree2dfc120887550aa11e149d709caf8576c35032ef
parent18ead2b03d9df251ab682539648a556ace239dc7
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()]
src/basic/virt.c
test/units/TEST-74-AUX-UTILS.detect-virt.sh