]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: declare file_handle union in cg_cgroupid_open() 40500/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Jan 2026 17:16:32 +0000 (02:16 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Feb 2026 17:45:17 +0000 (02:45 +0900)
This also effectively reverts eb2e91b9815bcbc59997c1092d7b52fc18930bff,
as now the object is only used as input, and kernel would need to handle
input with only ID no matter whether the struct later gets extended.

src/basic/cgroup-util.c

index 5b213921543439cb47459eae0cc616c205cdd737..d613e65c4b8202b06d1cc1ffcbdd3916e915b2ea 100644 (file)
 #include "user-util.h"
 #include "xattr-util.h"
 
-/* The structure to pass to name_to_handle_at() on cgroupfs2 */
-typedef union {
-        struct file_handle file_handle;
-        uint8_t space[MAX_HANDLE_SZ];
-} cg_file_handle;
-
-#define CG_FILE_HANDLE_INIT                                     \
-        (cg_file_handle) {                                      \
-                .file_handle.handle_bytes = sizeof(uint64_t),   \
-                .file_handle.handle_type = FILEID_KERNFS,       \
-        }
-
 int cg_is_available(void) {
         struct statfs fs;
 
@@ -82,7 +70,14 @@ int cg_cgroupid_open(int cgroupfs_fd, uint64_t id) {
                 cgroupfs_fd = fsfd;
         }
 
-        cg_file_handle fh = CG_FILE_HANDLE_INIT;
+        union {
+                struct file_handle file_handle;
+                uint8_t space[offsetof(struct file_handle, f_handle) + sizeof(uint64_t)];
+        } fh = {
+                .file_handle.handle_bytes = sizeof(uint64_t),
+                .file_handle.handle_type = FILEID_KERNFS,
+        };
+
         unaligned_write_ne64(fh.file_handle.f_handle, id);
 
         return RET_NERRNO(open_by_handle_at(cgroupfs_fd, &fh.file_handle, O_DIRECTORY|O_CLOEXEC));