[CRIU] [PATCH] tty: Don't forget to setup peers mode on restore
Cyrill Gorcunov
gorcunov at openvz.org
Fri Jun 24 07:19:08 PDT 2016
In commit ... we've started to carry @mode of the
files we're opening on restore, implying they are
static and should not be changed. This is true for
regular files but the pty peers are created
dynamically so if someone have set some special
mode beore the checkpoint procedure we will fail
on restore when regular file engine test it. So lets
setup @mode unconditionally.
https://travis-ci.org/xemul/criu/jobs/140011141
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
criu/tty.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/criu/tty.c b/criu/tty.c
index 302dd54528bf..8ec22bff7797 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -515,6 +515,27 @@ static void pty_free_fake_reg(struct reg_file_info **r)
}
}
+static int do_open_tty_reg(int ns_root_fd, struct reg_file_info *rfi, void *arg)
+{
+ int fd;
+
+ fd = do_open_reg_noseek_flags(ns_root_fd, rfi, arg);
+ if (fd >= 0) {
+ /*
+ * Peers might have differend modes set
+ * after creation before we've dumped
+ * them. So simply setup mode from image
+ * the regular file engine will check
+ * for this, so if we fail here it
+ * gonna be catched anyway.
+ */
+ if (rfi->rfe->has_mode)
+ fchmod(fd, rfi->rfe->mode);
+ }
+
+ return fd;
+}
+
static int open_tty_reg(struct file_desc *reg_d, u32 flags)
{
/*
@@ -522,7 +543,7 @@ static int open_tty_reg(struct file_desc *reg_d, u32 flags)
* ctty magic happens only in tty_set_sid().
*/
flags |= O_NOCTTY;
- return open_path(reg_d, do_open_reg_noseek_flags, &flags);
+ return open_path(reg_d, do_open_tty_reg, &flags);
}
static char *path_from_reg(struct file_desc *d)
@@ -840,6 +861,7 @@ static int pty_open_slaves(struct tty_info *info)
{
int sock = -1, fd = -1, ret = -1;
struct fdinfo_list_entry *fle;
+ struct reg_file_info *rfi;
struct tty_info *slave;
sock = socket(PF_UNIX, SOCK_DGRAM, 0);
@@ -851,6 +873,15 @@ static int pty_open_slaves(struct tty_info *info)
list_for_each_entry(slave, &info->sibling, sibling) {
BUG_ON(tty_is_master(slave));
+ /*
+ * FIXME: Restore the mode for peers. The
+ * slaves are dynamically created and might
+ * have mode different than by default.
+ */
+ rfi = container_of(slave->reg_d, struct reg_file_info, d);
+ if (rfi->rfe->has_mode)
+ rfi->rfe->has_mode = false;
+
fd = open_tty_reg(slave->reg_d, slave->tfe->flags);
if (fd < 0) {
pr_perror("Can't open slave %s", path_from_reg(slave->reg_d));
@@ -907,6 +938,7 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
{
struct reg_file_info *fake = NULL;
int master = -1, ret = -1, fd = -1;
+ struct reg_file_info *rfi;
/*
* We may have 2 cases here: the slave either need to
@@ -934,6 +966,15 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
unlock_pty(master);
+ /*
+ * FIXME: Restore the mode for peers. The
+ * slaves are dynamically created and might
+ * have mode different than by default.
+ */
+ rfi = container_of(slave->reg_d, struct reg_file_info, d);
+ if (rfi->rfe->has_mode)
+ rfi->rfe->has_mode = false;
+
fd = open_tty_reg(slave->reg_d, slave->tfe->flags);
if (fd < 0) {
pr_perror("Can't open slave %s", path_from_reg(slave->reg_d));
--
2.5.5
More information about the CRIU
mailing list