Skip to content

Commit

Permalink
don't hang on some errors in do_restore
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Tycho Andersen authored and stgraber committed Apr 10, 2015
1 parent 8eed906 commit f3b94d2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lxc/lxccontainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4063,13 +4063,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");
Expand All @@ -4094,6 +4095,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;

Expand Down Expand Up @@ -4127,7 +4131,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);
Expand All @@ -4138,6 +4142,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");
Expand Down Expand Up @@ -4189,6 +4194,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);
}

Expand Down

0 comments on commit f3b94d2

Please sign in to comment.