[CRIU] [PATCH v5 06/11] files: Make dup_fle() return newly allocated fle
Kirill Tkhai
ktkhai at virtuozzo.com
Thu Jun 16 06:53:52 PDT 2016
v5: New
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/autofs.c | 2 +-
criu/files.c | 19 ++++++++++---------
criu/include/files.h | 6 +++---
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/criu/autofs.c b/criu/autofs.c
index 6b2fa7e..c161a86 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -578,7 +578,7 @@ static int autofs_dup_pipe(struct pstree_item *task,
return -1;
}
- if (dup_fle(task, ple, new_fd, flags) < 0) {
+ if (!dup_fle(task, ple, new_fd, flags)) {
pr_err("Failed to add fd %d to process %d\n",
new_fd, task->pid.virt);
return -1;
diff --git a/criu/files.c b/criu/files.c
index 036e054..0bccb42 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -661,7 +661,8 @@ int rst_file_params(int fd, FownEntry *fown, int flags)
return 0;
}
-static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
+static struct fdinfo_list_entry *
+collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
{
struct fdinfo_list_entry *le, *new_le;
struct file_desc *fdesc;
@@ -671,7 +672,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
new_le = shmalloc(sizeof(*new_le));
if (!new_le)
- return -1;
+ return NULL;
futex_init(&new_le->real_pid);
new_le->pid = pid;
@@ -681,7 +682,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
fdesc = find_file_desc(e);
if (fdesc == NULL) {
pr_err("No file for fd %d id %#x\n", e->fd, e->id);
- return -1;
+ return NULL;
}
list_for_each_entry(le, &fdesc->fd_info_head, desc_list)
@@ -698,7 +699,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
list_add_tail(&new_le->desc_list, &le->desc_list);
new_le->desc = fdesc;
- return 0;
+ return new_le;
}
FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags)
@@ -718,14 +719,15 @@ FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags)
return e;
}
-int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
+struct fdinfo_list_entry *
+dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
int fd, unsigned flags)
{
FdinfoEntry *e;
e = dup_fdinfo(ple->fe, fd, flags);
if (!e)
- return -1;
+ return NULL;
return collect_fd(task->pid.virt, e, rsti(task));
}
@@ -749,7 +751,7 @@ int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id)
e->fd = reserve_service_fd(CTL_TTY_OFF);
e->type = FD_TYPES__TTY;
- if (collect_fd(pid, e, rst_info)) {
+ if (!collect_fd(pid, e, rst_info)) {
xfree(e);
return -1;
}
@@ -793,8 +795,7 @@ int prepare_fd_pid(struct pstree_item *item)
if (ret <= 0)
break;
- ret = collect_fd(pid, e, rst_info);
- if (ret < 0) {
+ if (!collect_fd(pid, e, rst_info)) {
fdinfo_entry__free_unpacked(e, NULL);
break;
}
diff --git a/criu/include/files.h b/criu/include/files.h
index 06a1f98..e7bc0cf 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -199,7 +199,7 @@ extern char *external_lookup_by_key(char *id);
extern bool inherited_fd(struct file_desc *, int *fdp);
extern FdinfoEntry *dup_fdinfo(FdinfoEntry *old, int fd, unsigned flags);
-int dup_fle(struct pstree_item *task, struct fdinfo_list_entry *ple,
- int fd, unsigned flags);
-
+extern struct fdinfo_list_entry *dup_fle(struct pstree_item *task,
+ struct fdinfo_list_entry *ple,
+ int fd, unsigned flags);
#endif /* __CR_FILES_H__ */
More information about the CRIU
mailing list