"proc dev/.lxc/proc proc create=dir,optional 0 0\n"
"sys dev/.lxc/sys sysfs create=dir,optional 0 0\n";
-FILE *make_anonymous_mount_file(struct lxc_list *mount,
+FILE *make_anonymous_mount_file(const struct list_head *mount_entries,
bool include_nesting_helpers)
{
__do_close int fd = -EBADF;
FILE *f;
int ret;
- char *mount_entry;
- struct lxc_list *iterator;
+ struct string_entry *entry;
fd = memfd_create(".lxc_mount_file", MFD_CLOEXEC);
if (fd < 0) {
TRACE("Created temporary mount file");
}
- lxc_list_for_each (iterator, mount) {
+ list_for_each_entry(entry, mount_entries, head) {
size_t len;
- mount_entry = iterator->elem;
- len = strlen(mount_entry);
+ len = strlen(entry->val);
- ret = lxc_write_nointr(fd, mount_entry, len);
+ ret = lxc_write_nointr(fd, entry->val, len);
if (ret != len)
return NULL;
}
static int setup_mount_entries(const struct lxc_conf *conf,
- struct lxc_rootfs *rootfs, struct lxc_list *mount,
+ struct lxc_rootfs *rootfs,
const char *lxc_name, const char *lxc_path)
{
__do_fclose FILE *f = NULL;
- f = make_anonymous_mount_file(mount, conf->lsm_aa_allow_nesting);
+ f = make_anonymous_mount_file(&conf->mount_entries, conf->lsm_aa_allow_nesting);
if (!f)
return -1;
int fret = -1;
struct lxc_conf *conf = handler->conf;
const char *fstab = conf->fstab;
- struct lxc_list *mount = &conf->mount_list;
int ret;
- f_entries = make_anonymous_mount_file(mount, conf->lsm_aa_allow_nesting);
+ f_entries = make_anonymous_mount_file(&conf->mount_entries,
+ conf->lsm_aa_allow_nesting);
if (!f_entries) {
SYSERROR("Failed to create anonymous mount file");
goto out;
/* Block ("allowlist") all devices by default. */
new->bpf_devices.list_type = LXC_BPF_DEVICE_CGROUP_ALLOWLIST;
INIT_LIST_HEAD(&(new->bpf_devices).devices);
- lxc_list_init(&new->mount_list);
+ INIT_LIST_HEAD(&new->mount_entries);
INIT_LIST_HEAD(&new->caps.list);
INIT_LIST_HEAD(&new->id_map);
new->root_nsuid_map = NULL;
if (ret < 0)
return log_error(-1, "Failed to setup mounts");
- if (!lxc_list_empty(&lxc_conf->mount_list)) {
- ret = setup_mount_entries(lxc_conf, &lxc_conf->rootfs,
- &lxc_conf->mount_list, name, lxcpath);
+ if (!list_empty(&lxc_conf->mount_entries)) {
+ ret = setup_mount_entries(lxc_conf, &lxc_conf->rootfs, name, lxcpath);
if (ret < 0)
return log_error(-1, "Failed to setup mount entries");
}
int lxc_clear_mount_entries(struct lxc_conf *c)
{
- struct lxc_list *it, *next;
+ struct string_entry *entry, *nentry;
- lxc_list_for_each_safe (it, &c->mount_list, next) {
- lxc_list_del(it);
- free(it->elem);
- free(it);
+ list_for_each_entry_safe(entry, nentry, &c->mount_entries, head) {
+ list_del(&entry->head);
+ free(entry->val);
+ free(entry);
}
- lxc_list_init(&c->mount_list);
+ INIT_LIST_HEAD(&c->mount_entries);
return 0;
}
struct list_head list;
};
+struct string_entry {
+ char *val;
+ struct list_head head;
+};
+
struct lxc_conf {
/* Pointer to the name of the container. Do not free! */
const char *name;
struct {
char *fstab;
int auto_mounts;
- struct lxc_list mount_list;
+ struct list_head mount_entries;
};
struct caps caps;
__hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char *mntopts);
__hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
__hidden extern void suggest_default_idmap(void);
-__hidden extern FILE *make_anonymous_mount_file(struct lxc_list *mount, bool include_nesting_helpers);
+__hidden extern FILE *make_anonymous_mount_file(const struct list_head *mount,
+ bool include_nesting_helpers);
__hidden extern int run_script(const char *name, const char *section, const char *script, ...);
__hidden extern int run_script_argv(const char *name, unsigned int hook_version, const char *section,
const char *script, const char *hookname, char **argsin);
struct lxc_conf *lxc_conf, void *data)
{
__do_free char *mntelem = NULL;
- __do_free struct lxc_list *mntlist = NULL;
+ __do_free struct string_entry *entry = NULL;
if (lxc_config_value_empty(value))
return lxc_clear_mount_entries(lxc_conf);
- mntlist = lxc_list_new();
- if (!mntlist)
+ entry = zalloc(sizeof(struct string_entry));
+ if (!entry)
return ret_errno(ENOMEM);
mntelem = strdup(value);
if (!mntelem)
return ret_errno(ENOMEM);
- mntlist->elem = move_ptr(mntelem);
- lxc_list_add_tail(&lxc_conf->mount_list, move_ptr(mntlist));
+ entry->val = move_ptr(mntelem);
+ list_add_tail(&entry->head, &lxc_conf->mount_entries);
+ move_ptr(entry);
return 0;
}
struct lxc_conf *c, void *data)
{
int len, fulllen = 0;
- struct lxc_list *it;
+ struct string_entry *entry;
if (!retv)
inlen = 0;
else
memset(retv, 0, inlen);
- lxc_list_for_each(it, &c->mount_list) {
- strprint(retv, inlen, "%s\n", (char *)it->elem);
+ list_for_each_entry(entry, &c->mount_entries, head) {
+ strprint(retv, inlen, "%s\n", entry->val);
}
return fulllen;
if (opts->user->action_script)
static_args += 2;
- static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list);
+ static_args += 2 * list_len(&opts->c->lxc_conf->mount_entries);
ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action);
if (ret < 0)
DECLARE_ARG(opts->user->action_script);
}
- f_mnt = make_anonymous_mount_file(&opts->c->lxc_conf->mount_list,
+ f_mnt = make_anonymous_mount_file(&opts->c->lxc_conf->mount_entries,
opts->c->lxc_conf->lsm_aa_allow_nesting);
if (!f_mnt)
return log_error_errno(-ENOENT, ENOENT, "Failed to create anonymous mount file");
/* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* with overlay lxc.mount.entry entries we need to update absolute paths for
* upper- and workdir. This update is done in two locations:
- * lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
+ * lxc_conf->unexpanded_config and lxc_conf->mount_entries. Both updates are done
* independent of each other since lxc_conf->mountlist may contain more mount
* entries (e.g. from other included files) than lxc_conf->unexpanded_config.
*/
char new_upper[PATH_MAX], new_work[PATH_MAX], old_upper[PATH_MAX],
old_work[PATH_MAX];
size_t i;
- struct lxc_list *iterator;
+ struct string_entry *entry;
char *cleanpath = NULL;
int fret = -1;
int ret = 0;
/*
* We have to update lxc_conf->unexpanded_config separately from
- * lxc_conf->mount_list.
+ * lxc_conf->mount_entries.
*/
for (i = 0; i < sizeof(ovl_dirs) / sizeof(ovl_dirs[0]); i++) {
if (!clone_update_unexp_ovl_paths(lxc_conf, lxc_path, newpath,
if (ret < 0 || ret >= PATH_MAX)
goto err;
- lxc_list_for_each(iterator, &lxc_conf->mount_list) {
+ list_for_each_entry(entry, &lxc_conf->mount_entries, head) {
char *mnt_entry = NULL, *new_mnt_entry = NULL, *tmp = NULL,
*tmp_mnt_entry = NULL;
- mnt_entry = iterator->elem;
+ mnt_entry = entry->val;
if (strstr(mnt_entry, "overlay"))
tmp = "upperdir";
if (ret < 0 || ret >= PATH_MAX)
goto err;
- if (strstr(mnt_entry, old_upper)) {
- tmp_mnt_entry =
- lxc_string_replace(old_upper, new_upper, mnt_entry);
- }
+ if (strstr(mnt_entry, old_upper))
+ tmp_mnt_entry = lxc_string_replace(old_upper, new_upper, mnt_entry);
if (strstr(mnt_entry, old_work)) {
if (tmp_mnt_entry)
- new_mnt_entry = lxc_string_replace(
- old_work, new_work, tmp_mnt_entry);
+ new_mnt_entry = lxc_string_replace(old_work,
+ new_work,
+ tmp_mnt_entry);
else
- new_mnt_entry = lxc_string_replace(
- old_work, new_work, mnt_entry);
+ new_mnt_entry = lxc_string_replace(old_work,
+ new_work,
+ mnt_entry);
}
if (new_mnt_entry) {
- free(iterator->elem);
- iterator->elem = strdup(new_mnt_entry);
+ free(entry->val);
+ entry->val = strdup(new_mnt_entry);
} else if (tmp_mnt_entry) {
- free(iterator->elem);
- iterator->elem = strdup(tmp_mnt_entry);
+ free(entry->val);
+ entry->val = strdup(tmp_mnt_entry);
}
free(new_mnt_entry);
/* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* with overlay lxc.mount.entry entries we need to update absolute paths for
* upper- and workdir. This update is done in two locations:
- * lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
- * independent of each other since lxc_conf->mountlist may container more mount
- * entries (e.g. from other included files) than lxc_conf->unexpanded_config .
+ * lxc_conf->unexpanded_config and lxc_conf->mount_entries. Both updates are
+ * done independent of each other since lxc_conf->mountlist may container more
+ * mount entries (e.g. from other included files) than
+ * lxc_conf->unexpanded_config .
*/
__hidden extern int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
const char *lxc_name, const char *newpath,