From 525f00025700ae351b9c53dfb0d5f10a70d6b083 Mon Sep 17 00:00:00 2001 From: Christian Seiler Date: Thu, 23 Feb 2012 09:57:14 +0100 Subject: Add lxc_config_parse_arch to parse architecture strings 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 --- src/lxc/confile.c | 52 +++++++++++++++++++++++++++++----------------------- src/lxc/confile.h | 3 +++ 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src') 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 #include "parse.h" +#include "confile.h" #include "utils.h" #include @@ -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 -- cgit v1.2.3-65-gdbad