simplify worker bootstrap

pull/445/head
romkatv 5 years ago
parent 0ae338dde1
commit 1208fd10ef

@ -1,7 +1,7 @@
# invoked in worker: _p9k_worker_main <timeout> # invoked in worker: _p9k_worker_main <timeout>
function _p9k_worker_main() { function _p9k_worker_main() {
emulate -L zsh emulate -L zsh
setopt no_hist_expand extended_glob no_prompt_bang prompt_percent prompt_subst no_aliases setopt no_hist_expand extended_glob no_prompt_bang prompt_percent prompt_subst no_aliases no_bgnice
zmodload zsh/system || return zmodload zsh/system || return
zmodload zsh/zselect || return zmodload zsh/zselect || return
@ -15,6 +15,7 @@ function _p9k_worker_main() {
local -A inflight # fd => id$'\x1f'sync local -A inflight # fd => id$'\x1f'sync
local -ri _p9k_worker_runs_me=1 local -ri _p9k_worker_runs_me=1
{
while zselect -a ready 0 ${(k)inflight}; do while zselect -a ready 0 ${(k)inflight}; do
[[ $ready[1] == -r ]] || return [[ $ready[1] == -r ]] || return
for fd in ${ready:1}; do for fd in ${ready:1}; do
@ -59,6 +60,9 @@ function _p9k_worker_main() {
fi fi
done done
done done
} always {
kill -- -$$
}
} }
typeset -g _p9k__worker_pid typeset -g _p9k__worker_pid
@ -237,6 +241,7 @@ function _p9k_worker_receive() {
} }
function _p9k_worker_start() { function _p9k_worker_start() {
setopt no_bgnice
{ {
[[ -n $_p9k__worker_resp_fd ]] && return [[ -n $_p9k__worker_resp_fd ]] && return
_p9k__worker_file_prefix=${TMPDIR:-/tmp}/p10k.worker.$EUID.$$.$EPOCHSECONDS _p9k__worker_file_prefix=${TMPDIR:-/tmp}/p10k.worker.$EUID.$$.$EPOCHSECONDS
@ -253,17 +258,21 @@ function _p9k_worker_start() {
trace=x trace=x
local fifo=$_p9k__worker_file_prefix.fifo local fifo=$_p9k__worker_file_prefix.fifo
local cmd=(
'emulate zsh'
'{ mkfifo '${(q)fifo}' && exec >&4 && echo -n "s$$\x1e" && exec 0<'${(q)fifo}' || exit } always { rm -f '${(q)fifo}' }'
'IFS= read -rd $'\''\x1e'\'' && eval $REPLY')
local setsid=${commands[setsid]:-/usr/local/opt/util-linux/bin/setsid}
[[ -x $setsid ]] && setsid=${(q)setsid} || setsid=
local zsh=${${:-/proc/self/exe}:A} local zsh=${${:-/proc/self/exe}:A}
[[ -x $zsh ]] || zsh=zsh [[ -x $zsh ]] || zsh=zsh
cmd="$setsid ${(q)zsh} --nobgnice --noaliases -${trace}dfc ${(q)${(j:; :)cmd}} &!" local bootstrap=(
'"emulate" "-L" "zsh" "-o" "no_aliases"'
'{ mkfifo '${(q)fifo}' && exec >&4 && echo -n "s$$\x1e" && exec 0<'${(q)fifo}' || exit } always { rm -f '${(q)fifo}' }'
'IFS= read -rd $'\''\x1e'\'' && eval $REPLY')
local child='"eval" "$_p9k_worker_bootstrap" &!'
local parent=(
'"emulate" "-L" "zsh" "-o" "no_aliases" "-o" "no_bgnice"'
${(qqq)zsh}' -'${trace}'dfc '${(qqq)child}
)
sysopen -r -o cloexec -u _p9k__worker_resp_fd <( sysopen -r -o cloexec -u _p9k__worker_resp_fd <(
$zsh --nobgnice --noaliases -${trace}dfmc $cmd </dev/null 4>&1 &>>$log_file &!) || return _p9k_worker_bootstrap=${(j:; :)bootstrap} \
</dev/null 4>&1 &>>$log_file $zsh -${trace}dfmc \
${(j:; :)parent}) || return
zle -F $_p9k__worker_resp_fd _p9k_worker_receive zle -F $_p9k__worker_resp_fd _p9k_worker_receive
_p9k__worker_shell_pid=$sysparams[pid] _p9k__worker_shell_pid=$sysparams[pid]
add-zsh-hook zshexit _p9k_worker_cleanup add-zsh-hook zshexit _p9k_worker_cleanup

Loading…
Cancel
Save