From 939bed2a3ebf2a1c1ec36a38b746daab61294505 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 10 Apr 2020 19:33:45 -0700 Subject: [PATCH] runc exec: don't enable terminal unless -t is set If container's config.json have `"terminal": true` setting in its "process" section, runc exec assumes that stdin (fd 0) is a terminal and tries to use it. This leads to the following error in case stdin is not a terminal: > ERRO[0000] exec failed: provided file is not a console So, even if -t/--tty is not set, exec uses stdin as a terminal. It does not help that urfave/cli v1 parser we use does not allow to use `-t no` or `-t false`. Since the settings in config.json is probably for the container run/start, not for the auxiliary process started inside a container with exec, do not use a setting from there, only treating stdin as a terminal in case `-t` is explicitly given. Tests that use runc exec with a terminal are amended with -t. Signed-off-by: Kir Kolyshkin --- exec.go | 1 + tests/integration/tty.bats | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/exec.go b/exec.go index b963d68e018..6053ea970ce 100644 --- a/exec.go +++ b/exec.go @@ -203,6 +203,7 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) { p.Env = append(p.Env, context.StringSlice("env")...) // set the tty + p.Terminal = false if context.IsSet("tty") { p.Terminal = context.Bool("tty") } diff --git a/tests/integration/tty.bats b/tests/integration/tty.bats index 688875df326..47815ee2e1c 100644 --- a/tests/integration/tty.bats +++ b/tests/integration/tty.bats @@ -68,7 +68,7 @@ function teardown() { testcontainer test_busybox running # run the exec - runc exec test_busybox sh -c 'for file in /proc/self/fd/[012]; do readlink $file; done' + runc exec -t test_busybox sh -c 'for file in /proc/self/fd/[012]; do readlink $file; done' [ "$status" -eq 0 ] [[ ${lines[0]} =~ /dev/pts/+ ]] [[ ${lines[1]} =~ /dev/pts/+ ]] @@ -88,7 +88,7 @@ function teardown() { testcontainer test_busybox running # run the exec - runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' + runc exec -t test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' [ "$status" -eq 0 ] [[ ${lines[0]} =~ 0 ]] [[ ${lines[1]} =~ 5 ]] @@ -111,7 +111,7 @@ function teardown() { testcontainer test_busybox running # run the exec - runc exec test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' + runc exec -t test_busybox sh -c 'stat -c %u:%g $(tty) | tr : \\n' [ "$status" -eq 0 ] [[ ${lines[0]} =~ 1000 ]] [[ ${lines[1]} =~ 5 ]] @@ -146,7 +146,7 @@ EOF ) # run the exec - runc exec --pid-file pid.txt -d --console-socket $CONSOLE_SOCKET -p <( echo $tty_info_with_consize_size ) test_busybox + runc exec -t --pid-file pid.txt -d --console-socket $CONSOLE_SOCKET -p <( echo $tty_info_with_consize_size ) test_busybox [ "$status" -eq 0 ] # check the pid was generated @@ -167,7 +167,7 @@ EOF ) # run the exec - runc exec -p <( echo $tty_info ) test_busybox + runc exec -t -p <( echo $tty_info ) test_busybox [ "$status" -eq 0 ] # test tty width and height against original process.json