[v2] tty: Don't forget to setup peers mode on restore

Submitted by Cyrill Gorcunov on June 25, 2016, 9:06 a.m.

Details

Message ID 20160625090611.GB10678@uranus
State Accepted
Series "tty: Don't forget to setup peers mode on restore"
Commit 86d9f16c61ad4a04b635c6751c005fc74f436549
Headers show

Commit Message

Cyrill Gorcunov June 25, 2016, 9:06 a.m.
In commit c6bc7259c 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@openvz.org>
---

Slightly improved version.

 criu/tty.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/tty.c b/criu/tty.c
index 302dd54528bf..092e480bc52c 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)

Comments

Pavel Emelianov June 28, 2016, 6:18 a.m.
Applied