[CRIU] [PATCH 4/5] tty: don't use global variables for saving service fds

Andrey Vagin avagin at openvz.org
Sun Jan 6 05:48:15 EST 2013


It's preparation for cloning service descriptors

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 tty.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tty.c b/tty.c
index f5f10f9..dc695e5 100644
--- a/tty.c
+++ b/tty.c
@@ -94,7 +94,7 @@ struct tty_dump_info {
 
 static LIST_HEAD(all_tty_info_entries);
 static LIST_HEAD(all_ttys);
-static int self_stdin = -1;
+static bool self_stdin_inited = false;
 
 #define INHERIT_SID			(-1)
 
@@ -1194,7 +1194,7 @@ int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set)
 
 int tty_prep_fds(void)
 {
-	self_stdin = get_service_fd(SELF_STDIN_OFF);
+	int self_stdin = get_service_fd(SELF_STDIN_OFF);
 
 	if (!isatty(STDIN_FILENO)) {
 		pr_err("Standart stream is not a terminal, aborting\n");
@@ -1202,15 +1202,22 @@ int tty_prep_fds(void)
 	}
 
 	if (dup2(STDIN_FILENO, self_stdin) < 0) {
-		self_stdin = -1;
 		pr_perror("Can't dup stdin to SELF_STDIN_OFF");
 		return -1;
 	}
 
+	self_stdin_inited = true;
+
 	return 0;
 }
 
 void tty_fini_fds(void)
 {
+	int self_stdin = get_service_fd(SELF_STDIN_OFF);
+
+	if (!self_stdin_inited)
+		return;
+
 	close_safe(&self_stdin);
+	self_stdin_inited = false;
 }
-- 
1.7.11.7



More information about the CRIU mailing list