diff options
author | 2012-02-23 09:57:14 +0100 | |
---|---|---|
committer | 2012-02-23 09:57:14 +0100 | |
commit | 525f00025700ae351b9c53dfb0d5f10a70d6b083 (patch) | |
tree | aada0d19b06a46b4033b1c1b19cfa0c215b5737e | |
parent | cgroup: Make cgroup_attach a public function (diff) | |
download | lxc-525f00025700ae351b9c53dfb0d5f10a70d6b083.tar.gz lxc-525f00025700ae351b9c53dfb0d5f10a70d6b083.tar.bz2 lxc-525f00025700ae351b9c53dfb0d5f10a70d6b083.zip |
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 <dlezcano@fr.ibm.com>
-rw-r--r-- | src/lxc/confile.c | 52 | ||||
-rw-r--r-- | 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 |