[CRIU] [PATCH 3/3] tty: Verify active pairs once dump complete

Cyrill Gorcunov gorcunov at openvz.org
Tue Sep 18 08:34:56 EDT 2012


We don't support yet detached terminals migration,
so fail early if we can't proceed.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c     |    4 ++++
 include/tty.h |    2 ++
 tty.c         |   23 +++++++++++++++++++++++
 3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 047e11c..0541e5c 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1630,6 +1630,10 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 	if (ret)
 		goto err;
 
+	ret = tty_verify_active_pairs();
+	if (ret)
+		goto err;
+
 	fd_id_show_tree();
 err:
 	close_cr_fdset(&glob_fdset);
diff --git a/include/tty.h b/include/tty.h
index 0283e4c..eccc3f2 100644
--- a/include/tty.h
+++ b/include/tty.h
@@ -18,4 +18,6 @@ extern int collect_tty(void);
 extern int prepare_shared_tty(void);
 extern void tty_setup_slavery(void);
 
+extern int tty_verify_active_pairs(void);
+
 #endif /* CR_TTY_H__ */
diff --git a/tty.c b/tty.c
index 0b38d06..9498bbc 100644
--- a/tty.c
+++ b/tty.c
@@ -138,6 +138,29 @@ static int tty_gen_id(int major, int index)
 	return (index << 1) + (major == TTYAUX_MAJOR);
 }
 
+static int tty_get_index(u32 id)
+{
+	return id >> 1;
+}
+
+/* Make sure the active pairs do exist */
+int tty_verify_active_pairs(void)
+{
+	int i;
+
+	for (i = 0; i < (MAX_TTYS << 1); i += 2) {
+		if (test_bit(i, tty_active_pairs) &&
+		    !test_bit(i + 1, tty_active_pairs)) {
+			pr_err("Found slave peer index %d without "
+				"correspond master peer\n",
+				tty_get_index(i));
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 static int parse_index(u32 id, int lfd, int major)
 {
 	int index = -1;
-- 
1.7.7.6



More information about the CRIU mailing list