chiark / gitweb /
Revert "util: Fine tune running_in_chroot() a bit" (#5506)
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Mar 2017 20:22:02 +0000 (21:22 +0100)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:36 +0000 (17:58 +0200)
This reverts commit 295ee9845c801300298d01256eb5a9e3ff117ae0.

Let'd revert this for now, see #5446 for discussions.

We want elogind-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.

src/basic/virt.c

index 276df83526cb93db3e35c19898ba023aa36ea2e1..9ea18e63f466a1251eb647f4cdc1bc32e4c85274 100644 (file)
@@ -572,32 +572,18 @@ int running_in_userns(void) {
 #endif // 0
 
 int running_in_chroot(void) {
 #endif // 0
 
 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 0 /// elogind does not allow to ignore chroots, we are never init!
         if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
                 return 0;
 #endif // 0
 
 
 #if 0 /// elogind does not allow to ignore chroots, we are never init!
         if (getenv_bool("SYSTEMD_IGNORE_CHROOT") > 0)
                 return 0;
 #endif // 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] = {
 }
 
 static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {