[CRIU] [PATCH RFC 2/3] files: Make .post_open methods return named retvals
Kirill Tkhai
ktkhai at virtuozzo.com
Sun Jul 31 05:43:32 PDT 2016
Make .post_open methods for all file types return named retvals,
and return the retvals directly in post_open_fd().
(This is only for .post_open just to describe idea)
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/autofs.c | 6 +++---
criu/eventpoll.c | 4 ++--
criu/files.c | 4 +---
criu/sk-inet.c | 2 +-
criu/sk-unix.c | 12 ++++++------
criu/tty.c | 4 ++--
6 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/criu/autofs.c b/criu/autofs.c
index 6b2fa7e..e1f6372 100644
--- a/criu/autofs.c
+++ b/criu/autofs.c
@@ -770,17 +770,17 @@ static int autofs_post_open(struct file_desc *d, int fd)
mnt_fd = autofs_mnt_open(i->mnt_path, i->mnt_dev);
if (mnt_fd < 0) {
pr_err("Failed to open %s\n", i->mnt_path);
- return -1;
+ return FDO_ERROR;
}
if (autofs_mnt_set_pipefd(i, mnt_fd)) {
pr_err("Failed to set %s owner\n", i->mnt_path);
- return -1;
+ return FDO_ERROR;
}
if (autofs_mnt_close(i->mnt_path, mnt_fd) < 0) {
pr_err("Failed to close %s\n", i->mnt_path);
- return -1;
+ return FDO_ERROR;
}
pr_info("autofs mount %s owner restored: pgrp=%d, fd=%d\n",
diff --git a/criu/eventpoll.c b/criu/eventpoll.c
index 38afeef..82fd02e 100644
--- a/criu/eventpoll.c
+++ b/criu/eventpoll.c
@@ -166,7 +166,7 @@ static int eventpoll_post_open(struct file_desc *d, int fd)
for (i = 0; i < info->efe->n_tfd; i++) {
if (eventpoll_retore_tfd(fd, info->efe->id, info->efe->tfd[i]))
- return -1;
+ return FDO_ERROR;
}
list_for_each_entry(td_info, &eventpoll_tfds, list) {
@@ -174,7 +174,7 @@ static int eventpoll_post_open(struct file_desc *d, int fd)
continue;
if (eventpoll_retore_tfd(fd, info->efe->id, td_info->tdefe))
- return -1;
+ return FDO_ERROR;
}
diff --git a/criu/files.c b/criu/files.c
index 325aa65..51556c9 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -993,9 +993,7 @@ static int post_open_fd(int pid, struct fdinfo_list_entry *fle)
if (fle != file_master(d))
return 0;
- if (d->ops->post_open(d, fle->fe->fd))
- return FDO_ERROR;
- return 0;
+ return d->ops->post_open(d, fle->fe->fd);
}
diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index f4bc519..37ecf49 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -534,7 +534,7 @@ static int post_open_inet_sk(struct file_desc *d, int sk)
val = ii->ie->opts->reuseaddr;
if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &val))
- return -1;
+ return FDO_ERROR;
return 0;
}
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 2bab17f..5d50c23 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -903,29 +903,29 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
pr_info("\tConnect %#x to %#x\n", ui->ue->ino, peer->ue->ino);
if (prep_unix_sk_cwd(peer, &cwd_fd))
- return -1;
+ return FDO_ERROR;
if (connect(fd, (struct sockaddr *)&addr,
sizeof(addr.sun_family) +
peer->ue->name.len) < 0) {
revert_unix_sk_cwd(&cwd_fd);
pr_perror("Can't connect %#x socket", ui->ue->ino);
- return -1;
+ return FDO_ERROR;
}
revert_unix_sk_cwd(&cwd_fd);
if (peer->queuer == ui->ue->ino && restore_sk_queue(fd, peer->ue->id))
- return -1;
+ return FDO_ERROR;
if (rst_file_params(fd, ui->ue->fown, ui->ue->flags))
- return -1;
+ return FDO_ERROR;
if (restore_socket_opts(fd, ui->ue->opts))
- return -1;
+ return FDO_ERROR;
if (shutdown_unix_sk(fd, ui))
- return -1;
+ return FDO_ERROR;
return 0;
}
diff --git a/criu/tty.c b/criu/tty.c
index ec09f30..bc54ca8 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -667,7 +667,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
if (driver->type == TTY_TYPE__EXT_TTY) {
slave = -1;
if (!inherited_fd(&info->d, &slave) && slave < 0)
- return -1;
+ return FDO_ERROR;
goto out;
}
if (driver->img_get_index)
@@ -702,7 +702,7 @@ static int tty_restore_ctl_terminal(struct file_desc *d, int fd)
err:
pty_free_fake_reg(&fake);
close(fd);
- return ret;
+ return ret ? FDO_ERROR: 0;
}
static bool tty_is_master(struct tty_info *info)
More information about the CRIU
mailing list