[lxc-devel] [lxc/master] Added 'mkdir -p' functionality in create_or_remove_cgroup
rjmccabe3701 on Github
lxc-bot at linuxcontainers.org
Wed Feb 15 20:37:03 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 356 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170215/3d0be619/attachment.bin>
-------------- next part --------------
From 948aa1165b5a527c04207aec1c7cf781cb86ddf2 Mon Sep 17 00:00:00 2001
From: "McCabe, Robert J" <Robert.McCabe at rockwellcollins.com>
Date: Wed, 15 Feb 2017 14:36:03 -0600
Subject: [PATCH] Added 'mkdir -p' functionality in create_or_remove_cgroup
This allows us to run LXC containers from within docker
---
src/lxc/cgroups/cgfs.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/lxc/cgroups/cgfs.c b/src/lxc/cgroups/cgfs.c
index 8499200..ebc47d2 100644
--- a/src/lxc/cgroups/cgfs.c
+++ b/src/lxc/cgroups/cgfs.c
@@ -1859,6 +1859,25 @@ static bool is_valid_cgroup(const char *name)
return strcmp(name, ".") != 0 && strcmp(name, "..") != 0;
}
+static int _mkdir(const char *dir, int perm) {
+ char tmp[256];
+ char *p = NULL;
+ size_t len;
+
+ snprintf(tmp, sizeof(tmp),"%s",dir);
+ len = strlen(tmp);
+ if(tmp[len - 1] == '/')
+ tmp[len - 1] = 0;
+ for(p = tmp + 1; *p; p++)
+ if(*p == '/') {
+ *p = 0;
+ mkdir(tmp, perm);
+ *p = '/';
+ }
+ return mkdir(tmp, perm);
+}
+
+
static int create_or_remove_cgroup(bool do_remove,
struct cgroup_mount_point *mp, const char *path, int recurse,
struct lxc_conf *conf)
@@ -1880,7 +1899,7 @@ static int create_or_remove_cgroup(bool do_remove,
} else
r = rmdir(buf);
} else
- r = mkdir(buf, 0777);
+ r = _mkdir(buf, 0777);
saved_errno = errno;
free(buf);
errno = saved_errno;
More information about the lxc-devel
mailing list