]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
start.c: do not reboot on lxc.hook.post-stop fail 862/head
authorChristian Brauner <christian.brauner@mailbox.org>
Tue, 1 Mar 2016 09:42:45 +0000 (10:42 +0100)
committerChristian Brauner <christian.brauner@mailbox.org>
Tue, 1 Mar 2016 11:54:55 +0000 (12:54 +0100)
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: Christian Brauner <christian.brauner@mailbox.org>
src/lxc/start.c

index 6a3ab9523743e39fc085a83d5083597712c34ce5..3e51ad528f8b5e63b9fcdb932a7edd915f37fe38 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#define _GNU_SOURCE
 #include "config.h"
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
+#include <alloca.h>
 #include <dirent.h>
 #include <errno.h>
-#include <unistd.h>
-#include <signal.h>
 #include <fcntl.h>
 #include <grp.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/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <sys/param.h>
 #include <sys/prctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
 #include <sys/types.h>
-#include <sys/wait.h>
 #include <sys/un.h>
-#include <sys/syscall.h>
+#include <sys/wait.h>
 
 #if HAVE_SYS_CAPABILITY_H
 #include <sys/capability.h>
 #define PR_CAPBSET_DROP 24
 #endif
 
-#include "start.h"
-#include "conf.h"
-#include "log.h"
+#include "af_unix.h"
+#include "caps.h"
 #include "cgroup.h"
+#include "commands.h"
+#include "conf.h"
+#include "console.h"
 #include "error.h"
-#include "af_unix.h"
-#include "mainloop.h"
-#include "utils.h"
+#include "log.h"
+#include "lxclock.h"
+#include "lxcseccomp.h"
 #include "lxcutmp.h"
+#include "mainloop.h"
 #include "monitor.h"
-#include "commands.h"
-#include "console.h"
-#include "sync.h"
 #include "namespace.h"
-#include "lxcseccomp.h"
-#include "caps.h"
+#include "start.h"
+#include "sync.h"
+#include "utils.h"
 #include "bdev/bdev.h"
 #include "lsm/lsm.h"
-#include "lxclock.h"
 
 lxc_log_define(lxc_start, lxc);
 
@@ -93,14 +94,16 @@ static void lxc_destroy_container_on_signal(struct lxc_handler *handler,
 static void print_top_failing_dir(const char *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);
 
        p = copy;
        e = copy + len;
        while (p < e) {
-               while (p < e && *p == '/') p++;
-               while (p < e && *p != '/') p++;
+               while (p < e && *p == '/')
+                       p++;
+               while (p < e && *p != '/')
+                       p++;
                saved = *p;
                *p = '\0';
                if (access(copy, X_OK)) {
@@ -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
  * message in *errmsg, which caller must free.
  */
-static
-bool preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags, pid_t pid, char **errmsg) {
+static bool preserve_ns(int ns_fd[LXC_NS_MAX], int clone_flags, pid_t pid,
+                       char **errmsg)
+{
        int i, ret;
        char path[MAXPATHLEN];
 
@@ -288,7 +292,7 @@ static int setup_signal_fd(sigset_t *oldmask)
 }
 
 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;
        siginfo_t info;
@@ -546,8 +550,14 @@ void lxc_fini(const char *name, struct lxc_handler *handler)
        }
        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);
+               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 */
        if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL))
@@ -1447,4 +1457,3 @@ static bool do_destroy_container(struct lxc_conf *conf) {
        }
        return bdev_destroy(conf);
 }
-