From 933790143774db4c848cf1fafc79dcfa627ee298 Mon Sep 17 00:00:00 2001
From: liuhao <liuhao27@huawei.com>
Date: Thu, 17 Jan 2019 20:46:33 +0800
Subject: [PATCH 048/131] clear ONLCR flag from master of terminal

clear ONLCR flag from master of terminal

Signed-off-by: liuhao <liuhao27@huawei.com>
Signed-off-by: LiFeng <lifeng68@huawei.com>
---
 src/lxc/terminal.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index a33830dd..95140e0b 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -1066,6 +1066,24 @@ static int lxc_terminal_fifo_default(struct lxc_terminal *terminal)
 	return lxc_terminal_set_fifo(terminal, terminal->init_fifo[0], terminal->init_fifo[1]);
 }
 
+/*
+ * isulad: disable (XSI) Map NL to CR-NL on output. 
+ * */
+static int use_unix_newline(int master_fd)
+{
+	struct termios oldtios;
+	int ret;
+
+	ret = tcgetattr(master_fd, &oldtios);
+	if (ret < 0)
+		return -1;
+	oldtios.c_oflag &= ~ONLCR;
+	ret = tcsetattr(master_fd, TCSAFLUSH, &oldtios);
+	if (ret < 0)
+		return -1;
+	return 0;
+}
+
 int lxc_terminal_create(struct lxc_terminal *terminal)
 {
 	int ret;
@@ -1082,6 +1100,13 @@ int lxc_terminal_create(struct lxc_terminal *terminal)
 		goto err;
 	}
 
+	/* isulad: clear ONLCR flag */
+	ret = use_unix_newline(terminal->master);
+	if (ret < 0) {
+		SYSERROR("Failed to clear ONLCR flag on terminal master");
+		goto err;
+	}
+
 	ret = fd_cloexec(terminal->master, true);
 	if (ret < 0) {
 		SYSERROR("Failed to set FD_CLOEXEC flag on terminal master");
-- 
2.23.0

