From 2c7b3b7036f783ce135cbb2363b123cb3a097f76 Mon Sep 17 00:00:00 2001 From: "Marc A. Paradise" Date: Mon, 3 Apr 2017 15:29:50 -0400 Subject: [PATCH] Do not continue doing things after Ctrl+C Call Kernel.exit! 1 to force an immediate error-exit if the operator uses Ctrl+C to prevent performing post-hook steps. Signed-off-by: Marc A. Paradise --- lib/omnibus-ctl.rb | 2 +- spec/omnibus-ctl_spec.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/omnibus-ctl.rb b/lib/omnibus-ctl.rb index c98a8b0..5c98095 100644 --- a/lib/omnibus-ctl.rb +++ b/lib/omnibus-ctl.rb @@ -321,7 +321,7 @@ def scary_cleanse_warning(*args) sleep 60 rescue Interrupt log "" - exit 0 + Kernel.exit 1 end end end diff --git a/spec/omnibus-ctl_spec.rb b/spec/omnibus-ctl_spec.rb index 186bd3d..fe91e62 100644 --- a/spec/omnibus-ctl_spec.rb +++ b/spec/omnibus-ctl_spec.rb @@ -676,19 +676,17 @@ def ctl_output describe "cleanse" do before(:each) do - # this is potentially destructive if run on a live system, - # not to mention loaded with sleeps - skip it. + # No-op everything cleanup_procs_and_nuke wants to do, it's destructive + # (and slow/sleep-laden): allow(@ctl).to receive("cleanup_procs_and_nuke").and_return 0 end it "should invoke the cleanse_post_hook" do - # No-op everything cleanup_procs_and_nuke wants to do, it's destructive: expect(@ctl).to receive("command_post_hook") @ctl.run(%w{cleanse yes}) end it "should invoke the scary_cleanse_warning" do - # No-op everything cleanup_procs_and_nuke wants to do, it's destructive: expect(@ctl).to receive("scary_cleanse_warning") @ctl.run(%w{cleanse yes}) end @@ -742,6 +740,12 @@ def ctl_output @ctl.scary_cleanse_warning("cleanse") expect(ctl_output).not_to match(/--with-external/) end + + it "will hard-stop when the operator uses Ctrl+C to exit" do + allow(@ctl).to receive(:sleep).and_raise(Interrupt) + expect(Kernel).to receive(:exit).with(1) + @ctl.scary_cleanse_warning("cleanse") + end end context "cleanse_post_hook" do