]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: port procs to new list type
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 25 Aug 2021 16:55:10 +0000 (18:55 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 26 Aug 2021 07:47:39 +0000 (09:47 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/start.c

index b1289e0ebab216b6d6818b88db75a4753ef1c908..39600196323eb85eca28e89cdf72f5f0b0038a4f 100644 (file)
@@ -1659,13 +1659,9 @@ int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
                goto on_error;
 
        /* Setup /proc limits */
-       if (!lxc_list_empty(&conf->procs)) {
-               ret = setup_proc_filesystem(&conf->procs, pid);
-               if (ret < 0)
-                       goto on_error;
-
-               TRACE("Setup /proc/%d settings", pid);
-       }
+       ret = setup_proc_filesystem(conf, pid);
+       if (ret < 0)
+               goto on_error;
 
        /* Setup resource limits */
        ret = setup_resource_limits(conf, pid);
index f4bb53c9fa7f9f93ccbbd38651d727f7ea0e2344..d048874ef60828b76e8d3a899f6b7e969a025dfb 100644 (file)
@@ -3305,30 +3305,33 @@ int setup_sysctl_parameters(struct lxc_conf *conf)
        return 0;
 }
 
-int setup_proc_filesystem(struct lxc_list *procs, pid_t pid)
+int setup_proc_filesystem(struct lxc_conf *conf, pid_t pid)
 {
        __do_free char *tmp = NULL;
-       struct lxc_list *it;
-       struct lxc_proc *elem;
        int ret = 0;
        char filename[PATH_MAX] = {0};
+       struct lxc_proc *proc;
+
+       if (!list_empty(&conf->procs))
+               return 0;
 
-       lxc_list_for_each (it, procs) {
-               elem = it->elem;
-               tmp = lxc_string_replace(".", "/", elem->filename);
+       list_for_each_entry(proc, &conf->procs, head) {
+               tmp = lxc_string_replace(".", "/", proc->filename);
                if (!tmp)
-                       return log_error(-1, "Failed to replace key %s", elem->filename);
+                       return log_error(-1, "Failed to replace key %s", proc->filename);
 
                ret = strnprintf(filename, sizeof(filename), "/proc/%d/%s", pid, tmp);
                if (ret < 0)
                        return log_error(-1, "Error setting up proc filesystem path");
 
-               ret = lxc_write_to_file(filename, elem->value,
-                                       strlen(elem->value), false, 0666);
+               ret = lxc_write_to_file(filename, proc->value,
+                                       strlen(proc->value), false, 0666);
                if (ret < 0)
-                       return log_error_errno(-1, errno, "Failed to setup proc filesystem %s to %s", elem->filename, elem->value);
+                       return log_error_errno(-1, errno, "Failed to setup proc filesystem %s to %s",
+                                              proc->filename, proc->value);
        }
 
+       TRACE("Setup /proc/%d settings", pid);
        return 0;
 }
 
@@ -3392,7 +3395,7 @@ struct lxc_conf *lxc_conf_init(void)
        lxc_list_init(&new->environment);
        INIT_LIST_HEAD(&new->limits);
        INIT_LIST_HEAD(&new->sysctls);
-       lxc_list_init(&new->procs);
+       INIT_LIST_HEAD(&new->procs);
        new->hooks_version = 0;
        for (i = 0; i < NUM_LXC_HOOKS; i++)
                lxc_list_init(&new->hooks[i]);
@@ -4647,9 +4650,9 @@ int lxc_clear_sysctls(struct lxc_conf *c, const char *key)
 
 int lxc_clear_procs(struct lxc_conf *c, const char *key)
 {
-       struct lxc_list *it, *next;
        const char *k = NULL;
        bool all = false;
+       struct lxc_proc *proc, *nproc;
 
        if (strequal(key, "lxc.proc"))
                all = true;
@@ -4658,21 +4661,18 @@ int lxc_clear_procs(struct lxc_conf *c, const char *key)
        else
                return -1;
 
-       lxc_list_for_each_safe(it, &c->procs, next) {
-               struct lxc_proc *proc = it->elem;
-
+       list_for_each_entry_safe(proc, nproc, &c->procs, head) {
                if (!all && !strequal(proc->filename, k))
                        continue;
 
-               lxc_list_del(it);
+               list_del(&proc->head);
                free(proc->filename);
                free(proc->value);
                free(proc);
-               free(it);
        }
 
        if (all)
-               lxc_list_init(&c->procs);
+               INIT_LIST_HEAD(&c->procs);
 
        return 0;
 }
index 59cbce6026fe8785fabe194e01aa43ea6d912f60..00b4a58499d50cafdbb410ad4d57c8b13d58d501 100644 (file)
@@ -153,6 +153,7 @@ define_cleanup_function(struct lxc_sysctl *, free_lxc_sysctl);
 struct lxc_proc {
        char *filename;
        char *value;
+       struct list_head head;
 };
 
 static void free_lxc_proc(struct lxc_proc *ptr)
@@ -496,7 +497,7 @@ struct lxc_conf {
        struct list_head sysctls;
 
        /* procs */
-       struct lxc_list procs;
+       struct list_head procs;
 
        struct shmount {
                /* Absolute path to the shared mount point on the host */
@@ -575,7 +576,7 @@ static inline bool lxc_wants_cap(int cap, struct lxc_conf *conf)
 
 __hidden extern int setup_sysctl_parameters(struct lxc_conf *conf);
 __hidden extern int lxc_clear_sysctls(struct lxc_conf *c, const char *key);
-__hidden extern int setup_proc_filesystem(struct lxc_list *procs, pid_t pid);
+__hidden extern int setup_proc_filesystem(struct lxc_conf *conf, pid_t pid);
 __hidden extern int lxc_clear_procs(struct lxc_conf *c, const char *key);
 __hidden extern int lxc_clear_apparmor_raw(struct lxc_conf *c);
 __hidden extern int lxc_clear_namespace(struct lxc_conf *c);
index 4d3437d6d2100cb6119ce294d4e197f8c43d9c98..97b822b1abe271d589e45095a3d1532c142e7894 100644 (file)
@@ -2183,8 +2183,7 @@ static int set_config_sysctl(const char *key, const char *value,
 static int set_config_proc(const char *key, const char *value,
                            struct lxc_conf *lxc_conf, void *data)
 {
-       __do_free struct lxc_list *proclist = NULL;
-       call_cleaner(free_lxc_proc) struct lxc_proc *procelem = NULL;
+       call_cleaner(free_lxc_proc) struct lxc_proc *new_proc = NULL;
        const char *subkey;
 
        if (lxc_config_value_empty(value))
@@ -2197,24 +2196,20 @@ static int set_config_proc(const char *key, const char *value,
        if (*subkey == '\0')
                return ret_errno(EINVAL);
 
-       proclist = lxc_list_new();
-       if (!proclist)
+       new_proc = zalloc(sizeof(*new_proc));
+       if (!new_proc)
                return ret_errno(ENOMEM);
 
-       procelem = zalloc(sizeof(*procelem));
-       if (!procelem)
+       new_proc->filename = strdup(subkey);
+       if (!new_proc->filename)
                return ret_errno(ENOMEM);
 
-       procelem->filename = strdup(subkey);
-       if (!procelem->filename)
+       new_proc->value = strdup(value);
+       if (!new_proc->value)
                return ret_errno(ENOMEM);
 
-       procelem->value = strdup(value);
-       if (!procelem->value)
-               return ret_errno(ENOMEM);
-
-       proclist->elem = move_ptr(procelem);
-       lxc_list_add_tail(&lxc_conf->procs, move_ptr(proclist));
+       list_add_tail(&new_proc->head, &lxc_conf->procs);
+       move_ptr(new_proc);
 
        return 0;
 }
@@ -4632,10 +4627,10 @@ static int get_config_sysctl(const char *key, char *retv, int inlen,
 static int get_config_proc(const char *key, char *retv, int inlen,
                           struct lxc_conf *c, void *data)
 {
-       struct lxc_list *it;
-       int len;
        int fulllen = 0;
        bool get_all = false;
+       int len;
+       struct lxc_proc *proc;
 
        if (!retv)
                inlen = 0;
@@ -4649,9 +4644,7 @@ static int get_config_proc(const char *key, char *retv, int inlen,
        else
                return ret_errno(EINVAL);
 
-       lxc_list_for_each(it, &c->procs) {
-               struct lxc_proc *proc = it->elem;
-
+       list_for_each_entry(proc, &c->procs, head) {
                if (get_all) {
                        strprint(retv, inlen, "lxc.proc.%s = %s\n",
                                 proc->filename, proc->value);
index 1d4d229081a63ebabc782e2a39b7cd531b458f26..4f09e4e5c07ff784759dac5fa9389868c8fc270e 100644 (file)
@@ -1816,10 +1816,10 @@ static int lxc_spawn(struct lxc_handler *handler)
                }
        }
 
-       if (!lxc_list_empty(&conf->procs)) {
-               ret = setup_proc_filesystem(&conf->procs, handler->pid);
-               if (ret < 0)
-                       goto out_delete_net;
+       ret = setup_proc_filesystem(conf, handler->pid);
+       if (ret < 0) {
+               ERROR("Failed to setup procfs limits");
+               goto out_delete_net;
        }
 
        ret = setup_resource_limits(conf, handler->pid);