Commit bc3da65f by Tycho Andersen Committed by Stéphane Graber

c/r: write status only after trying to parse the pid

Previously, we write a "success" status but tried to parse the pid. This meant that we wouldn't notice a successful restore but failure to parse the pid, which was a little strange. We still don't know the child pid, so we will end up with a restored process tree and a running container, but at least in this case the API will return false indicating that something failed. We could kill(-1, 9) in this case, but since liblxc runs as root sometimes (e.g. LXD), that would be a Very Bad Thing. Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
parent 063ce092
...@@ -723,15 +723,6 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -723,15 +723,6 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
goto out_fini_handler; goto out_fini_handler;
} }
ret = write(status_pipe, &status, sizeof(status));
close(status_pipe);
status_pipe = -1;
if (sizeof(status) != ret) {
SYSERROR("failed to write all of status");
goto out_fini_handler;
}
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
char buf[4096]; char buf[4096];
...@@ -780,6 +771,15 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_ ...@@ -780,6 +771,15 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
close(pipes[0]); close(pipes[0]);
ret = write(status_pipe, &status, sizeof(status));
close(status_pipe);
status_pipe = -1;
if (sizeof(status) != ret) {
SYSERROR("failed to write all of status");
goto out_fini_handler;
}
/* /*
* See comment in lxcapi_start; we don't care if these * See comment in lxcapi_start; we don't care if these
* fail because it's just a beauty thing. We just * fail because it's just a beauty thing. We just
...@@ -805,7 +805,12 @@ out_fini_handler: ...@@ -805,7 +805,12 @@ out_fini_handler:
out: out:
if (status_pipe >= 0) { if (status_pipe >= 0) {
status = 1; /* ensure getting here was a failure, e.g. if we failed to
* parse the child pid or something, even after a successful
* restore
*/
if (!status)
status = 1;
if (write(status_pipe, &status, sizeof(status)) != sizeof(status)) { if (write(status_pipe, &status, sizeof(status)) != sizeof(status)) {
SYSERROR("writing status failed"); SYSERROR("writing status failed");
} }
......
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