[2/4] files: Make find_used_fd work on pstree_item

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

Details

Message ID 589DAC8D.1050806@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/files.c         | 9 +++++----
 criu/include/files.h | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files.c b/criu/files.c
index 179afc6..6240062 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -98,10 +98,12 @@  static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
 	return find_file_desc_raw(fe->type, fe->id);
 }
 
-struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd)
+struct fdinfo_list_entry *find_used_fd(struct pstree_item *task, int fd)
 {
+	struct list_head *head;
 	struct fdinfo_list_entry *fle;
 
+	head = &rsti(task)->used;
 	list_for_each_entry_reverse(fle, head, used_list) {
 		if (fle->fe->fd == fd)
 			return fle;
@@ -134,14 +136,13 @@  unsigned int find_unused_fd(struct pstree_item *task, int hint_fd)
 	struct fdinfo_list_entry *fle;
 	int fd = 0, prev_fd;
 
-	head = &rsti(task)->used;
-
-	if ((hint_fd >= 0) && (!find_used_fd(head, hint_fd))) {
+	if ((hint_fd >= 0) && (!find_used_fd(task, hint_fd))) {
 		fd = hint_fd;
 		goto out;
 	}
 
 	prev_fd = service_fd_min_fd() - 1;
+	head = &rsti(task)->used;
 
 	list_for_each_entry_reverse(fle, head, used_list) {
 		fd = fle->fe->fd;
diff --git a/criu/include/files.h b/criu/include/files.h
index 751e531..036b9e6 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -118,7 +118,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 pstree_item *, int hint_fd);
-struct fdinfo_list_entry *find_used_fd(struct list_head *head, int fd);
+struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
 
 struct file_desc {
 	u32			id;		/* File id, unique */