]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: move clearing config items into one place
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 30 May 2017 02:16:34 +0000 (04:16 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 30 May 2017 16:43:03 +0000 (18:43 +0200)
Let's place lxc_get_config_item() and lxc_clear_config_item() into a single
place. This causes less confusion, less looking around and makes it clear that
both must be implemented when adding new configuration items.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index 2872589ca2a4a83ead4c500e95842f6328d9f257..25acb8bfb3de69d73815b5916a6e1e31864e503d 100644 (file)
@@ -4562,7 +4562,7 @@ static inline void lxc_clear_aliens(struct lxc_conf *conf)
        }
 }
 
-static inline void lxc_clear_includes(struct lxc_conf *conf)
+void lxc_clear_includes(struct lxc_conf *conf)
 {
        struct lxc_list *it,*next;
 
@@ -4958,87 +4958,3 @@ struct lxc_list *sort_cgroup_settings(struct lxc_list* cgroup_settings)
 
        return result;
 }
-
-int lxc_clear_simple_config_item(struct lxc_conf *c, const char *key)
-{
-       if (strcmp(key, "lxc.utsname") == 0) {
-               free(c->utsname);
-               c->utsname = NULL;
-       } else if (strcmp(key, "lxc.arch") == 0) {
-               c->personality = -1;
-       } else if (strcmp(key, "lxc.haltsignal") == 0) {
-               c->haltsignal = 0;
-       } else if (strcmp(key, "lxc.rebootsignal") == 0) {
-               c->rebootsignal = 0;
-       } else if (strcmp(key, "lxc.stopsignal") == 0) {
-               c->stopsignal = 0;
-       } else if (strcmp(key, "lxc.init_cmd") == 0) {
-               free(c->init_cmd);
-               c->init_cmd = NULL;
-       } else if (strcmp(key, "lxc.init_uid") == 0) {
-               c->init_uid = 0;
-       } else if (strcmp(key, "lxc.init_gid") == 0) {
-               c->init_gid = 0;
-       } else if (strcmp(key, "lxc.ephemeral") == 0) {
-               c->ephemeral = 0;
-       } else if (strcmp(key, "lxc.console.logfile") == 0) {
-               free(c->console.log_path);
-               c->console.log_path = NULL;
-       } else if (strcmp(key, "lxc.console") == 0) {
-               free(c->console.path);
-               c->console.path = NULL;
-       } else if (strcmp(key, "lxc.tty") == 0) {
-               c->tty = 0;
-       } else if (strcmp(key, "lxc.devttydir") == 0) {
-               free(c->ttydir);
-               c->ttydir = NULL;
-       } else if (strcmp(key, "lxc.autodev") == 0) {
-               c->autodev = 1;
-       } else if (strcmp(key, "lxc.kmsg") == 0) {
-               c->kmsg = 0;
-       } else if (strcmp(key, "lxc.mount") == 0) {
-               free(c->fstab);
-               c->fstab = NULL;
-       } else if (strcmp(key, "lxc.rootfs") == 0) {
-               free(c->rootfs.path);
-               c->rootfs.path = NULL;
-       } else if (strcmp(key, "lxc.rootfs.mount") == 0) {
-               free(c->rootfs.mount);
-               c->rootfs.mount = NULL;
-       } else if (strcmp(key, "lxc.rootfs.options") == 0) {
-               free(c->rootfs.options);
-               c->rootfs.options = NULL;
-       } else if (strcmp(key, "lxc.rootfs.backend") == 0) {
-               free(c->rootfs.bdev_type);
-               c->rootfs.bdev_type = NULL;
-       } else if (strcmp(key, "lxc.aa_profile") == 0) {
-               free(c->lsm_aa_profile);
-               c->lsm_aa_profile = NULL;
-       } else if (strcmp(key, "lxc.aa_allow_incomplete") == 0) {
-               c->lsm_aa_allow_incomplete = 0;
-       } else if (strcmp(key, "lxc.se_context") == 0) {
-               free(c->lsm_se_context);
-               c->lsm_se_context = NULL;
-       } else if (strcmp(key, "lxc.seccomp") == 0) {
-               free(c->seccomp);
-               c->seccomp = NULL;
-       } else if (strcmp(key, "lxc.loglevel") == 0) {
-               c->loglevel = LXC_LOG_PRIORITY_NOTSET;
-       } else if (strcmp(key, "lxc.logfile") == 0) {
-               free(c->logfile);
-               c->logfile = NULL;
-       } else if (strcmp(key, "lxc.monitor.unshare") == 0) {
-               c->monitor_unshare = 0;
-       } else if (strcmp(key, "lxc.pts") == 0) {
-               c->pts = 0;
-       } else if (strcmp(key, "lxc.include") == 0) {
-               lxc_clear_includes(c);
-       } else if (strcmp(key, "lxc.syslog") == 0) {
-               free(c->syslog);
-               c->syslog = NULL;
-       } else {
-               return -1;
-       }
-
-       return 0;
-}
index a0bb05b0a0a6681ad84ef717a88712145a2a6355..ff6747c0e4259cf9652fd5dfc4163ee7cac664cf 100644 (file)
@@ -453,7 +453,7 @@ extern int lxc_clear_groups(struct lxc_conf *c);
 extern int lxc_clear_environment(struct lxc_conf *c);
 extern int lxc_clear_limits(struct lxc_conf *c, const char *key);
 extern int lxc_delete_autodev(struct lxc_handler *handler);
