]> git.proxmox.com Git - mirror_lxc.git/commitdiff
namespace: add api to convert namespaces to standard identifiers
author2xsec <dh48.jeong@samsung.com>
Fri, 6 Jul 2018 16:10:10 +0000 (01:10 +0900)
committer2xsec <dh48.jeong@samsung.com>
Fri, 6 Jul 2018 16:10:10 +0000 (01:10 +0900)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/namespace.c
src/lxc/namespace.h

index 2459c9d2ec7bed6bbe8491a2c40811e29a10d918..b6e3938b1debe45fa15205d3f0dde9c7becf9dd3 100644 (file)
@@ -193,6 +193,40 @@ int lxc_namespace_2_ns_idx(const char *namespace)
        return -EINVAL;
 }
 
+extern int lxc_namespace_2_std_identifiers(char *namespaces)
+{
+       char **it;
+       char *del;
+
+       /* The identifiers for namespaces used with lxc-attach and lxc-unshare
+        * as given on the manpage do not align with the standard identifiers.
+        * This affects network, mount, and uts namespaces. The standard identifiers
+        * are: "mnt", "uts", and "net" whereas lxc-attach and lxc-unshare uses
+        * "MOUNT", "UTSNAME", and "NETWORK". So let's use some cheap memmove()s
+        * to replace them by their standard identifiers.
+        * Let's illustrate this with an example:
+        * Assume the string:
+        *
+        *      "IPC|MOUNT|PID"
+        *
+        * then we memmove()
+        *
+        *      dest: del + 1 == OUNT|PID
+        *      src:  del + 3 == NT|PID
+        */
+       if (!namespaces)
+               return -1;
+
+       while ((del = strstr(namespaces, "MOUNT")))
+               memmove(del + 1, del + 3, strlen(del) - 2);
+
+       for (it = (char *[]){"NETWORK", "UTSNAME", NULL}; it && *it; it++)
+               while ((del = strstr(namespaces, *it)))
+                       memmove(del + 3, del + 7, strlen(del) - 6);
+
+       return 0;
+}
+
 int lxc_fill_namespace_flags(char *flaglist, int *flags)
 {
        char *token, *saveptr = NULL;
index 4bfe9c4f5a047ea2660cd86c46cac541ef658f03..1341af0e62ab0b99dd97f5e476f51243a80bef67 100644 (file)
@@ -181,6 +181,7 @@ extern pid_t lxc_raw_clone_cb(int (*fn)(void *), void *args,
 
 extern int lxc_namespace_2_cloneflag(const char *namespace);
 extern int lxc_namespace_2_ns_idx(const char *namespace);
+extern int lxc_namespace_2_std_identifiers(char *namespaces);
 extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
 
 /**