Introduce a state variable in the following functions,
1. cg_build_path
Signed-off-by: Dhaval Giani <[email protected]>
---
src/api.c | 51 +++++++++++++++++++++++------------------------
src/deprecated-api.c | 14 ++++++++++++
src/libcgroup-internal.h | 3 ++
3 files changed, 42 insertions(+), 26 deletions(-)
Index: libcg/src/api.c
===================================================================
--- libcg.orig/src/api.c
+++ libcg/src/api.c
@@ -191,23 +191,32 @@ static char *cgroup_basename(const char
return base;
}
-static int cgroup_test_subsys_mounted(const char *name)
+static int cgroup_test_subsys_context(struct cgroup_context_s *cg_context,
+ const char *name)
{
int i;
- pthread_rwlock_rdlock(&cg_mount_table_lock);
-
- for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
- if (strncmp(cg_mount_table[i].name, name,
- sizeof(cg_mount_table[i].name)) == 0) {
- pthread_rwlock_unlock(&cg_mount_table_lock);
+ for (i = 0; i < cg_context->size; i++) {
+ if (strncmp(cg_context->mount[i].name, name,
+ sizeof(cg_context->mount[i].name)) == 0) {
return 1;
}
}
- pthread_rwlock_unlock(&cg_mount_table_lock);
+
return 0;
}
+static int cgroup_test_subsys_mounted(const char *name)
+{
+ int ret;
+
+ pthread_rwlock_rdlock(&cg_mount_table_lock);
+ ret = cgroup_test_subsys_context(cgroup_context, name);
+ pthread_rwlock_unlock(&cg_mount_table_lock);
+
+ return ret;
+}
+
/**
* Free a single cgroup_rule struct.
* @param r The rule to free from memory
@@ -883,21 +892,20 @@ 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)
+char *cg_build_path_context(struct cgroup_context_s *context, char *name,
+ char *path, char *type)
{
int i;
- for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
+ for (i = 0; i < context->size; i++) {
/*
* XX: Change to snprintf once you figure what n should be
*/
- if (strcmp(cg_mount_table[i].name, type) == 0) {
- if (cg_namespace_table[i]) {
- sprintf(path, "%s/%s/", cg_mount_table[i].path,
- cg_namespace_table[i]);
+ if (strcmp(context->mount[i].name, type) == 0) {
+ if (context->cg_namespace[i]) {
+ sprintf(path, "%s/%s/", context->mount[i].path,
+ context->cg_namespace[i]);
} else {
- sprintf(path, "%s/", cg_mount_table[i].path);
+ sprintf(path, "%s/", context->mount[i].path);
}
if (name) {
@@ -915,15 +923,6 @@ static char *cg_build_path_locked(const
return NULL;
}
-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);
- pthread_rwlock_unlock(&cg_mount_table_lock);
-
- return path;
-}
-
static int __cgroup_attach_task_pid(char *path, pid_t tid)
{
int ret = 0;
Index: libcg/src/deprecated-api.c
===================================================================
--- libcg.orig/src/deprecated-api.c
+++ libcg/src/deprecated-api.c
@@ -64,3 +64,17 @@ out:
return ret;
}
+/* Call with cg_mount_table_lock taken */
+char *cg_build_path_locked(char *name, char *path, char *type)
+{
+ return cg_build_path_context(cgroup_context, name, path, 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);
+ pthread_rwlock_unlock(&cg_mount_table_lock);
+
+ return path;
+}
Index: libcg/src/libcgroup-internal.h
===================================================================
--- libcg.orig/src/libcgroup-internal.h
+++ libcg/src/libcgroup-internal.h
@@ -143,12 +143,15 @@ struct cgroup_context_s *cgroup_context;
extern __thread int last_errno;
/* Internal API */
+char *cg_build_path_locked(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);
struct cgroup *create_cgroup_from_name_value_pairs(const char *name,
struct control_value *name_value, int nv_number);
+char *cg_build_path_context(struct cgroup_context_s *context, char *name,
+ char *path, char *type);
/*
* Main mounting structures
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel