77 *
88 * \author Cory R. Thornsberry
99 *
10- * \date Oct. 1st , 2015
10+ * \date Oct. 2nd , 2015
1111 *
12- * \version 1.2.00
12+ * \version 1.2.02
1313*/
1414
1515#include < iostream>
3131
3232#ifdef USE_NCURSES
3333
34+ bool SIGNAL_SEGFAULT = false ;
3435bool SIGNAL_INTERRUPT = false ;
3536bool SIGNAL_TERMSTOP = false ;
3637bool SIGNAL_RESIZE = false ;
@@ -275,6 +276,10 @@ void CommandString::Pop(unsigned int index_){
275276// Terminal
276277// /////////////////////////////////////////////////////////////////////////////
277278
279+ void sig_segv_handler (int ignore_){
280+ SIGNAL_SEGFAULT = true ;
281+ }
282+
278283void sig_int_handler (int ignore_){
279284 SIGNAL_INTERRUPT = true ;
280285}
@@ -290,6 +295,13 @@ void signalResize(int ignore_) {
290295
291296// Setup the interrupt signal intercept
292297void setup_signal_handlers (){
298+ // Handle segmentation faults press (SIGSEGV)
299+ if (signal (SIGSEGV, SIG_IGN) != SIG_IGN){
300+ if (signal (SIGSEGV, sig_segv_handler) == SIG_ERR){
301+ throw std::runtime_error (" Error setting up SIGSEGV signal handler!" );
302+ }
303+ }
304+
293305 // Handle ctrl-c press (SIGINT)
294306 if (signal (SIGINT, SIG_IGN) != SIG_IGN){
295307 if (signal (SIGINT, sig_int_handler) == SIG_ERR){
@@ -816,6 +828,10 @@ std::string Terminal::GetCommand(){
816828 }
817829
818830 while (true ){
831+ if (SIGNAL_SEGFAULT){ // segmentation fault (SIGSEGV)
832+ Close ();
833+ return " _SIGSEGV_" ;
834+ }
819835 if (SIGNAL_INTERRUPT){ // ctrl-c (SIGINT)
820836 SIGNAL_INTERRUPT = false ;
821837 output = " CTRL_C" ;
0 commit comments