[lxc-devel] [lxc/master] DO NOT add the handles of adjust winsize when the 'stdin' is not a tty
lifeng68 on Github
lxc-bot at linuxcontainers.org
Fri May 19 06:28:39 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 545 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170519/3f670d6b/attachment.bin>
-------------- next part --------------
From 95188b31b0251b19b1c3d3eb53e6ae5aec217a42 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng68 at huawei.com>
Date: Fri, 19 May 2017 22:17:32 +0800
Subject: [PATCH] DO NOT add the handles of adjust winsize when the 'stdin' is
not a tty
Signed-off-by: Li Feng <lifeng68 at huawei.com>
---
src/lxc/console.c | 65 +++++++++++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 31 deletions(-)
mode change 100644 => 100755 src/lxc/console.c
diff --git a/src/lxc/console.c b/src/lxc/console.c
old mode 100644
new mode 100755
index 0cfc9ab..ea7eaf7
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -121,27 +121,29 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
ts->masterfd = dstfd;
ts->sigfd = -1;
- /* add tty to list to be scanned at SIGWINCH time */
- lxc_list_add_elem(&ts->node, ts);
- lxc_list_add_tail(&lxc_ttys, &ts->node);
+ if (isatty(srcfd)) {
+ /* add tty to list to be scanned at SIGWINCH time */
+ lxc_list_add_elem(&ts->node, ts);
+ lxc_list_add_tail(&lxc_ttys, &ts->node);
+
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGWINCH);
+ if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
+ SYSERROR("failed to block SIGWINCH.");
+ ts->sigfd = -1;
+ return ts;
+ }
- sigemptyset(&mask);
- sigaddset(&mask, SIGWINCH);
- if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
- SYSERROR("failed to block SIGWINCH.");
- ts->sigfd = -1;
- return ts;
- }
+ ts->sigfd = signalfd(-1, &mask, 0);
+ if (ts->sigfd < 0) {
+ SYSERROR("failed to get signalfd.");
+ sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
+ ts->sigfd = -1;
+ return ts;
+ }
- ts->sigfd = signalfd(-1, &mask, 0);
- if (ts->sigfd < 0) {
- SYSERROR("failed to get signalfd.");
- sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
- ts->sigfd = -1;
- return ts;
+ DEBUG("%d got SIGWINCH fd %d", getpid(), ts->sigfd);
}
-
- DEBUG("%d got SIGWINCH fd %d", getpid(), ts->sigfd);
return ts;
}
@@ -647,16 +649,15 @@ int lxc_console(struct lxc_container *c, int ttynum,
struct lxc_epoll_descr descr;
struct termios oldtios;
struct lxc_tty_state *ts;
+ int istty = 0;
- if (!isatty(stdinfd)) {
- ERROR("stdin is not a tty");
- return -1;
- }
-
- ret = lxc_setup_tios(stdinfd, &oldtios);
- if (ret) {
- ERROR("failed to setup tios");
- return -1;
+ istty = isatty(stdinfd);
+ if (istty) {
+ ret = lxc_setup_tios(stdinfd, &oldtios);
+ if (ret) {
+ ERROR("failed to setup tios");
+ return -1;
+ }
}
ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
@@ -684,8 +685,10 @@ int lxc_console(struct lxc_container *c, int ttynum,
ts->winch_proxy = c->name;
ts->winch_proxy_lxcpath = c->config_path;
- lxc_console_winsz(stdinfd, masterfd);
- lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
+ if (istty) {
+ lxc_console_winsz(stdinfd, masterfd);
+ lxc_cmd_console_winch(ts->winch_proxy, ts->winch_proxy_lxcpath);
+ }
ret = lxc_mainloop_open(&descr);
if (ret) {
@@ -733,8 +736,8 @@ int lxc_console(struct lxc_container *c, int ttynum,
close(masterfd);
close(ttyfd);
err1:
- tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
+ if (istty)
+ tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
return ret;
}
-
More information about the lxc-devel
mailing list