]> git.proxmox.com Git - mirror_lxc.git/commitdiff
don't hang on some errors in do_restore
authorTycho Andersen <tycho.andersen@canonical.com>
Fri, 3 Apr 2015 21:17:25 +0000 (21:17 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 6 Apr 2015 16:49:44 +0000 (12:49 -0400)
Instead, the parent always writes a status to the pipe.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c

index 6ac829a1f8addbae4cc559399903eea498040beb..6ce51853757a1c07afe16fd4746068d022e75bff 100644 (file)
@@ -4066,13 +4066,14 @@ static void do_restore(struct lxc_container *c, int pipe, char *directory, bool
        pid_t pid;
        char pidfile[L_tmpnam];
        struct lxc_handler *handler;
+       int status;
 
        if (!tmpnam(pidfile))
-               exit(1);
+               goto out;
 
        handler = lxc_init(c->name, c->lxc_conf, c->config_path);
        if (!handler)
-               exit(1);
+               goto out;
 
        if (!cgroup_init(handler)) {
                ERROR("failed initing cgroups");
@@ -4097,6 +4098,9 @@ static void do_restore(struct lxc_container *c, int pipe, char *directory, bool
                struct criu_opts os;
                struct lxc_rootfs *rootfs;
 
+               close(pipe);
+               pipe = -1;
+
                if (unshare(CLONE_NEWNS))
                        goto out_fini_handler;
 
@@ -4130,7 +4134,7 @@ static void do_restore(struct lxc_container *c, int pipe, char *directory, bool
                rmdir(rootfs->mount);
                goto out_fini_handler;
        } else {
-               int status, ret;
+               int ret;
                char title[2048];
 
                pid_t w = waitpid(pid, &status, 0);
@@ -4141,6 +4145,7 @@ static void do_restore(struct lxc_container *c, int pipe, char *directory, bool
 
                ret = write(pipe, &status, sizeof(status));
                close(pipe);
+               pipe = -1;
 
                if (sizeof(status) != ret) {
                        perror("write");
@@ -4192,6 +4197,16 @@ static void do_restore(struct lxc_container *c, int pipe, char *directory, bool
 
 out_fini_handler:
        lxc_fini(c->name, handler);
+
+out:
+       if (pipe >= 0) {
+               status = 1;
+               if (write(pipe, &status, sizeof(status)) != sizeof(status)) {
+                       SYSERROR("writing status failed");
+               }
+               close(pipe);
+       }
+
        exit(1);
 }