From: Christian Brauner Date: Wed, 31 May 2017 06:06:06 +0000 (+0200) Subject: confile: add getters for lxc.hook{.*} X-Git-Tag: lxc-2.1.0~110^2~78 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=466c2e93cc3dc489af003bc4cdb1a7e0d8e0c185;p=thirdparty%2Flxc.git confile: add getters for lxc.hook{.*} Signed-off-by: Christian Brauner --- diff --git a/src/lxc/confile.c b/src/lxc/confile.c index fef4c1642..a4257848a 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -126,7 +126,9 @@ static int get_config_pivotdir(struct lxc_container *, const char *, char *, int static int set_config_utsname(const char *, const char *, struct lxc_conf *); static int get_config_utsname(struct lxc_container *, const char *, char *, int); -static int set_config_hook(const char *, const char *, struct lxc_conf *lxc_conf); +static int set_config_hooks(const char *, const char *, struct lxc_conf *lxc_conf); +static int get_config_hooks(struct lxc_container *, const char *, char *, int); + static int set_config_network(const char *, const char *, struct lxc_conf *); static int set_config_network_type(const char *, const char *, struct lxc_conf *); static int set_config_network_flags(const char *, const char *, struct lxc_conf *); @@ -188,16 +190,16 @@ static struct lxc_config_t config[] = { { "lxc.rootfs", set_config_rootfs, get_config_rootfs, NULL}, { "lxc.pivotdir", set_config_pivotdir, get_config_pivotdir, NULL}, { "lxc.utsname", set_config_utsname, get_config_utsname, NULL}, - { "lxc.hook.pre-start", set_config_hook, NULL, NULL}, - { "lxc.hook.pre-mount", set_config_hook, NULL, NULL}, - { "lxc.hook.mount", set_config_hook, NULL, NULL}, - { "lxc.hook.autodev", set_config_hook, NULL, NULL}, - { "lxc.hook.start", set_config_hook, NULL, NULL}, - { "lxc.hook.stop", set_config_hook, NULL, NULL}, - { "lxc.hook.post-stop", set_config_hook, NULL, NULL}, - { "lxc.hook.clone", set_config_hook, NULL, NULL}, - { "lxc.hook.destroy", set_config_hook, NULL, NULL}, - { "lxc.hook", set_config_hook, NULL, NULL}, + { "lxc.hook.pre-start", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.pre-mount", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.mount", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.autodev", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.start", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.stop", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.post-stop", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.clone", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook.destroy", set_config_hooks, get_config_hooks, NULL}, + { "lxc.hook", set_config_hooks, get_config_hooks, NULL}, { "lxc.network.type", set_config_network_type, NULL, NULL}, { "lxc.network.flags", set_config_network_flags, NULL, NULL}, { "lxc.network.link", set_config_network_link, NULL, NULL}, @@ -1232,8 +1234,8 @@ static int set_config_init_gid(const char *key, const char *value, return 0; } -static int set_config_hook(const char *key, const char *value, - struct lxc_conf *lxc_conf) +static int set_config_hooks(const char *key, const char *value, + struct lxc_conf *lxc_conf) { char *copy; @@ -2676,42 +2678,6 @@ static int lxc_get_limit_entry(struct lxc_conf *c, char *retv, int inlen, return fulllen; } -static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen, - const char *key) -{ - char *subkey; - int len, fulllen = 0, found = -1; - struct lxc_list *it; - int i; - - /* "lxc.hook.mount" */ - subkey = strchr(key, '.'); - if (subkey) subkey = strchr(subkey+1, '.'); - if (!subkey) - return -1; - subkey++; - if (!*subkey) - return -1; - for (i=0; ihooks[found]) { - strprint(retv, inlen, "%s\n", (char *)it->elem); - } - return fulllen; -} - static int lxc_get_item_groups(struct lxc_conf *c, char *retv, int inlen) { int len, fulllen = 0; @@ -2916,8 +2882,6 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, return lxc_get_item_cap_drop(c, retv, inlen); else if (strcmp(key, "lxc.cap.keep") == 0) return lxc_get_item_cap_keep(c, retv, inlen); - else if (strncmp(key, "lxc.hook", 8) == 0) - return lxc_get_item_hooks(c, retv, inlen, key); else if (strcmp(key, "lxc.network") == 0) return lxc_get_item_network(c, retv, inlen); else if (strncmp(key, "lxc.network.", 12) == 0) @@ -3868,3 +3832,40 @@ static int get_config_utsname(struct lxc_container *c, const char *key, retv, inlen, c->lxc_conf->utsname ? c->lxc_conf->utsname->nodename : NULL); } + +static int get_config_hooks(struct lxc_container *c, const char *key, + char *retv, int inlen) +{ + char *subkey; + int len, fulllen = 0, found = -1; + struct lxc_list *it; + int i; + + /* "lxc.hook.mount" */ + subkey = strchr(key, '.'); + if (subkey) + subkey = strchr(subkey + 1, '.'); + if (!subkey) + return -1; + subkey++; + if (!*subkey) + return -1; + for (i = 0; i < NUM_LXC_HOOKS; i++) { + if (strcmp(lxchook_names[i], subkey) == 0) { + found = i; + break; + } + } + if (found == -1) + return -1; + + if (!retv) + inlen = 0; + else + memset(retv, 0, inlen); + + lxc_list_for_each(it, &c->lxc_conf->hooks[found]) { + strprint(retv, inlen, "%s\n", (char *)it->elem); + } + return fulllen; +}