This makes the whole setup more flexible.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
return true;
}
-/**
- * Note that this function needs to run before the mainloop starts. Since we
- * register a handler for the console's masterfd when we create the mainloop
- * the console handler needs to see an allocated ringbuffer.
- */
-static int lxc_setup_console_ringbuf(struct lxc_console *console)
-{
- int ret;
- struct lxc_ringbuf *buf = &console->ringbuf;
- uint64_t size = console->log_size;
-
- /* no ringbuffer previously allocated and no ringbuffer requested */
- if (!buf->addr && size <= 0)
- return 0;
-
- /* ringbuffer allocated but no new ringbuffer requested */
- if (buf->addr && size <= 0) {
- lxc_ringbuf_release(buf);
- buf->addr = NULL;
- buf->r_off = 0;
- buf->w_off = 0;
- buf->size = 0;
- TRACE("Deallocated console ringbuffer");
- return 0;
- }
-
- if (size <= 0)
- return 0;
-
- /* check wether the requested size for the ringbuffer has changed */
- if (buf->addr && buf->size != size) {
- TRACE("Console ringbuffer size changed from %" PRIu64
- " to %" PRIu64 " bytes. Deallocating console ringbuffer",
- buf->size, size);
- lxc_ringbuf_release(buf);
- }
-
- ret = lxc_ringbuf_create(buf, size);
- if (ret < 0) {
- ERROR("Failed to setup %" PRIu64 " byte console ringbuffer", size);
- return -1;
- }
-
- TRACE("Allocated %" PRIu64 " byte console ringbuffer", size);
- return 0;
-}
-
-int lxc_setup_parent(struct lxc_handler *handler)
-{
- int ret;
-
- ret = lxc_setup_console_ringbuf(&handler->conf->console);
- if (ret < 0)
- return -1;
-
- return 0;
-}
-
-int lxc_setup_child(struct lxc_handler *handler)
+int lxc_setup(struct lxc_handler *handler)
{
int ret;
const char *name = handler->name;
extern void lxc_clear_includes(struct lxc_conf *conf);
extern int do_rootfs_setup(struct lxc_conf *conf, const char *name,
const char *lxcpath);
-extern int lxc_setup_child(struct lxc_handler *handler);
+extern int lxc_setup(struct lxc_handler *handler);
extern int lxc_setup_parent(struct lxc_handler *handler);
extern int setup_resource_limits(struct lxc_list *limits, pid_t pid);
extern int find_unmapped_nsid(struct lxc_conf *conf, enum idtype idtype);
console->log_fd = -1;
}
+/**
+ * Note that this function needs to run before the mainloop starts. Since we
+ * register a handler for the console's masterfd when we create the mainloop
+ * the console handler needs to see an allocated ringbuffer.
+ */
+static int lxc_setup_console_ringbuf(struct lxc_console *console)
+{
+ int ret;
+ struct lxc_ringbuf *buf = &console->ringbuf;
+ uint64_t size = console->log_size;
+
+ /* no ringbuffer previously allocated and no ringbuffer requested */
+ if (!buf->addr && size <= 0)
+ return 0;
+
+ /* ringbuffer allocated but no new ringbuffer requested */
+ if (buf->addr && size <= 0) {
+ lxc_ringbuf_release(buf);
+ buf->addr = NULL;
+ buf->r_off = 0;
+ buf->w_off = 0;
+ buf->size = 0;
+ TRACE("Deallocated console ringbuffer");
+ return 0;
+ }
+
+ if (size <= 0)
+ return 0;
+
+ /* check wether the requested size for the ringbuffer has changed */
+ if (buf->addr && buf->size != size) {
+ TRACE("Console ringbuffer size changed from %" PRIu64
+ " to %" PRIu64 " bytes. Deallocating console ringbuffer",
+ buf->size, size);
+ lxc_ringbuf_release(buf);
+ }
+
+ ret = lxc_ringbuf_create(buf, size);
+ if (ret < 0) {
+ ERROR("Failed to setup %" PRIu64 " byte console ringbuffer", size);
+ return -1;
+ }
+
+ TRACE("Allocated %" PRIu64 " byte console ringbuffer", size);
+ return 0;
+}
+
int lxc_console_create(struct lxc_conf *conf)
{
int ret, saved_errno;
DEBUG("Using \"%s\" as console log file", console->log_path);
}
+ ret = lxc_setup_console_ringbuf(console);
+ if (ret < 0)
+ goto err;
+
return 0;
err:
}
/* Setup the container, ip, names, utsname, ... */
- ret = lxc_setup_child(handler);
+ ret = lxc_setup(handler);
close(handler->data_sock[0]);
close(handler->data_sock[1]);
if (ret < 0) {
flags &= ~CLONE_NEWNET;
}
- ret = lxc_setup_parent(handler);
- if (ret < 0)
- goto out_delete_net;
-
if (fork_before_clone)
handler->pid = lxc_fork_attach_clone(do_start, handler, flags | CLONE_PARENT);
else