0

I am working on a program that requires that you type a password to exit a ruby program, and I need a way to disable control-c, as it is failing my evil plans. I need to make it so that the user cannot interrupt the program, without having a bunch of these:

rescue Interrupt
    while true
        puts "\nExiting..."
    end
end
Dimitrius Lachi
  • 1,277
  • 2
  • 9
  • 21
DangerDC
  • 3
  • 1
  • A bunch? You need only this one. – Sergio Tulentsev Mar 06 '19 at 19:31
  • I doubt that anyone will search for questions with a tag "macos". – Cary Swoveland Mar 06 '19 at 20:30
  • There are [quite a few more](http://www.lostsaloon.com/technology/7-keyboard-shortcuts-you-should-know-in-linux-command-shell/) signals a user can send from the terminal, e.g. `SIGQUIT` with `CTRL+\ ` and `SIGTSTP` with `CTRL+Z`. There might be more depending on your used shell. You should probably not strongly rely on being able to capture all these signals for any actual security purposes. – Holger Just Mar 06 '19 at 20:51
  • Possibly duplicate of: https://stackoverflow.com/questions/2089421/capturing-ctrl-c-in-ruby?noredirect=1&lq=1 – Danilo Cabello Mar 06 '19 at 22:30

1 Answers1

3

you can trap SIGINT like this

trap "SIGINT" do
  # this is called when you press control-c
  # be very careful, you can't kill this program with control-c
end

You can also see Capturing Ctrl-c in ruby for some other ways to interact with control-c