lxccontainer: clear whole indexed networks

parent 31ee747b
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "commands_utils.h" #include "commands_utils.h"
#include "confile.h" #include "confile.h"
#include "confile_legacy.h" #include "confile_legacy.h"
#include "confile_utils.h"
#include "console.h" #include "console.h"
#include "criu.h" #include "criu.h"
#include "log.h" #include "log.h"
...@@ -1839,18 +1840,30 @@ out: ...@@ -1839,18 +1840,30 @@ out:
static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key) static void do_clear_unexp_config_line(struct lxc_conf *conf, const char *key)
{ {
if (strcmp(key, "lxc.cgroup") == 0) if (!strcmp(key, "lxc.cgroup"))
clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
else if (strcmp(key, "lxc.network") == 0)
clear_unexp_config_line(conf, key, true); if (!strcmp(key, "lxc.network"))
else if (strcmp(key, "lxc.net") == 0) return clear_unexp_config_line(conf, key, true);
clear_unexp_config_line(conf, key, true);
else if (strcmp(key, "lxc.hook") == 0) if (!strcmp(key, "lxc.net"))
clear_unexp_config_line(conf, key, true); return clear_unexp_config_line(conf, key, true);
else
clear_unexp_config_line(conf, key, false); /* Clear a network with a specific index. */
if (!do_append_unexp_config_line(conf, key, "")) if (!strncmp(key, "lxc.net.", 8)) {
WARN("Error clearing configuration for %s", key); int ret;
const char *idx;
idx = key + 8;
ret = lxc_safe_uint(idx, &(unsigned int){0});
if (!ret)
return clear_unexp_config_line(conf, key, true);
}
if (!strcmp(key, "lxc.hook"))
return clear_unexp_config_line(conf, key, true);
return clear_unexp_config_line(conf, key, false);
} }
static bool do_lxcapi_clear_config_item(struct lxc_container *c, static bool do_lxcapi_clear_config_item(struct lxc_container *c,
...@@ -2656,13 +2669,22 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con ...@@ -2656,13 +2669,22 @@ static bool set_config_item_locked(struct lxc_container *c, const char *key, con
if (!c->lxc_conf) if (!c->lxc_conf)
c->lxc_conf = lxc_conf_init(); c->lxc_conf = lxc_conf_init();
if (!c->lxc_conf) if (!c->lxc_conf)
return false; return false;
config = lxc_getconfig(key); config = lxc_getconfig(key);
if (!config) if (!config)
return false; return false;
if (config->set(key, v, c->lxc_conf, NULL) != 0) if (config->set(key, v, c->lxc_conf, NULL) != 0)
return false; return false;
if (lxc_config_value_empty(v)) {
do_clear_unexp_config_line(c->lxc_conf, key);
return true;
}
return do_append_unexp_config_line(c->lxc_conf, key, v); return do_append_unexp_config_line(c->lxc_conf, key, v);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment