diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-11-03 06:29:59 +0100 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-11-03 17:05:52 +0100 |
commit | 7636caf5b32d98b094f2830f52ff5c46e3a22a68 (patch) | |
tree | 2d72e3f51aebd8ce4cf91101cf25c4e7d87aa93c /src/basic/virt.c | |
parent | nspawn: allow disabling os-release check (diff) | |
download | systemd-7636caf5b32d98b094f2830f52ff5c46e3a22a68.tar.xz systemd-7636caf5b32d98b094f2830f52ff5c46e3a22a68.zip |
virt: also check if PID1 is in chroot
In PID1, running_in_chroot() is called by safety_checks(), but without
this change, the check did nothing.
Diffstat (limited to '')
-rw-r--r-- | src/basic/virt.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c index 4e2a4f7fcd..a0b6fbcd65 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -886,15 +886,15 @@ int running_in_chroot(void) { if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0) return 0; - if (getpid_cached() == 1) - return false; /* We're PID 1, we can't be in a chroot. */ - r = inode_same("/proc/1/root", "/", 0); if (r == -ENOENT) { r = proc_mounted(); if (r == 0) { + if (getpid_cached() == 1) + return false; /* We will mount /proc, assuming we're not in a chroot. */ + log_debug("/proc is not mounted, assuming we're in a chroot."); - return 1; + return true; } if (r > 0) /* If we have fake /proc/, we can't do the check properly. */ return -ENOSYS; |