From 2b00a504a99bb1a5b8035c77b09bb5af6b8a0ee8 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Mon, 11 Sep 2017 11:31:21 +0100 Subject: [PATCH] handle SIGINT many ncurses programs such as hexedit use SIGINT (CTRL-C) as the command to shut down the application, but when one does the same with vbindiff, the terminal modes are not properly reset, leaving a messed up terminal that can not even be restored completely with `reset` command. so practically everytime i used vbindiff, this happened to me, accompanied by a "sh... it happened again". --- vbindiff.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vbindiff.cpp b/vbindiff.cpp index 5c29aad..6c24093 100644 --- a/vbindiff.cpp +++ b/vbindiff.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1816,6 +1817,13 @@ void processOptions(int& argc, char**& argv) } } // end processOptions +static int ctrlc_pressed; + +static void sighandler(int signo) { + (void) signo; + ctrlc_pressed = 1; +} + //==================================================================== // Main Program: //==================================================================== @@ -1863,8 +1871,10 @@ VBinDiff comes with ABSOLUTELY NO WARRANTY; for details type `vbindiff -L'.\n"; file1.display(); file2.display(); + signal(SIGINT, sighandler); + Command cmd; - while ((cmd = getCommand()) != cmQuit) + while (!ctrlc_pressed && (cmd = getCommand()) != cmQuit) handleCmd(cmd); file1.shutDown();