mirror of
git://github.com/lxc/lxc
synced 2025-08-31 04:59:37 +00:00
Move the configuration file to the start function
We want to store more information in the configuration structure, especially the ttys. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
@@ -1619,66 +1619,44 @@ void lxc_delete_tty(struct lxc_tty_info *tty_info)
|
||||
tty_info->nbtty = 0;
|
||||
}
|
||||
|
||||
extern int lxc_config_read(const char *file, struct lxc_conf *conf);
|
||||
|
||||
int lxc_setup(const char *name, const char *cons,
|
||||
const struct lxc_tty_info *tty_info)
|
||||
|
||||
int lxc_setup(const char *name, struct lxc_handler *handler)
|
||||
{
|
||||
struct lxc_conf lxc_conf;
|
||||
char path[MAXPATHLEN];
|
||||
|
||||
if (lxc_conf_init(&lxc_conf)) {
|
||||
ERROR("failed to initialize the configuration");
|
||||
return -1;
|
||||
}
|
||||
|
||||
snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
|
||||
|
||||
if (!access(path, F_OK)) {
|
||||
|
||||
if (lxc_config_read(path, &lxc_conf)) {
|
||||
ERROR("failed to read the configuration file");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (setup_utsname(lxc_conf.utsname)) {
|
||||
if (setup_utsname(handler->lxc_conf.utsname)) {
|
||||
ERROR("failed to setup the utsname for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!lxc_list_empty(&lxc_conf.networks) && setup_network(name)) {
|
||||
if (!lxc_list_empty(&handler->lxc_conf.networks) && setup_network(name)) {
|
||||
ERROR("failed to setup the network for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_cgroup(name, &lxc_conf.cgroup)) {
|
||||
if (setup_cgroup(name, &handler->lxc_conf.cgroup)) {
|
||||
ERROR("failed to setup the cgroups for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_mount(lxc_conf.fstab)) {
|
||||
if (setup_mount(handler->lxc_conf.fstab)) {
|
||||
ERROR("failed to setup the mounts for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_console(lxc_conf.rootfs, cons)) {
|
||||
if (setup_console(handler->lxc_conf.rootfs, handler->tty)) {
|
||||
ERROR("failed to setup the console for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_tty(lxc_conf.rootfs, tty_info)) {
|
||||
if (setup_tty(handler->lxc_conf.rootfs, &handler->tty_info)) {
|
||||
ERROR("failed to setup the ttys for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_rootfs(lxc_conf.rootfs)) {
|
||||
if (setup_rootfs(handler->lxc_conf.rootfs)) {
|
||||
ERROR("failed to set rootfs for '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setup_pts(lxc_conf.pts)) {
|
||||
if (setup_pts(handler->lxc_conf.pts)) {
|
||||
ERROR("failed to setup the new pts instance");
|
||||
return -1;
|
||||
}
|
||||
|
@@ -176,8 +176,10 @@ extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
|
||||
/*
|
||||
* Configure the container from inside
|
||||
*/
|
||||
extern int lxc_setup(const char *name, const char *tty,
|
||||
const struct lxc_tty_info *tty_info);
|
||||
|
||||
struct lxc_handler;
|
||||
|
||||
extern int lxc_setup(const char *name, struct lxc_handler *handler);
|
||||
|
||||
extern int conf_has(const char *name, const char *info);
|
||||
|
||||
|
@@ -44,6 +44,9 @@
|
||||
#include <sys/un.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include <lxc/lxc.h>
|
||||
#include <lxc/confile.h>
|
||||
|
||||
#ifdef HAVE_SYS_SIGNALFD_H
|
||||
# include <sys/signalfd.h>
|
||||
#else
|
||||
@@ -235,6 +238,7 @@ static int console_init(char *console, size_t size)
|
||||
struct lxc_handler *lxc_init(const char *name)
|
||||
{
|
||||
struct lxc_handler *handler;
|
||||
char path[MAXPATHLEN];
|
||||
|
||||
handler = malloc(sizeof(*handler));
|
||||
if (!handler)
|
||||
@@ -252,6 +256,21 @@ struct lxc_handler *lxc_init(const char *name)
|
||||
goto out_put_lock;
|
||||
}
|
||||
|
||||
if (lxc_conf_init(&handler->lxc_conf)) {
|
||||
ERROR("failed to initialize the configuration");
|
||||
goto out_aborting;
|
||||
}
|
||||
|
||||
snprintf(path, sizeof(path), LXCPATH "/%s/config", name);
|
||||
|
||||
if (!access(path, F_OK)) {
|
||||
|
||||
if (lxc_config_read(path, &handler->lxc_conf)) {
|
||||
ERROR("failed to read the configuration file");
|
||||
goto out_aborting;
|
||||
}
|
||||
}
|
||||
|
||||
if (console_init(handler->tty, sizeof(handler->tty))) {
|
||||
ERROR("failed to initialize the console");
|
||||
goto out_aborting;
|
||||
@@ -358,7 +377,7 @@ static int do_start(void *arg)
|
||||
}
|
||||
|
||||
/* Setup the container, ip, names, utsname, ... */
|
||||
if (lxc_setup(name, handler->tty, &handler->tty_info)) {
|
||||
if (lxc_setup(name, handler)) {
|
||||
ERROR("failed to setup the container");
|
||||
goto out_warn_father;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ struct lxc_handler {
|
||||
char nsgroup[MAXPATHLEN];
|
||||
sigset_t oldmask;
|
||||
struct lxc_tty_info tty_info;
|
||||
struct lxc_conf lxc_conf;
|
||||
};
|
||||
|
||||
extern struct lxc_handler *lxc_init(const char *name);
|
||||
|
Reference in New Issue
Block a user