]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
virt: make use of ns inode check in running_in_userns() and running_in_cgroupns(...
authorLennart Poettering <lennart@poettering.net>
Fri, 22 Nov 2024 16:37:35 +0000 (17:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 22 Nov 2024 23:14:20 +0000 (00:14 +0100)
src/basic/virt.c

index 7792d64f16b1d344a42c7e30fdbb5f48d6e618e0..9dcafb9dea0d32d10532d45a8bb7713b95e138c1 100644 (file)
@@ -585,6 +585,14 @@ static int running_in_cgroupns(void) {
         if (!cg_ns_supported())
                 return false;
 
+        r = namespace_is_init(NAMESPACE_CGROUP);
+        if (r < 0)
+                log_debug_errno(r, "Failed to test if in root cgroup namespace, ignoring: %m");
+        else if (r > 0)
+                return false;
+
+        // FIXME: We really should drop the heuristics below.
+
         r = cg_all_unified();
         if (r < 0)
                 return r;
@@ -882,6 +890,14 @@ int running_in_userns(void) {
         _cleanup_free_ char *line = NULL;
         int r;
 
+        r = namespace_is_init(NAMESPACE_USER);
+        if (r < 0)
+                log_debug_errno(r, "Failed to test if in root user namespace, ignoring: %m");
+        else if (r > 0)
+                return false;
+
+        // FIXME: We really should drop the heuristics below.
+
         r = userns_has_mapping("/proc/self/uid_map");
         if (r != 0)
                 return r;