start: lxc_fini()

parent 2170b263
...@@ -838,7 +838,7 @@ out_close_maincmd_fd: ...@@ -838,7 +838,7 @@ out_close_maincmd_fd:
void lxc_fini(const char *name, struct lxc_handler *handler) void lxc_fini(const char *name, struct lxc_handler *handler)
{ {
int i, rc; int i, ret;
pid_t self; pid_t self;
struct lxc_list *cur, *next; struct lxc_list *cur, *next;
char *namespaces[LXC_NS_MAX + 1]; char *namespaces[LXC_NS_MAX + 1];
...@@ -855,14 +855,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -855,14 +855,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
continue; continue;
if (handler->conf->hooks_version == 0) if (handler->conf->hooks_version == 0)
rc = asprintf(&namespaces[namespace_count], ret = asprintf(&namespaces[namespace_count],
"%s:/proc/%d/fd/%d", ns_info[i].proc_name, "%s:/proc/%d/fd/%d", ns_info[i].proc_name,
self, handler->nsfd[i]); self, handler->nsfd[i]);
else else
rc = asprintf(&namespaces[namespace_count], ret = asprintf(&namespaces[namespace_count],
"/proc/%d/fd/%d", self, handler->nsfd[i]); "/proc/%d/fd/%d", self, handler->nsfd[i]);
if (rc == -1) { if (ret == -1) {
SYSERROR("Failed to allocate memory."); SYSERROR("Failed to allocate memory");
break; break;
} }
...@@ -871,8 +871,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -871,8 +871,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
continue; continue;
} }
rc = setenv(ns_info[i].env_name, namespaces[namespace_count], 1); ret = setenv(ns_info[i].env_name, namespaces[namespace_count], 1);
if (rc < 0) if (ret < 0)
SYSERROR("Failed to set environment variable %s=%s", SYSERROR("Failed to set environment variable %s=%s",
ns_info[i].env_name, namespaces[namespace_count]); ns_info[i].env_name, namespaces[namespace_count]);
else else
...@@ -883,16 +883,26 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -883,16 +883,26 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
} }
namespaces[namespace_count] = NULL; namespaces[namespace_count] = NULL;
if (handler->conf->reboot && setenv("LXC_TARGET", "reboot", 1)) if (handler->conf->reboot) {
SYSERROR("Failed to set environment variable: LXC_TARGET=reboot."); ret = setenv("LXC_TARGET", "reboot", 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_TARGET=reboot");
}
if (!handler->conf->reboot && setenv("LXC_TARGET", "stop", 1)) if (!handler->conf->reboot) {
SYSERROR("Failed to set environment variable: LXC_TARGET=stop."); ret = setenv("LXC_TARGET", "stop", 1);
if (ret < 0)
SYSERROR("Failed to set environment variable: "
"LXC_TARGET=stop");
}
if (handler->conf->hooks_version == 0) if (handler->conf->hooks_version == 0)
rc = run_lxc_hooks(name, "stop", handler->conf, namespaces); ret = run_lxc_hooks(name, "stop", handler->conf, namespaces);
else else
rc = run_lxc_hooks(name, "stop", handler->conf, NULL); ret = run_lxc_hooks(name, "stop", handler->conf, NULL);
if (ret < 0)
ERROR("Failed to run \"lxc.hook.stop\" hook");
while (namespace_count--) while (namespace_count--)
free(namespaces[namespace_count]); free(namespaces[namespace_count]);
...@@ -925,18 +935,22 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -925,18 +935,22 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
} }
if (run_lxc_hooks(name, "post-stop", handler->conf, NULL)) { if (run_lxc_hooks(name, "post-stop", handler->conf, NULL)) {
ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name); ERROR("Failed to run lxc.hook.post-stop for container \"%s\"", name);
if (handler->conf->reboot) { if (handler->conf->reboot) {
WARN("Container will be stopped instead of rebooted."); WARN("Container will be stopped instead of rebooted");
handler->conf->reboot = 0; handler->conf->reboot = 0;
if (setenv("LXC_TARGET", "stop", 1))
WARN("Failed to set environment variable: LXC_TARGET=stop."); ret = setenv("LXC_TARGET", "stop", 1);
if (ret < 0)
WARN("Failed to set environment variable: "
"LXC_TARGET=stop");
} }
} }
/* Reset mask set by setup_signal_fd. */ /* Reset mask set by setup_signal_fd. */
if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) ret = sigprocmask(SIG_SETMASK, &handler->oldmask, NULL);
WARN("Failed to restore signal mask."); if (ret < 0)
WARN("%s - Failed to restore signal mask", strerror(errno));
lxc_console_delete(&handler->conf->console); lxc_console_delete(&handler->conf->console);
lxc_delete_tty(&handler->conf->tty_info); lxc_delete_tty(&handler->conf->tty_info);
...@@ -952,8 +966,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -952,8 +966,8 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
continue; continue;
/* close state client socket */ /* close state client socket */
close(client->clientfd);
lxc_list_del(cur); lxc_list_del(cur);
close(client->clientfd);
free(cur->elem); free(cur->elem);
free(cur); free(cur);
} }
......
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