[lxc-devel] [lxc/master] c/r: detatch from controlling tty on restore

tych0 on Github lxc-bot at linuxcontainers.org
Wed Sep 21 21:46:55 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 361 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160921/03763740/attachment.bin>
-------------- next part --------------
From a7fb6043b9208d8a13ddf814bb0ee86f9e6a10be Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Wed, 21 Sep 2016 21:45:49 +0000
Subject: [PATCH] c/r: detatch from controlling tty on restore

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 src/lxc/criu.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/lxc/criu.c b/src/lxc/criu.c
index 3e586b9..67d6fdc 100644
--- a/src/lxc/criu.c
+++ b/src/lxc/criu.c
@@ -662,9 +662,22 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
 {
 	pid_t pid;
 	struct lxc_handler *handler;
-	int status;
+	int status, fd;
 	int pipes[2] = {-1, -1};
 
+	/* Try to detach from the current controlling tty if it exists.
+	 * Othwerise, lxc_init (via lxc_console) will attach the container's
+	 * console output to the current tty, which is probably not what any
+	 * library user wants, and if they do, they can just manually configure
+	 * it :)
+	 */
+	fd = open("/dev/tty", O_RDWR);
+	if (fd >= 0) {
+		if (ioctl(fd, TIOCNOTTY, NULL) < 0)
+			SYSERROR("couldn't detach from tty");
+		close(fd);
+	}
+
 	handler = lxc_init(c->name, c->lxc_conf, c->config_path);
 	if (!handler)
 		goto out;


More information about the lxc-devel mailing list