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

Commit 62734c3

Browse files
committed
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.
1 parent b8067c0 commit 62734c3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/cmd/shell.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,20 @@ coder sh front-end-dev cat ~/config.json`,
8282

8383
func shell(cmd *cobra.Command, cmdArgs []string) error {
8484
ctx := cmd.Context()
85-
command := "sh"
86-
args := []string{"-c"}
85+
var command string
86+
var args []string
8787
if len(cmdArgs) > 1 {
88+
command = "/bin/sh"
89+
args = []string{"-c"}
8890
args = append(args, strings.Join(cmdArgs[1:], " "))
8991
} else {
9092
// Bring user into shell if no command is specified.
9193
shell := "$(getent passwd $(id -u) | cut -d: -f 7)"
92-
name := "-$(basename " + shell + ")"
93-
args = append(args, fmt.Sprintf("exec -a %q %q", name, shell))
94+
95+
// force bash for the '-l' flag to the exec built-in
96+
command = "/bin/bash"
97+
args = []string{"-c"}
98+
args = append(args, fmt.Sprintf("exec -l %q", shell))
9499
}
95100

96101
envName := cmdArgs[0]

0 commit comments

Comments
 (0)