]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
add const where applicable, drop const where unnecessary
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Mar 2010 18:06:49 +0000 (19:06 +0100)
committerDhaval Giani <dhaval.giani@gmail.com>
Fri, 26 Mar 2010 11:56:43 +0000 (12:56 +0100)
This patch adds the const qualifier to a number of function arguments
(mostly string arguments) so that client libraries can pass their own
const strings to the library without having to cast their const'ness
away.

This also drops a couple of consts where call-by-value is done anyway,
and which hence has no effect and just misleads the users and adds
unnecessary noise to the signal. After all this is C, not C++.

Signed-off-by: Lennart Poettering <lennart@poettering.net>
Acked-by: Dhaval Giani <dhaval.giani@gmail.com>
Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
include/libcgroup/init.h
include/libcgroup/iterators.h
include/libcgroup/tasks.h
src/api.c
src/libcgroup-internal.h
src/tools/cgclassify.c
src/tools/cgexec.c

index b38eb615775724e66dbcd53caa98c09797e21828..d0e93b4d6daa9cadfa2dfcdb9fed523789d6b2db 100644 (file)
@@ -18,7 +18,7 @@ int cgroup_init(void);
  * @mount_point: The string where the mount point is stored. Please note,
  * the caller must free mount_point.
  */
-int cgroup_get_subsys_mount_point(char *controller, char **mount_point);
+int cgroup_get_subsys_mount_point(const char *controller, char **mount_point);
 
 __END_DECLS
 
