Run startup command in interactive AND login shells#67
Open
jmcphers wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relates to posit-dev/positron#13949
Summary
When a kernel is launched with a startup command or script, the supervisor ran it in a plain interactive shell. That was introduced in df17d2b to pick up environment setup users put in interactive rc files (
~/.bashrc,~/.zshrc).The problem: a non-login interactive shell sources
~/.bashrcbut not the system profile scripts (/etc/profile,/etc/profile.d/*). On many systems themodulecommand (Lmod / Environment Modules) is only defined for login shells, via/etc/profile.d. So amodule load ...startup command failed at launch withmodule: command not found, even though interpreter discovery (which uses a login shell) succeeded. bash's login and non-login-interactive startup-file sets are mutually exclusive, so a plain-ishell could never see the module setup.This PR runs startup-command/script kernels as a shell that is both a login and an interactive shell (e.g.
bash --login -i -c ...,zsh --login -i -c ...), so the environment picks up both the profile scripts (wheremodulelives) and the interactive rc files (where users put PATH and tool init). Plain shell mode (StartupEnvironment::Shell, no command) is unchanged: still a non-interactive login shell.Behavior by shell:
.zprofile(login) and.zshrc(interactive) unconditionally -- fully correct.~/.bashrcvia the standard~/.profile/~/.bash_profile->~/.bashrcchain shipped by default on the major distributions. The-iflag also satisfies thecase $- in *i*)interactivity guard at the top of~/.bashrc(e.g. conda's init block), which a login-only shell would skip.-i), since the-dlogin emulation can't combine with-creliably.This change fixes the module case at the supervisor layer (it also benefits any other startup command that depends on login-only init) and is complementary to the Positron-side fix in posit-dev/positron#13949, which makes the module startup command self-source its init script.
Caveat
A bash user who relies on
~/.bashrc-only setup via a startup command and whose~/.bash_profileexists but does not source~/.bashrcwill no longer pick up~/.bashrchere (a login shell reaches profile files, not~/.bashrc, unless chained). This is uncommon -- such a setup also breaks the user's own login terminals -- and zsh is unaffected. Documented in the code.Validation
cargo test -p kcserver --lib shell_wrapper-- new unit tests cover flag selection for login mode, login+interactive mode, and the csh fallback.moduleis defined only in login shells, configure an environment module for R or Python in Positron and start a session. Before this change the kernel fails withmodule: command not found; after, it starts.