From 9172bf678dd0e93daa158e4fe03cd81c43f3dcaa Mon Sep 17 00:00:00 2001 From: Dhaval Giani Date: Fri, 26 Mar 2010 15:04:33 +0100 Subject: libcgroup: Fix coding style issues in api.c Pre this patch total: 16 errors, 40 warnings, 3321 lines checked Post this patch total: 2 errors, 5 warnings, 3323 lines checked The remaining errors will cause a code change, and so go in a separate patch. Signed-off-by: Dhaval Giani --- src/api.c | 112 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/src/api.c b/src/api.c index 0370b01..e822749 100644 --- a/src/api.c +++ b/src/api.c @@ -197,7 +197,7 @@ static int cgroup_test_subsys_mounted(const char *name) /** * Free a single cgroup_rule struct. - * @param r The rule to free from memory + * @param r The rule to free from memory */ static void cgroup_free_rule(struct cgroup_rule *r) { @@ -214,7 +214,7 @@ static void cgroup_free_rule(struct cgroup_rule *r) r->procname = NULL; } /* We must free any used controller strings, too. */ - for(i = 0; i < MAX_MNT_ELEMENTS; i++) { + for (i = 0; i < MAX_MNT_ELEMENTS; i++) { if (r->controllers[i]) free(r->controllers[i]); } @@ -225,7 +225,7 @@ static void cgroup_free_rule(struct cgroup_rule *r) /** * Free a list of cgroup_rule structs. If rl is the main list of rules, * the lock must be taken for writing before calling this function! - * @param rl Pointer to the list of rules to free from memory + * @param rl Pointer to the list of rules to free from memory */ static void cgroup_free_rule_list(struct cgroup_rule_list *rl) { @@ -288,10 +288,10 @@ static char *cg_skip_unused_charactors_in_rule(char *rule) * as well as any children rules (rules that begin with a %) that it has. * * This function is NOT thread safe! - * @param cache True to cache rules, else false - * @param muid If cache is false, the UID to match against - * @param mgid If cache is false, the GID to match against - * @return 0 on success, -1 if no cache and match found, > 0 on error. + * @param cache True to cache rules, else false + * @param muid If cache is false, the UID to match against + * @param mgid If cache is false, the GID to match against + * @return 0 on success, -1 if no cache and match found, > 0 on error. * TODO: Make this function thread safe! */ static int cgroup_parse_rules(bool cache, uid_t muid, @@ -483,9 +483,8 @@ static int cgroup_parse_rules(bool cache, uid_t muid, } } - if (uid == muid || gid == mgid || uid == CGRULE_WILD) { + if (uid == muid || gid == mgid || uid == CGRULE_WILD) matched = true; - } if (!cache) { if (!matched) @@ -502,7 +501,10 @@ static int cgroup_parse_rules(bool cache, uid_t muid, continue; } - /* FIXME: basename() modifies the string and really shouldn't! */ + /* + * FIXME: basename() modifies the + * string and really shouldn't! + **/ if (strcmp(mprocname, procname) && strcmp(basename(mprocname), procname)) { @@ -584,9 +586,8 @@ static int cgroup_parse_rules(bool cache, uid_t muid, cgroup_dbg("Added rule %s (UID: %d, GID: %d) -> %s for" " controllers:", lst->tail->username, lst->tail->uid, lst->tail->gid, lst->tail->destination); - for (i = 0; lst->tail->controllers[i]; i++) { + for (i = 0; lst->tail->controllers[i]; i++) cgroup_dbg(" %s", lst->tail->controllers[i]); - } cgroup_dbg("\n"); /* Finally, clear the buffer. */ @@ -631,7 +632,7 @@ int cgroup_init(void) FILE *proc_cgroup = NULL; char subsys_name[FILENAME_MAX]; int hierarchy, num_cgroups, enabled; - int i=0; + int i = 0; int j; int duplicate = 0; char *mntopt = NULL; @@ -716,8 +717,8 @@ int cgroup_init(void) /* do not have duplicates in mount table */ duplicate = 0; for (j = 0; j < found_mnt; j++) { - if (strncmp(mntopt, cg_mount_table[j].name, FILENAME_MAX) - == 0) { + if (strncmp(mntopt, cg_mount_table[j].name, + FILENAME_MAX) == 0) { duplicate = 1; break; } @@ -775,9 +776,8 @@ static int cg_test_mounted_fs(void) int ret = 1; proc_mount = fopen("/proc/mounts", "r"); - if (proc_mount == NULL) { + if (proc_mount == NULL) return 0; - } temp_ent = (struct mntent *) malloc(sizeof(struct mntent)); if (!temp_ent) { @@ -794,7 +794,7 @@ static int cg_test_mounted_fs(void) goto done; } - while (strcmp(ent->mnt_type, "cgroup") !=0) { + while (strcmp(ent->mnt_type, "cgroup") != 0) { ent = getmntent_r(proc_mount, temp_ent, mntent_buff, sizeof(mntent_buff)); if (ent == NULL) { @@ -815,7 +815,8 @@ static inline pid_t cg_gettid(void) /* Call with cg_mount_table_lock taken */ -static char *cg_build_path_locked(const char *name, char *path, const char *type) +static char *cg_build_path_locked(const char *name, char *path, + const char *type) { int i; for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) { @@ -834,7 +835,7 @@ static char *cg_build_path_locked(const char *name, char *path, const char *type char *tmp; tmp = strdup(path); - /* FIXME: missing OOM check here! */ + /* FIXME: missing OOM check here! */ sprintf(path, "%s%s/", tmp, name); free(tmp); @@ -908,11 +909,10 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid) cgroup_dbg("libcgroup is not initialized\n"); return ECGROUPNOTINITIALIZED; } - if(!cgroup) - { + if (!cgroup) { pthread_rwlock_rdlock(&cg_mount_table_lock); - for(i = 0; i < CG_CONTROLLER_MAX && - cg_mount_table[i].name[0]!='\0'; i++) { + for (i = 0; i < CG_CONTROLLER_MAX && + cg_mount_table[i].name[0] != '\0'; i++) { if (!cg_build_path_locked(NULL, path, cg_mount_table[i].name)) continue; @@ -1551,7 +1551,7 @@ static int cg_move_task_files(FILE *input_tasks, FILE *output_tasks) * @param target_tasks Opened tasks file of the target group, where all * processes should be moved. * @param flags Flag indicating whether the errors from task - * migration should be ignored (CGROUP_DELETE_IGNORE_MIGRATION) or not (0). + * migration should be ignored (CGROUP_DELETE_IGNORE_MIGRATION) or not (0). * @returns 0 on success, >0 on error. */ static int cg_delete_cgroup_controller(char *cgroup_name, char *controller, @@ -1789,7 +1789,8 @@ int cgroup_delete_cgroup_ext(struct cgroup *cgroup, int flags) * will assume that the callers have taken care of everything. * Including the locking. */ -static int cg_rd_ctrl_file(const char *subsys, const char *cgroup, const char *file, char **value) +static int cg_rd_ctrl_file(const char *subsys, const char *cgroup, + const char *file, char **value) { char path[FILENAME_MAX]; FILE *ctrl_file = NULL; @@ -2162,10 +2163,10 @@ static struct cgroup_rule *cgroup_find_matching_rule_uid_gid(uid_t uid, * This function uses rl_lock. * * This function may NOT be thread safe. - * @param uid The UID to match - * @param gid The GID to match - * @param procname The PROCESS NAME to match - * @return Pointer to the first matching rule, or NULL if no match + * @param uid The UID to match + * @param gid The GID to match + * @param procname The PROCESS NAME to match + * @return Pointer to the first matching rule, or NULL if no match * TODO: Determine thread-safeness and fix if not safe. */ static struct cgroup_rule *cgroup_find_matching_rule(uid_t uid, @@ -2188,8 +2189,9 @@ static struct cgroup_rule *cgroup_find_matching_rule(uid_t uid, break; if (!strcmp(ret->procname, procname)) break; - - /* FIXME: basename() modifies the string and really shouldn't! */ + /* + * FIXME: basename() modifies the string and really shouldn't! + **/ if (!strcmp(ret->procname, basename(procname))) /* Check a rule of basename. */ @@ -2260,7 +2262,7 @@ int cgroup_change_cgroup_flags(uid_t uid, gid_t gid, cgroup_dbg("Executing rule %s for PID %d... ", tmp->username, pid); ret = cgroup_change_cgroup_path(tmp->destination, - pid, (const char* const*)tmp->controllers); + pid, (const char * const *)tmp->controllers); if (ret) { cgroup_dbg("FAILED! (Error Code: %d)\n", ret); goto finished; @@ -2289,10 +2291,10 @@ int cgroup_change_cgroup_uid_gid_flags(uid_t uid, gid_t gid, * function is deprecated, and cgroup_change_cgroup_uid_gid_flags() should be * used instead. In fact, this function simply calls the newer one with flags * set to 0 (none). - * @param uid The UID to match - * @param gid The GID to match - * @param pid The PID of the process to move - * @return 0 on success, > 0 on error + * @param uid The UID to match + * @param gid The GID to match + * @param pid The PID of the process to move + * @return 0 on success, > 0 on error * */ int cgroup_change_cgroup_uid_gid(uid_t uid, gid_t gid, pid_t pid) @@ -2307,7 +2309,8 @@ int cgroup_change_cgroup_uid_gid(uid_t uid, gid_t gid, pid_t pid) * * returns 0 on success. */ -int cgroup_change_cgroup_path(const char *dest, pid_t pid, const char *const controllers[]) +int cgroup_change_cgroup_path(const char *dest, pid_t pid, + const char *const controllers[]) { int ret; struct cgroup cgroup; @@ -2333,7 +2336,7 @@ int cgroup_change_cgroup_path(const char *dest, pid_t pid, const char *const con * Print the cached rules table. This function should be called only after * first calling cgroup_parse_config(), but it will work with an empty rule * list. - * @param fp The file stream to print to + * @param fp The file stream to print to */ void cgroup_print_rules_config(FILE *fp) { @@ -2376,9 +2379,8 @@ void cgroup_print_rules_config(FILE *fp) fprintf(fp, " CONTROLLERS:\n"); for (i = 0; i < MAX_MNT_ELEMENTS; i++) { - if (itr->controllers[i]) { + if (itr->controllers[i]) fprintf(fp, " %s\n", itr->controllers[i]); - } } fprintf(fp, "\n"); itr = itr->next; @@ -2389,7 +2391,7 @@ void cgroup_print_rules_config(FILE *fp) /** * Reloads the rules list, using the given configuration file. This function * is probably NOT thread safe (calls cgroup_parse_rules()). - * @return 0 on success, > 0 on failure + * @return 0 on success, > 0 on failure */ int cgroup_reload_cached_rules(void) { @@ -2415,7 +2417,7 @@ finished: /** * Initializes the rules cache. - * @return 0 on success, > 0 on error + * @return 0 on success, > 0 on error */ int cgroup_init_rules_cache(void) { @@ -2440,7 +2442,7 @@ int cgroup_init_rules_cache(void) * @pid: pid of the current process for which the path is to be determined * @controller: name of the controller for which to determine current path * @current_path: a pointer that is filled with the value of the current - * path as seen in /proc//cgroup + * path as seen in /proc//cgroup */ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char **current_path) @@ -2527,9 +2529,9 @@ cleanup_path: const char *cgroup_strerror(int code) { - if (code == ECGOTHER) { + if (code == ECGOTHER) return strerror_r(cgroup_get_last_errno(), errtext, MAXLEN); - } + return cgroup_strerror_codes[code % ECGROUPNOTCOMPILED]; } @@ -2634,9 +2636,9 @@ int cgroup_walk_tree_end(void **handle) /* * TODO: Need to decide a better place to put this function. */ -int cgroup_walk_tree_begin(const char *controller, const char *base_path, int depth, - void **handle, struct cgroup_file_info *info, - int *base_level) +int cgroup_walk_tree_begin(const char *controller, const char *base_path, + int depth, void **handle, struct cgroup_file_info *info, + int *base_level) { int ret = 0; cgroup_dbg("path is %s\n", base_path); @@ -2774,8 +2776,8 @@ int cgroup_read_stats_next(void **handle, struct cgroup_stat *stat) /* * TODO: Need to decide a better place to put this function. */ -int cgroup_read_stats_begin(const char *controller, const char *path, void **handle, - struct cgroup_stat *stat) +int cgroup_read_stats_begin(const char *controller, const char *path, + void **handle, struct cgroup_stat *stat) { int ret = 0; char stat_file[FILENAME_MAX]; @@ -2839,8 +2841,8 @@ int cgroup_get_task_next(void **handle, pid_t *pid) return 0; } -int cgroup_get_task_begin(const char *cgroup, const char *controller, void **handle, - pid_t *pid) +int cgroup_get_task_begin(const char *cgroup, const char *controller, + void **handle, pid_t *pid) { int ret = 0; char path[FILENAME_MAX]; @@ -3048,8 +3050,8 @@ static int cg_get_procname_from_proc_status(pid_t pid, char **procname_status) * @param pname_cmdline: The process name taken from /proc//cmdline * @return 0 on success, > 0 on error. */ -static int cg_get_procname_from_proc_cmdline(pid_t pid, const char *pname_status, - char **pname_cmdline) +static int cg_get_procname_from_proc_cmdline(pid_t pid, + const char *pname_status, char **pname_cmdline) { FILE *f; int ret = ECGFAIL; -- cgit