diff --git a/core/executor.py b/core/executor.py index fa379b70f0..6021d54fbf 100644 --- a/core/executor.py +++ b/core/executor.py @@ -138,13 +138,6 @@ def RunBuiltin(self, builtin_id, cmd_val): # e.g. 'type' doesn't accept flag '-x' self.errfmt.PrefixPrint(e.msg, prefix='%r ' % arg0, span_id=e.span_id) status = 2 # consistent error code for usage error - except KeyboardInterrupt: - if self.exec_opts.interactive(): - print('') # newline after ^C - status = 130 # 128 + 2 for SIGINT - else: - # Abort a batch script - raise finally: # Flush stdout after running ANY builtin. This is very important! # Silence errors like we did from 'echo'. diff --git a/osh/cmd_eval.py b/osh/cmd_eval.py index 36173aa408..15e650a972 100755 --- a/osh/cmd_eval.py +++ b/osh/cmd_eval.py @@ -289,12 +289,6 @@ def _RunAssignBuiltin(self, cmd_val): e.span_id = self.errfmt.CurrentLocation() self.errfmt.PrefixPrint(e.msg, prefix='%r ' % arg0, span_id=e.span_id) status = 2 # consistent error code for usage error - except KeyboardInterrupt: - if self.exec_opts.interactive(): - print('') # newline after ^C - status = 130 # 128 + 2 for SIGINT - else: - raise finally: try: sys.stdout.flush() diff --git a/spec/stateful/bug-858-trap.sh b/spec/stateful/bug-858-wait-trap.sh similarity index 100% rename from spec/stateful/bug-858-trap.sh rename to spec/stateful/bug-858-wait-trap.sh diff --git a/spec/stateful/signal-during-read.sh b/spec/stateful/bug-986-read-trap.sh similarity index 100% rename from spec/stateful/signal-during-read.sh rename to spec/stateful/bug-986-read-trap.sh diff --git a/spec/stateful/signals.py b/spec/stateful/signals.py index 3cecdfd880..f6cf73ec4d 100755 --- a/spec/stateful/signals.py +++ b/spec/stateful/signals.py @@ -143,7 +143,8 @@ def sigwinch_untrapped_wait(sh): sh.expect('status=0') -@register() +# dash and mksh don't have pipestatus +@register(skip_shells=['dash', 'mksh']) def sigwinch_untrapped_wait_n(sh): 'untrapped SIGWINCH during wait -n' @@ -178,7 +179,8 @@ def sigwinch_untrapped_external(sh): sh.expect('status=0') -@register() +# dash doesn't have pipestatus +@register(skip_shells=['dash']) def sigwinch_untrapped_pipeline(sh): 'untrapped SIGWINCH during pipeline' @@ -224,6 +226,12 @@ def t4(sh): sh.expect('status=130') +# TODO: +# - Expand this to call kinds of reads +# - note that mksh only has some of them +# - Expand to trapped and untrapped +# - Expand to Ctrl-C vs. SIGWINCH + @register() def t2(sh): 'Ctrl-C during read builtin' @@ -275,6 +283,24 @@ def c_wait_n(sh): sh.expect('status=130') +@register() +def c_wait_line(sh): + 'Ctrl-C (untrapped) cancels entire interactive line' + + # the echo should be cancelled + sh.sendline('sleep 10 & wait; echo status=$?') + + time.sleep(0.1) + + # TODO: actually send Ctrl-C through the terminal, not SIGINT? + sh.sendintr() # SIGINT + + sh.expect(r'.*\$') # expect prompt + + sh.sendline('echo done=$?') + sh.expect('done=130') + + @register() def t5(sh): 'Ctrl-C during Command Sub (issue 467)' diff --git a/test/stateful.sh b/test/stateful.sh index a7b2a2029b..9b5c76b7db 100755 --- a/test/stateful.sh +++ b/test/stateful.sh @@ -29,6 +29,11 @@ readonly BASE_DIR=_tmp/stateful signals() { spec/stateful/signals.py \ $OSH bash "$@" + + # They now pass for dash and mksh, with wait -n and PIPESTATUS skipped. + # zsh doesn't work now, but could if the prompt was changed to $ ? + + #$OSH bash dash mksh "$@" } interactive() {