start: lxc_init()

parent bba8123b
...@@ -719,55 +719,84 @@ int lxc_init(const char *name, struct lxc_handler *handler) ...@@ -719,55 +719,84 @@ int lxc_init(const char *name, struct lxc_handler *handler)
struct lxc_conf *conf = handler->conf; struct lxc_conf *conf = handler->conf;
lsm_init(); lsm_init();
TRACE("initialized LSM"); TRACE("Initialized LSM");
if (lxc_read_seccomp_config(conf) != 0) { ret = lxc_read_seccomp_config(conf);
ERROR("Failed loading seccomp policy."); if (ret < 0) {
ERROR("Failed loading seccomp policy");
goto out_close_maincmd_fd; goto out_close_maincmd_fd;
} }
TRACE("read seccomp policy"); TRACE("Read seccomp policy");
/* Begin by setting the state to STARTING. */ /* Begin by setting the state to STARTING. */
if (lxc_set_state(name, handler, STARTING)) { ret = lxc_set_state(name, handler, STARTING);
ERROR("Failed to set state for container \"%s\" to \"%s\".", name, lxc_state2str(STARTING)); if (ret < 0) {
ERROR("Failed to set state to \"%s\"", lxc_state2str(STARTING));
goto out_close_maincmd_fd; goto out_close_maincmd_fd;
} }
TRACE("set container state to \"STARTING\""); TRACE("set container state to \"STARTING\"");
/* Start of environment variable setup for hooks. */ /* Start of environment variable setup for hooks. */
if (name && setenv("LXC_NAME", name, 1)) if (name) {
SYSERROR("Failed to set environment variable: LXC_NAME=%s.", name); ret = setenv("LXC_NAME", name, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: LXC_NAME=%s", name);
}
if (conf->rcfile && setenv("LXC_CONFIG_FILE", conf->rcfile, 1)) if (conf->rcfile) {
SYSERROR("Failed to set environment variable: LXC_CONFIG_FILE=%s.", conf->rcfile); ret = setenv("LXC_CONFIG_FILE", conf->rcfile, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_CONFIG_FILE=%s", conf->rcfile);
}
if (conf->rootfs.mount && setenv("LXC_ROOTFS_MOUNT", conf->rootfs.mount, 1)) if (conf->rootfs.mount) {
SYSERROR("Failed to set environment variable: LXC_ROOTFS_MOUNT=%s.", conf->rootfs.mount); ret = setenv("LXC_ROOTFS_MOUNT", conf->rootfs.mount, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_ROOTFS_MOUNT=%s", conf->rootfs.mount);
}
if (conf->rootfs.path && setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1)) if (conf->rootfs.path) {
SYSERROR("Failed to set environment variable: LXC_ROOTFS_PATH=%s.", conf->rootfs.path); ret = setenv("LXC_ROOTFS_PATH", conf->rootfs.path, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_ROOTFS_PATH=%s", conf->rootfs.path);
}
if (conf->console.path && setenv("LXC_CONSOLE", conf->console.path, 1)) if (conf->console.path) {
SYSERROR("Failed to set environment variable: LXC_CONSOLE=%s.", conf->console.path); ret = setenv("LXC_CONSOLE", conf->console.path, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_CONSOLE=%s", conf->console.path);
}
if (conf->console.log_path && setenv("LXC_CONSOLE_LOGPATH", conf->console.log_path, 1)) if (conf->console.log_path) {
SYSERROR("Failed to set environment variable: LXC_CONSOLE_LOGPATH=%s.", conf->console.log_path); ret = setenv("LXC_CONSOLE_LOGPATH", conf->console.log_path, 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_CONSOLE_LOGPATH=%s", conf->console.log_path);
}
if (setenv("LXC_CGNS_AWARE", "1", 1)) if (cgns_supported()) {
SYSERROR("Failed to set environment variable LXC_CGNS_AWARE=1."); ret = setenv("LXC_CGNS_AWARE", "1", 1);
if (ret < 0)
SYSERROR("Failed to set environment variable "
"LXC_CGNS_AWARE=1");
}
loglevel = lxc_log_priority_to_string(lxc_log_get_level()); loglevel = lxc_log_priority_to_string(lxc_log_get_level());
if (setenv("LXC_LOG_LEVEL", loglevel, 1)) if (setenv("LXC_LOG_LEVEL", loglevel, 1))
SYSERROR("Failed to set environment variable LXC_LOG_LEVEL=%s", loglevel); SYSERROR("Failed to set environment variable LXC_LOG_LEVEL=%s", loglevel);
/* End of environment variable setup for hooks. */
TRACE("set environment variables"); TRACE("Set environment variables");
if (run_lxc_hooks(name, "pre-start", conf, handler->lxcpath, NULL)) { ret = run_lxc_hooks(name, "pre-start", conf, handler->lxcpath, NULL);
ERROR("Failed to run lxc.hook.pre-start for container \"%s\".", name); if (ret < 0) {
ERROR("Failed to run lxc.hook.pre-start for container \"%s\"", name);
goto out_aborting; goto out_aborting;
} }
TRACE("ran pre-start hooks"); TRACE("Ran pre-start hooks");
/* The signal fd has to be created before forking otherwise if the child /* The signal fd has to be created before forking otherwise if the child
* process exits before we setup the signal fd, the event will be lost * process exits before we setup the signal fd, the event will be lost
...@@ -778,7 +807,7 @@ int lxc_init(const char *name, struct lxc_handler *handler) ...@@ -778,7 +807,7 @@ int lxc_init(const char *name, struct lxc_handler *handler)
ERROR("Failed to setup SIGCHLD fd handler."); ERROR("Failed to setup SIGCHLD fd handler.");
goto out_delete_tty; goto out_delete_tty;
} }
TRACE("set up signal fd"); TRACE("Set up signal fd");
/* Do this after setting up signals since it might unblock SIGWINCH. */ /* Do this after setting up signals since it might unblock SIGWINCH. */
ret = lxc_console_create(conf); ret = lxc_console_create(conf);
...@@ -790,12 +819,12 @@ int lxc_init(const char *name, struct lxc_handler *handler) ...@@ -790,12 +819,12 @@ int lxc_init(const char *name, struct lxc_handler *handler)
ret = lxc_pty_map_ids(conf, &conf->console); ret = lxc_pty_map_ids(conf, &conf->console);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to shift tty into container."); ERROR("Failed to chown console");
goto out_restore_sigmask; goto out_restore_sigmask;
} }
TRACE("shifted tty ids"); TRACE("Chowned console");
INFO("container \"%s\" is initialized", name); INFO("Container \"%s\" is initialized", name);
return 0; return 0;
out_restore_sigmask: out_restore_sigmask:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment