dev_container: Simplify interactive/tty logic

Always enable interactive mode when a tty is present. This allows
commands to receive SIGINT.
Otherwise, still allocate a pseudo tty to enable proper console
output.

BUG=b:275613273
TEST=dev_container presubmit - then CTRL-C

Change-Id: I7fb5c6897404f7d3e9f70755c237da0fd8b82c41
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4475490
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
This commit is contained in:
Dennis Kempin 2023-04-25 14:41:11 -07:00 committed by crosvm LUCI
parent e804cf38d5
commit 25b8e44250

View file

@ -199,7 +199,6 @@ def main(
stop: bool = False,
clean: bool = False,
hermetic: bool = False,
interactive: bool = False,
use_docker: bool = False,
self_test: bool = False,
pull: bool = False,
@ -268,13 +267,10 @@ def main(
docker("pull", f"gcr.io/crosvm-infra/crosvm_dev:{DEV_IMAGE_VERSION}").fg()
return
# If a command is provided run non-interactive unless explicitly asked for.
tty_args = []
if not command or interactive:
if not sys.stdin.isatty():
raise Exception("Trying to run an interactive session in a non-interactive terminal.")
# Default to interactive mode if a tty is present.
if sys.stdin.isatty():
tty_args = ["--interactive", "--tty"]
elif sys.stdin.isatty():
else:
# Even if run non-interactively, we do want to pass along a tty for proper output.
tty_args = ["--tty"]