Add $SYSTEMD_IN_CHROOT to override chroot detection
When running unprivileged, checking /proc/1/root doesn't work because it requires privileges. Instead, let's add an environment variable so the process that chroot's can tell (systemd) subprocesses whether they're running in a chroot or not.
This commit is contained in:
@@ -896,6 +896,13 @@ int running_in_chroot(void) {
|
||||
* mount /proc, so all other programs can assume that if /proc is *not* available, we're in some
|
||||
* chroot. */
|
||||
|
||||
r = getenv_bool("SYSTEMD_IN_CHROOT");
|
||||
if (r >= 0)
|
||||
return r > 0;
|
||||
if (r != -ENXIO)
|
||||
log_debug_errno(r, "Failed to parse $SYSTEMD_IN_CHROOT, ignoring: %m");
|
||||
|
||||
/* Deprecated but kept for backwards compatibility. */
|
||||
if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user