start: lxc_start()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner 2018-02-19 00:45:56 +01:00
parent cfc62c6036
commit c30e9b193e
No known key found for this signature in database
GPG Key ID: 8EB056D53EECB12D

View File

@ -1828,12 +1828,12 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
struct lxc_operations* ops, void *data, const char *lxcpath, struct lxc_operations* ops, void *data, const char *lxcpath,
bool backgrounded) bool backgrounded)
{ {
int status; int ret, status;
int err = -1;
struct lxc_conf *conf = handler->conf; struct lxc_conf *conf = handler->conf;
if (lxc_init(name, handler) < 0) { ret = lxc_init(name, handler);
ERROR("Failed to initialize container \"%s\".", name); if (ret < 0) {
ERROR("Failed to initialize container \"%s\"", name);
return -1; return -1;
} }
handler->ops = ops; handler->ops = ops;
@ -1841,31 +1841,33 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
handler->backgrounded = backgrounded; handler->backgrounded = backgrounded;
if (!attach_block_device(handler->conf)) { if (!attach_block_device(handler->conf)) {
ERROR("Failed to attach block device."); ERROR("Failed to attach block device");
goto out_fini_nonet; goto out_fini_nonet;
} }
if (geteuid() == 0 && !lxc_list_empty(&conf->id_map)) { if (geteuid() == 0 && !lxc_list_empty(&conf->id_map)) {
/* If the backing store is a device, mount it here and now. */ /* If the backing store is a device, mount it here and now. */
if (rootfs_is_blockdev(conf)) { if (rootfs_is_blockdev(conf)) {
if (unshare(CLONE_NEWNS) < 0) { ret = unshare(CLONE_NEWNS);
ERROR("Failed to unshare CLONE_NEWNS."); if (ret < 0) {
ERROR("Failed to unshare CLONE_NEWNS");
goto out_fini_nonet; goto out_fini_nonet;
} }
INFO("Unshared CLONE_NEWNS."); INFO("Unshared CLONE_NEWNS");
remount_all_slave(); remount_all_slave();
if (do_rootfs_setup(conf, name, lxcpath) < 0) { ret = do_rootfs_setup(conf, name, lxcpath);
ERROR("Error setting up rootfs mount as root before spawn."); if (ret < 0) {
ERROR("Error setting up rootfs mount as root before spawn");
goto out_fini_nonet; goto out_fini_nonet;
} }
INFO("Set up container rootfs as host root."); INFO("Set up container rootfs as host root");
} }
} }
err = lxc_spawn(handler); ret = lxc_spawn(handler);
if (err) { if (ret < 0) {
ERROR("Failed to spawn container \"%s\".", name); ERROR("Failed to spawn container \"%s\"", name);
goto out_detach_blockdev; goto out_detach_blockdev;
} }
/* close parent side of data socket */ /* close parent side of data socket */
@ -1876,14 +1878,15 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
handler->conf->reboot = 0; handler->conf->reboot = 0;
err = lxc_poll(name, handler); ret = lxc_poll(name, handler);
if (err) { if (ret) {
ERROR("LXC mainloop exited with error: %d.", err); ERROR("LXC mainloop exited with error: %d", ret);
goto out_abort; goto out_abort;
} }
while (waitpid(handler->pid, &status, 0) < 0 && errno == EINTR) status = lxc_wait_for_pid_status(handler->pid);
continue; if (status < 0)
SYSERROR("Failed to retrieve status for %d", handler->pid);
/* If the child process exited but was not signaled, it didn't call /* If the child process exited but was not signaled, it didn't call
* reboot. This should mean it was an lxc-execute which simply exited. * reboot. This should mean it was an lxc-execute which simply exited.
@ -1892,23 +1895,23 @@ int __lxc_start(const char *name, struct lxc_handler *handler,
if (WIFSIGNALED(status)) { if (WIFSIGNALED(status)) {
switch(WTERMSIG(status)) { switch(WTERMSIG(status)) {
case SIGINT: /* halt */ case SIGINT: /* halt */
DEBUG("Container \"%s\" is halting.", name); DEBUG("Container \"%s\" is halting", name);
break; break;
case SIGHUP: /* reboot */ case SIGHUP: /* reboot */
DEBUG("Container \"%s\" is rebooting.", name); DEBUG("Container \"%s\" is rebooting", name);
handler->conf->reboot = 1; handler->conf->reboot = 1;
break; break;
case SIGSYS: /* seccomp */ case SIGSYS: /* seccomp */
DEBUG("Container \"%s\" violated its seccomp policy.", name); DEBUG("Container \"%s\" violated its seccomp policy", name);
break; break;
default: default:
DEBUG("Unknown exit status for container \"%s\" init %d.", name, WTERMSIG(status)); DEBUG("Unknown exit status for container \"%s\" init %d", name, WTERMSIG(status));
break; break;
} }
} }
err = lxc_restore_phys_nics_to_netns(handler); ret = lxc_restore_phys_nics_to_netns(handler);
if (err < 0) if (ret < 0)
ERROR("Failed to move physical network devices back to parent " ERROR("Failed to move physical network devices back to parent "
"network namespace"); "network namespace");
@ -1928,7 +1931,7 @@ out_detach_blockdev:
out_fini_nonet: out_fini_nonet:
lxc_fini(name, handler); lxc_fini(name, handler);
return err; return ret;
out_abort: out_abort:
lxc_abort(name, handler); lxc_abort(name, handler);