Commit cd19b2fe authored by Pavel Emelyanov's avatar Pavel Emelyanov

fs: Reshuffle prepare_fs code flow

Make it ready for root dir restore:
* fix comments
* rename variables
* tune error paths
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent fe3fb885
...@@ -940,28 +940,27 @@ out: ...@@ -940,28 +940,27 @@ out:
int prepare_fs(int pid) int prepare_fs(int pid)
{ {
int ifd, cwd, ret = -1; int ifd, dd, ret = -1;
FsEntry *fe; FsEntry *fe;
ifd = open_image(CR_FD_FS, O_RSTR, pid); ifd = open_image(CR_FD_FS, O_RSTR, pid);
if (ifd < 0) if (ifd < 0)
return -1; goto out;
if (pb_read_one(ifd, &fe, PB_FS) < 0) { if (pb_read_one(ifd, &fe, PB_FS) < 0)
close_safe(&ifd); goto out_i;
return -1;
}
cwd = open_reg_by_id(fe->cwd_id); dd = open_reg_by_id(fe->cwd_id);
if (cwd < 0) { if (dd < 0) {
pr_err("Can't open root %#x\n", fe->cwd_id); pr_err("Can't open cwd %#x\n", fe->cwd_id);
close_safe(&ifd);
goto err; goto err;
} }
if (fchdir(cwd) < 0) { ret = fchdir(dd);
pr_perror("Can't change root"); close(dd);
goto close; if (ret < 0) {
pr_perror("Can't change cwd");
goto err;
} }
/* /*
...@@ -979,11 +978,11 @@ int prepare_fs(int pid) ...@@ -979,11 +978,11 @@ int prepare_fs(int pid)
} }
ret = 0; ret = 0;
close:
close_safe(&cwd);
close_safe(&ifd);
err: err:
fs_entry__free_unpacked(fe, NULL); fs_entry__free_unpacked(fe, NULL);
out_i:
close_safe(&ifd);
out:
return ret; return ret;
} }
......
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