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.
---
 src/lxc/confile.c |   52 +++++++++++++++++++++++++++++-----------------------
 src/lxc/confile.h |    3 +++
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 550102c..1adce91 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -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;
+}
diff --git a/src/lxc/confile.h b/src/lxc/confile.h
index f415e55..d2faa75 100644
--- a/src/lxc/confile.h
+++ b/src/lxc/confile.h
@@ -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
-- 
1.7.2.5


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to