From 5832cfe75b9a7643e92c4d8c2b8219d3f7f9f67f Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Thu, 1 Apr 2021 19:06:10 +0900 Subject: [PATCH] SIGINT should raise Interrupt after IRB session --- lib/irb.rb | 3 ++- test/irb/test_init.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/irb.rb b/lib/irb.rb index 5a2aed035..93c4d25c9 100644 --- a/lib/irb.rb +++ b/lib/irb.rb @@ -472,7 +472,7 @@ def run(conf = IRB.conf) conf[:IRB_RC].call(context) if conf[:IRB_RC] conf[:MAIN_CONTEXT] = context - trap("SIGINT") do + prev_trap = trap("SIGINT") do signal_handle end @@ -481,6 +481,7 @@ def run(conf = IRB.conf) eval_input end ensure + trap("SIGINT", prev_trap) conf[:AT_EXIT].each{|hook| hook.call} end end diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index 83b4b5a54..2c50b5da3 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -64,6 +64,12 @@ def test_rc_file_in_subdir ENV["IRBRC"] = backup_irbrc end + def test_recovery_sigint + bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : [] + status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //) + Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled? + end + private def with_argv(argv)