void lxc_fini(const char *name, struct lxc_handler *handler) { /* The STOPPING state is there for future cleanup code * which can take awhile */ lxc_set_state(name, handler, STOPPING); lxc_set_state(name, handler, STOPPED); if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) ERROR("failed to run post-stop hooks for container '%s'.", name); /* reset mask set by setup_signal_fd */ if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) WARN("failed to restore sigprocmask"); lxc_console_delete(&handler->conf->console); lxc_delete_tty(&handler->conf->tty_info); close(handler->conf->maincmd_fd); handler->conf->maincmd_fd = -1; free(handler->name); if (handler->ttysock[0] != -1) { close(handler->ttysock[0]); close(handler->ttysock[1]); } cgroup_destroy(handler); free(handler); }
void lxc_fini(const char *name, struct lxc_handler *handler) { int i, rc; pid_t self = getpid(); char *namespaces[LXC_NS_MAX+1]; size_t namespace_count = 0; /* The STOPPING state is there for future cleanup code * which can take awhile */ lxc_set_state(name, handler, STOPPING); for (i = 0; i < LXC_NS_MAX; i++) { if (handler->nsfd[i] != -1) { rc = asprintf(&namespaces[namespace_count], "%s:/proc/%d/fd/%d", ns_info[i].proc_name, self, handler->nsfd[i]); if (rc == -1) { SYSERROR("failed to allocate memory"); break; } ++namespace_count; } } namespaces[namespace_count] = NULL; if (run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, namespaces)) ERROR("failed to run stop hooks for container '%s'.", name); while (namespace_count--) free(namespaces[namespace_count]); for (i = 0; i < LXC_NS_MAX; i++) { if (handler->nsfd[i] != -1) { close(handler->nsfd[i]); handler->nsfd[i] = -1; } } lxc_set_state(name, handler, STOPPED); if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) ERROR("failed to run post-stop hooks for container '%s'.", name); /* reset mask set by setup_signal_fd */ if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) WARN("failed to restore sigprocmask"); lxc_console_delete(&handler->conf->console); lxc_delete_tty(&handler->conf->tty_info); close(handler->conf->maincmd_fd); handler->conf->maincmd_fd = -1; free(handler->name); if (handler->ttysock[0] != -1) { close(handler->ttysock[0]); close(handler->ttysock[1]); } if (handler->conf->ephemeral == 1 && handler->conf->reboot != 1) { lxc_destroy_container_on_signal(handler, name); } cgroup_destroy(handler); free(handler); }
void lxc_fini(const char *name, struct lxc_handler *handler) { int i, rc; pid_t self = getpid(); char *namespaces[LXC_NS_MAX+1]; size_t namespace_count = 0; /* The STOPPING state is there for future cleanup code which can take * awhile. */ lxc_set_state(name, handler, STOPPING); for (i = 0; i < LXC_NS_MAX; i++) { if (handler->nsfd[i] != -1) { rc = asprintf(&namespaces[namespace_count], "%s:/proc/%d/fd/%d", ns_info[i].proc_name, self, handler->nsfd[i]); if (rc == -1) { SYSERROR("Failed to allocate memory."); break; } ++namespace_count; } } namespaces[namespace_count] = NULL; if (handler->conf->reboot && setenv("LXC_TARGET", "reboot", 1)) SYSERROR("Failed to set environment variable: LXC_TARGET=reboot."); if (!handler->conf->reboot && setenv("LXC_TARGET", "stop", 1)) SYSERROR("Failed to set environment variable: LXC_TARGET=stop."); if (run_lxc_hooks(name, "stop", handler->conf, handler->lxcpath, namespaces)) ERROR("Failed to run lxc.hook.stop for container \"%s\".", name); while (namespace_count--) free(namespaces[namespace_count]); for (i = 0; i < LXC_NS_MAX; i++) { if (handler->nsfd[i] != -1) { close(handler->nsfd[i]); handler->nsfd[i] = -1; } } if (handler->netnsfd >= 0) { close(handler->netnsfd); handler->netnsfd = -1; } lxc_set_state(name, handler, STOPPED); if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) { ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name); if (handler->conf->reboot) { WARN("Container will be stopped instead of rebooted."); handler->conf->reboot = 0; if (setenv("LXC_TARGET", "stop", 1)) WARN("Failed to set environment variable: LXC_TARGET=stop."); } } /* Reset mask set by setup_signal_fd. */ if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) WARN("Failed to restore signal mask."); lxc_console_delete(&handler->conf->console); lxc_delete_tty(&handler->conf->tty_info); close(handler->conf->maincmd_fd); handler->conf->maincmd_fd = -1; free(handler->name); if (handler->ttysock[0] != -1) { close(handler->ttysock[0]); close(handler->ttysock[1]); } if (handler->conf->ephemeral == 1 && handler->conf->reboot != 1) lxc_destroy_container_on_signal(handler, name); cgroup_destroy(handler); free(handler); }