]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix unused variable in cgroup_parse_rules_file()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 19 Jul 2023 04:35:44 +0000 (10:05 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 19 Jul 2023 18:15:41 +0000 (12:15 -0600)
Fix an unused variable warning, reported by the Coverity tool:

CID 320877 (#1 of 1): Unused value (UNUSED_VALUE) assigned_pointer:
Assigning value NULL to pwd here, but that stored value is overwritten
before it can be used.

Move the grp, pwd variables assignment to beginning of the while loop in
the cgroup_parse_rules_file().

Tested with following cgrules
-----------------------------
$ cat /etc/cgrules.conf
student         devices         /usergroup/students
@admin          *               admingroup/
peter           cpu             test1/
%               memory          test2/
*               *               default/

$ sudo CGROUP_LOGLEVEL=DEBUG ./src/daemon/cgrulesengd -d -n
Parsing configuration file /etc/cgrules.conf.
Added rule student (UID: 1001, GID: -1) -> /usergroup/students for
controllers: devices
Added rule @admin (UID: -1, GID: 1004) -> admingroup/ for controllers: *
Added rule peter (UID: 1003, GID: -1) -> test1/ for controllers: cpu
Added rule % (UID: 1003, GID: -1) -> test2/ for controllers: memory
Added rule * (UID: -2, GID: -2) -> default/ for controllers: *
Parsing of configuration file complete.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 46842164320e6113f795e45c9f24c511828a6d60..f2991a40cbbb3c4fcba2a05a205c985c22ca6b6e 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -596,10 +596,10 @@ static int cgroup_parse_rules_file(char *filename, bool cache, uid_t muid, gid_t
        struct cgroup_rule *newrule = NULL;
 
        /* Structure to get GID from group name */
-       struct group *grp = NULL;
+       struct group *grp;
 
        /* Structure to get UID from user name */
-       struct passwd *pwd = NULL;
+       struct passwd *pwd;
 
        /* Temporary storage for a configuration rule */
        char key[CGROUP_RULE_MAXKEY] = { '\0' };
@@ -666,6 +666,10 @@ static int cgroup_parse_rules_file(char *filename, bool cache, uid_t muid, gid_t
                        continue;
                }
 
+               /* clear the buffer. */
+               grp = NULL;
+               pwd = NULL;
+
                /*
                 * If there is something left, it should be a rule.  Otherwise,
                 * there's an error in the configuration file.
@@ -883,10 +887,6 @@ static int cgroup_parse_rules_file(char *filename, bool cache, uid_t muid, gid_t
                for (i = 0; lst->tail->controllers[i]; i++)
                        cgroup_dbg(" %s", lst->tail->controllers[i]);
                cgroup_dbg("\n");
-
-               /* Finally, clear the buffer. */
-               grp = NULL;
-               pwd = NULL;
        }
 
        /* If we make it here, there were no errors. */