process-util: port pid_from_same_root_fs() to pidref, and port three places over to it

This commit is contained in:
Lennart Poettering
2025-01-16 11:55:21 +01:00
parent a65de78d5c
commit d6267b9b18
6 changed files with 123 additions and 50 deletions
+8 -11
View File
@@ -799,19 +799,16 @@ int running_in_chroot(void) {
if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
return 0;
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. */
r = pidref_from_same_root_fs(&PIDREF_MAKE_FROM_PID(1), NULL);
if (r == -ENOSYS) {
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 true;
}
if (r > 0) /* If we have fake /proc/, we can't do the check properly. */
return -ENOSYS;
log_debug("/proc/ is not mounted, assuming we're in a chroot.");
return true;
}
if (r == -ESRCH) /* We must have a fake /proc/, we can't do the check properly. */
return -ENOSYS;
if (r < 0)
return r;