mirror of
https://github.com/containers/podman.git
synced 2025-10-19 12:12:36 +08:00
Check tty flag to set default terminal in Env
First, all the defaults for TERM=xterm were removed from c/common, then accordingly the same will be added if encountered a set tty flag. Signed-off-by: Chetan Giradkar <cgiradka@redhat.com>
This commit is contained in:
1
pkg/env/env.go
vendored
1
pkg/env/env.go
vendored
@ -32,7 +32,6 @@ const whiteSpaces = " \t"
|
|||||||
func DefaultEnvVariables() map[string]string {
|
func DefaultEnvVariables() map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||||
"TERM": "xterm",
|
|
||||||
"container": "podman",
|
"container": "podman",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,12 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
|
|||||||
defaultEnvs = envLib.Join(envLib.DefaultEnvVariables(), envLib.Join(defaultEnvs, envs))
|
defaultEnvs = envLib.Join(envLib.DefaultEnvVariables(), envLib.Join(defaultEnvs, envs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add default terminal to env if tty flag is set
|
||||||
|
_, ok := defaultEnvs["TERM"]
|
||||||
|
if s.Terminal && !ok {
|
||||||
|
defaultEnvs["TERM"] = "xterm"
|
||||||
|
}
|
||||||
|
|
||||||
for _, e := range s.EnvMerge {
|
for _, e := range s.EnvMerge {
|
||||||
processedWord, err := imagebuilder.ProcessWord(e, envLib.Slice(defaultEnvs))
|
processedWord, err := imagebuilder.ProcessWord(e, envLib.Slice(defaultEnvs))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -818,9 +818,18 @@ EOF
|
|||||||
|
|
||||||
@test "podman run defaultenv" {
|
@test "podman run defaultenv" {
|
||||||
run_podman run --rm $IMAGE printenv
|
run_podman run --rm $IMAGE printenv
|
||||||
assert "$output" =~ "TERM=xterm" "env includes TERM"
|
assert "$output" !~ "TERM=" "env doesn't include TERM by default"
|
||||||
assert "$output" =~ "container=podman" "env includes container=podman"
|
assert "$output" =~ "container=podman" "env includes container=podman"
|
||||||
|
|
||||||
|
run_podman 1 run -t=false --rm $IMAGE printenv TERM
|
||||||
|
assert "$output" == "" "env doesn't include TERM"
|
||||||
|
|
||||||
|
run_podman run -t=true --rm $IMAGE printenv TERM # uses CRLF terminators
|
||||||
|
assert "$output" == $'xterm\r' "env includes default TERM"
|
||||||
|
|
||||||
|
run_podman run -t=false -e TERM=foobar --rm $IMAGE printenv TERM
|
||||||
|
assert "$output" == "foobar" "env includes TERM"
|
||||||
|
|
||||||
run_podman run --unsetenv=TERM --rm $IMAGE printenv
|
run_podman run --unsetenv=TERM --rm $IMAGE printenv
|
||||||
assert "$output" =~ "container=podman" "env includes container=podman"
|
assert "$output" =~ "container=podman" "env includes container=podman"
|
||||||
assert "$output" != "TERM" "unwanted TERM environment variable despite --unsetenv=TERM"
|
assert "$output" != "TERM" "unwanted TERM environment variable despite --unsetenv=TERM"
|
||||||
|
@ -372,7 +372,6 @@ _EOF
|
|||||||
is "$output" bin "expect container within pod to run as the bin user"
|
is "$output" bin "expect container within pod to run as the bin user"
|
||||||
run_podman inspect --format "{{ .Config.Env }}" test_pod-test
|
run_podman inspect --format "{{ .Config.Env }}" test_pod-test
|
||||||
is "$output" ".*PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.*" "expect PATH to be set"
|
is "$output" ".*PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.*" "expect PATH to be set"
|
||||||
is "$output" ".*TERM=xterm.*" "expect TERM to be set"
|
|
||||||
is "$output" ".*container=podman.*" "expect container to be set"
|
is "$output" ".*container=podman.*" "expect container to be set"
|
||||||
|
|
||||||
run_podman stop -a -t 0
|
run_podman stop -a -t 0
|
||||||
|
Reference in New Issue
Block a user