The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/5526

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber <[email protected]>
From 1a22b1956d85c501573f7446a9203359bafae958 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]>
Date: Tue, 26 Feb 2019 09:12:04 +0100
Subject: [PATCH] lxc/exec: Cleanup terminal logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <[email protected]>
---
 lxc/exec.go | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/lxc/exec.go b/lxc/exec.go
index b130e81a9d..28610e71fd 100644
--- a/lxc/exec.go
+++ b/lxc/exec.go
@@ -154,8 +154,13 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) 
error {
        }
 
        // Configure the terminal
-       cfd := int(syscall.Stdin)
+       stdinFd := int(syscall.Stdin)
+       stdoutFd := int(syscall.Stdout)
 
+       stdinTerminal := termios.IsTerminal(stdinFd)
+       stdoutTerminal := termios.IsTerminal(stdoutFd)
+
+       // Determine interaction mode
        var interactive bool
        if c.flagDisableStdin {
                interactive = false
@@ -164,25 +169,29 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) 
error {
        } else if c.flagMode == "non-interactive" || c.flagForceNonInteractive {
                interactive = false
        } else {
-               interactive = termios.IsTerminal(cfd) && 
termios.IsTerminal(int(syscall.Stdout))
+               interactive = stdinTerminal && stdoutTerminal
        }
 
+       // Record terminal state
        var oldttystate *termios.State
-       if interactive {
-               oldttystate, err = termios.MakeRaw(cfd)
+       if interactive && stdinTerminal {
+               oldttystate, err = termios.MakeRaw(stdinFd)
                if err != nil {
                        return err
                }
-               defer termios.Restore(cfd, oldttystate)
+
+               defer termios.Restore(stdinFd, oldttystate)
        }
 
+       // Setup interactive console handler
        handler := c.controlSocketHandler
        if !interactive {
                handler = nil
        }
 
+       // Grab current terminal dimensions
        var width, height int
-       if interactive {
+       if stdoutTerminal {
                width, height, err = termios.GetSize(int(syscall.Stdout))
                if err != nil {
                        return err
@@ -239,7 +248,7 @@ func (c *cmdExec) Run(cmd *cobra.Command, args []string) 
error {
                 * Additionally, since os.Exit() exits without running deferred
                 * functions, we restore the terminal explicitly.
                 */
-               termios.Restore(cfd, oldttystate)
+               termios.Restore(stdinFd, oldttystate)
        }
 
        os.Exit(int(opAPI.Metadata["return"].(float64)))
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to