-extern int lxc_clear_simple_config_item(struct lxc_conf *c, const char *key);
+extern void lxc_clear_includes(struct lxc_conf *conf);
 
 extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
                           const char *lxcpath);
index 222fe7b5d4f68613383ad6a5956e0791c2868d16..3ee73646418bc6c7b6cb9ac71d4165e1103137b4 100644 (file)
@@ -2905,32 +2905,153 @@ int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
 
 int lxc_clear_config_item(struct lxc_conf *c, const char *key)
 {
-       if (strcmp(key, "lxc.network") == 0)
-               return lxc_clear_config_network(c);
-       else if (strncmp(key, "lxc.network.", 12) == 0)
-               return lxc_clear_nic(c, key + 12);
-       else if (strcmp(key, "lxc.cap.drop") == 0)
-               return lxc_clear_config_caps(c);
-       else if (strcmp(key, "lxc.cap.keep") == 0)
-               return lxc_clear_config_keepcaps(c);
-       else if (strncmp(key, "lxc.cgroup", 10) == 0)
-               return lxc_clear_cgroups(c, key);
-       else if (strcmp(key, "lxc.mount.entry") == 0)
-               return lxc_clear_mount_entries(c);
-       else if (strcmp(key, "lxc.mount.auto") == 0)
-               return lxc_clear_automounts(c);
-       else if (strncmp(key, "lxc.hook", 8) == 0)
-               return lxc_clear_hooks(c, key);
-       else if (strncmp(key, "lxc.group", 9) == 0)
-               return lxc_clear_groups(c);
-       else if (strncmp(key, "lxc.environment", 15) == 0)
-               return lxc_clear_environment(c);
-       else if (strncmp(key, "lxc.id_map", 10) == 0)
-               return lxc_clear_idmaps(c);
-       else if (strncmp(key, "lxc.limit", 9) == 0)
-               return lxc_clear_limits(c, key);
-
-       return lxc_clear_simple_config_item(c, key);
+       int ret = 0;
+
+       if (strcmp(key, "lxc.network") == 0) {
+               ret = lxc_clear_config_network(c);
+
+       } else if (strncmp(key, "lxc.network.", 12) == 0) {
+               ret = lxc_clear_nic(c, key + 12);
+
+       } else if (strcmp(key,  "lxc.cap.drop") == 0) {
+               ret = lxc_clear_config_caps(c);
+
+       } else if (strcmp(key,  "lxc.cap.keep") == 0) {
+               ret = lxc_clear_config_keepcaps(c);
+
+       } else if (strncmp(key, "lxc.cgroup", 10) == 0) {
+               ret = lxc_clear_cgroups(c, key);
+
+       } else if (strcmp(key,  "lxc.mount.entry") == 0) {
+               ret = lxc_clear_mount_entries(c);
+
+       } else if (strcmp(key,  "lxc.mount.auto") == 0) {
+               ret = lxc_clear_automounts(c);
+
+       } else if (strncmp(key, "lxc.hook", 8) == 0) {
+               ret = lxc_clear_hooks(c, key);
+
+       } else if (strncmp(key, "lxc.group", 9) == 0) {
+               ret = lxc_clear_groups(c);
+
+       } else if (strncmp(key, "lxc.environment", 15) == 0) {
+               ret = lxc_clear_environment(c);
+
+       } else if (strncmp(key, "lxc.id_map", 10) == 0) {
+               ret = lxc_clear_idmaps(c);
+
+       } else if (strncmp(key, "lxc.limit", 9) == 0) {
+               ret = lxc_clear_limits(c, key);
+
+       } else if (strcmp(key, "lxc.utsname") == 0) {
+               free(c->utsname);
+               c->utsname = NULL;
+
+       } else if (strcmp(key, "lxc.arch") == 0) {
+               c->personality = -1;
+
+       } else if (strcmp(key, "lxc.haltsignal") == 0) {
+               c->haltsignal = 0;
+
+       } else if (strcmp(key, "lxc.rebootsignal") == 0) {
+               c->rebootsignal = 0;
+
+       } else if (strcmp(key, "lxc.stopsignal") == 0) {
+               c->stopsignal = 0;
+
+       } else if (strcmp(key, "lxc.init_cmd") == 0) {
+               free(c->init_cmd);
+               c->init_cmd = NULL;
+
+       } else if (strcmp(key, "lxc.init_uid") == 0) {
+               c->init_uid = 0;
+
+       } else if (strcmp(key, "lxc.init_gid") == 0) {
+               c->init_gid = 0;
+
+       } else if (strcmp(key, "lxc.ephemeral") == 0) {
+               c->ephemeral = 0;
+
+       } else if (strcmp(key, "lxc.console.logfile") == 0) {
+               free(c->console.log_path);
+               c->console.log_path = NULL;
+
+       } else if (strcmp(key, "lxc.console") == 0) {
+               free(c->console.path);
+               c->console.path = NULL;
+
+       } else if (strcmp(key, "lxc.tty") == 0) {
+               c->tty = 0;
+
+       } else if (strcmp(key, "lxc.devttydir") == 0) {
+               free(c->ttydir);
+               c->ttydir = NULL;
+
+       } else if (strcmp(key, "lxc.autodev") == 0) {
+               c->autodev = 1;
+
+       } else if (strcmp(key, "lxc.kmsg") == 0) {
+               c->kmsg = 0;
+
+       } else if (strcmp(key, "lxc.mount") == 0) {
+               free(c->fstab);
+               c->fstab = NULL;
+
+       } else if (strcmp(key, "lxc.rootfs") == 0) {
+               free(c->rootfs.path);
+               c->rootfs.path = NULL;
+
+       } else if (strcmp(key, "lxc.rootfs.mount") == 0) {
+               free(c->rootfs.mount);
+               c->rootfs.mount = NULL;
+
+       } else if (strcmp(key, "lxc.rootfs.options") == 0) {
+               free(c->rootfs.options);
+               c->rootfs.options = NULL;
+
+       } else if (strcmp(key, "lxc.rootfs.backend") == 0) {
+               free(c->rootfs.bdev_type);
+               c->rootfs.bdev_type = NULL;
+
+       } else if (strcmp(key, "lxc.aa_profile") == 0) {
+               free(c->lsm_aa_profile);
+               c->lsm_aa_profile = NULL;
+
+       } else if (strcmp(key, "lxc.aa_allow_incomplete") == 0) {
+               c->lsm_aa_allow_incomplete = 0;
+
+       } else if (strcmp(key, "lxc.se_context") == 0) {
+               free(c->lsm_se_context);
+               c->lsm_se_context = NULL;
+
+       } else if (strcmp(key, "lxc.seccomp") == 0) {
+               free(c->seccomp);
+               c->seccomp = NULL;
+
+       } else if (strcmp(key, "lxc.loglevel") == 0) {
+               c->loglevel = LXC_LOG_PRIORITY_NOTSET;
+
+       } else if (strcmp(key, "lxc.logfile") == 0) {
+               free(c->logfile);
+               c->logfile = NULL;
+
+       } else if (strcmp(key, "lxc.monitor.unshare") == 0) {
+               c->monitor_unshare = 0;
+
+       } else if (strcmp(key, "lxc.pts") == 0) {
+               c->pts = 0;
+
+       } else if (strcmp(key, "lxc.include") == 0) {
+               lxc_clear_includes(c);
+
+       } else if (strcmp(key, "lxc.syslog") == 0) {
+               free(c->syslog);
+               c->syslog = NULL;
+       } else {
+               ret = -1;
+       }
+
+       return ret;
 }
 
 /*