Skip to content

Commit a0bf76b

Browse files
committed
cmd/run, doc/toolbox-run: 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 03c6989 commit a0bf76b

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

@@ -59,6 +60,12 @@ func init() {
5960
"",
6061
"Run command inside a toolbox container for a different operating system release than the host.")
6162

63+
flags.BoolVarP(&runFlags.noTty,
64+
"no-tty",
65+
"T",
66+
false,
67+
"Run command without allocating a pseudo-TTY.")
68+
6269
runCmd.SetHelpFunc(runHelp)
6370
rootCmd.AddCommand(runCmd)
6471
}
@@ -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
@@ -71,6 +71,7 @@ toolbox_container_prefix_default=""
7171
toolbox_image=""
7272
toolbox_runtime_directory="$XDG_RUNTIME_DIR"/toolbox
7373
user_id_real=$(id -ru 2>&3)
74+
tty=true
7475
verbose=false
7576

7677

@@ -1582,13 +1583,17 @@ run()
15821583

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

1586+
extra_podman_args=()
1587+
if "$tty"; then
1588+
extra_podman_args+=(--tty)
1589+
fi
15851590
# shellcheck disable=SC2016
15861591
# for the command passed to capsh
15871592
# shellcheck disable=SC2086
15881593
$podman_command exec \
15891594
--interactive \
1590-
--tty \
15911595
--user "$USER" \
1596+
"${extra_podman_args[@]}" \
15921597
--workdir "$PWD" \
15931598
$set_environment \
15941599
"$toolbox_container" \
@@ -2611,6 +2616,9 @@ case $op in
26112616
exit_if_non_positive_argument --release "$arg"
26122617
release=$arg
26132618
;;
2619+
-T | --no-tty )
2620+
tty=false
2621+
;;
26142622
* )
26152623
exit_if_unrecognized_option "$1"
26162624
esac

0 commit comments

Comments
 (0)