mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-12-24 16:11:57 +00:00
workaround for a bug in sysread
There is a bug in sysread from zsh/system. It triggers in the following case: 1. zsh has been compiled with HAVE_SELECT and without HAVE_POLL. 2. sysread is called with timeout (-t). 3. the input file descriptor is valid but there is no data to read. 4. errno happens to be EINTR prior to the call to sysread. This results in an infinite loop in sysread: while ((ret = select(infd+1, (SELECT_ARG_2_T) &fds, NULL, NULL,&select_tv)) < 1) { if (errno != EINTR || errflag || retflag || breaks || contflag) break; } Here select() keeps returning 0, indicating timeout. This is not an error, so errno doesn't get set. If it was EINTR prior to the call, it stays EINTR, and the loop keeps spinning. As a workaround, powerlevel10k sets errno to ENOTTY (any value other than EINTR will do) prior to calling sysread with timeout.
This commit is contained in:
parent
a12f7ac8ee
commit
7354eeaa96
2 changed files with 23 additions and 16 deletions
|
@ -4154,22 +4154,27 @@ function _p9k_fetch_nordvpn_status() {
|
|||
>&$fd echo -nE - $'PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\0\0\0\4\1\0\0\0\0\0\0N\1\4\0\0\0\1\203\206E\221bA\226\223\325\\k\337\31i=LnH\323j?A\223\266\243y\270\303\fYmLT{$\357]R.\203\223\257_\213\35u\320b\r&=LMedz\212\232\312\310\264\307`+\210K\203@\2te\206M\2035\5\261\37\0\0\5\0\1\0\0\0\1\0\0\0\0\0'
|
||||
local tag len val
|
||||
local -i n
|
||||
IFS='' read -t 0.25 -r tag <&3
|
||||
tag=$'\015'
|
||||
while true; do
|
||||
tag=$((#tag))
|
||||
(( (tag >>= 3) && tag <= $#__p9k_nordvpn_tag )) || break
|
||||
tag=$__p9k_nordvpn_tag[tag]
|
||||
sysread -c n -s 1 -t 0.25 len <&3
|
||||
len=$((#len))
|
||||
val=
|
||||
(( ! len )) || {
|
||||
sysread -c n -s $len -t 0.25 val <&3
|
||||
(( n == len ))
|
||||
}
|
||||
typeset -g $tag=$val
|
||||
sysread -c n -s 1 -t 0.25 tag <&3
|
||||
done
|
||||
{
|
||||
IFS='' read -t 0.25 -r tag
|
||||
tag=$'\015'
|
||||
while true; do
|
||||
tag=$((#tag))
|
||||
(( (tag >>= 3) && tag <= $#__p9k_nordvpn_tag )) || break
|
||||
tag=$__p9k_nordvpn_tag[tag]
|
||||
[[ -t $fd ]] || true
|
||||
sysread -c n -s 1 -t 0.25 len
|
||||
len=$((#len))
|
||||
val=
|
||||
(( ! len )) || {
|
||||
[[ -t $fd ]] || true
|
||||
sysread -c n -s $len -t 0.25 val
|
||||
(( n == len ))
|
||||
}
|
||||
typeset -g $tag=$val
|
||||
[[ -t $fd ]] || true
|
||||
sysread -c n -s 1 -t 0.25 tag
|
||||
done
|
||||
} <&$fd
|
||||
} always {
|
||||
exec {fd}>&-
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ function _p9k_worker_main() {
|
|||
if [[ $fd == 0 ]]; then
|
||||
local buf=
|
||||
while true; do
|
||||
[[ -t 0 ]]
|
||||
sysread -t 0 'buf[$#buf+1]' && continue
|
||||
(( $? == 4 )) || return
|
||||
[[ $buf[-1] == (|$'\x1e') ]] && break
|
||||
|
@ -115,6 +116,7 @@ function _p9k_worker_receive() {
|
|||
|
||||
local buf resp
|
||||
while true; do
|
||||
[[ -t $_p9k__worker_resp_fd ]]
|
||||
sysread -t 0 -i $_p9k__worker_resp_fd 'buf[$#buf+1]' && continue
|
||||
(( $? == 4 )) || return
|
||||
[[ $buf == (|*$'\x1e')$'\x05'# ]] && break
|
||||
|
|
Loading…
Reference in a new issue