[CRIU] [PATCH 2/3] restore: reserve the service descriptor for a control tty

Andrey Vagin avagin at openvz.org
Mon Mar 18 13:40:08 EDT 2013


I'm really lucky.

prepare_ctl_tty:
	e->fd           = reserve_service_fd(CTL_TTY_OFF); // -1

send_fd_to_self:
if (dup2(fd, dfd) != dfd) { // -1 == -1

tty_restore_ctl_terminal:
	if (!is_service_fd(fd, CTL_TTY_OFF))
		return fd == get_service_fd(type); // -1 = -1

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 files.c           |  2 +-
 include/crtools.h |  1 +
 util.c            | 10 ++++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/files.c b/files.c
index 3464cba..4b5f721 100644
--- a/files.c
+++ b/files.c
@@ -405,7 +405,7 @@ int prepare_ctl_tty(int pid, struct rst_info *rst_info, u32 ctl_tty_id)
 	fdinfo_entry__init(e);
 
 	e->id		= ctl_tty_id;
-	e->fd		= get_service_fd(CTL_TTY_OFF);
+	e->fd		= reserve_service_fd(CTL_TTY_OFF);
 	e->type		= FD_TYPES__TTY;
 
 	if (collect_fd(pid, e, rst_info)) {
diff --git a/include/crtools.h b/include/crtools.h
index d3e1f55..c499ffb 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -129,6 +129,7 @@ enum sfd_type {
 extern int clone_service_fd(int id);
 extern int init_service_fd(void);
 extern int get_service_fd(enum sfd_type type);
+extern int reserve_service_fd(enum sfd_type type);
 extern int install_service_fd(enum sfd_type type, int fd);
 extern int close_service_fd(enum sfd_type type);
 extern bool is_service_fd(int fd, enum sfd_type type);
diff --git a/util.c b/util.c
index 2b2596e..5109a57 100644
--- a/util.c
+++ b/util.c
@@ -296,6 +296,16 @@ static int __get_service_fd(enum sfd_type type, int service_fd_id)
 
 static DECLARE_BITMAP(sfd_map, SERVICE_FD_MAX);
 
+int reserve_service_fd(enum sfd_type type)
+{
+	int sfd = __get_service_fd(type, service_fd_id);
+
+	BUG_ON((int)type <= SERVICE_FD_MIN || (int)type >= SERVICE_FD_MAX);
+
+	set_bit(type, sfd_map);
+	return sfd;
+}
+
 int install_service_fd(enum sfd_type type, int fd)
 {
 	int sfd = __get_service_fd(type, service_fd_id);
-- 
1.7.11.7



More information about the CRIU mailing list