Bug#910770: dash: systemd-detect-virt fails to detect virtualized environment when run under dash

наб nabijaczleweli at nabijaczleweli.xyz
Fri Jan 6 17:37:15 GMT 2023


Control: retitle -1 systemd-detect-virt only detects systemd-nspawn container if run as PID1
Control: reassign -1 systemd 215-17+deb8u7
Control: fixed -1 218-1

I can repro this on bullseye (with apologies to the snapshot.d.o maintainers):
-- >8 --
# debootstrap --variant=minbase --no-check-gpg jessie jessie-18-10-10  http://snapshot.debian.org/archive/debian/20181010T111800Z/
# systemd-nspawn -D jessie-18-10-10/ /bin/bash -c "systemd-detect-virt"
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
systemd-nspawn
Container jessie-18-10-10 exited successfully.
# systemd-nspawn -D jessie-18-10-10/ /bin/dash -c "systemd-detect-virt"
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
none
Container jessie-18-10-10 failed with error code 1.
-- >8 --

By excluding the environment &a., I arrived at:
-- >8 --
# systemd-nspawn -D jessie-18-10-10/ /bin/bash -c 'cat /proc/$$/cmdline'
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
cat^@-A^@/proc/1/cmdline^@
Container jessie-18-10-10 exited successfully.
# systemd-nspawn -D jessie-18-10-10/ /bin/dash -c 'cat /proc/$$/cmdline'
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
/bin/dash^@-c^@cat -A /proc/$$/cmdline^@
Container jessie-18-10-10 exited successfully.
-- >8 --
and its natural extension:
-- >8 --
# systemd-nspawn -D jessie-18-10-10/ /bin/bash -c "(systemd-detect-virt)"
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
none
# systemd-nspawn -D jessie-18-10-10/ /bin/dash -c "exec systemd-detect-virt"
Spawning container jessie-18-10-10 on /home/nabijaczleweli/uwu/jessie-18-10-10.
Press ^] three times within 1s to kill container.
systemd-nspawn
Container jessie-18-10-10 exited successfully.
Container jessie-18-10-10 failed with error code 1.
-- >8 --

This is a systemd bug,
insofar as the container detection code only works if the caller is PID 1.

By further bisecting through systemd versions available on s.d.o, I got to:
-- >8 --
root at jessie-18-10-10:~# 217-4/usr/bin/systemd-detect-virt
none
root at jessie-18-10-10:~# 218-1/usr/bin/systemd-detect-virt
systemd-nspawn
-- >8 --

Best,
наб
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-systemd-maintainers/attachments/20230106/9380532e/attachment.sig>


More information about the Pkg-systemd-maintainers mailing list