[lxc-devel] [lxc/master] Init "busy" field in "lxc_terminal_info" to -1 (not 0)

Rachid-Koucha on Github lxc-bot at linuxcontainers.org
Thu Dec 5 09:16:27 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 575 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191205/30c7996c/attachment.bin>
-------------- next part --------------
From f398ed87bf839190becc3f1792f457d60b96bc47 Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Thu, 5 Dec 2019 10:07:52 +0100
Subject: [PATCH 1/2] init of "busy" field of "struct lxc_terminal_info"

As the "busy" field of the "struct lxc_terminal_info" is set to a socket descriptor when the embedding structure is marked "in use", it should be initialized to -1 instead of 0 as 0 is also a valid file descriptor.

Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
 src/lxc/terminal.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index aba8bb9217..26b2d50d7c 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -593,7 +593,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
 		if (*ttyreq > ttys->max)
 			goto out;
 
-		if (ttys->tty[*ttyreq - 1].busy)
+		if (ttys->tty[*ttyreq - 1].busy >= 0)
 			goto out;
 
 		/* The requested tty is available. */
@@ -602,7 +602,7 @@ int lxc_terminal_allocate(struct lxc_conf *conf, int sockfd, int *ttyreq)
 	}
 
 	/* Search for next available tty, fixup index tty1 => [0]. */
-	for (ttynum = 1; ttynum <= ttys->max && ttys->tty[ttynum - 1].busy; ttynum++) {
+	for (ttynum = 1; ttynum <= ttys->max && ttys->tty[ttynum - 1].busy >= 0; ttynum++) {
 		;
 	}
 
@@ -628,7 +628,7 @@ void lxc_terminal_free(struct lxc_conf *conf, int fd)
 
 	for (i = 0; i < ttys->max; i++)
 		if (ttys->tty[i].busy == fd)
-			ttys->tty[i].busy = 0;
+			ttys->tty[i].busy = -1;
 
 	if (terminal->proxy.busy != fd)
 		return;

From ddaf1002166f88f86a79e8d65c786fab36e97ccd Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Thu, 5 Dec 2019 10:14:24 +0100
Subject: [PATCH 2/2] Init of "busy" field in "struct lxc_terminal_info"

As the "busy" field of the "struct lxc_terminal_info" is set to a socket descriptor when the embedding structure is marked "in use", it should be initialized to -1 instead of 0 as 0 is also a valid file descriptor.

Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
 src/lxc/conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index b192c7550a..03f4d69587 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -1006,7 +1006,7 @@ int lxc_allocate_ttys(struct lxc_conf *conf)
 			SYSWARN("Failed to set FD_CLOEXEC flag on slave fd %d of "
 			        "tty device \"%s\"", tty->slave, tty->name);
 
-		tty->busy = 0;
+		tty->busy = -1;
 	}
 
 	INFO("Finished creating %zu tty devices", ttys->max);


More information about the lxc-devel mailing list