summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-03-24 19:06:49 +0100
committerDhaval Giani <dhaval.giani@gmail.com>2010-03-26 12:56:43 +0100
commit127da29e9ab20a3be8096cbd7f7ff225a2ddd7b7 (patch)
treec06b98c7ddd7bd922cd049e4431872e6b6023f2e
parentbdc36c15b77dd7db3720540efbd164899bee53c0 (diff)
downloadlibcg-127da29e9ab20a3be8096cbd7f7ff225a2ddd7b7.tar.gz
libcg-127da29e9ab20a3be8096cbd7f7ff225a2ddd7b7.tar.xz
libcg-127da29e9ab20a3be8096cbd7f7ff225a2ddd7b7.zip
add const where applicable, drop const where unnecessary
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>
-rw-r--r--include/libcgroup/init.h2
-rw-r--r--include/libcgroup/iterators.h8
-rw-r--r--include/libcgroup/tasks.h10
-rw-r--r--src/api.c56
-rw-r--r--src/libcgroup-internal.h2
-rw-r--r--src/tools/cgclassify.c2
-rw-r--r--src/tools/cgexec.c2
7 files changed, 41 insertions, 41 deletions
diff --git a/include/libcgroup/init.h b/include/libcgroup/init.h
index b38eb61..d0e93b4 100644
--- a/include/libcgroup/init.h
+++ b/include/libcgroup/init.h
@@ -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
diff --git a/include/libcgroup/iterators.h b/include/libcgroup/iterators.h
index 3e9f9f7..e8df12a 100644
--- a/include/libcgroup/iterators.h
+++ b/include/libcgroup/iterators.h
@@ -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);
/**
diff --git a/include/libcgroup/tasks.h b/include/libcgroup/tasks.h
index 665f993..913251c 100644
--- a/include/libcgroup/tasks.h
+++ b/include/libcgroup/tasks.h
@@ -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
diff --git a/src/api.c b/src/api.c
index 4525311..365ab21 100644
--- 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;
diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h
index 55fa9fd..722bc65 100644
--- a/src/libcgroup-internal.h
+++ b/src/libcgroup-internal.h
@@ -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);
diff --git a/src/tools/cgclassify.c b/src/tools/cgclassify.c
index b2d6f18..f12fb22 100644
--- a/src/tools/cgclassify.c
+++ b/src/tools/cgclassify.c
@@ -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));
diff --git a/src/tools/cgexec.c b/src/tools/cgexec.c
index 2c92964..6fec85a 100644
--- a/src/tools/cgexec.c
+++ b/src/tools/cgexec.c
@@ -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");