From: Kamalesh Babulal Date: Fri, 6 May 2022 15:36:33 +0000 (+0530) Subject: api.c: resize controller name to 32 from 4096 bytes X-Git-Tag: v3.0~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1ea1e7164c7feebddf021938b50061946e712a4;p=thirdparty%2Flibcgroup.git api.c: resize controller name to 32 from 4096 bytes Linux kernel warns on the cgroup controller name length greater than 32 bytes during the cgroup initialization in cgroup_init_early(). Adopt the same size of 32 bytes (including the null byte) for controller name in the struct cg_controller and struct cg_mount_table_s. This resize from FILENAME_MAX (4096 bytes) to a mere 32 bytes, reduces the libcgroup.so library: Without the patch: ------------------ $ size -d src/.libs/libcgroup.so text data bss dec hex filename 123841 3600 2476532 2603973 27bbc5 src/.libs/libcgroup.so With the patch: --------------- $ size -d src/.libs/libcgroup.so text data bss dec hex filename 123569 3600 1257332 1384501 152035 src/.libs/libcgroup.so also replace the index FILENAME_MAX with CONTROL_NAMELEN_MAX at the struct cg_controller::name and struct cg_mount_table_s::name references. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 814660a1..a0278f93 100644 --- a/src/api.c +++ b/src/api.c @@ -1104,8 +1104,8 @@ static void cgroup_cg_mount_table_append(const char *name, { int i = *mnt_tbl_idx; - strncpy(cg_mount_table[i].name, name, FILENAME_MAX); - cg_mount_table[i].name[FILENAME_MAX-1] = '\0'; + strncpy(cg_mount_table[i].name, name, CONTROL_NAMELEN_MAX); + cg_mount_table[i].name[CONTROL_NAMELEN_MAX-1] = '\0'; strncpy(cg_mount_table[i].mount.path, mount_path, FILENAME_MAX); cg_mount_table[i].mount.path[FILENAME_MAX-1] = '\0'; @@ -2461,7 +2461,7 @@ int cgroup_copy_controller_values(struct cgroup_controller * const dst, if (!dst || !src) return ECGFAIL; - strncpy(dst->name, src->name, FILENAME_MAX); + strncpy(dst->name, src->name, CONTROL_NAMELEN_MAX); for (i = 0; i < src->index; i++, dst->index++) { struct control_value *src_val = src->values[i]; struct control_value *dst_val; diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h index a138eab1..afc9494c 100644 --- a/src/libcgroup-internal.h +++ b/src/libcgroup-internal.h @@ -43,6 +43,9 @@ extern "C" { */ #define CG_HIER_MAX CG_CONTROLLER_MAX +/* Maximum length of a controller's name */ +#define CONTROL_NAMELEN_MAX 32 + /* Definitions for the uid and gid members of a cgroup_rules */ #define CGRULE_INVALID ((uid_t) -1) #define CGRULE_WILD ((uid_t) -2) @@ -99,7 +102,7 @@ struct control_value { }; struct cgroup_controller { - char name[FILENAME_MAX]; + char name[CONTROL_NAMELEN_MAX]; struct control_value *values[CG_NV_MAX]; struct cgroup *cgroup; int index; @@ -126,7 +129,7 @@ struct cg_mount_point { struct cg_mount_table_s { /** Controller name. */ - char name[FILENAME_MAX]; + char name[CONTROL_NAMELEN_MAX]; /** * List of mount points, at least one mount point is there for sure. */