diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-03-01 21:22:02 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-03-01 15:22:02 -0500 |
commit | d6d0473dc9688dbfcd9e9b6ed005de26dd1131b7 (patch) | |
tree | 2a21ff05389668c0276eb59f6e6a68f1f6513717 | |
parent | b7a09e35ccb5eaaf8fba583ffbae7caa2b8a16af (diff) |
Revert "util: Fine tune running_in_chroot() a bit" (#5506)
This reverts commit 295ee9845c801300298d01256eb5a9e3ff117ae0.
Let'd revert this for now, see #5446 for discussions.
We want systemd-detect-virt --chroot to return true for all chroot-like stuff, for
example mock environments which have use a mount namespace. The downside
of this revert that systemctl will not work from our own namespaced services, anything
with RootDirectory=/RootImage= set.
-rw-r--r-- | src/basic/virt.c | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c index 9d615da681..ff4491d6d6 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -28,7 +28,6 @@ #include "env-util.h" #include "fd-util.h" #include "fileio.h" -#include "fs-util.h" #include "macro.h" #include "process-util.h" #include "stat-util.h" @@ -570,30 +569,16 @@ int running_in_userns(void) { } int running_in_chroot(void) { - _cleanup_free_ char *self_mnt = NULL, *pid1_mnt = NULL; - int r; - - /* Try to detect whether we are running in a chroot() environment. Specifically, check whether we have a - * different root directory than PID 1, even though we live in the same mount namespace as it. */ + int ret; if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0) return 0; - r = files_same("/proc/1/root", "/"); - if (r < 0) - return r; - if (r > 0) - return 0; - - r = readlink_malloc("/proc/self/ns/mnt", &self_mnt); - if (r < 0) - return r; - - r = readlink_malloc("/proc/1/ns/mnt", &pid1_mnt); - if (r < 0) - return r; + ret = files_same("/proc/1/root", "/"); + if (ret < 0) + return ret; - return streq(self_mnt, pid1_mnt); /* Only if we live in the same namespace! */ + return ret == 0; } static const char *const virtualization_table[_VIRTUALIZATION_MAX] = { |