From: Kamalesh Babulal Date: Wed, 19 Jul 2023 04:35:44 +0000 (+0530) Subject: api.c: fix unused variable in cgroup_parse_rules_file() X-Git-Tag: v3.1.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de5127c3947159edfeca9a7f86780d829ea81ab2;p=thirdparty%2Flibcgroup.git api.c: fix unused variable in cgroup_parse_rules_file() 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 Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 46842164..f2991a40 100644 --- 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. */