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

Create login shell with coder sh #224

Merged
merged 1 commit into from
Jan 22, 2021
Merged

Create login shell with coder sh #224

merged 1 commit into from
Jan 22, 2021

Conversation

jawnsy
Copy link
Contributor

@jawnsy jawnsy commented Jan 22, 2021

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.

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.
@jawnsy jawnsy self-assigned this Jan 22, 2021
@shortcut-integration
Copy link

This pull request has been linked to Clubhouse Story #418: Use a login shell for terminals.

@cmoog
Copy link
Contributor

cmoog commented Jan 22, 2021

@jawnsy no need to use a fork. I think you should have the proper perms to push to a branch in cdr/coder-cli. Let me know if that's not the case.

@jawnsy
Copy link
Contributor Author

jawnsy commented Jan 22, 2021

@jawnsy no need to use a fork. I think you should have the proper perms to push to a branch in cdr/coder-cli. Let me know if that's not the case.

Haha I like the forking workflow, though 😁

@cmoog cmoog merged commit daa3f7a into coder:master Jan 22, 2021
@jawnsy jawnsy deleted the ch418 branch January 23, 2021 21:05
jawnsy added a commit that referenced this pull request Jan 24, 2021
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.
jawnsy added a commit that referenced this pull request Jan 25, 2021
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.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants