zsh-workers
 help / color / mirror / code / Atom feed
* Re: closing stdin (Re: _make suppress error on OpenBSD.)
@ 2000-05-10  7:20 Sven Wischnowsky
  2000-05-10 10:22 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Sven Wischnowsky @ 2000-05-10  7:20 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> ...
> 
> 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:

This was done (by me) in 6484. For messages leading up to this, see:
6462 etc. (subject `Re: forwarded bug report', original: 6383).

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: closing stdin (Re: _make suppress error on OpenBSD.)
  2000-05-10  7:20 closing stdin (Re: _make suppress error on OpenBSD.) Sven Wischnowsky
@ 2000-05-10 10:22 ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-05-10 10:22 UTC (permalink / raw)
  To: zsh-workers

On May 10,  9:20am, Sven Wischnowsky wrote:
} Subject: Re: closing stdin (Re: _make suppress error on OpenBSD.)
}
} Bart Schaefer wrote:
} 
} > I've long forgotten (if I ever knew) why the stdin of ZLE functions is
} > closed.
} 
} This was done (by me) in 6484. For messages leading up to this, see:
} 6462 etc.

Oh, goody, so it was even my idea.  Sigh.

This should be documented somewhere (for both completion and widgets); I
just tried searching the docs for the string "close" starting at "Zsh Line
Editor" and except for a couple of times in "enclosed" it's not mentioned
until you hit Zftp.  It probably would have saved Peter some grief when
trying to answer that recent vi question on zsh-users.

These may not be the best places to mention it, but they were the closest
that I could find.

Index: Doc/Zsh/compwid.yo
===================================================================
@@ -12,22 +12,27 @@
 
 example(zle -C complete expand-or-complete completer)
 
-defines a widget named tt(complete). When this widget is bound to a key
-using the tt(bindkey) builtin command defined in the tt(zsh/zle) module
-(see 
-ifzman(zmanref(zshzle))\
-ifnzman(noderef(Zsh Line Editor))\
-), typing that key will call the shell function tt(completer). This
-function is responsible for generating the possible matches using the
-builtins described below. Once the function returns, the completion code
-takes over control again and treats the matches as the builtin widget
-tt(expand-or-complete) would do.  For this second argument, the name of any
-of the builtin widgets that handle completions can be given:
+defines a widget named `tt(complete)'.  The second argument is the name
+of any of the builtin widgets that handle completions:
 tt(complete-word), tt(expand-or-complete),
 tt(expand-or-complete-prefix), tt(menu-complete),
 tt(menu-expand-or-complete), tt(reverse-menu-complete),
 tt(list-choices), or tt(delete-char-or-list).  Note that this will still
 work even if the widget in question has been rebound.
+
+When this newly defined widget is bound to a key
+using the tt(bindkey) builtin command defined in the tt(zsh/zle) module
+(\
+ifzman(see zmanref(zshzle))\
+ifnzman(noderef(Zsh Line Editor))\
+), typing that key will call the shell function `tt(completer)'. This
+function is responsible for generating the possible matches using the
+builtins described below.  As with other ZLE widgets, the function is
+called with its standard input closed.
+
+Once the function returns, the completion code takes over control again
+and treats the matches in the same manner as the specified builtin
+widget, in this case tt(expand-or-complete).
 
 startmenu()
 menu(Special Parameters)
Index: Doc/Zsh/zle.yo
===================================================================
@@ -104,8 +104,10 @@
 User-defined widgets, being implemented as shell functions,
 can execute any normal shell command.  They can also run other widgets
 (whether built-in or user-defined) using the tt(zle) builtin command.
-They can use tt(read -k) or tt(read -q) to read characters from standard
-input.  Finally, they can examine and edit the ZLE buffer being edited by
+The standard input of the function is closed to prevent external commands
+from unintentionally blocking ZLE by reading from the terminal, but
+tt(read -k) or tt(read -q) can be used to read characters.  Finally,
+they can examine and edit the ZLE buffer being edited by
 reading and setting the special parameters described below.
 
 cindex(parameters, editor)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: closing stdin (Re: _make suppress error on OpenBSD.)
  2000-05-10  4:48   ` Bart Schaefer
@ 2000-05-10  7:22     ` Tanaka Akira
  0 siblings, 0 replies; 5+ messages in thread
From: Tanaka Akira @ 2000-05-10  7:22 UTC (permalink / raw)
  To: zsh-workers

In article <1000510044838.ZM2434@candle.brasslantern.com>,
  "Bart Schaefer" <schaefer@candle.brasslantern.com> writes:

> In any case, that latter suggests what I think is the best solution for the
> completion system.

Thanks.  I reverted 11280.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: closing stdin (Re: _make suppress error on OpenBSD.)
  2000-05-09 19:34 ` closing stdin (Re: _make suppress error on OpenBSD.) Tanaka Akira
@ 2000-05-10  4:48   ` Bart Schaefer
  2000-05-10  7:22     ` Tanaka Akira
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2000-05-10  4:48 UTC (permalink / raw)
  To: Tanaka Akira, zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* closing stdin (Re: _make suppress error on OpenBSD.)
  2000-05-09 12:08 _make suppress error on OpenBSD Tanaka Akira
@ 2000-05-09 19:34 ` Tanaka Akira
  2000-05-10  4:48   ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Tanaka Akira @ 2000-05-09 19:34 UTC (permalink / raw)
  To: zsh-workers

In article <hvoog6ggc41.fsf@serein.m17n.org>,
  Tanaka Akira <akr@m17n.org> writes:

> Z:akr@coulee% Src/zsh -f
> coulee% bindkey -e; autoload -U compinit; compinit -D
> coulee% make awk: i/o error occurred while closing /dev/stdin
>  input record number 366, file Makefile
>  source line number 1

I found same problem in zfcd_match.  It can easily fixed but I like
more fundamental fix.

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.
Of course, it assumes that stdin is opened.

http://cm.bell-labs.com/who/bwk/awk.tar.gz

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.
-- 
Tanaka Akira


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-05-10 10:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-10  7:20 closing stdin (Re: _make suppress error on OpenBSD.) Sven Wischnowsky
2000-05-10 10:22 ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2000-05-09 12:08 _make suppress error on OpenBSD Tanaka Akira
2000-05-09 19:34 ` closing stdin (Re: _make suppress error on OpenBSD.) Tanaka Akira
2000-05-10  4:48   ` Bart Schaefer
2000-05-10  7:22     ` Tanaka Akira

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).