Re: [PATCH] compinit forks less

Charles Blake <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAKiz1a_Zaw5U45GQ3+Did5rGxhA9t6_00_LtW5gmuhfeGUCUZw@mail.gmail.com>
I had no problem with temp files per se - it was just a TOCTTOU race as
Dana explained well.

I also like Bart's alternative.  That patch applied, compiled, and ran
fine. I did strace it and the trace looks fine as it should from the
C source.  gettempfile seems more sound than gettempname.

Out of curiosity, I also strace'd `zsh -fc ': =(echo 1)'`.  That showed
O_EXCL also, though it seems there is a maybe no longer needed stat()?
I didn't look into the C.  Maybe a minor optimization opportunity.

Anyway, attached is an updated patch with Dana's approach in all 3 spots,
but with ':' as delimiter-delimiter rather than Dana's '<' '>' since ':'
is what the man page uses for that splitting expansion flag.  It seems
to work fine for me, but someone else should maybe give it a try.

Also, it may not matter, but on that, there seems to be a special rule
for space itself and `bindkey " "` formats as `" "-value` which breaks
both old and new parses, giving a 3-element array.  E.g.:
    bindkey ' ' | IFS=$' \t' read -A x; for e in $x;echo $e
compinitBindKeyNoFork.patch (text/x-patch, 1.2 KB)
diff --git a/Completion/compinit b/Completion/compinit
index 2bfd30f2e..c904dc6ef 100644
--- a/Completion/compinit
+++ b/Completion/compinit
@@ -344,7 +344,7 @@ compdef() {
         [[ $2 = .menu-select ]] && zmodload -i zsh/complist
 	zle -C "$1" "$2" "$func"
 	if [[ -n $new ]]; then
-	  bindkey "$3" | IFS=$' \t' read -A opt
+	  opt=( ${(s: :)${ bindkey "$3" }} )
 	  [[ $opt[-1] = undefined-key ]] && bindkey "$3" "$1"
 	else
 	  bindkey "$3" "$1"
@@ -371,7 +371,7 @@ compdef() {
       # And bind the keys...
       for i; do
         if [[ -n $new ]]; then
-	   bindkey "$i" | IFS=$' \t' read -A opt
+	   opt=( ${(s: :)${ bindkey "$i" }} )
 	   [[ $opt[-1] = undefined-key ]] || continue
 	fi
         bindkey "$i" "$func"
@@ -560,7 +560,7 @@ zle -la menu-select && zle -C menu-select .menu-select _main_complete
 
 # If the default completer set includes _expand, and tab is bound
 # to expand-or-complete, rebind it to complete-word instead.
-bindkey '^i' | IFS=$' \t' read -A _i_line
+_i_line=( ${(s: :)${ bindkey '^i' }} )
 if [[ ${_i_line[2]} = expand-or-complete ]] &&
   zstyle -a ':completion:' completer _i_line &&
   (( ${_i_line[(i)_expand]} <= ${#_i_line} )); then
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.