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)