[CRIU] [PATCH 2/3] tty: use a pair of dev and rdev to identify a terminal

Andrey Vagin avagin at openvz.org
Thu Nov 26 01:32:46 PST 2015


From: Andrew Vagin <avagin at virtuozzo.com>

We can't use only a terminal device, because we can not distinguish
two pty-s from different mounts in this case.

$ mount -t devpts -o newinstance xxx pts1
$ mount -t devpts -o newinstance xxx pts2
$ stat pts1/0
Device: 27h/39d	Inode: 3           Links: 1     Device type: 88,0
$ stat pts2/0
Device: 28h/40d	Inode: 3           Links: 1     Device type: 88,0

Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 files.c            |  2 +-
 include/tty.h      |  6 +++---
 protobuf/tty.proto |  1 +
 tty.c              | 13 ++++++++++---
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/files.c b/files.c
index c0f7586..f4bdc80 100644
--- a/files.c
+++ b/files.c
@@ -366,7 +366,7 @@ static int dump_chrdev(struct fd_parms *p, int lfd, struct cr_img *img)
 	default: {
 		char more[32];
 
-		if (is_tty(maj, minor(p->stat.st_rdev))) {
+		if (is_tty(p->stat.st_rdev, p->stat.st_dev)) {
 			struct fd_link link;
 
 			if (fill_fdlink(lfd, p, &link))
diff --git a/include/tty.h b/include/tty.h
index 1d1a2e9..c8b6209 100644
--- a/include/tty.h
+++ b/include/tty.h
@@ -12,10 +12,10 @@
 extern const struct fdtype_ops tty_dump_ops;
 
 struct tty_driver;
-struct tty_driver *get_tty_driver(int major, int minor);
-static inline int is_tty(int major, int minor)
+struct tty_driver *get_tty_driver(dev_t rdev, dev_t dev);
+static inline int is_tty(dev_t rdev, dev_t dev)
 {
-	return get_tty_driver(major, minor) != NULL;
+	return get_tty_driver(rdev, dev) != NULL;
 }
 
 extern int dump_verify_tty_sids(void);
diff --git a/protobuf/tty.proto b/protobuf/tty.proto
index 9da840c..fce5e79 100644
--- a/protobuf/tty.proto
+++ b/protobuf/tty.proto
@@ -60,6 +60,7 @@ message tty_info_entry {
 	 * TTY type.
 	 */
 	optional tty_pty_entry		pty		= 12;
+	optional uint32			dev		= 13;
 };
 
 message tty_file_entry {
diff --git a/tty.c b/tty.c
index 1286742..b745483 100644
--- a/tty.c
+++ b/tty.c
@@ -232,8 +232,13 @@ static struct tty_driver pts_driver = {
 	.open			= pty_open_ptmx,
 };
 
-struct tty_driver *get_tty_driver(int major, int minor)
+struct tty_driver *get_tty_driver(dev_t rdev, dev_t dev)
 {
+	int major, minor;
+
+	major = major(rdev);
+	minor = minor(rdev);
+
 	switch (major) {
 	case TTYAUX_MAJOR:
 		if (minor == 2)
@@ -1353,7 +1358,7 @@ static int collect_one_tty(void *obj, ProtobufCMessage *msg)
 	}
 
 	INIT_LIST_HEAD(&info->sibling);
-	info->driver = get_tty_driver(major(info->tie->rdev), minor(info->tie->rdev));
+	info->driver = get_tty_driver(info->tie->rdev, info->tie->dev);
 	info->create = tty_is_master(info);
 	info->inherit = false;
 	info->ctl_tty = NULL;
@@ -1498,6 +1503,8 @@ static int dump_tty_info(int lfd, u32 id, const struct fd_parms *p, struct tty_d
 	info.sid		= pti->sid;
 	info.pgrp		= pti->pgrp;
 	info.rdev		= p->stat.st_rdev;
+	info.dev		= p->stat.st_dev;
+	info.has_dev		= true;
 	info.locked		= pti->st_lock;
 	info.exclusive		= pti->st_excl;
 	info.packet_mode	= pti->st_pckt;
@@ -1578,7 +1585,7 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
 	if (dump_one_reg_file(lfd, id, p))
 		return -1;
 
-	driver = get_tty_driver(major(p->stat.st_rdev), minor(p->stat.st_rdev));
+	driver = get_tty_driver(p->stat.st_rdev, p->stat.st_dev);
 	if (driver->fd_get_index)
 		index = driver->fd_get_index(lfd, p);
 	else
-- 
2.4.3



More information about the CRIU mailing list