zsh-workers
 help / color / mirror / code / Atom feed
* [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130
@ 2016-09-20 13:17 Martijn Dekker
  2016-09-23  6:08 ` Daniel Shahaf
  2016-09-25 17:56 ` Peter Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Martijn Dekker @ 2016-09-20 13:17 UTC (permalink / raw)
  To: Zsh hackers list

On an interactive shell, sending SIGINT to the shell (which could be
done with 'kill -s INT $$' or simply by pressing Ctrl+C) causes zsh to
return to the command prompt with an exit status of 0, which represents
a normal/successful exit. This should be 130, the exit status
corresponding to SIGINT (128+2).

% while :; do :; done
^C%
% echo $?                     # should produce 130
0
% kill -s INT $$; echo oops   # no output produced, as expected
% echo $?                     # should produce 130
0


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

* Re: [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130
  2016-09-20 13:17 [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130 Martijn Dekker
@ 2016-09-23  6:08 ` Daniel Shahaf
  2016-09-25 17:56 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Shahaf @ 2016-09-23  6:08 UTC (permalink / raw)
  To: Martijn Dekker; +Cc: Zsh hackers list

Martijn Dekker wrote on Tue, Sep 20, 2016 at 14:17:08 +0100:
> On an interactive shell, sending SIGINT to the shell (which could be
> done with 'kill -s INT $$' or simply by pressing Ctrl+C) causes zsh to
> return to the command prompt with an exit status of 0, which represents
> a normal/successful exit. This should be 130, the exit status
> corresponding to SIGINT (128+2).
> 
> % while :; do :; done
> ^C%
> % echo $?                     # should produce 130
> 0
> % kill -s INT $$; echo oops   # no output produced, as expected
> % echo $?                     # should produce 130
> 0

What are the consequences of this?  Does it cause anything besides the
%? prompt escape, and printexitvalue, not reflecting the signal?

It only happens for builtins:
    while =true; do =true; done
gets it right but 
    while true; do true; done
does not.


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

* Re: [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130
  2016-09-20 13:17 [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130 Martijn Dekker
  2016-09-23  6:08 ` Daniel Shahaf
@ 2016-09-25 17:56 ` Peter Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2016-09-25 17:56 UTC (permalink / raw)
  To: Zsh hackers list

On Tue, 20 Sep 2016 14:17:08 +0100
Martijn Dekker <martijn@inlv.org> wrote:
> On an interactive shell, sending SIGINT to the shell (which could be
> done with 'kill -s INT $$' or simply by pressing Ctrl+C) causes zsh to
> return to the command prompt with an exit status of 0, which represents
> a normal/successful exit. This should be 130, the exit status
> corresponding to SIGINT (128+2).
> 
> % while :; do :; done
> ^C%
> % echo $?                     # should produce 130
> 0
> % kill -s INT $$; echo oops   # no output produced, as expected
> % echo $?                     # should produce 130
> 0

It's fairly easy to do a bit better.

We could add an "intlastval" to test in the main loop before we reset
errflag, to use if ERRFLAG_INT is present.  But I'm not sure if that's
worth it; with the current fix we remain sensitive to things we
shouldn't really be doing anyway on an interrupt.

pws

diff --git a/Src/exec.c b/Src/exec.c
index a5086c3..4e89340 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3701,7 +3701,8 @@ execcmd(Estate state, int input, int output, int how, int last1)
 		    state->pc = opc;
 		}
 		dont_queue_signals();
-		lastval = execbuiltin(args, assigns, (Builtin) hn);
+		if (!errflag)
+		    lastval = execbuiltin(args, assigns, (Builtin) hn);
 		if (do_save & BINF_COMMAND)
 		    errflag &= ~ERRFLAG_ERROR;
 		restore_queue_signals(q);
diff --git a/Src/signals.c b/Src/signals.c
index 30dde71..e2587dc 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -646,6 +646,7 @@ zhandler(int sig)
 		inerrflush();
 		check_cursh_sig(SIGINT);
             }
+	    lastval = 128 + SIGINT;
         }
         break;
 


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

end of thread, other threads:[~2016-09-25 17:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-20 13:17 [buglet] Ctrl+C and 'kill -s INT $$' should produce exit status 130 Martijn Dekker
2016-09-23  6:08 ` Daniel Shahaf
2016-09-25 17:56 ` 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).