[lxc-devel] [lxc/master] attach: allow attach with empty conf
brauner on Github
lxc-bot at linuxcontainers.org
Wed Nov 8 21:14:57 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171108/f74854a2/attachment.bin>
-------------- next part --------------
From c55065c2b5efb011e4123023bb7fdd421e9f0c21 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 8 Nov 2017 22:13:15 +0100
Subject: [PATCH 1/2] conf: initialize all member explicitly
and in the same order they appear in conf.h
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 86 +++++++++++++++++++++++++++++++++++++++++-----------------
src/lxc/conf.h | 3 +-
2 files changed, 63 insertions(+), 26 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 88a1cf4e2..b1434f18c 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -2427,51 +2427,87 @@ struct lxc_conf *lxc_conf_init(void)
}
memset(new, 0, sizeof(*new));
- new->loglevel = LXC_LOG_LEVEL_NOTSET;
+ new->is_execute = -1;
+ new->fstab = NULL;
+ new->tty = 0;
+ new->pts = 0;
+ new->reboot = -1;
new->personality = -1;
- new->autodev = 1;
- new->console.log_path = NULL;
- new->console.log_fd = -1;
- new->console.log_size = 0;
- new->console.path = NULL;
+ new->utsname = NULL;
+ lxc_list_init(&new->cgroup);
+ lxc_list_init(&new->id_map);
+ lxc_list_init(&new->network);
+ new->auto_mounts = -1;
+ lxc_list_init(&new->mount_list);
+ lxc_list_init(&new->caps);
+ lxc_list_init(&new->keepcaps);
+ memset(&new->tty_info, 0, sizeof(struct lxc_tty_info));
+ new->pty_names = NULL;
+ new->console.slave = -1;
+ new->console.master = -1;
new->console.peer = -1;
- new->console.peerpty.busy = -1;
new->console.peerpty.master = -1;
new->console.peerpty.slave = -1;
- new->console.master = -1;
- new->console.slave = -1;
+ new->console.peerpty.busy = -1;
new->console.name[0] = '\0';
+ new->console.descr = NULL;
+ new->console.path = NULL;
+ new->console.log_path = NULL;
+ new->console.log_fd = -1;
+ new->console.tios = NULL;
+ new->console.tty_state = NULL;
+ new->console.log_size = 0;
memset(&new->console.ringbuf, 0, sizeof(struct lxc_ringbuf));
- new->maincmd_fd = -1;
- new->nbd_idx = -1;
+ memset(&new->rootfs, 0, sizeof(struct lxc_rootfs));
new->rootfs.mount = strdup(default_rootfs_mount);
if (!new->rootfs.mount) {
ERROR("lxc_conf_init : %s", strerror(errno));
free(new);
return NULL;
}
- new->logfd = -1;
- lxc_list_init(&new->cgroup);
- lxc_list_init(&new->network);
- lxc_list_init(&new->mount_list);
- lxc_list_init(&new->caps);
- lxc_list_init(&new->keepcaps);
- lxc_list_init(&new->id_map);
- lxc_list_init(&new->includes);
- lxc_list_init(&new->aliens);
- lxc_list_init(&new->environment);
- lxc_list_init(&new->limits);
+ new->ttydir = NULL;
+ new->close_all_fds = -1;
for (i = 0; i < NUM_LXC_HOOKS; i++)
lxc_list_init(&new->hooks[i]);
- lxc_list_init(&new->groups);
new->lsm_aa_profile = NULL;
+ new->lsm_aa_allow_incomplete = 0;
new->lsm_se_context = NULL;
- new->tmp_umount_proc = 0;
-
+ new->tmp_umount_proc = -1;
+ new->seccomp = NULL;
+ memset(&new->seccomp_ctx, 0, sizeof(scmp_filter_ctx));
+ new->maincmd_fd = -1;
+ new->autodev = 1;
+ new->haltsignal = -1;
+ new->rebootsignal = -1;
+ new->stopsignal = -1;
+ new->rcfile = 0;
+ new->logfile = NULL;
+ new->loglevel = LXC_LOG_LEVEL_NOTSET;
+ new->logfd = -1;
+ new->start_auto = 0;
+ new->start_delay = 0;
+ new->start_order = -1;
+ lxc_list_init(&new->groups);
+ new->nbd_idx = -1;
+ new->monitor_unshare = 0;
+ new->rootfs_setup = 0;
+ lxc_list_init(&new->includes);
+ lxc_list_init(&new->aliens);
+ lxc_list_init(&new->environment);
+ new->unexpanded_config = NULL;
+ new->unexpanded_len = 0;
+ new->unexpanded_alloced = 0;
+ new->execute_cmd = NULL;
+ new->init_cmd = NULL;
/* if running in a new user namespace, init and COMMAND
* default to running as UID/GID 0 when using lxc-execute */
new->init_uid = 0;
new->init_gid = 0;
+ new->ephemeral = 0;
+ new->syslog = NULL;
+ new->no_new_privs = false;
+ lxc_list_init(&new->limits);
+ new->contains_legacy_key = false;
memset(&new->cgroup_meta, 0, sizeof(struct lxc_cgroup));
memset(&new->inherit_ns, 0, sizeof(char *) * LXC_NS_MAX);
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 063b58980..753156f34 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -308,7 +308,8 @@ struct lxc_conf {
/* text representation of the config file */
char *unexpanded_config;
- size_t unexpanded_len, unexpanded_alloced;
+ size_t unexpanded_len;
+ size_t unexpanded_alloced;
/* default command for lxc-execute */
char *execute_cmd;
From b8443291eb9db50ee7f7300ce14742aae05bfe68 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Wed, 8 Nov 2017 22:13:48 +0100
Subject: [PATCH 2/2] attach: allow attach with empty conf
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index cc17f308a..44ac31edd 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -848,6 +848,12 @@ int lxc_attach(const char *name, const char *lxcpath,
if (!init_ctx->container)
return -1;
+ if (!init_ctx->container->lxc_conf) {
+ init_ctx->container->lxc_conf = lxc_conf_init();
+ if (!init_ctx->container->lxc_conf)
+ return -ENOMEM;
+ }
+
if (!fetch_seccomp(init_ctx->container, options))
WARN("Failed to get seccomp policy.");
More information about the lxc-devel
mailing list