[CRIU] Re: [PATCH 3/7] fowners: Add regular files/pipes owners dumping

Cyrill Gorcunov gorcunov at openvz.org
Wed Apr 11 07:53:39 EDT 2012


On Wed, Apr 11, 2012 at 02:05:04PM +0400, Pavel Emelyanov wrote:
> 
> I don't understand this thirst for zeroifying everything larger than int even if
> this thing is about to be re-initialized one line of code below. The code from you
> is always full of this. Please, explain it to me.
> 

Please use attached instead.

	Cyrill
-------------- next part --------------
>From 2a851d66b9db8bb78e16a9237da0fa69cbce28d5 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Wed, 11 Apr 2012 15:50:49 +0400
Subject: [PATCH] fowners: Add regular files/pipes owners dumping

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c       |   36 ++++++++++++++++++++++++++++++++++++
 include/files.h |    1 +
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 944e1e9..74f65b1 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -177,6 +177,7 @@ static int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
 	rfe.flags = p->flags;
 	rfe.pos = p->pos;
 	rfe.id = id;
+	rfe.fown = p->fown;
 
 	rfd = fdset_fd(glob_fdset, CR_FD_REG_FILES);
 
@@ -246,6 +247,7 @@ dump:
 	pe.id = id;
 	pe.pipe_id = p->id;
 	pe.flags = p->flags;
+	pe.fown = p->fown;
 
 	if (write_img(fd_pipes, &pe))
 		goto err_close;
@@ -361,6 +363,7 @@ static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
 	params.type = FDINFO_REG;
 	params.flags = 0;
 	params.pos = 0;
+	params.fown = (fown_t){ };
 	mm->exe_file_id = fd_id_generate_special();
 
 	ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
@@ -371,6 +374,9 @@ static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
 
 static int fill_fd_params(pid_t pid, int fd, int lfd, char fd_flags, struct fd_parms *p)
 {
+	struct f_owner_ex owner_ex;
+	u32 v[2];
+
 	if (fstat(lfd, &p->stat) < 0) {
 		pr_perror("Can't stat fd %d\n", lfd);
 		return -1;
@@ -382,10 +388,38 @@ static int fill_fd_params(pid_t pid, int fd, int lfd, char fd_flags, struct fd_p
 	p->pid		= pid;
 	p->id		= FD_ID_INVALID;
 	p->fd_flags	= fd_flags;
+	p->fown		= (fown_t){ };
 
 	pr_info("%d fdinfo %d: pos: %16lx flags: %16o/%x\n",
 		pid, fd, p->pos, p->flags, (int)fd_flags);
 
+	p->fown.signum = fcntl(lfd, F_GETSIG, 0);
+	if (p->fown.signum < 0) {
+		pr_perror("Can't get owner signum on %d\n", lfd);
+		return -1;
+	}
+
+	if (fcntl(lfd, F_GETOWN_EX, (long)&owner_ex)) {
+		pr_perror("Can't get owners on %d\n", lfd);
+		return -1;
+	}
+
+	/*
+	 * Simple case -- nothing is changed.
+	 */
+	if (owner_ex.pid == 0)
+		return 0;
+
+	if (fcntl(lfd, F_GETOWNER_UIDS, (long)&v)) {
+		pr_perror("Can't get owner uids on %d\n", lfd);
+		return -1;
+	}
+
+	p->fown.uid	= v[0];
+	p->fown.euid	= v[1];
+	p->fown.pid_type= owner_ex.type;
+	p->fown.pid	= owner_ex.pid;
+
 	return 0;
 }
 
@@ -494,6 +528,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset)
 	p.type = FDINFO_REG;
 	p.flags = 0;
 	p.pos = 0;
+	p.fown = (fown_t){ };
 	fe.cwd_id = fd_id_generate_special();
 
 	ret = dump_one_reg_file(fd, fe.cwd_id, &p);
@@ -592,6 +627,7 @@ static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
 	}
 
 	p.type = FDINFO_REG;
+	p.fown = (fown_t){ };
 	if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED))
 		p.flags = O_RDWR;
 	else
diff --git a/include/files.h b/include/files.h
index 381a38a..31a5689 100644
--- a/include/files.h
+++ b/include/files.h
@@ -16,6 +16,7 @@ struct fd_parms {
 	struct stat	stat;
 	u32		id;
 	pid_t		pid;
+	fown_t		fown;
 };
 
 enum fdinfo_states {
-- 
1.7.7.6



More information about the CRIU mailing list