Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

fix: Force bash for non-standard flags to exec #226

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Force bash for non-standard flags to exec
This addresses a regression introduced by #224. POSIX sh does not
define arguments to the exec built-in, resulting in an error when
using 'exec -a' to set the process name (argv[0]).

This change executes /bin/bash instead of sh, and also changes
to use 'exec -l', which automatically handles the hyphen prefix
required to trigger login shell behavior.

This also explicitly runs /bin/sh, aligning the behavior of
"coder sh" and the frontend Terminal application.
  • Loading branch information
jawnsy committed Jan 24, 2021
commit 62734c38b082eeca2f696fe47507a04a2b5cda2c
13 changes: 9 additions & 4 deletions internal/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ coder sh front-end-dev cat ~/config.json`,

func shell(cmd *cobra.Command, cmdArgs []string) error {
ctx := cmd.Context()
command := "sh"
args := []string{"-c"}
var command string
var args []string
if len(cmdArgs) > 1 {
command = "/bin/sh"
args = []string{"-c"}
args = append(args, strings.Join(cmdArgs[1:], " "))
} else {
// Bring user into shell if no command is specified.
shell := "$(getent passwd $(id -u) | cut -d: -f 7)"
name := "-$(basename " + shell + ")"
args = append(args, fmt.Sprintf("exec -a %q %q", name, shell))

// force bash for the '-l' flag to the exec built-in
command = "/bin/bash"
args = []string{"-c"}
args = append(args, fmt.Sprintf("exec -l %q", shell))
}

envName := cmdArgs[0]
Expand Down