Unverified Commit 755d1e1f by Christian Brauner Committed by Stéphane Graber

start: fix container reboot

parent 3f96727b
...@@ -942,7 +942,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -942,7 +942,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
close(fd); close(fd);
} }
handler = lxc_init_handler(c->name, c->lxc_conf, c->config_path, false); handler = lxc_init_handler(NULL, c->name, c->lxc_conf, c->config_path, false);
if (!handler) if (!handler)
goto out; goto out;
......
...@@ -899,7 +899,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -899,7 +899,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
conf = c->lxc_conf; conf = c->lxc_conf;
/* initialize handler */ /* initialize handler */
handler = lxc_init_handler(c->name, conf, c->config_path, c->daemonize); handler = lxc_init_handler(NULL, c->name, conf, c->config_path, c->daemonize);
container_mem_unlock(c); container_mem_unlock(c);
if (!handler) if (!handler)
...@@ -916,7 +916,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -916,7 +916,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
if (!argv) { if (!argv) {
if (useinit) { if (useinit) {
ERROR("No valid init detected"); ERROR("No valid init detected");
lxc_free_handler(handler); lxc_put_handler(handler);
return false; return false;
} }
argv = default_args; argv = default_args;
...@@ -934,7 +934,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -934,7 +934,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
pid_first = fork(); pid_first = fork();
if (pid_first < 0) { if (pid_first < 0) {
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
return false; return false;
} }
...@@ -951,7 +951,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -951,7 +951,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
started = wait_on_daemonized_start(handler, pid_first); started = wait_on_daemonized_start(handler, pid_first);
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
return started; return started;
} }
...@@ -983,7 +983,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -983,7 +983,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
/* second parent */ /* second parent */
if (pid_second != 0) { if (pid_second != 0) {
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
...@@ -1017,7 +1017,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1017,7 +1017,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
} else if (!am_single_threaded()) { } else if (!am_single_threaded()) {
ERROR("Cannot start non-daemonized container when threaded"); ERROR("Cannot start non-daemonized container when threaded");
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
return false; return false;
} }
...@@ -1031,7 +1031,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1031,7 +1031,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
w = snprintf(pidstr, sizeof(pidstr), "%d", lxc_raw_getpid()); w = snprintf(pidstr, sizeof(pidstr), "%d", lxc_raw_getpid());
if (w < 0 || (size_t)w >= sizeof(pidstr)) { if (w < 0 || (size_t)w >= sizeof(pidstr)) {
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
SYSERROR("Failed to write monitor pid to \"%s\"", c->pidfile); SYSERROR("Failed to write monitor pid to \"%s\"", c->pidfile);
...@@ -1044,7 +1044,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1044,7 +1044,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
ret = lxc_write_to_file(c->pidfile, pidstr, w, false, 0600); ret = lxc_write_to_file(c->pidfile, pidstr, w, false, 0600);
if (ret < 0) { if (ret < 0) {
free_init_cmd(init_cmd); free_init_cmd(init_cmd);
lxc_free_handler(handler); lxc_put_handler(handler);
SYSERROR("Failed to write monitor pid to \"%s\"", c->pidfile); SYSERROR("Failed to write monitor pid to \"%s\"", c->pidfile);
...@@ -1062,7 +1062,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1062,7 +1062,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
ret = unshare(CLONE_NEWNS); ret = unshare(CLONE_NEWNS);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to unshare mount namespace"); SYSERROR("Failed to unshare mount namespace");
lxc_free_handler(handler); lxc_put_handler(handler);
ret = 1; ret = 1;
goto on_error; goto on_error;
} }
...@@ -1070,7 +1070,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1070,7 +1070,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
ret = mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL); ret = mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to make / rslave at startup"); SYSERROR("Failed to make / rslave at startup");
lxc_free_handler(handler); lxc_put_handler(handler);
ret = 1; ret = 1;
goto on_error; goto on_error;
} }
...@@ -1079,19 +1079,20 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a ...@@ -1079,19 +1079,20 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
reboot: reboot:
if (conf->reboot == REBOOT_INIT) { if (conf->reboot == REBOOT_INIT) {
/* initialize handler */ /* initialize handler */
handler = lxc_init_handler(c->name, conf, c->config_path, c->daemonize); handler = lxc_init_handler(handler, c->name, conf, c->config_path, c->daemonize);
if (!handler) { if (!handler) {
ret = 1; ret = 1;
goto on_error; goto on_error;
} }
} else {
keepfds[1] = handler->state_socket_pair[0];
keepfds[2] = handler->state_socket_pair[1];
} }
keepfds[0] = handler->conf->maincmd_fd; keepfds[0] = handler->conf->maincmd_fd;
keepfds[1] = handler->state_socket_pair[0];
keepfds[2] = handler->state_socket_pair[1];
ret = lxc_check_inherited(conf, c->daemonize, keepfds, ARRAY_SIZE(keepfds)); ret = lxc_check_inherited(conf, c->daemonize, keepfds, ARRAY_SIZE(keepfds));
if (ret < 0) { if (ret < 0) {
lxc_free_handler(handler); lxc_put_handler(handler);
ret = 1; ret = 1;
goto on_error; goto on_error;
} }
......
...@@ -605,7 +605,7 @@ out_sigfd: ...@@ -605,7 +605,7 @@ out_sigfd:
return ret; return ret;
} }
void lxc_free_handler(struct lxc_handler *handler) void lxc_put_handler(struct lxc_handler *handler)
{ {
close_prot_errno_disarm(handler->pinfd); close_prot_errno_disarm(handler->pinfd);
close_prot_errno_disarm(handler->pidfd); close_prot_errno_disarm(handler->pidfd);
...@@ -617,22 +617,26 @@ void lxc_free_handler(struct lxc_handler *handler) ...@@ -617,22 +617,26 @@ void lxc_free_handler(struct lxc_handler *handler)
close_prot_errno_disarm(handler->state_socket_pair[0]); close_prot_errno_disarm(handler->state_socket_pair[0]);
close_prot_errno_disarm(handler->state_socket_pair[1]); close_prot_errno_disarm(handler->state_socket_pair[1]);
cgroup_exit(handler->cgroup_ops); cgroup_exit(handler->cgroup_ops);
handler->conf = NULL; if (handler->conf && handler->conf->reboot == REBOOT_NONE)
free_disarm(handler); free_disarm(handler);
else
handler->conf = NULL;
} }
struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf, struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
const char *name, struct lxc_conf *conf,
const char *lxcpath, bool daemonize) const char *lxcpath, bool daemonize)
{ {
int ret; int ret;
struct lxc_handler *handler; struct lxc_handler *handler;
handler = malloc(sizeof(*handler)); if (!old)
handler = zalloc(sizeof(*handler));
else
handler = old;
if (!handler) if (!handler)
return NULL; return NULL;
memset(handler, 0, sizeof(*handler));
/* Note that am_guest_unpriv() checks the effective uid. We /* Note that am_guest_unpriv() checks the effective uid. We
* probably don't care if we are real root only if we are running * probably don't care if we are real root only if we are running
* as root so this should be fine. * as root so this should be fine.
...@@ -692,7 +696,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf, ...@@ -692,7 +696,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf,
return handler; return handler;
on_error: on_error:
lxc_free_handler(handler); lxc_put_handler(handler);
return NULL; return NULL;
} }
...@@ -983,7 +987,7 @@ void lxc_end(struct lxc_handler *handler) ...@@ -983,7 +987,7 @@ void lxc_end(struct lxc_handler *handler)
if (handler->conf->ephemeral == 1 && handler->conf->reboot != REBOOT_REQ) if (handler->conf->ephemeral == 1 && handler->conf->reboot != REBOOT_REQ)
lxc_destroy_container_on_signal(handler, name); lxc_destroy_container_on_signal(handler, name);
lxc_free_handler(handler); lxc_put_handler(handler);
} }
void lxc_abort(struct lxc_handler *handler) void lxc_abort(struct lxc_handler *handler)
......
...@@ -143,11 +143,11 @@ extern int lxc_serve_state_clients(const char *name, ...@@ -143,11 +143,11 @@ extern int lxc_serve_state_clients(const char *name,
struct lxc_handler *handler, struct lxc_handler *handler,
lxc_state_t state); lxc_state_t state);
extern void lxc_abort(struct lxc_handler *handler); extern void lxc_abort(struct lxc_handler *handler);
extern struct lxc_handler *lxc_init_handler(const char *name, extern struct lxc_handler *lxc_init_handler(struct lxc_handler *old,
const char *name,
struct lxc_conf *conf, struct lxc_conf *conf,
const char *lxcpath, const char *lxcpath, bool daemonize);
bool daemonize); extern void lxc_put_handler(struct lxc_handler *handler);
extern void lxc_free_handler(struct lxc_handler *handler);
extern int lxc_init(const char *name, struct lxc_handler *handler); extern int lxc_init(const char *name, struct lxc_handler *handler);
extern void lxc_end(struct lxc_handler *handler); extern void lxc_end(struct lxc_handler *handler);
......
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