Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e72927f

Browse files
authored
fix: Avoid running shell twice in coder agent (#5061)
The users login shell would be executed as: /bin/bash -c '/bin/bash -l' This simplifies the command for login shells so that the executed command is: /bin/bash -l
1 parent c515085 commit e72927f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

agent/agent.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,25 +561,26 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
561561
return nil, xerrors.Errorf("metadata is the wrong type: %T", metadata)
562562
}
563563

564+
// OpenSSH executes all commands with the users current shell.
565+
// We replicate that behavior for IDE support.
566+
caller := "-c"
567+
if runtime.GOOS == "windows" {
568+
caller = "/c"
569+
}
570+
args := []string{caller, rawCommand}
571+
564572
// gliderlabs/ssh returns a command slice of zero
565573
// when a shell is requested.
566-
command := rawCommand
567-
if len(command) == 0 {
568-
command = shell
574+
if len(rawCommand) == 0 {
575+
args = []string{}
569576
if runtime.GOOS != "windows" {
570577
// On Linux and macOS, we should start a login
571578
// shell to consume juicy environment variables!
572-
command += " -l"
579+
args = append(args, "-l")
573580
}
574581
}
575582

576-
// OpenSSH executes all commands with the users current shell.
577-
// We replicate that behavior for IDE support.
578-
caller := "-c"
579-
if runtime.GOOS == "windows" {
580-
caller = "/c"
581-
}
582-
cmd := exec.CommandContext(ctx, shell, caller, command)
583+
cmd := exec.CommandContext(ctx, shell, args...)
583584
cmd.Dir = metadata.Directory
584585
if cmd.Dir == "" {
585586
// Default to $HOME if a directory is not set!

0 commit comments

Comments
 (0)