bash: avoid subprocess spawns during interactive shell startup
On the live image, a fork/exec during login-shell startup can stall the shell before its first prompt. Replace command substitutions with pure builtins in the startup path: - bash.bashrc: read /etc/redox_chroot with the 'read' builtin instead of $(cat ...) - profile: derive the root prompt from EUID/USER/LOGNAME (set by login(1)) instead of $(id -u) - skel/.bashrc: disable lesspipe and dircolors eval (both spawn subprocesses); keep the ls --color=auto alias
This commit is contained in:
@@ -11,8 +11,11 @@
|
||||
shopt -s checkwinsize
|
||||
|
||||
# TODO: redox_chroot
|
||||
# Read the file with the `read` builtin instead of `$(cat ...)`: a command
|
||||
# substitution here fork/execs a subprocess, and a spawn during interactive
|
||||
# shell startup can stall the shell on the live image before its first prompt.
|
||||
if [ -z "${redox_chroot:-}" ] && [ -r /etc/redox_chroot ]; then
|
||||
redox_chroot=$(cat /etc/redox_chroot)
|
||||
read -r redox_chroot < /etc/redox_chroot 2>/dev/null || redox_chroot=
|
||||
fi
|
||||
|
||||
# set a fancy prompt (non-color, overwrite the one in /etc/profile)
|
||||
|
||||
@@ -9,7 +9,12 @@ if [ "${PS1-}" ]; then
|
||||
. /etc/bash.bashrc
|
||||
fi
|
||||
else
|
||||
if [ "$(id -u)" -eq 0 ]; then
|
||||
# Do NOT spawn a subprocess here (the old `$(id -u)` command substitution).
|
||||
# A login shell sources this file before drawing its first prompt; on Redox
|
||||
# a process spawn during that window can stall, hanging the shell before it
|
||||
# is ever usable. Use the shell/login-provided EUID or USER instead — both
|
||||
# are set by login(1) — so this stays a pure builtin test with no fork/exec.
|
||||
if [ "${EUID-}" = 0 ] || [ "${USER-}" = root ] || [ "${LOGNAME-}" = root ]; then
|
||||
PS1='# '
|
||||
else
|
||||
PS1='$ '
|
||||
|
||||
@@ -26,7 +26,9 @@ shopt -s checkwinsize
|
||||
#shopt -s globstar
|
||||
|
||||
# make less more friendly for non-text input files, see lesspipe(1)
|
||||
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
# lesspipe disabled: `$(lesspipe)` spawns a subprocess during shell startup,
|
||||
# which can stall the shell on the live image before its first prompt.
|
||||
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
|
||||
|
||||
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||
case "$TERM" in
|
||||
@@ -58,7 +60,9 @@ unset color_prompt force_color_prompt
|
||||
|
||||
# enable color support of ls and also add handy aliases
|
||||
if [ -x /usr/bin/dircolors ]; then
|
||||
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
||||
# dircolors disabled: `$(dircolors -b)` spawns a subprocess during shell
|
||||
# startup, which can stall the shell on the live image before its prompt.
|
||||
# test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
||||
alias ls='ls --color=auto'
|
||||
#alias dir='dir --color=auto'
|
||||
#alias vdir='vdir --color=auto'
|
||||
|
||||
Reference in New Issue
Block a user