]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tools: lxc-attach: replace converting standard identifiers of namespaces to api
author2xsec <dh48.jeong@samsung.com>
Fri, 6 Jul 2018 16:16:41 +0000 (01:16 +0900)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 11 Jul 2018 20:15:11 +0000 (22:15 +0200)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
src/lxc/tools/lxc_attach.c

index 6729a1e1eb1aceb96546c2cc270e1536e3a4ec8c..d33d9c440bd534f5fea0e958faef4373fd448346 100644 (file)
@@ -100,8 +100,6 @@ static int add_to_simple_array(char ***array, ssize_t *capacity, char *value)
 
 static int my_parser(struct lxc_arguments *args, int c, char *arg)
 {
-       char **it;
-       char *del;
        int ret;
 
        switch (c) {
@@ -121,32 +119,13 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
        case 's':
                namespace_flags = 0;
 
-               /* The identifiers for namespaces used with lxc-attach 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
-                * 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
-                */
-               while ((del = strstr(arg, "MOUNT")))
-                       memmove(del + 1, del + 3, strlen(del) - 2);
-
-               for (it = (char *[]){"NETWORK", "UTSNAME", NULL}; it && *it; it++)
-                       while ((del = strstr(arg, *it)))
-                               memmove(del + 3, del + 7, strlen(del) - 6);
+               if (lxc_namespace_2_std_identifiers(arg) < 0)
+                       return -1;
 
                ret = lxc_fill_namespace_flags(arg, &namespace_flags);
                if (ret)
                        return -1;
+
                /* -s implies -e */
                lxc_fill_elevated_privileges(NULL, &elevated_privileges);
                break;