]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
DO NOT add the handles of adjust winsize when the 'stdin' is not a tty
authorLi Feng <lifeng68@huawei.com>
Sat, 20 May 2017 09:40:36 +0000 (17:40 +0800)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 29 Nov 2017 11:52:32 +0000 (12:52 +0100)
Signed-off-by: Li Feng <lifeng68@huawei.com>
src/lxc/console.c

index 86bc4a95682480a1dcb8092a4443bf65bf62a192..6a2fc72fd910de734a4ee8db2d922627692ccc16 100644 (file)
@@ -121,6 +121,11 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
        ts->masterfd = dstfd;
        ts->sigfd = -1;
 
+       if (!isatty(srcfd)) {
+               INFO("fd %d does not refer to a tty device", srcfd);
+               return ts;
+       }
+
        /* 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);
@@ -128,20 +133,20 @@ struct lxc_tty_state *lxc_console_sigwinch_init(int srcfd, int dstfd)
        sigemptyset(&mask);
        sigaddset(&mask, SIGWINCH);
        if (sigprocmask(SIG_BLOCK, &mask, &ts->oldmask)) {
-               SYSERROR("failed to block SIGWINCH.");
+               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.");
+               SYSERROR("failed to create signal fd");
                sigprocmask(SIG_SETMASK, &ts->oldmask, NULL);
                ts->sigfd = -1;
                return ts;
        }
 
-       DEBUG("%d got SIGWINCH fd %d", getpid(), ts->sigfd);
+       DEBUG("process %d created signal fd %d to handle SIGWINCH events", getpid(), ts->sigfd);
        return ts;
 }
 
@@ -656,16 +661,17 @@ 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 terminal properties");
+                       return -1;
+               }
+       } else {
+               INFO("fd %d does not refer to a tty device", stdinfd);
        }
 
        ttyfd = lxc_cmd_console(c->name, &ttynum, &masterfd, c->config_path);
@@ -687,8 +693,10 @@ int lxc_console(struct lxc_container *c, int ttynum,
        ts->winch_proxy_lxcpath = c->config_path;
        ts->stdoutfd = stdoutfd;
 
-       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) {
@@ -745,8 +753,10 @@ err2:
        close(masterfd);
        close(ttyfd);
 err1:
-       tcsetattr(stdinfd, TCSAFLUSH, &oldtios);
+       if (istty) {
+               if (tcsetattr(stdinfd, TCSAFLUSH, &oldtios) < 0)
+                       WARN("failed to reset terminal properties: %s.", strerror(errno));
+       }
 
        return ret;
 }
-