index 3e9f9f726ec0af827fe172f65b6d325b752c98ca..e8df12a6122da46e1ab90fa55a84d766020b8652 100644 (file)
@@ -74,7 +74,7 @@ struct controller_data {
  * @handle: Handle to be used during iteration
  * @info: info filled and returned about directory information
  */
-int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth,
+int cgroup_walk_tree_begin(const char *controller, const char *base_path, int depth,
                                void **handle, struct cgroup_file_info *info,
                                int *base_level);
 /**
@@ -86,7 +86,7 @@ int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth,
  *
  * Returns ECGEOF when we are done walking through the nodes.
  */
-int cgroup_walk_tree_next(const int depth, void **handle,
+int cgroup_walk_tree_next(int depth, void **handle,
                                struct cgroup_file_info *info, int base_level);
 int cgroup_walk_tree_end(void **handle);
 
@@ -107,7 +107,7 @@ int cgroup_walk_tree_set_flags(void **handle, int flags);
  * @handle: Handle to be used during iteration.
  * @stat: Stats values will be filled and returned here.
  */
-int cgroup_read_stats_begin(char *controller, char *path, void **handle,
+int cgroup_read_stats_begin(const char *controller, const char *path, void **handle,
                                struct cgroup_stat *stat);
 
 /**
@@ -126,7 +126,7 @@ int cgroup_read_stats_end(void **handle);
  * @handle: Handle to be used in the iteration
  * @pid: The pid read from the tasks file. Will be filled in by the API
  */
-int cgroup_get_task_begin(char *cgroup, char *controller, void **handle,
+int cgroup_get_task_begin(const char *cgroup, const char *controller, void **handle,
                                                                pid_t *pid);
 
 /**
index 665f993ddb5e1f894725cf8341be68a6f4cdb1f4..913251c4383fe52fc2364e297fe9fc168627ea99 100644 (file)
@@ -42,8 +42,8 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid);
  *     @return 0 on success, > 0 on error
  * TODO: Determine thread-safeness and fix of not safe.
  */
-int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
-               char *procname, const pid_t pid, const int flags);
+int cgroup_change_cgroup_flags(uid_t uid, gid_t gid,
+               const char *procname, pid_t pid, int flags);
 
 /**
  * Changes the cgroup of a program based on the rules in the config file.  If a
@@ -62,8 +62,8 @@ int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
  *     @return 0 on success, > 0 on error
  * TODO: Determine thread-safeness and fix if not safe.
  */
-int cgroup_change_cgroup_uid_gid_flags(const uid_t uid, const gid_t gid,
-                               const pid_t pid, const int flags);
+int cgroup_change_cgroup_uid_gid_flags(uid_t uid, gid_t gid,
+                               pid_t pid, int flags);
 
 /**
  * Provides backwards-compatibility with older versions of the API.  This
@@ -84,7 +84,7 @@ int cgroup_change_cgroup_uid_gid(uid_t uid, gid_t gid, pid_t pid);
  *
  *  returns 0 on success.
  */
-int cgroup_change_cgroup_path(char *path, pid_t pid, char *controllers[]);
+int cgroup_change_cgroup_path(const char *path, pid_t pid, const char * const controllers[]);
 
 /**
  * Print the cached rules table.  This function should be called only after
index 45253112c9f75e89ba3644f802d7d2971a1b028f..365ab21602689fcbe74b31571e312a11caeb8f53 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -292,7 +292,7 @@ static char *cg_skip_unused_charactors_in_rule(char *rule)
  * TODO: Make this function thread safe!
  */
 static int cgroup_parse_rules(bool cache, uid_t muid,
-                                         gid_t mgid, char *mprocname)
+                                         gid_t mgid, const char *mprocname)
 {
        /* File descriptor for the configuration file */
        FILE *fp = NULL;
@@ -802,14 +802,14 @@ done:
        return ret;
 }
 
-static inline pid_t cg_gettid()
+static inline pid_t cg_gettid(void)
 {
        return syscall(__NR_gettid);
 }
 
 
 /* Call with cg_mount_table_lock taken */
-static char *cg_build_path_locked(char *name, char *path, 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++) {
@@ -836,7 +836,7 @@ static char *cg_build_path_locked(char *name, char *path, char *type)
        return NULL;
 }
 
-char *cg_build_path(char *name, char *path, char *type)
+char *cg_build_path(const char *name, char *path, const char *type)
 {
        pthread_rwlock_rdlock(&cg_mount_table_lock);
        path = cg_build_path_locked(name, path, type);
@@ -1041,7 +1041,7 @@ done:
  * just makes the group. It does not set any permissions, or any control values.
  * The argument path is the fully qualified path name to make it generic.
  */
-static int cg_create_control_group(char *path)
+static int cg_create_control_group(const char *path)
 {
        int error;
        if (!cg_test_mounted_fs())
@@ -1056,7 +1056,7 @@ static int cg_create_control_group(char *path)
  * This function takes in the complete path and sets the value in val in that
  * file.
  */
-static int cg_set_control_value(char *path, char *val)
+static int cg_set_control_value(char *path, const char *val)
 {
        FILE *control_file = NULL;
        if (!cg_test_mounted_fs())
@@ -1780,7 +1780,7 @@ 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(char *subsys, char *cgroup, 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;
@@ -2032,10 +2032,10 @@ unlock_error:
  */
 static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t pid,
                                        const char *dest,
-                                       char *controllers[])
+                                       const char * const controllers[])
 {
        int ret = 0, i;
-       char *controller = NULL;
+       const char *controller = NULL;
        struct cgroup_controller *cptr = NULL;
 
        /* Fill in cgroup details.  */
@@ -2086,8 +2086,8 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t pid,
        return ret;
 }
 
-static struct cgroup_rule *cgroup_find_matching_rule_uid_gid(const uid_t uid,
-                               const gid_t gid, struct cgroup_rule *rule)
+static struct cgroup_rule *cgroup_find_matching_rule_uid_gid(uid_t uid,
+                               gid_t gid, struct cgroup_rule *rule)
 {
        /* Temporary user data */
        struct passwd *usr = NULL;
@@ -2159,8 +2159,8 @@ static struct cgroup_rule *cgroup_find_matching_rule_uid_gid(const uid_t uid,
  *     @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(const uid_t uid,
-                               const gid_t gid, char *procname)
+static struct cgroup_rule *cgroup_find_matching_rule(uid_t uid,
+                               gid_t gid, const char *procname)
 {
        /* Return value */
        struct cgroup_rule *ret = rl.head;
@@ -2189,8 +2189,8 @@ static struct cgroup_rule *cgroup_find_matching_rule(const uid_t uid,
        return ret;
 }
 
-int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
-               char *procname, const pid_t pid, const int flags)
+int cgroup_change_cgroup_flags(uid_t uid, gid_t gid,
+               const char *procname, pid_t pid, int flags)
 {
        /* Temporary pointer to a rule */
        struct cgroup_rule *tmp = NULL;
@@ -2205,7 +2205,7 @@ int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
                goto finished;
        }
 
-       /* 
+       /*
         * If the user did not ask for cached rules, we must parse the
         * configuration to find a matching rule (if one exists).  Else, we'll
         * find the first match in the cached list (rl).
@@ -2248,7 +2248,7 @@ int cgroup_change_cgroup_flags(const uid_t uid, const gid_t gid,
                cgroup_dbg("Executing rule %s for PID %d... ", tmp->username,
                                                                pid);
                ret = cgroup_change_cgroup_path(tmp->destination,
-                               pid, tmp->controllers);
+                                                pid, (const char* const*)tmp->controllers);
                if (ret) {
                        cgroup_dbg("FAILED! (Error Code: %d)\n", ret);
                        goto finished;
@@ -2266,8 +2266,8 @@ finished:
        return ret;
 }
 
-int cgroup_change_cgroup_uid_gid_flags(const uid_t uid, const gid_t gid,
-                               const pid_t pid, const int flags)
+int cgroup_change_cgroup_uid_gid_flags(uid_t uid, gid_t gid,
+                               pid_t pid, int flags)
 {
        return cgroup_change_cgroup_flags(uid, gid, NULL, pid, flags);
 }
@@ -2281,7 +2281,7 @@ int cgroup_change_cgroup_uid_gid_flags(const uid_t uid, const gid_t gid,
  *     @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)
 {
@@ -2295,7 +2295,7 @@ int cgroup_change_cgroup_uid_gid(uid_t uid, gid_t gid, pid_t pid)
  *
  *  returns 0 on success.
  */
-int cgroup_change_cgroup_path(char *dest, pid_t pid, char *controllers[])
+int cgroup_change_cgroup_path(const char *dest, pid_t pid, const char *const controllers[])
 {
        int ret;
        struct cgroup cgroup;
@@ -2392,7 +2392,7 @@ int cgroup_reload_cached_rules()
                ret = ECGRULESPARSEFAIL;
                goto finished;
        }
-               
+
        #ifdef CGROUP_DEBUG
                cgroup_print_rules_config(stdout);
        #endif
@@ -2574,7 +2574,7 @@ static int cg_walk_node(FTS *fts, FTSENT *ent, const int depth,
        return ret;
 }
 
-int cgroup_walk_tree_next(const int depth, void **handle,
+int cgroup_walk_tree_next(int depth, void **handle,
                                struct cgroup_file_info *info, int base_level)
 {
        int ret = 0;
@@ -2622,7 +2622,7 @@ int cgroup_walk_tree_end(void **handle)
 /*
  * TODO: Need to decide a better place to put this function.
  */
-int cgroup_walk_tree_begin(char *controller, char *base_path, const int depth,
+int cgroup_walk_tree_begin(const char *controller, const char *base_path, int depth,
                                void **handle, struct cgroup_file_info *info,
                                int *base_level)
 {
@@ -2762,7 +2762,7 @@ 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(char *controller, char *path, void **handle,
+int cgroup_read_stats_begin(const char *controller, const char *path, void **handle,
                                struct cgroup_stat *stat)
 {
        int ret = 0;
@@ -2827,7 +2827,7 @@ int cgroup_get_task_next(void **handle, pid_t *pid)
        return 0;
 }
 
-int cgroup_get_task_begin(char *cgroup, char *controller, void **handle,
+int cgroup_get_task_begin(const char *cgroup, const char *controller, void **handle,
                                                                pid_t *pid)
 {
        int ret = 0;
@@ -3036,7 +3036,7 @@ static int cg_get_procname_from_proc_status(pid_t pid, char **procname_status)
  * @param pname_cmdline: The process name taken from /proc/<pid>/cmdline
  * @return 0 on success, > 0 on error.
  */
-static int cg_get_procname_from_proc_cmdline(pid_t pid, char *pname_status,
+static int cg_get_procname_from_proc_cmdline(pid_t pid, const char *pname_status,
                                                        char **pname_cmdline)
 {
        FILE *f;
@@ -3212,7 +3212,7 @@ close:
        return ret;
 }
 
-int cgroup_get_subsys_mount_point(char *controller, char **mount_point)
+int cgroup_get_subsys_mount_point(const char *controller, char **mount_point)
 {
        int i;
        int ret = ECGROUPNOTEXIST;
index 55fa9fdc761c38ea8b5a07149f2474d65f0df206..722bc65d63225009fa92e8c775c92c27d2a264ff 100644 (file)
@@ -133,7 +133,7 @@ struct cgroup_tree_handle {
 extern __thread int last_errno;
 
 /* Internal API */
-char *cg_build_path(char *name, char *path, char *type);
+char *cg_build_path(const char *name, char *path, const char *type);
 int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t *euid, gid_t *egid);
 int cgroup_get_procname_from_procfs(pid_t pid, char **procname);
 int cg_mkdir_p(const char *path);
index b2d6f1885af7ff55549e68e9926e07b3d0ccb9e3..f12fb228bc51d439232b83a18714c994c3f44156 100644 (file)
@@ -44,7 +44,7 @@ int change_group_path(pid_t pid, struct cgroup_group_spec *cgroup_list[])
                        break;
 
                ret = cgroup_change_cgroup_path(cgroup_list[i]->path, pid,
-                       cgroup_list[i]->controllers);
+                                                (const char*const*) cgroup_list[i]->controllers);
                if (ret)
                        fprintf(stderr, "Error changing group of pid %d: %s\n",
                                pid, cgroup_strerror(ret));
index 2c9296499671d69a301497094d771e49e0d50e1d..6fec85a7bcf2bd3900da0e1a2ff42578c78e8339 100644 (file)
@@ -123,7 +123,7 @@ int main(int argc, char *argv[])
 
                        ret = cgroup_change_cgroup_path(cgroup_list[i]->path,
                                                        pid,
-                                               cgroup_list[i]->controllers);
+                                                        (const char*const*) cgroup_list[i]->controllers);
                        if (ret) {
                                fprintf(stderr,
                                        "cgroup change of group failed\n");