[PATCH virt-what] Add detection for systemd-nspawn instances

Elias Probst mail at eliasprobst.eu
Thu Dec 15 09:46:02 UTC 2022


Also improve LXC/nspawn checks by not invoking `cat`

Co-authored-by: Elias Probst <e.probst at ssc-services.de>
Signed-off-by: Elias Probst <e.probst at ssc-services.de>
---
 virt-what.in | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/virt-what.in b/virt-what.in
index d090898..97aef3e 100644
--- a/virt-what.in
+++ b/virt-what.in
@@ -174,9 +174,12 @@ fi
 # http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface
 # Added by Marc Fournier

-if [ -e "${root}/proc/1/environ" ] &&
-    cat "${root}/proc/1/environ" | tr '\000' '\n' | grep -Eiq '^container=lxc'; then
-    echo lxc
+if [ -e "${root}/proc/1/environ" ]; then
+    if tr '\000' '\n' < "${root}/proc/1/environ" | grep -Eiq '^container=lxc'; then
+        echo lxc
+    elif tr '\000' '\n' < "${root}/proc/1/environ" | grep -Eiq '^container=systemd-nspawn'; then
+        echo systemd-nspawn
+    fi
 fi

 if [ -e "${root}/proc/1/environ" ] &&
--
2.34.1



More information about the virt-tools-list mailing list