Merge pull request #359 from zsh-users/fixes/async-bad-file-descriptor

Fixes/async bad file descriptor
This commit is contained in:
Eric Freese 2018-07-13 20:50:31 -07:00 committed by GitHub
commit b8bf86f6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View File

@ -10,8 +10,9 @@ _zsh_autosuggest_async_request() {
# If we've got a pending request, cancel it # If we've got a pending request, cancel it
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
# Close the file descriptor # Close the file descriptor and remove the handler
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
# Zsh will make a new process group for the child process only if job # Zsh will make a new process group for the child process only if job
# control is enabled (MONITOR option) # control is enabled (MONITOR option)
@ -49,10 +50,14 @@ _zsh_autosuggest_async_request() {
# First arg will be fd ready for reading # First arg will be fd ready for reading
# Second arg will be passed in case of error # Second arg will be passed in case of error
_zsh_autosuggest_async_response() { _zsh_autosuggest_async_response() {
if [[ -z "$2" || "$2" == "hup" ]]; then
# Read everything from the fd and give it as a suggestion # Read everything from the fd and give it as a suggestion
zle autosuggest-suggest -- "$(cat <&$1)" zle autosuggest-suggest -- "$(cat <&$1)"
# Remove the handler and close the fd # Close the fd
zle -F "$1"
exec {1}<&- exec {1}<&-
fi
# Always remove the handler
zle -F "$1"
} }

View File

@ -689,8 +689,9 @@ _zsh_autosuggest_async_request() {
# If we've got a pending request, cancel it # If we've got a pending request, cancel it
if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then if [[ -n "$_ZSH_AUTOSUGGEST_ASYNC_FD" ]] && { true <&$_ZSH_AUTOSUGGEST_ASYNC_FD } 2>/dev/null; then
# Close the file descriptor # Close the file descriptor and remove the handler
exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&- exec {_ZSH_AUTOSUGGEST_ASYNC_FD}<&-
zle -F $_ZSH_AUTOSUGGEST_ASYNC_FD
# Zsh will make a new process group for the child process only if job # Zsh will make a new process group for the child process only if job
# control is enabled (MONITOR option) # control is enabled (MONITOR option)
@ -728,12 +729,16 @@ _zsh_autosuggest_async_request() {
# First arg will be fd ready for reading # First arg will be fd ready for reading
# Second arg will be passed in case of error # Second arg will be passed in case of error
_zsh_autosuggest_async_response() { _zsh_autosuggest_async_response() {
if [[ -z "$2" || "$2" == "hup" ]]; then
# Read everything from the fd and give it as a suggestion # Read everything from the fd and give it as a suggestion
zle autosuggest-suggest -- "$(cat <&$1)" zle autosuggest-suggest -- "$(cat <&$1)"
# Remove the handler and close the fd # Close the fd
zle -F "$1"
exec {1}<&- exec {1}<&-
fi
# Always remove the handler
zle -F "$1"
} }
#--------------------------------------------------------------------# #--------------------------------------------------------------------#