Skip to content

Commit

Permalink
cmd/run, doc/toolbox-run, sh: Add flag --no-tty/-T to run command.
Browse files Browse the repository at this point in the history
Summary:
VSCode remote SSH extension needs to run commands inside toolbox without
a TTY, otherwise it fails. With this patch, vscode can connect to
toolbox in a remote host if you put `RemoteCommand toolbox run -T bash`
in ssh config; it should work as well if using `authorized_keys`
instead. The naming of `-T` option is borrowed from `ssh -T`.

containers#587
  • Loading branch information
likan999 committed Nov 4, 2020
1 parent 43957e7 commit b5d4b43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion doc/toolbox-run.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ toolbox\-run - Run a command in an existing toolbox container

## SYNOPSIS
**toolbox run** [*--container NAME* | *-c NAME*]
[*--release RELEASE* | *-r RELEASE*] [*COMMAND*]
[*--release RELEASE* | *-r RELEASE*]
[*--no-tty* | *-T*] [*COMMAND*]

## DESCRIPTION

Expand Down Expand Up @@ -34,6 +35,10 @@ or entirely customized containers created from custom-built base images.
Run command inside a toolbox container for a different operating system
RELEASE than the host.

**--no-tty**, **-T**

Don't allocate pseudo-TTY.

## EXAMPLES

### Run ls inside a toolbox container using the default image matching the host OS
Expand Down
12 changes: 11 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
runFlags struct {
container string
release string
noTty bool
}
)

Expand All @@ -53,6 +54,12 @@ func init() {
"",
"Run command inside a toolbox container with the given name.")

flags.BoolVarP(&runFlags.noTty,
"no-tty",
"T",
false,
"Run command without allocating a pseudo-TTY.")

flags.StringVarP(&runFlags.release,
"release",
"r",
Expand Down Expand Up @@ -290,11 +297,14 @@ func runCommand(container string,

execArgs = append(execArgs, []string{
"--interactive",
"--tty",
"--user", currentUser.Username,
"--workdir", workingDirectory,
}...)

if !runFlags.noTty {
execArgs = append(execArgs, "--tty")
}

execArgs = append(execArgs, envOptions...)

execArgs = append(execArgs, []string{
Expand Down
10 changes: 9 additions & 1 deletion toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ toolbox_container_old_v2=""
toolbox_container_prefix_default=""
toolbox_hostname=toolbox
toolbox_image=""
toolbox_run_with_tty=true
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
user_id_real=$(id -ru 2>&3)
verbose=false
Expand Down Expand Up @@ -1585,13 +1586,17 @@ run()

$emit_escape_sequence && printf "\033]777;container;push;%s;toolbox\033\\" "$toolbox_container"

extra_podman_args=()
if "${toolbox_run_with_tty}"; then
extra_podman_args+=(--tty)
fi
# shellcheck disable=SC2016
# for the command passed to capsh
# shellcheck disable=SC2086
$podman_command exec \
--interactive \
--tty \
--user "$USER" \
"${extra_podman_args[@]}" \
--workdir "$PWD" \
$set_environment \
"$toolbox_container" \
Expand Down Expand Up @@ -2619,6 +2624,9 @@ case $op in
exit_if_non_positive_argument --release "$arg"
release=$arg
;;
-T | --no-tty )
toolbox_run_with_tty=false
;;
* )
exit_if_unrecognized_option "$1"
esac
Expand Down

0 comments on commit b5d4b43

Please sign in to comment.