[CRIU] [PATCH 3/3] tty: Restore external ttys

Cyrill Gorcunov gorcunov at openvz.org
Thu Sep 20 07:00:33 EDT 2012


With this patch we try to restore external ttys
if a process tree was dumped with --ext-tty option.

There might be two cases

 - plain external tty, ie the slave peer to some
   /dev/pts/N. We restore it by trying to connect
   to /dev/pts/N without any other actions.

 - master/slave peers which controlling terminal SID does
   not belong our session (ie the result of subtree of
   some process tree dumping). In this case we reset SID to
   our own (printing warning) and continue restore.

Both scenarions are unpleasant but there nothing else we can do.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 tty.c |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/tty.c b/tty.c
index 1ee1b9b..eca05e9 100644
--- a/tty.c
+++ b/tty.c
@@ -546,21 +546,23 @@ static int receive_tty(struct tty_info *info)
 	return fd;
 }
 
-static int pty_open_fake_ptmx(struct tty_info *slave)
+static int pty_open_slave(struct tty_info *slave)
 {
 	int master = -1, ret = -1, fd = -1;
 	char pts_name[64];
 
 	snprintf(pts_name, sizeof(pts_name), PTS_FMT, slave->tie->pty->index);
 
-	master = pty_open_ptmx_index(O_RDONLY, slave->tie->pty->index);
-	if (master < 0) {
-		pr_perror("Can't open fale %x (index %d)",
-			  slave->tfe->id, slave->tie->pty->index);
-		return -1;
-	}
+	if (!slave->tie->termios) {
+		master = pty_open_ptmx_index(O_RDONLY, slave->tie->pty->index);
+		if (master < 0) {
+			pr_perror("Can't open fale %x (index %d)",
+				  slave->tfe->id, slave->tie->pty->index);
+			return -1;
+		}
 
-	unlock_pty(master);
+		unlock_pty(master);
+	}
 
 	fd = open(pts_name, slave->tfe->flags);
 	if (fd < 0) {
@@ -633,7 +635,7 @@ static int tty_open(struct file_desc *d)
 		return receive_tty(info);
 
 	if (!pty_is_master(info))
-		return pty_open_fake_ptmx(info);
+		return pty_open_slave(info);
 
 	return pty_open_ptmx(info);
 
@@ -679,8 +681,22 @@ static int tty_find_restoring_task(struct tty_info *info)
 		if (item->sid == info->tie->sid)
 			return prepare_ctl_tty(item->pid.virt, item->rst, info->tfe->id);
 
-	pr_err("No task found with sid %d\n", info->tie->sid);
-	return -1;
+	/*
+	 * OK, no proper SID found, this means we were dumped as
+	 * a part of some other session and can't restore the session
+	 * needed back.
+	 *
+	 * To workaround this just reset SID to the process root SID,
+	 * there nothing else we can do.
+	 */
+
+	pr_warn("No task found with sid %d, reset constrol terminal to sid %d\n",
+		info->tie->sid, root_item->sid);
+
+	info->tie->sid = root_item->sid;
+	info->tie->pgrp = root_item->pgid;
+
+	return prepare_ctl_tty(root_item->pid.virt, item->rst, info->tfe->id);
 }
 
 static void tty_setup_orphan_slavery(void)
-- 
1.7.7.6



More information about the CRIU mailing list