zsh-users
 help / color / mirror / code / Atom feed
* read still active after Ctrl-C
@ 2016-06-02  6:19 Sebastian Gniazdowski
  2016-06-02  9:32 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2016-06-02  6:19 UTC (permalink / raw)
  To: Zsh Users

Hello,
how to leave whole script on Ctrl-C? Below is a simple example where
read is still active and waits for a key after Ctrl-C is pressed

#!/usr/bin/env zsh

trap "endprog; exit" TERM INT QUIT
trap "endprog" EXIT

endprog() {
    echo "Am called"
}

wait_for_any_key() {
    read -rs -k 1 -t "$1"
}

wait_for_any_key 60 && exit


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

* Re: read still active after Ctrl-C
  2016-06-02  6:19 read still active after Ctrl-C Sebastian Gniazdowski
@ 2016-06-02  9:32 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2016-06-02  9:32 UTC (permalink / raw)
  To: Zsh Users

On Thu, 02 Jun 2016 08:19:56 +0200
Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> how to leave whole script on Ctrl-C? Below is a simple example where
> read is still active and waits for a key after Ctrl-C is pressed

There's a bug here, definitely.  As it wasn't entirely clear to me what
the result of all those traps was going to be I actually tried it with a
simpler trap on SIGINT only.

That second catch-all attempt to read from the terminal if the first
attempt via select failed was always voodoo.  I've a vague feeling it
was inspired by playing around on an old SunOS system a good twenty
years ago.  I'm not sure if this particular cargo cult now needs to be
expunged.

pws

diff --git a/Src/utils.c b/Src/utils.c
index 12911d3..95be1fb 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2534,7 +2534,7 @@ read_poll(int fd, int *readchar, int polltty, zlong microseconds)
 #endif
 #endif
 
-    if (fd >= 0 && ret < 0) {
+    if (fd >= 0 && ret < 0 && !errflag) {
 	/*
 	 * Final attempt: set non-blocking read and try to read a character.
 	 * Praise Bill, this works under Cygwin (nothing else seems to).


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

end of thread, other threads:[~2016-06-02  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-02  6:19 read still active after Ctrl-C Sebastian Gniazdowski
2016-06-02  9:32 ` Peter Stephenson

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