From: Christian Brauner Date: Mon, 28 May 2018 22:48:15 +0000 (+0200) Subject: start: add reboot macros X-Git-Tag: lxc-3.1.0~282^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80308d07b37387f718405a87fe908064c1969cdf;p=thirdparty%2Flxc.git start: add reboot macros Signed-off-by: Christian Brauner --- diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 8a21d97e4..04a6050f1 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -1036,7 +1036,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a } } - conf->reboot = 0; + conf->reboot = REBOOT_NONE; /* Unshare the mount namespace if requested */ if (conf->monitor_unshare) { @@ -1058,7 +1058,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a } reboot: - if (conf->reboot == 2) { + if (conf->reboot == REBOOT_INIT) { /* initialize handler */ handler = lxc_init_handler(c->name, conf, c->config_path, c->daemonize); if (!handler) { @@ -1085,9 +1085,9 @@ reboot: ret = lxc_start(c->name, argv, handler, c->config_path, c->daemonize, &c->error_num); - if (conf->reboot == 1) { + if (conf->reboot == REBOOT_REQ) { INFO("Container requested reboot"); - conf->reboot = 2; + conf->reboot = REBOOT_INIT; goto reboot; } diff --git a/src/lxc/start.c b/src/lxc/start.c index 7ec151e1c..a8cd82771 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -646,7 +646,7 @@ void lxc_free_handler(struct lxc_handler *handler) lxc_put_nsfds(handler); - if (handler->conf && handler->conf->reboot == 0) + if (handler->conf && handler->conf->reboot == REBOOT_NONE) if (handler->conf->maincmd_fd >= 0) close(handler->conf->maincmd_fd); @@ -684,7 +684,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf, handler->sigfd = -EBADF; handler->init_died = false; handler->state_socket_pair[0] = handler->state_socket_pair[1] = -1; - if (handler->conf->reboot == 0) + if (handler->conf->reboot == REBOOT_NONE) lxc_list_init(&handler->conf->state_clients); for (i = 0; i < LXC_NS_MAX; i++) @@ -692,7 +692,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf, handler->name = name; - if (daemonize && !handler->conf->reboot) { + if (daemonize && handler->conf->reboot == REBOOT_NONE) { /* Create socketpair() to synchronize on daemonized startup. * When the container reboots we don't need to synchronize * again currently so don't open another socketpair(). @@ -708,7 +708,7 @@ struct lxc_handler *lxc_init_handler(const char *name, struct lxc_conf *conf, handler->state_socket_pair[1]); } - if (handler->conf->reboot == 0) { + if (handler->conf->reboot == REBOOT_NONE) { handler->conf->maincmd_fd = lxc_cmd_init(name, lxcpath, "command"); if (handler->conf->maincmd_fd < 0) { ERROR("Failed to set up command socket"); @@ -918,14 +918,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler) } namespaces[namespace_count] = NULL; - if (handler->conf->reboot) { + if (handler->conf->reboot > REBOOT_NONE) { ret = setenv("LXC_TARGET", "reboot", 1); if (ret < 0) SYSERROR("Failed to set environment variable: " "LXC_TARGET=reboot"); } - if (!handler->conf->reboot) { + if (handler->conf->reboot == REBOOT_NONE) { ret = setenv("LXC_TARGET", "stop", 1); if (ret < 0) SYSERROR("Failed to set environment variable: " @@ -945,7 +945,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler) cgroup_ops->destroy(cgroup_ops, handler); cgroup_exit(cgroup_ops); - if (handler->conf->reboot == 0) { + if (handler->conf->reboot == REBOOT_NONE) { /* For all new state clients simply close the command socket. * This will inform all state clients that the container is * STOPPED and also prevents a race between a open()/close() on @@ -973,9 +973,9 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ret = run_lxc_hooks(name, "post-stop", handler->conf, NULL); if (ret < 0) { ERROR("Failed to run lxc.hook.post-stop for container \"%s\"", name); - if (handler->conf->reboot) { + if (handler->conf->reboot > REBOOT_NONE) { WARN("Container will be stopped instead of rebooted"); - handler->conf->reboot = 0; + handler->conf->reboot = REBOOT_NONE; ret = setenv("LXC_TARGET", "stop", 1); if (ret < 0) @@ -999,7 +999,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler) struct lxc_state_client *client = cur->elem; /* Keep state clients that want to be notified about reboots. */ - if ((handler->conf->reboot > 0) && (client->states[RUNNING] == 2)) + if ((handler->conf->reboot > REBOOT_NONE) && + (client->states[RUNNING] == 2)) continue; /* close state client socket */ @@ -1009,7 +1010,7 @@ void lxc_fini(const char *name, struct lxc_handler *handler) free(cur); } - if (handler->conf->ephemeral == 1 && handler->conf->reboot != 1) + if (handler->conf->ephemeral == 1 && handler->conf->reboot != REBOOT_REQ) lxc_destroy_container_on_signal(handler, name); lxc_free_handler(handler); @@ -1892,7 +1893,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler, close(handler->data_sock[1]); handler->data_sock[1] = -1; - handler->conf->reboot = 0; + handler->conf->reboot = REBOOT_NONE; ret = lxc_poll(name, handler); if (ret) { @@ -1915,7 +1916,7 @@ int __lxc_start(const char *name, struct lxc_handler *handler, break; case SIGHUP: /* reboot */ DEBUG("Container \"%s\" is rebooting", name); - handler->conf->reboot = 1; + handler->conf->reboot = REBOOT_REQ; break; case SIGSYS: /* seccomp */ DEBUG("Container \"%s\" violated its seccomp policy", name); diff --git a/src/lxc/state.h b/src/lxc/state.h index f34efd992..dc5b34af3 100644 --- a/src/lxc/state.h +++ b/src/lxc/state.h @@ -35,6 +35,12 @@ typedef enum { MAX_STATE, } lxc_state_t; +enum { + REBOOT_NONE, + REBOOT_REQ, + REBOOT_INIT +}; + extern lxc_state_t lxc_getstate(const char *name, const char *lxcpath); extern lxc_state_t lxc_str2state(const char *state);