Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: closing stdin (Re: _make suppress error on OpenBSD.)
- X-seq: zsh-workers 11288
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: Tanaka Akira <akr@xxxxxxxx>, zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: closing stdin (Re: _make suppress error on OpenBSD.)
- Date: Wed, 10 May 2000 04:48:38 +0000
- In-reply-to: <hvohfc7h61c.fsf@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <hvoog6ggc41.fsf@xxxxxxxxxxxxxxx> <hvohfc7h61c.fsf@xxxxxxxxxxxxxxx>
On May 10, 4:34am, Tanaka Akira wrote:
} Subject: closing stdin (Re: _make suppress error on OpenBSD.)
}
} > coulee% make awk: i/o error occurred while closing /dev/stdin
}
} This problem is caused by the one true awk behavior. (OpenBSD comes
} with the one true awk.) The one true awk closes all file descriptors
} which should be opened when exit and complain if it causes an error.
}
[...]
}
} However, we can suppress the error by modifying each awk invocation,
} but I think that completion system should redirect stdin from
} /dev/null instead of closing it.
It's a little more complex than this.
Descriptor 0 is being closed by movefd(0) which is called from zle_main()
before executing any user-defined widget, completion or otherwise. This
explains why it doesn't work to invoke e.g. vim from a widget function.
This has some odd side effects, including that assorted opens for things
like shared library loading and directory scans for path searching can end
up using FD 0 temporarily (look at strace output). (Memory mapping of
autoloaded functions also sometimes gets FD 0 but immediately movefd()s it
elsewhere.)
It makes more sense to me from the standpoint of the shell's internals to
simply close FD 0 rather than reopen it on /dev/null. On the other hand,
I've long forgotten (if I ever knew) why the stdin of ZLE functions is
closed. (Zefram?) It's trivial to reopen it again:
function vi-vi-buffer() {
local tmp=${TMPPREFIX}${$}vi
print -R - $BUFFER >| $tmp
vi $tmp </dev/tty # Reopen stdin closed by ZLE
BUFFER="$(<$tmp)"
}
zle -N vi-vi-buffer
bindkey -v ; bindkey -a v vi-vi-buffer
On the other hand, it's probably a good idea that `exec < file' in a widget
doesn't change the whole shell's standard input, so duping and restoring FD
0 is good even if closing it may not be.
In any case, that latter suggests what I think is the best solution for the
completion system.
Index: Completion/Commands/_complete_help
===================================================================
@@ -3,6 +3,7 @@
_complete_help() {
setopt localoptions nullglob rcexpandparam extendedglob
unsetopt markdirs globsubst shwordsplit nounset ksharrays
+ exec </dev/null # ZLE closes stdin, which can cause errors
local _sort_tags=_help_sort_tags text i j k
typeset -A help_funcs help_tags help_sfuncs help_styles
Index: Completion/Core/_main_complete
===================================================================
@@ -18,6 +18,7 @@
setopt localoptions nullglob rcexpandparam extendedglob
unsetopt markdirs globsubst shwordsplit nounset ksharrays
+exec </dev/null # ZLE closes stdin, which can cause errors
local func funcs ret=1 tmp _compskip format nm \
_completers _completer _completer_num curtag _comp_force_list \
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author