Commit f3787121 by Christian Brauner

start.c: do not reboot on lxc.hook.post-stop fail

lxc should not reboot the container when lxc.hook.post-stop fails. It should simply shutdown. This makes the behavior of lxc.hook.post-stop and lxc.hook.pre-start consistent. When lxc.hook.pre-start fails, the container does not start. Signed-off-by: 's avatarChristian Brauner <christian.brauner@mailbox.org>
parent e6eb4c3e
...@@ -21,29 +21,30 @@ ...@@ -21,29 +21,30 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define _GNU_SOURCE
#include "config.h" #include "config.h"
#include <stdio.h> #include <alloca.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include <grp.h> #include <grp.h>
#include <poll.h> #include <poll.h>
#include <sys/param.h> #include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/stat.h> #include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/syscall.h> #include <sys/wait.h>
#if HAVE_SYS_CAPABILITY_H #if HAVE_SYS_CAPABILITY_H
#include <sys/capability.h> #include <sys/capability.h>
...@@ -53,25 +54,25 @@ ...@@ -53,25 +54,25 @@
#define PR_CAPBSET_DROP 24 #define PR_CAPBSET_DROP 24
#endif #endif
#include "start.h" #include "af_unix.h"
#include "conf.h" #include "caps.h"
#include "log.h"
#include "cgroup.h" #include "cgroup.h"
#include "commands.h"
#include "conf.h"
#include "console.h"
#include "error.h" #include "error.h"
#include "af_unix.h" #include "log.h"
#include "mainloop.h" #include "lxclock.h"
#include "utils.h" #include "lxcseccomp.h"
#include "lxcutmp.h" #include "lxcutmp.h"
#include "mainloop.h"
#include "monitor.h" #include "monitor.h"
#include "commands.h"
#include "console.h"
#include "sync.h"
#include "namespace.h" #include "namespace.h"
#include "lxcseccomp.h" #include "start.h"
#include "caps.h" #include "sync.h"
#include "utils.h"
#include "bdev/bdev.h" #include "bdev/bdev.h"
#include "lsm/lsm.h" #include "lsm/lsm.h"
#include "lxclock.h"
lxc_log_define(lxc_start, lxc); lxc_log_define(lxc_start, lxc);
...@@ -93,14 +94,16 @@ static void lxc_destroy_container_on_signal(struct lxc_handler *handler, ...@@ -93,14 +94,16 @@ static void lxc_destroy_container_on_signal(struct lxc_handler *handler,
static void print_top_failing_dir(const char *path) static void print_top_failing_dir(const char *path)
{ {
size_t len = strlen(path); size_t len = strlen(path);
char *copy = alloca(len+1), *p, *e, saved; char *copy = alloca(len + 1), *p, *e, saved;
strcpy(copy, path); strcpy(copy, path);
p = copy; p = copy;
e = copy + len; e = copy + len;
while (p < e) { while (p < e) {
while (p < e && *p == '/') p++; while (p < e && *p == '/')
while (p < e && *p != '/') p++; p++;
while (p < e && *p != '/')
p++;
saved = *p; saved = *p;
*p = '\0'; *p = '\0';
if (access(copy, X_OK)) { if (access(copy, X_OK)) {
...@@ -130,8 +133,9 @@ static void close_ns(int ns_fd[LXC_NS_MAX]) { ...@@ -130,8 +133,9 @@ static void close_ns(int ns_fd[LXC_NS_MAX]) {
* Return true on success, false on failure. On failure, leave an error * Return true on success, false on failure. On failure, leave an error
* message in *errmsg, which caller must free. * message in *errmsg, which caller must free.
*/ */
static static bool preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags, pid_t pid,
bool preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags, pid_t pid, char **errmsg) { char **errmsg)
{
int i, ret; int i, ret;
char path[MAXPATHLEN]; char path[MAXPATHLEN];
...@@ -288,7 +292,7 @@ static int setup_signal_fd(sigset_t *oldmask) ...@@ -288,7 +292,7 @@ static int setup_signal_fd(sigset_t *oldmask)
} }
static int signal_handler(int fd, uint32_t events, void *data, static int signal_handler(int fd, uint32_t events, void *data,
struct lxc_epoll_descr *descr) struct lxc_epoll_descr *descr)
{ {
struct signalfd_siginfo siginfo; struct signalfd_siginfo siginfo;
siginfo_t info; siginfo_t info;
...@@ -546,8 +550,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler) ...@@ -546,8 +550,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
} }
lxc_set_state(name, handler, STOPPED); lxc_set_state(name, handler, STOPPED);
if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) if (run_lxc_hooks(name, "post-stop", handler->conf, handler->lxcpath, NULL)) {
ERROR("failed to run post-stop hooks for container '%s'.", name); ERROR("failed to run post-stop hooks for container '%s'.", name);
if (handler->conf->reboot) {
WARN("Container will be stopped instead of rebooted.");
handler->conf->reboot = 0;
setenv("LXC_TARGET", "stop", 1);
}
}
/* reset mask set by setup_signal_fd */ /* reset mask set by setup_signal_fd */
if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL))
...@@ -1447,4 +1457,3 @@ static bool do_destroy_container(struct lxc_conf *conf) { ...@@ -1447,4 +1457,3 @@ static bool do_destroy_container(struct lxc_conf *conf) {
} }
return bdev_destroy(conf); return bdev_destroy(conf);
} }
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