diff options
author | Nick Rosbrook <enr0n@ubuntu.com> | 2023-09-28 20:10:59 +0200 |
---|---|---|
committer | Nick Rosbrook <enr0n@ubuntu.com> | 2023-10-13 21:13:11 +0200 |
commit | b426b4eed8d83ac3111c8d9814b96bca0d88382f (patch) | |
tree | 8beab72085b84fa0b56c71533a59ade9aa14763b /src/shared/cgroup-show.c | |
parent | core: fix checking for extension-releases for ExtensionImages/Directories (diff) | |
download | systemd-b426b4eed8d83ac3111c8d9814b96bca0d88382f.tar.xz systemd-b426b4eed8d83ac3111c8d9814b96bca0d88382f.zip |
cgroup-util: add cg_is_delegated helper
Take is_delegated from cgroup-show.c, and make it a generic helper
function. This new helper will be used again in a later commit.
Diffstat (limited to '')
-rw-r--r-- | src/shared/cgroup-show.c | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index d2d0339910..32e1176a57 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -128,33 +128,6 @@ static int show_cgroup_one_by_path( return 0; } -static int is_delegated(int cgfd, const char *path) { - _cleanup_free_ char *b = NULL; - int r; - - assert(cgfd >= 0 || path); - - const char *t = cgfd >= 0 ? FORMAT_PROC_FD_PATH(cgfd) : path; - - r = getxattr_malloc(t, "trusted.delegate", &b); - if (ERRNO_IS_NEG_XATTR_ABSENT(r)) { - /* If the trusted xattr isn't set (preferred), then check the untrusted one. Under the - * assumption that whoever is trusted enough to own the cgroup, is also trusted enough to - * decide if it is delegated or not this should be safe. */ - r = getxattr_malloc(t, "user.delegate", &b); - if (ERRNO_IS_NEG_XATTR_ABSENT(r)) - return false; - } - if (r < 0) - return log_debug_errno(r, "Failed to read delegate xattr from %s, ignoring: %m", t); - - r = parse_boolean(b); - if (r < 0) - return log_debug_errno(r, "Failed to parse delegate xattr from %s, ignoring: %m", t); - - return r; -} - static int show_cgroup_name( const char *path, const char *prefix, @@ -173,7 +146,10 @@ static int show_cgroup_name( log_debug_errno(errno, "Failed to open cgroup '%s', ignoring: %m", path); } - delegate = is_delegated(fd, path) > 0; + r = cg_is_delegated(fd >= 0 ? FORMAT_PROC_FD_PATH(fd) : path); + if (r < 0) + log_debug_errno(r, "Failed to check if cgroup is delegated, ignoring: %m"); + delegate = r > 0; if (FLAGS_SET(flags, OUTPUT_CGROUP_ID)) { cg_file_handle fh = CG_FILE_HANDLE_INIT; |