[CRIU] [PATCH 2/2] criu: tty -- Restore pty queued data

Cyrill Gorcunov gorcunov at openvz.org
Tue Mar 15 12:18:36 PDT 2016


Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 criu/tty.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/criu/tty.c b/criu/tty.c
index 869d6593a150..e1ceeec672b1 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -93,6 +93,7 @@ struct tty_info {
 	bool				inherit;
 
 	struct tty_info			*ctl_tty;
+	struct tty_info			*link;
 };
 
 struct tty_dump_info {
@@ -822,6 +823,14 @@ static int pty_open_slaves(struct tty_info *info)
 			goto err;
 		}
 
+		if (slave->link && slave->link->tie->has_qdata) {
+			ProtobufCBinaryData qdata = slave->link->tie->qdata;
+
+			pr_debug("restore queued data on master %#x (%zu bytes)\n",
+				 slave->link->tfe->id, (size_t)qdata.len);
+			write(fd, qdata.data, qdata.len);
+		}
+
 		close(fd);
 		fd = -1;
 	}
@@ -959,6 +968,15 @@ static int pty_open_ptmx(struct tty_info *info)
 		}
 	}
 
+	if (info->link && info->link->tie->has_qdata) {
+		ProtobufCBinaryData qdata = info->link->tie->qdata;
+
+		pr_debug("restore queued data on slave %#x (%zu bytes)\n",
+			 info->link->tfe->id, (size_t)qdata.len);
+
+		write(master, qdata.data, qdata.len);
+	}
+
 	if (pty_open_slaves(info))
 		goto err;
 
@@ -1226,6 +1244,27 @@ int tty_setup_slavery(void)
 	struct tty_info *info, *peer, *m;
 
 	/*
+	 * Setup links for PTY terminal pairs.
+	 */
+	list_for_each_entry(info, &all_ttys, list) {
+		if (!is_pty(info->driver) || info->link)
+			continue;
+
+		peer = info;
+		list_for_each_entry_safe_continue(peer, m, &all_ttys, list) {
+			if (!is_pty(peer->driver) || peer->link)
+				continue;
+			if (peer->tie->pty->index == info-> tie->pty->index) {
+				info->link = peer;
+				peer->link = info;
+
+				pr_debug("Link PTYs (%#x)\n", info->tfe->id);
+				break;
+			}
+		}
+	}
+
+	/*
 	 * The image may carry several terminals opened
 	 * belonging to the same session, so choose the
 	 * leader which gonna be setting up the controlling
@@ -1416,6 +1455,7 @@ static int collect_one_tty(void *obj, ProtobufCMessage *msg)
 	info->create = tty_is_master(info);
 	info->inherit = false;
 	info->ctl_tty = NULL;
+	info->link = NULL;
 
 	if (verify_info(info))
 		return -1;
-- 
2.5.0



More information about the CRIU mailing list