]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: resize controller name to 32 from 4096 bytes
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 6 May 2022 15:36:33 +0000 (21:06 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 16 May 2022 16:04:37 +0000 (10:04 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c
src/libcgroup-internal.h

index 814660a1a064339bb093833c0de1b0a9d01d4c15..a0278f9353de2b9100cca7db9e924d795ba4563d 100644 (file)
--- 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;
index a138eab10b1bffc6428a8cfd6cbf56ab772ef2f1..afc9494cee786a17dd0e74f59ae06c663ffc73b6 100644 (file)
@@ -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.
         */