Skip to content

Commit b5d4b43

Browse files
committed
cmd/run, doc/toolbox-run, sh: Add flag --no-tty/-T to run command.
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
1 parent 43957e7 commit b5d4b43

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

doc/toolbox-run.1.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ toolbox\-run - Run a command in an existing toolbox container
55

66
## SYNOPSIS
77
**toolbox run** [*--container NAME* | *-c NAME*]
8-
[*--release RELEASE* | *-r RELEASE*] [*COMMAND*]
8+
[*--release RELEASE* | *-r RELEASE*]
9+
[*--no-tty* | *-T*] [*COMMAND*]
910

1011
## DESCRIPTION
1112

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

38+
**--no-tty**, **-T**
39+
40+
Don't allocate pseudo-TTY.
41+
3742
## EXAMPLES
3843

3944
### Run ls inside a toolbox container using the default image matching the host OS

src/cmd/run.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
runFlags struct {
3535
container string
3636
release string
37+
noTty bool
3738
}
3839
)
3940

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

57+
flags.BoolVarP(&runFlags.noTty,
58+
"no-tty",
59+
"T",
60+
false,
61+
"Run command without allocating a pseudo-TTY.")
62+
5663
flags.StringVarP(&runFlags.release,
5764
"release",
5865
"r",
@@ -290,11 +297,14 @@ func runCommand(container string,
290297

291298
execArgs = append(execArgs, []string{
292299
"--interactive",
293-
"--tty",
294300
"--user", currentUser.Username,
295301
"--workdir", workingDirectory,
296302
}...)
297303

304+
if !runFlags.noTty {
305+
execArgs = append(execArgs, "--tty")
306+
}
307+
298308
execArgs = append(execArgs, envOptions...)
299309

300310
execArgs = append(execArgs, []string{

toolbox

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ toolbox_container_old_v2=""
7272
toolbox_container_prefix_default=""
7373
toolbox_hostname=toolbox
7474
toolbox_image=""
75+
toolbox_run_with_tty=true
7576
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
7677
user_id_real=$(id -ru 2>&3)
7778
verbose=false
@@ -1585,13 +1586,17 @@ run()
15851586

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

1589+
extra_podman_args=()
1590+
if "${toolbox_run_with_tty}"; then
1591+
extra_podman_args+=(--tty)
1592+
fi
15881593
# shellcheck disable=SC2016
15891594
# for the command passed to capsh
15901595
# shellcheck disable=SC2086
15911596
$podman_command exec \
15921597
--interactive \
1593-
--tty \
15941598
--user "$USER" \
1599+
"${extra_podman_args[@]}" \
15951600
--workdir "$PWD" \
15961601
$set_environment \
15971602
"$toolbox_container" \
@@ -2619,6 +2624,9 @@ case $op in
26192624
exit_if_non_positive_argument --release "$arg"
26202625
release=$arg
26212626
;;
2627+
-T | --no-tty )
2628+
toolbox_run_with_tty=false
2629+
;;
26222630
* )
26232631
exit_if_unrecognized_option "$1"
26242632
esac

0 commit comments

Comments
 (0)