#define _GNU_SOURCE
#include "config.h"
+#include "confile.h"
#include <arpa/inet.h>
#include <dirent.h>
#endif
}
+static int add_shmount_to_list(struct lxc_conf *conf) {
+ char new_mount[MAXPATHLEN];
+ size_t len_mount;
+ /* Offset for the leading '/' since the path_cont
+ * is absolute inside the container */
+ int ret = -1, offset = 1;
+
+ /* +1 for the separating whitespace */
+ len_mount = strlen(conf->lxc_shmount.path_host) + 1
+ + strlen(conf->lxc_shmount.path_cont) - offset
+ + sizeof(" none bind,create=dir 0 0") - 1;
+
+ ret = snprintf(new_mount, len_mount + 1, "%s %s none bind,create=dir 0 0",
+ conf->lxc_shmount.path_host, conf->lxc_shmount.path_cont + offset);
+ if (ret < 0 || (size_t)ret >= len_mount + 1)
+ return -1;
+
+ ret = add_elem_to_mount_list(new_mount, conf);
+ if (ret < 0)
+ ERROR("Failed to add new mount \"%s\" to the config", new_mount);
+
+ return ret;
+}
+
static int lxc_mount_auto_mounts(struct lxc_conf *conf, int flags, struct lxc_handler *handler)
{
int i, r;
}
}
+ if (flags & LXC_AUTO_SHMOUNTS_MASK) {
+ int ret = add_shmount_to_list(conf);
+ if (ret < 0) {
+ ERROR("Failed to add shmount entry to container config");
+ return ret;
+ }
+ }
+
return 0;
}
return -1;
for (autoptr = autos;; autoptr = NULL) {
+ bool is_shmounts = false;
+
token = strtok_r(autoptr, " \t", &sptr);
if (!token) {
ret = 0;
for (i = 0; allowed_auto_mounts[i].token; i++) {
if (!strcmp(allowed_auto_mounts[i].token, token))
break;
+
+ if (strcmp("shmounts:", allowed_auto_mounts[i].token) == 0
+ && strncmp("shmounts:", token, sizeof("shmounts:") - 1) == 0) {
+ is_shmounts = true;
+ break;
+ }
}
if (!allowed_auto_mounts[i].token) {
lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
+ if (is_shmounts) {
+ lxc_conf->lxc_shmount.path_host = strdup(token + (sizeof("shmounts:") - 1));
+ if (strcmp(lxc_conf->lxc_shmount.path_host, "") == 0) {
+ ERROR("Invalid shmounts path: empty");
+ break;
+ }
+ lxc_conf->lxc_shmount.path_cont = strdup("/dev/.lxc-mounts");
+ }
}
free(autos);
return 0;
}
+int add_elem_to_mount_list(const char *value, struct lxc_conf *lxc_conf) {
+ return set_config_mount(NULL, value, lxc_conf, NULL);
+}
+
static int set_config_cap_keep(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
extern bool network_new_hwaddrs(struct lxc_conf *conf);
+extern int add_elem_to_mount_list(const char *value, struct lxc_conf *lxc_conf);
+
#endif /* __LXC_CONFILE_H */