fix: detect storage:exec TTY with isatty, not ModeCharDevice

/dev/null is a character device but not a terminal. Treating it as a TTY
made docker run -it fail under docker exec without -t, which broke the
Dokku-in-Docker storage bats job in CI.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-10-16 11:52:01 -04:00
1 parent f768eb6d07
commit 3dafdcb3f9
3 files changed
+55 -7

No files matched your search

+9 -6
View File
@@ -9,6 +9,7 @@ import (
"strings"
"github.com/dokku/dokku/plugins/common"
"github.com/mattn/go-isatty"
)
// CommandCreateInput captures the flags accepted by storage:create.
@@ -422,14 +423,16 @@ func CommandExec(input CommandExecInput) error {
// stdinModes inspects os.Stdin to decide whether docker / the k8s exec
// SDK should request an interactive session and a TTY.
//
// TTY detection uses isatty rather than ModeCharDevice: /dev/null is a
// character device but not a terminal, and treating it as a TTY makes
// docker run -it fail with "cannot attach stdin to a TTY-enabled
// container because stdin is not a terminal" (e.g. docker exec without
// -t, as in CI).
func stdinModes() (interactive bool, tty bool) {
tty = isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
fi, err := os.Stdin.Stat()
if err != nil || fi == nil {
return false, false
}
mode := fi.Mode()
tty = mode&os.ModeCharDevice != 0
hasStdinData := mode&os.ModeNamedPipe != 0
hasStdinData := err == nil && fi != nil && fi.Mode()&os.ModeNamedPipe != 0
interactive = tty || hasStdinData
return interactive, tty
}