From: Dhaval Giani Date: Fri, 26 Jun 2009 17:36:18 +0000 (+0530) Subject: libcgroup: Introduce an API to get the mount point of a specific subsystem X-Git-Tag: v0.34~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=305fdb705e4eca50f3dc18d7cc685b547ce0ee98;p=thirdparty%2Flibcgroup.git libcgroup: Introduce an API to get the mount point of a specific subsystem Introduce an API which will query the mount table and return the mount point of a specific subsystem. This is needed in the case when the user knows which subsystem he wants the details of, which would make the use of the get_controller* APIs cumbersome. Signed-off-by: Dhaval Giani --- diff --git a/include/libcgroup.h b/include/libcgroup.h index ce0d8a5b..9bc74d64 100644 --- a/include/libcgroup.h +++ b/include/libcgroup.h @@ -324,6 +324,15 @@ int cgroup_get_controller_begin(void **handle, struct cgroup_mount_point *info); */ int cgroup_get_controller_next(void **handle, struct cgroup_mount_point *info); int cgroup_get_controller_end(void **handle); + +/* + * Reads the mount to table to give the mount point of a controller + * @controller: Name of the controller + * @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); + /* The wrappers for filling libcg structures */ struct cgroup *cgroup_new_cgroup(const char *name); diff --git a/src/api.c b/src/api.c index 76ba833f..03d7520b 100644 --- a/src/api.c +++ b/src/api.c @@ -2668,3 +2668,31 @@ int cgroup_get_uid_gid_from_procfs(pid_t pid, uid_t *euid, gid_t *egid) return 0; } +int cgroup_get_subsys_mount_point(char *controller, char **mount_point) +{ + int i; + int ret = ECGROUPNOTEXIST; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + + 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, controller, FILENAME_MAX)) + continue; + + *mount_point = strdup(cg_mount_table[i].path); + + if (!*mount_point) { + last_errno = errno; + ret = ECGOTHER; + goto out_exit; + } + + ret = 0; + break; + } +out_exit: + pthread_rwlock_unlock(&cg_mount_table_lock); + return ret; +} diff --git a/src/libcgroup.map b/src/libcgroup.map index 5b088d4b..53598928 100644 --- a/src/libcgroup.map +++ b/src/libcgroup.map @@ -69,4 +69,5 @@ global: cgroup_unload_cgroups; cgroup_get_controller; cgroup_get_uid_gid_from_procfs; + cgroup_get_subsys_mount_point; } CGROUP_0.33; diff --git a/tests/Makefile.am b/tests/Makefile.am index e8401f22..b10f3562 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include LDADD = $(top_srcdir)/src/.libs/libcgroup.la # compile the tests, but do not install them -noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller +noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h libcg_ba_SOURCES=libcg_ba.cpp @@ -12,6 +12,7 @@ walk_test_SOURCES=walk_test.c read_stats_SOURCES=read_stats.c walk_task_SOURCES=walk_task.c get_controller_SOURCES=get_controller.c +get_mount_point_SOURCES=get_mount_point.c EXTRA_DIST = pathtest.sh runlibcgrouptest.sh