From: Lennart Poettering Date: Wed, 25 Oct 2023 21:05:24 +0000 (+0200) Subject: cgroup-show: rework cgroup tree display to operate by fd only X-Git-Tag: v255-rc1~129^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F29720%2Fhead;p=thirdparty%2Fsystemd.git cgroup-show: rework cgroup tree display to operate by fd only This restores display of the "delegate" flag of a cgroup. Previously we erroneously passed a full fs path where a cgroup path was expected (the difference being the /sys/fs/cgroup/ prefix), which meant we never read the xattr properly. Let's fix that by simply operating by fd on the cgroup and using it for all operations. --- diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index b77bab0215e..c2ee1c5aef6 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -140,13 +140,11 @@ static int show_cgroup_name( bool delegate; int r; - if (FLAGS_SET(flags, OUTPUT_CGROUP_XATTRS) || FLAGS_SET(flags, OUTPUT_CGROUP_ID)) { - fd = open(path, O_PATH|O_CLOEXEC|O_NOFOLLOW|O_DIRECTORY, 0); - if (fd < 0) - log_debug_errno(errno, "Failed to open cgroup '%s', ignoring: %m", path); - } + fd = open(path, O_PATH|O_CLOEXEC|O_NOFOLLOW|O_DIRECTORY, 0); + if (fd < 0) + return log_debug_errno(errno, "Failed to open cgroup '%s', ignoring: %m", path); - r = cg_is_delegated(fd >= 0 ? FORMAT_PROC_FD_PATH(fd) : path); + r = cg_is_delegated_fd(fd); if (r < 0) log_debug_errno(r, "Failed to check if cgroup is delegated, ignoring: %m"); delegate = r > 0; @@ -156,11 +154,11 @@ static int show_cgroup_name( int mnt_id = -1; if (name_to_handle_at( - fd < 0 ? AT_FDCWD : fd, - fd < 0 ? path : "", + fd, + "", &fh.file_handle, &mnt_id, - fd < 0 ? 0 : AT_EMPTY_PATH) < 0) + AT_EMPTY_PATH) < 0) log_debug_errno(errno, "Failed to determine cgroup ID of %s, ignoring: %m", path); else cgroupid = CG_FILE_HANDLE_CGROUPID(fh); @@ -187,7 +185,7 @@ static int show_cgroup_name( printf("\n"); - if (FLAGS_SET(flags, OUTPUT_CGROUP_XATTRS) && fd >= 0) { + if (FLAGS_SET(flags, OUTPUT_CGROUP_XATTRS)) { _cleanup_free_ char *nl = NULL; r = flistxattr_malloc(fd, &nl); @@ -266,7 +264,7 @@ int show_cgroup_by_path( continue; if (!shown_pids) { - show_cgroup_one_by_path(path, prefix, n_columns, true, flags); + (void) show_cgroup_one_by_path(path, prefix, n_columns, true, flags); shown_pids = true; } @@ -292,7 +290,7 @@ int show_cgroup_by_path( return r; if (!shown_pids) - show_cgroup_one_by_path(path, prefix, n_columns, !!last, flags); + (void) show_cgroup_one_by_path(path, prefix, n_columns, !!last, flags); if (last) { r = show_cgroup_name(last, prefix, SPECIAL_GLYPH_TREE_RIGHT, flags);