diff options
author | Lennart Poettering <lennart@poettering.net> | 2024-11-22 17:37:35 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2024-11-23 00:14:20 +0100 |
commit | a2429f507ca72278bb6d2893b58906ab313d6e0c (patch) | |
tree | eb66245dc0dd60365d420f7b72ad008ba00d3bd3 /src/basic | |
parent | detect-virt: check the inode number of the pid namespace (diff) | |
download | systemd-a2429f507ca72278bb6d2893b58906ab313d6e0c.tar.xz systemd-a2429f507ca72278bb6d2893b58906ab313d6e0c.zip |
virt: make use of ns inode check in running_in_userns() and running_in_cgroupns() too
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/virt.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c index 7792d64f16..9dcafb9dea 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -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; |