zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Tanaka Akira <akr@m17n.org>, zsh-workers@sunsite.auc.dk
Subject: Re: closing stdin (Re: _make suppress error on OpenBSD.)
Date: Wed, 10 May 2000 04:48:38 +0000	[thread overview]
Message-ID: <1000510044838.ZM2434@candle.brasslantern.com> (raw)
In-Reply-To: <hvohfc7h61c.fsf@serein.m17n.org>

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


  reply	other threads:[~2000-05-10  4:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2000-05-10  7:22     ` Tanaka Akira
2000-05-10  7:20 Sven Wischnowsky
2000-05-10 10:22 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1000510044838.ZM2434@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=akr@m17n.org \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).