[1/4] files: Make find_unused_fd work on pstree_item

Submitted by Pavel Emelianov on Feb. 10, 2017, 12:05 p.m.

Details

Message ID 589DAC7F.9030302@virtuozzo.com
State New
Series "sanitize rsti fds and used lists"
Headers show

Commit Message

Pavel Emelianov Feb. 10, 2017, 12:05 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>

---
 criu/autofs.c        | 4 ++--
 criu/files.c         | 5 ++++-
 criu/include/files.h | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/autofs.c b/criu/autofs.c
index 1875fe7..0ba99fc 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -569,7 +569,7 @@  static int autofs_dup_pipe(struct pstree_item *task,
 	struct pipe_info *pi = container_of(ple->desc, struct pipe_info, d);
 	unsigned flags = O_WRONLY;
 
-	new_fd = find_unused_fd(&rsti(task)->used, new_fd);
+	new_fd = find_unused_fd(task, new_fd);
 
 	if (dup_pipe_info(pi, flags, pi->d.ops) < 0) {
 		pr_err("Failed to dup pipe entry ID %#x PIPE_ID %#x\n",
@@ -911,7 +911,7 @@  static int autofs_create_pipe(struct pstree_item *task, autofs_info_t *i,
 	struct file_desc_ops *ops;
 	PipeEntry *pe;
 
-	fd = find_unused_fd(&rsti(task)->used, fd);
+	fd = find_unused_fd(task, fd);
 
 	ops = shmalloc(sizeof(*ops));
 	if (!ops)
diff --git a/criu/files.c b/criu/files.c
index 1a76313..179afc6 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -128,11 +128,14 @@  void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri)
 	list_add_tail(&new_fle->used_list, &fle->used_list);
 }
 
-unsigned int find_unused_fd(struct list_head *head, int hint_fd)
+unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)
 {
+	struct list_head *head;
 	struct fdinfo_list_entry *fle;
 	int fd = 0, prev_fd;
 
+	head = &rsti(task)->used;
+
 	if ((hint_fd >= 0) && (!find_used_fd(head, hint_fd))) {
 		fd = hint_fd;
 		goto out;
diff --git a/criu/include/files.h b/criu/include/files.h
index 39ef23b..751e531 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -117,7 +117,7 @@  struct file_desc_ops {
 
 void collect_task_fd(struct fdinfo_list_entry *new_fle, struct rst_info *ri);
 
-unsigned int find_unused_fd(struct list_head *head, int hint_fd);
+unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
 struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
 
 struct file_desc {