From 7db0308d2d89a5b6ae91408258c31d2ebb8c17b6 Mon Sep 17 00:00:00 2001
From: LiFeng <lifeng68@huawei.com>
Date: Tue, 15 Jan 2019 23:24:21 -0500
Subject: [PATCH 038/131] make the given terminal as controlling terminal

Avoid warning when start cmd /bin/sh :
sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell

Signed-off-by: LiFeng <lifeng68@huawei.com>
---
 src/lxc/start.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index 708ab7f5..ec61b322 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -1330,7 +1330,15 @@ static int do_start(void *data)
 	 * setup on its console ie. the pty allocated in lxc_terminal_setup() so
 	 * make sure that that pty is stdin,stdout,stderr.
 	 */
+	 setsid();
 	 if (handler->conf->console.slave >= 0) {
+		/* isulad:make the given terminal as controlling terminal to avoid warning
+		* sh: cannot set terminal process group (-1): Inappropriate ioctl for device
+		* sh: no job control in this shell */
+		 if (ioctl(handler->conf->console.slave, TIOCSCTTY, NULL) < 0) {
+			 ERROR("Faild to make the given terminal the controlling terminal of the calling process");
+			 goto out_warn_father;
+		 }
 		 if (handler->daemonize || !handler->conf->is_execute)
 			 ret = set_stdfds(handler->conf->console.slave);
 		 else
@@ -1377,8 +1385,6 @@ static int do_start(void *data)
 		devnull_fd = -1;
 	}
 
-	setsid();
-
 	if (handler->conf->init_cwd) {
 		/* isulad: try to craete workdir if not exist */
 		struct stat st;
-- 
2.23.0

