]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
virt: also check if PID1 is in chroot
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 3 Nov 2023 05:29:59 +0000 (14:29 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 3 Nov 2023 16:05:52 +0000 (16:05 +0000)
In PID1, running_in_chroot() is called by safety_checks(), but without
this change, the check did nothing.

src/basic/virt.c

index 4e2a4f7fcdd8c172d6257223ec9dfc6c4c53877a..a0b6fbcd658c230c49930186a7c6683c70d34f42 100644 (file)
@@ -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;