#include <netinet/in.h>
#include <net/if.h>
-#include <lxc/lxc.h>
-#include <lxc/log.h>
-#include <lxc/utils.h>
-
-#include "arguments.h"
+#include "log.h"
+#include "lxc.h"
+#include "conf.h"
+#include "utils.h"
#include "config.h"
+#include "confile.h"
+#include "arguments.h"
lxc_log_define(lxc_start, lxc);
};
char *rcfile = NULL;
+ struct lxc_conf conf;
if (lxc_arguments_parse(&my_args, argc, argv))
return err;
}
}
+ if (lxc_conf_init(&conf)) {
+ ERROR("failed to initialze configuration");
+ return err;
+ }
+
+ if (rcfile && lxc_config_read(rcfile, &conf)) {
+ ERROR("failed to read configuration file");
+ return err;
+ }
+
if (my_args.daemonize) {
/* do not chdir as we want to open the log file,
save_tty(&tios);
- err = lxc_start(my_args.name, args, rcfile);
+ err = lxc_start(my_args.name, args, &conf);
restore_tty(&tios);
return 0;
}
-struct lxc_handler *lxc_init(const char *name, const char *rcfile)
+struct lxc_handler *lxc_init(const char *name, struct lxc_conf *conf)
{
struct lxc_handler *handler;
memset(handler, 0, sizeof(*handler));
+ handler->conf = conf;
+
/* Begin the set the state to STARTING*/
if (lxc_set_state(name, handler, STARTING)) {
ERROR("failed to set state '%s'", lxc_state2str(STARTING));
goto out_free;
}
- if (lxc_conf_init(&handler->conf)) {
- ERROR("failed to initialize the configuration");
- goto out_aborting;
- }
-
- if (rcfile) {
- if (access(rcfile, F_OK)) {
- ERROR("failed to access '%s'", rcfile);
- goto out_aborting;
- }
-
- if (lxc_config_read(rcfile, &handler->conf)) {
- ERROR("failed to read '%s'", rcfile);
- goto out_aborting;
- }
- }
-
- if (console_init(handler->conf.console,
- sizeof(handler->conf.console))) {
+ if (console_init(conf->console, sizeof(conf->console))) {
ERROR("failed to initialize the console");
goto out_aborting;
}
- if (lxc_create_tty(name, &handler->conf)) {
+ if (lxc_create_tty(name, conf)) {
ERROR("failed to create the ttys");
goto out_aborting;
}
return handler;
out_delete_tty:
- lxc_delete_tty(&handler->conf.tty_info);
+ lxc_delete_tty(&conf->tty_info);
out_aborting:
lxc_set_state(name, handler, ABORTING);
out_free:
lxc_unlink_nsgroup(name);
if (handler) {
- lxc_delete_tty(&handler->conf.tty_info);
+ lxc_delete_tty(&handler->conf->tty_info);
free(handler);
}
}
/* Setup the container, ip, names, utsname, ... */
- if (lxc_setup(name, &handler->conf)) {
+ if (lxc_setup(name, handler->conf)) {
ERROR("failed to setup the container");
goto out_warn_father;
}
}
clone_flags = CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS;
- if (!lxc_list_empty(&handler->conf.network)) {
+ if (!lxc_list_empty(&handler->conf->network)) {
clone_flags |= CLONE_NEWNET;
/* that should be done before the clone because we will
* fill the netdev index and use them in the child
*/
- if (lxc_create_network(&handler->conf.network)) {
+ if (lxc_create_network(&handler->conf->network)) {
ERROR("failed to create the network");
goto out_close;
}
/* Create the network configuration */
if (clone_flags & CLONE_NEWNET) {
- if (lxc_assign_network(&handler->conf.network, handler->pid)) {
+ if (lxc_assign_network(&handler->conf->network, handler->pid)) {
ERROR("failed to create the configured network");
goto out_abort;
}
goto out_close;
}
-int lxc_start(const char *name, char *const argv[], const char *rcfile)
+int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
{
struct lxc_handler *handler;
int err = -1;
int status;
- handler = lxc_init(name, rcfile);
+ handler = lxc_init(name, conf);
if (!handler) {
ERROR("failed to initialize the container");
return -1;