Skip to content

Commit

Permalink
only set term if rsh is running /bin/sh
Browse files Browse the repository at this point in the history
also set it without using env so it will work in containers
that don't have /bin/env
  • Loading branch information
bparees committed Jan 16, 2017
1 parent a5eaf99 commit 9a8cf9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/cmd/cli/cmd/rsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)

const RshRecommendedName = "rsh"
const (
RshRecommendedName = "rsh"
DefaultShell = "/bin/sh"
)

var (
rshLong = templates.LongDesc(`
Expand Down Expand Up @@ -94,7 +97,7 @@ func NewCmdRsh(name string, parent string, f *clientcmd.Factory, in io.Reader, o
}
cmd.Flags().BoolVarP(&options.ForceTTY, "tty", "t", false, "Force a pseudo-terminal to be allocated")
cmd.Flags().BoolVarP(&options.DisableTTY, "no-tty", "T", false, "Disable pseudo-terminal allocation")
cmd.Flags().StringVar(&options.Executable, "shell", "/bin/sh", "Path to the shell command")
cmd.Flags().StringVar(&options.Executable, "shell", DefaultShell, "Path to the shell command")
cmd.Flags().IntVar(&options.Timeout, "timeout", 10, "Request timeout for obtaining a pod from the server; defaults to 10 seconds")
cmd.Flags().StringVarP(&options.ContainerName, "container", "c", "", "Container name; defaults to first container")
cmd.Flags().SetInterspersed(false)
Expand Down Expand Up @@ -155,8 +158,9 @@ func (o *RshOptions) Validate() error {
// Run starts a remote shell session on the server
func (o *RshOptions) Run() error {
// Insert the TERM into the command to be run
term := fmt.Sprintf("TERM=%s", util.Env("TERM", "xterm"))
o.Command = append([]string{"env", term}, o.Command...)

if len(o.Command) == 1 && o.Command[0] == DefaultShell {
termsh := fmt.Sprintf("TERM=%q %s", util.Env("TERM", "xterm"), DefaultShell)
o.Command = append(o.Command, "-c", termsh)
}
return o.ExecOptions.Run()
}
11 changes: 11 additions & 0 deletions test/end-to-end/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ frontend_pod=$(oc get pod -l deploymentconfig=frontend --template='{{(index .ite
os::cmd::expect_success_and_text "oc exec -p ${frontend_pod} id" '1000'
os::cmd::expect_success_and_text "oc rsh pod/${frontend_pod} id -u" '1000'
os::cmd::expect_success_and_text "oc rsh -T ${frontend_pod} id -u" '1000'

# test that rsh inherits the TERM variable by default
oldterm=$TERM
TERM=test_terminal
# this must be done as an echo and not an argument to rsh because rsh only sets the TERM if
# no arguments are supplied.
os::cmd::expect_success_and_text "echo 'echo $TERM' | oc rsh ${frontend_pod}" $TERM
# and does not inherit it when the user provides a command.
os::cmd::expect_success_and_not_text "oc rsh ${frontend_pod} echo \$TERM" $TERM
TERM=$oldterm

# Wait for the rollout to finish
os::cmd::expect_success "oc rollout status dc/frontend --revision=1"
# Test retrieving application logs from dc
Expand Down

0 comments on commit 9a8cf9f

Please sign in to comment.