diff options
author | Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> | 2009-06-03 15:02:59 +0900 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-06-08 13:27:21 +0530 |
commit | 3aa3c6e17b2874b8a8d4afed503f92b5117946d0 (patch) | |
tree | fa6392fff5c2d8b9c2b5d791dfe320644e4d7835 | |
parent | d9cc9ce82bf7d696d549246a7c6ff4313564b2b3 (diff) | |
download | libcg-3aa3c6e17b2874b8a8d4afed503f92b5117946d0.tar.gz libcg-3aa3c6e17b2874b8a8d4afed503f92b5117946d0.tar.xz libcg-3aa3c6e17b2874b8a8d4afed503f92b5117946d0.zip |
Cleanup: Add cg_skip_unused_charactors_in_rule().
Hi,
CHANGELOG of v2:
================
* No change.
The loop in cgroup_parse_rules() is a little long now, and it is not
easy to read the loop.
Then, This patch shortens the loop for the readability.
Thanks
Ken'ichi Ohmichi
Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Reviewed-By: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
-rw-r--r-- | src/api.c | 45 |
1 files changed, 29 insertions, 16 deletions
@@ -243,6 +243,32 @@ static void cgroup_free_rule_list(struct cgroup_rule_list *rl) rl->tail = NULL; } +static char *cg_skip_unused_charactors_in_rule(char *rule) +{ + char *itr; + + /* We ignore anything after a # sign as comments. */ + itr = strchr(rule, '#'); + if (itr) + *itr = '\0'; + + /* We also need to remove the newline character. */ + itr = strchr(rule, '\n'); + if (itr) + *itr = '\0'; + + /* Now, skip any leading tabs and spaces. */ + itr = rule; + while (itr && isblank(*itr)) + itr++; + + /* If there's nothing left, we can ignore this line. */ + if (!strlen(itr)) + return NULL; + + return itr; +} + /** * Parse the configuration file that maps UID/GIDs to cgroups. If ever the * configuration file is modified, applications should call this function to @@ -334,24 +360,11 @@ static int cgroup_parse_rules(bool cache, uid_t muid, gid_t mgid) /* Now, parse the configuration file one line at a time. */ cgroup_dbg("Parsing configuration file.\n"); - while ((itr = fgets(buff, sizeof(buff), fp)) != NULL) { + while (fgets(buff, sizeof(buff), fp) != NULL) { linenum++; - /* We ignore anything after a # sign as comments. */ - if ((itr = strchr(buff, '#'))) - *itr = '\0'; - - /* We also need to remove the newline character. */ - if ((itr = strchr(buff, '\n'))) - *itr = '\0'; - - /* Now, skip any leading tabs and spaces. */ - itr = buff; - while (itr && isblank(*itr)) - itr++; - - /* If there's nothing left, we can ignore this line. */ - if (!strlen(itr)) + itr = cg_skip_unused_charactors_in_rule(buff); + if (!itr) continue; /* |