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);
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;
}
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]);
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;
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;
}
struct lxc_proc {
char *filename;
char *value;
+ struct list_head head;
};
static void free_lxc_proc(struct lxc_proc *ptr)
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 */
__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);
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))
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;
}
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;
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);
}
}
- 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);