From ede1caeada6a055a0ae0ca9893376084347f312b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 29 Jan 2026 02:16:32 +0900 Subject: [PATCH] cgroup-util: declare file_handle union in cg_cgroupid_open() 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 | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index 5b213921543..d613e65c4b8 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -35,18 +35,6 @@ #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)); -- 2.47.3