aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Seiler <christian@iwakd.de>2012-02-23 09:57:13 +0100
committerDaniel Lezcano <daniel.lezcano@free.fr>2012-02-23 09:57:13 +0100
commit3ea24eb8e68ba18e215aec0f10d96f75b23c340b (patch)
tree8f3ee2bd30b9a0f6654bd145c54774402fcae2de
parentAdd missing double-include #ifndef/#define/#endif to confile.h (diff)
downloadlxc-3ea24eb8e68ba18e215aec0f10d96f75b23c340b.tar.gz
lxc-3ea24eb8e68ba18e215aec0f10d96f75b23c340b.tar.bz2
lxc-3ea24eb8e68ba18e215aec0f10d96f75b23c340b.zip
Enable get_cgroup_mount to search for mount points satisfying multiple subsystems at once
lxc-attach functionality reads /proc/init_pid/cgroup to determine the cgroup of the container for a given subsystem. However, since subsystems may be mounted together, we want to be on the safe side and be sure that we really find the correct mount point, so we allow get_cgroup_mount to check for *all* the subsystems; the subsystem parameter may now be a comma-separated list. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
-rw-r--r--src/lxc/cgroup.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
index 6ae67bd..2e04c79 100644
--- a/src/lxc/cgroup.c
+++ b/src/lxc/cgroup.c
@@ -52,6 +52,35 @@ enum {
CGROUP_CLONE_CHILDREN,
};
+static char *hasmntopt_multiple(struct mntent *mntent, const char *options)
+{
+ const char *ptr = options;
+ const char *ptr2 = strchr(options, ',');
+ char *result;
+
+ while (ptr2 != NULL) {
+ char *option = strndup(ptr, ptr2 - ptr);
+ if (!option) {
+ SYSERROR("Temporary memory allocation error");
+ return NULL;
+ }
+
+ result = hasmntopt(mntent, option);
+ free(option);
+
+ if (!result) {
+ return NULL;
+ }
+
+ ptr = ptr2 + 1;
+ ptr2 = strchr(ptr, ',');
+ }
+
+ /* for multiple mount options, the return value is basically NULL
+ * or non-NULL, so this should suffice for our purposes */
+ return hasmntopt(mntent, ptr);
+}
+
static int get_cgroup_mount(const char *subsystem, char *mnt)
{
struct mntent *mntent;
@@ -67,7 +96,7 @@ static int get_cgroup_mount(const char *subsystem, char *mnt)
if (strcmp(mntent->mnt_type, "cgroup"))
continue;
- if (!subsystem || hasmntopt(mntent, subsystem)) {
+ if (!subsystem || hasmntopt_multiple(mntent, subsystem)) {
strcpy(mnt, mntent->mnt_dir);
fclose(file);
DEBUG("using cgroup mounted at '%s'", mnt);