]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-show: rework cgroup tree display to operate by fd only 29720/head
authorLennart Poettering <lennart@poettering.net>
Wed, 25 Oct 2023 21:05:24 +0000 (23:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 26 Oct 2023 07:28:29 +0000 (09:28 +0200)
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.

src/shared/cgroup-show.c

index b77bab0215ec37a2d89e1de5e2c40da4ac92a5e0..c2ee1c5aef6c7974af89d65c6d8a0ec6c196db47 100644 (file)
@@ -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);