diff options
author | Jan Safranek <jsafrane@redhat.com> | 2009-05-26 14:52:42 +0200 |
---|---|---|
committer | Jan Safranek <jsafrane@redhat.com> | 2009-05-26 14:52:42 +0200 |
commit | 83ed907a1d449e8f43db580e7cd0b7542c8ed97e (patch) | |
tree | df45e3e7aab958b9a36390feb186a4108e009104 | |
parent | 84da02ebfc7fbc2862ca238d00a53548b2e0b2b1 (diff) | |
download | libcg-83ed907a1d449e8f43db580e7cd0b7542c8ed97e.tar.gz libcg-83ed907a1d449e8f43db580e7cd0b7542c8ed97e.tar.xz libcg-83ed907a1d449e8f43db580e7cd0b7542c8ed97e.zip |
Hi,
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>
-rw-r--r-- | src/api.c | 43 |
1 files changed, 27 insertions, 16 deletions
@@ -243,6 +243,30 @@ 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. */ + if ((itr = strchr(rule, '#'))) + *itr = '\0'; + + /* We also need to remove the newline character. */ + if ((itr = strchr(rule, '\n'))) + *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 @@ -337,23 +361,10 @@ static int cgroup_parse_rules(bool cache, uid_t muid, gid_t mgid) while ((itr = 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)) + if (!(itr = cg_skip_unused_charactors_in_rule(buff))) { + memset(buff, '\0', sizeof(buff)); continue; - + } /* * If we skipped the last rule and this rule is a continuation * of it (begins with %), then we should skip this rule too. |