]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add lxc_config_parse_arch to parse architecture strings
authorChristian Seiler <christian@iwakd.de>
Thu, 23 Feb 2012 08:57:14 +0000 (09:57 +0100)
committerDaniel Lezcano <daniel.lezcano@free.fr>
Thu, 23 Feb 2012 08:57:14 +0000 (09:57 +0100)
Add the function lxc_config_parse_arch that parses an architecture string
(x86, i686, x86_64, amd64) and returns the corresponding personality. This
is required for lxc-attach, which accepts architectures independently of
lxc.arch. The parsing of lxc.arch now also uses the same function to ensure
consistency.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/confile.c
src/lxc/confile.h

index 550102cf2664dce57c9ea507189f0c488113bd0f..1adce918b34d5fbae518dc2f6f6d9e8580e1d654 100644 (file)
@@ -37,6 +37,7 @@
 #include <net/if.h>
 
 #include "parse.h"
+#include "confile.h"
 #include "utils.h"
 
 #include <lxc/log.h>
@@ -584,30 +585,12 @@ static int config_network_script(const char *key, char *value,
 static int config_personality(const char *key, char *value,
                              struct lxc_conf *lxc_conf)
 {
-       struct per_name {
-               char *name;
-               int per;
-       } pername[4] = {
-               { "x86", PER_LINUX32 },
-               { "i686", PER_LINUX32 },
-               { "x86_64", PER_LINUX },
-               { "amd64", PER_LINUX },
-       };
-       size_t len = sizeof(pername) / sizeof(pername[0]);
+       signed long personality = lxc_config_parse_arch(value);
 
-       int i;
-
-       for (i = 0; i < len; i++) {
-
-               if (strcmp(pername[i].name, value))
-                   continue;
-
-               lxc_conf->personality = pername[i].per;
-
-               return 0;
-       }
-
-       WARN("unsupported personality '%s'", value);
+       if (personality >= 0)
+               lxc_conf->personality = personality;
+       else
+               WARN("unsupported personality '%s'", value);
 
        return 0;
 }
@@ -974,3 +957,26 @@ int lxc_config_define_load(struct lxc_list *defines, struct lxc_conf *conf)
 
        return ret;
 }
+
+signed long lxc_config_parse_arch(const char *arch)
+{
+       struct per_name {
+               char *name;
+               unsigned long per;
+       } pername[4] = {
+               { "x86", PER_LINUX32 },
+               { "i686", PER_LINUX32 },
+               { "x86_64", PER_LINUX },
+               { "amd64", PER_LINUX },
+       };
+       size_t len = sizeof(pername) / sizeof(pername[0]);
+
+       int i;
+
+       for (i = 0; i < len; i++) {
+               if (!strcmp(pername[i].name, arch))
+                   return pername[i].per;
+       }
+
+       return -1;
+}
index f415e550598369ca2ae4de2fafdd0a73e95372a6..d2faa750231581334081ccaa1ee9e3b34f887060 100644 (file)
@@ -34,4 +34,7 @@ extern int lxc_config_define_add(struct lxc_list *defines, char* arg);
 extern int lxc_config_define_load(struct lxc_list *defines,
                                  struct lxc_conf *conf);
 
+/* needed for lxc-attach */
+extern signed long lxc_config_parse_arch(const char *arch);
+
 #endif