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

Commit daa3f7a

Browse files
authored
fix: create login shell with coder sh (#224)
When creating a shell, we should use "exec -a" to set argv[0] to the basename of the command being run, prefixing a hyphen. This is how su --login creates login shells: it runs /bin/bash as "-bash", causing bash to execute .bash_profile, etc. We change the use of awk to cut, since cut is part of coreutils and thus more likely to be installed than gawk. We also pass the uid (from "id -u") instead of username to getent.
1 parent ae35620 commit daa3f7a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

internal/cmd/shell.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func shell(cmd *cobra.Command, cmdArgs []string) error {
8585
args = append(args, strings.Join(cmdArgs[1:], " "))
8686
} else {
8787
// Bring user into shell if no command is specified.
88-
args = append(args, "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')")
88+
shell := "$(getent passwd $(id -u) | cut -d: -f 7)"
89+
name := "-$(basename " + shell + ")"
90+
args = append(args, fmt.Sprintf("exec -a %q %q", name, shell))
8991
}
9092

9193
envName := cmdArgs[0]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy