[lxc-devel] [PATCH v3 4/6] lxc-unshare: Move functions to determine clone flags from command line options to namespace.c
Christian Seiler
christian at iwakd.de
Thu May 24 13:55:57 UTC 2012
In order to be able to reuse code in lxc-attach, the functions
lxc_namespace_2_cloneflag and lxc_fill_namespace_flags are moved from
lxc_unshare.c to namespace.c.
Signed-off-by: Christian Seiler <christian at iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano at free.fr>
Cc: Serge Hallyn <serge.hallyn at canonical.com>
---
src/lxc/lxc_unshare.c | 45 ---------------------------------------------
src/lxc/namespace.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/lxc/namespace.h | 3 +++
3 files changed, 48 insertions(+), 45 deletions(-)
diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c
index 0baccb0..fda2ed8 100644
--- a/src/lxc/lxc_unshare.c
+++ b/src/lxc/lxc_unshare.c
@@ -85,51 +85,6 @@ static uid_t lookup_user(const char *optarg)
return uid;
}
-static char *namespaces_list[] = {
- "MOUNT", "PID", "UTSNAME", "IPC",
- "USER", "NETWORK"
-};
-static int cloneflags_list[] = {
- CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWUTS, CLONE_NEWIPC,
- CLONE_NEWUSER, CLONE_NEWNET
-};
-
-static int lxc_namespace_2_cloneflag(char *namespace)
-{
- int i, len;
- len = sizeof(namespaces_list)/sizeof(namespaces_list[0]);
- for (i = 0; i < len; i++)
- if (!strcmp(namespaces_list[i], namespace))
- return cloneflags_list[i];
-
- ERROR("invalid namespace name %s", namespace);
- return -1;
-}
-
-static int lxc_fill_namespace_flags(char *flaglist, int *flags)
-{
- char *token, *saveptr = NULL;
- int aflag;
-
- if (!flaglist) {
- ERROR("need at least one namespace to unshare");
- return -1;
- }
-
- token = strtok_r(flaglist, "|", &saveptr);
- while (token) {
-
- aflag = lxc_namespace_2_cloneflag(token);
- if (aflag < 0)
- return -1;
-
- *flags |= aflag;
-
- token = strtok_r(NULL, "|", &saveptr);
- }
- return 0;
-}
-
struct start_arg {
char ***args;
diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c
index 3e6fc3a..3fa027b 100644
--- a/src/lxc/namespace.c
+++ b/src/lxc/namespace.c
@@ -69,3 +69,48 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
return ret;
}
+
+static char *namespaces_list[] = {
+ "MOUNT", "PID", "UTSNAME", "IPC",
+ "USER", "NETWORK"
+};
+static int cloneflags_list[] = {
+ CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWUTS, CLONE_NEWIPC,
+ CLONE_NEWUSER, CLONE_NEWNET
+};
+
+int lxc_namespace_2_cloneflag(char *namespace)
+{
+ int i, len;
+ len = sizeof(namespaces_list)/sizeof(namespaces_list[0]);
+ for (i = 0; i < len; i++)
+ if (!strcmp(namespaces_list[i], namespace))
+ return cloneflags_list[i];
+
+ ERROR("invalid namespace name %s", namespace);
+ return -1;
+}
+
+int lxc_fill_namespace_flags(char *flaglist, int *flags)
+{
+ char *token, *saveptr = NULL;
+ int aflag;
+
+ if (!flaglist) {
+ ERROR("need at least one namespace to unshare");
+ return -1;
+ }
+
+ token = strtok_r(flaglist, "|", &saveptr);
+ while (token) {
+
+ aflag = lxc_namespace_2_cloneflag(token);
+ if (aflag < 0)
+ return -1;
+
+ *flags |= aflag;
+
+ token = strtok_r(NULL, "|", &saveptr);
+ }
+ return 0;
+}
diff --git a/src/lxc/namespace.h b/src/lxc/namespace.h
index 5442dd3..04e81bb 100644
--- a/src/lxc/namespace.h
+++ b/src/lxc/namespace.h
@@ -50,4 +50,7 @@
extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags);
+extern int lxc_namespace_2_cloneflag(char *namespace);
+extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
+
#endif
--
1.7.2.5
More information about the lxc-devel
mailing list