[CRIU] [PATCH 12/16] dump: hide regular file open
Kinsbursky Stanislav
skinsbursky at openvz.org
Thu Mar 1 12:57:37 EST 2012
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 45 +++++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index 09e362a..40af29f 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -97,20 +97,19 @@ struct fd_parms {
pid_t pid;
};
-static int dump_one_reg_file(struct fd_parms *p, int lfd,
- struct cr_fdset *cr_fdset,
- bool do_close_lfd)
+static int dump_one_reg_file_fd(struct fd_parms *p, int lfd,
+ struct cr_fdset *cr_fdset,
+ bool do_close_lfd)
{
struct fdinfo_entry e;
char fd_str[128];
int len;
- int ret = -1;
snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
len = readlink(fd_str, big_buffer, sizeof(big_buffer) - 1);
if (len < 0) {
pr_perror("Can't readlink %s", fd_str);
- goto err;
+ return -1;
}
big_buffer[len] = '\0';
@@ -138,7 +137,7 @@ static int dump_one_reg_file(struct fd_parms *p, int lfd,
entry = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
if (!entry)
- goto err;
+ return -1;
/* Now it might have completely new ID here */
e.id = entry->u.id;
@@ -148,12 +147,26 @@ static int dump_one_reg_file(struct fd_parms *p, int lfd,
p->type, len, p->flags, p->pos, p->fd_name);
if (write_img(cr_fdset->fds[CR_FD_FDINFO], &e))
- goto err;
+ return -1;
if (write_img_buf(cr_fdset->fds[CR_FD_FDINFO], big_buffer, e.len))
- goto err;
+ return -1;
+ return 0;
+}
- ret = 0;
-err:
+static int dump_one_reg_file(struct fd_parms *p, struct cr_fdset *cr_fdset)
+{
+ char fd_str[128];
+ int ret;
+ int lfd;
+
+ snprintf(fd_str, sizeof(fd_str), "/proc/%d/fd/%ld", p->pid, p->fd_name);
+ lfd = open(fd_str, O_RDONLY);
+ if (lfd < 0) {
+ pr_perror("Failed to open regular file '%s'\n", fd_str);
+ return -1;
+ }
+ ret = dump_one_reg_file_fd(p, lfd, cr_fdset, 0);
+ close_safe(&lfd);
return ret;
}
@@ -173,7 +186,7 @@ static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
fd = open_proc(pid, "cwd");
if (fd < 0)
return -1;
- ret = dump_one_reg_file(¶ms, fd, cr_fdset, 1);
+ ret = dump_one_reg_file_fd(¶ms, fd, cr_fdset, 1);
if (ret)
return ret;
@@ -188,7 +201,7 @@ static int dump_task_special_files(pid_t pid, struct cr_fdset *cr_fdset)
fd = open_proc(pid, "exe");
if (fd < 0)
return -1;
- ret = dump_one_reg_file(¶ms, fd, cr_fdset, 1);
+ ret = dump_one_reg_file_fd(¶ms, fd, cr_fdset, 1);
return ret;
}
@@ -334,7 +347,6 @@ static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
struct stat fd_stat;
int err = -1;
struct fd_parms p;
- int lfd;
char file_path[128];
snprintf(file_path, sizeof(file_path), "/proc/%d/fd/%s", pid, d_name);
@@ -346,8 +358,6 @@ static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
if (read_fd_params(pid, d_name, &fd_stat, &p))
return -1;
- lfd = open(file_path, O_RDONLY);
-
switch (fd_stat.st_mode & S_IFMT) {
case S_IFCHR:
if (major(fd_stat.st_rdev) != MEM_MAJOR) {
@@ -367,7 +377,7 @@ static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
* Proceed to dump_one_reg_file().
*/
case S_IFREG:
- err = dump_one_reg_file(&p, lfd, cr_fdset, 0);
+ err = dump_one_reg_file(&p, cr_fdset);
break;
case S_IFIFO:
err = dump_one_pipe(&p, cr_fdset);
@@ -389,7 +399,6 @@ static int dump_one_fd(pid_t pid, char *d_name, struct cr_fdset *cr_fdset,
}
if (err)
pr_err("Can't dump file %ld of that type [%x]\n", p.fd_name, fd_stat.st_mode);
- close_safe(&lfd);
return err;
}
@@ -481,7 +490,7 @@ static int dump_task_mappings(pid_t pid, struct list_head *vma_area_list, struct
else
p.flags = O_RDONLY;
- ret = dump_one_reg_file(&p, vma_area->vm_file_fd, cr_fdset, 0);
+ ret = dump_one_reg_file_fd(&p, vma_area->vm_file_fd, cr_fdset, 0);
if (ret)
goto err;
}
More information about the CRIU
mailing list