2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

image: Open images via openat

Using absolute paths for this is dangerous - while doing c/r we should
be extremely carefully and not change tasks' roots and mount namespaces
too early. Sometimes it will not work -- when restoring containers we'll
be unable to switch to new CT and still have the ability to open images.

Rework the images opening via openat and keep the image dir fd open all
the time as the service fd (introduced earlier).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2012-03-16 17:24:00 +04:00
parent 3dd8f2e659
commit ffacd0f17c
4 changed files with 49 additions and 33 deletions

View File

@@ -23,7 +23,6 @@
static struct cr_options opts;
struct page_entry zero_page_entry;
char image_dir[PATH_MAX];
/*
* The cr fd set is the set of files where the information
@@ -205,20 +204,17 @@ static struct cr_fdset *cr_fdset_open(int pid, unsigned long use_mask,
if (fdset->fds[i] != -1)
continue;
ret = get_image_path(path, sizeof(path),
fdset_template[i].fmt, pid);
if (ret)
goto err;
sprintf(path, fdset_template[i].fmt, pid);
if (flags & O_EXCL) {
ret = unlink(path);
ret = unlinkat(image_dir_fd, path, 0);
if (ret && errno != ENOENT) {
pr_perror("Unable to unlink %s", path);
goto err;
}
}
ret = open(path, flags, CR_FD_PERM);
ret = openat(image_dir_fd, path, flags, CR_FD_PERM);
if (ret < 0) {
if (!(flags & O_CREAT))
/* caller should check himself */
@@ -381,8 +377,9 @@ int main(int argc, char *argv[])
return ret;
}
if (!getcwd(image_dir, sizeof(image_dir))) {
pr_perror("can't get currect directory");
ret = open_image_dir();
if (ret < 0) {
pr_perror("can't open currect directory");
return -1;
}