Skip to content

Commit 162e8be

Browse files
committed
CTerminal now catches seg-faults (SIGSEGV)
1 parent 25de63e commit 162e8be

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

Core/include/CTerminal.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* \date Oct. 1st, 2015
1111
*
12-
* \version 1.2.01
12+
* \version 1.2.02
1313
*/
1414

1515
#ifndef CTERMINAL_H
@@ -23,13 +23,11 @@
2323
///Default size of terminal scroll back buffer in lines.
2424
#define SCROLLBACK_SIZE 1000
2525

26-
#define CTERMINAL_VERSION "1.2.01"
27-
#define CTERMINAL_DATE "Oct. 1st, 2015"
26+
#define CTERMINAL_VERSION "1.2.02"
27+
#define CTERMINAL_DATE "Oct. 2nd, 2015"
2828

2929
#include <curses.h>
3030

31-
extern bool SIGNAL_INTERRUPT;
32-
3331
extern std::string CPP_APP_VERSION;
3432

3533
template <typename T>

Core/source/CTerminal.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
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>
@@ -31,6 +31,7 @@
3131

3232
#ifdef USE_NCURSES
3333

34+
bool SIGNAL_SEGFAULT = false;
3435
bool SIGNAL_INTERRUPT = false;
3536
bool SIGNAL_TERMSTOP = false;
3637
bool 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+
278283
void 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
292297
void 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";

Poll/include/poll2_core.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*
1111
* \author Cory R. Thornsberry
1212
*
13-
* \date Sept. 29th, 2015
13+
* \date Oct. 2nd, 2015
1414
*
15-
* \version 1.3.07
15+
* \version 1.3.08
1616
*/
1717

1818
#ifndef POLL2_CORE_H
@@ -24,8 +24,8 @@
2424
#include "hribf_buffers.h"
2525
#define maxEventSize 4095 // (0x1FFE0000 >> 17)
2626

27-
#define POLL2_CORE_VERSION "1.3.07"
28-
#define POLL2_CORE_DATE "Oct. 1st, 2015"
27+
#define POLL2_CORE_VERSION "1.3.08"
28+
#define POLL2_CORE_DATE "Oct. 2nd, 2015"
2929

3030
// Maximum length of UDP data packet (in bytes)
3131
#define MAX_ORPH_DATA 1464

Poll/source/poll2_core.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* \date Oct. 1st, 2015
1414
*
15-
* \version 1.3.07
15+
* \version 1.3.08
1616
*/
1717

1818
#include <algorithm>
@@ -757,7 +757,12 @@ void Poll::CommandControl(){
757757
}
758758

759759
cmd = poll_term_->GetCommand();
760-
if(cmd == "CTRL_D"){
760+
if(cmd == "_SIGSEGV_"){
761+
std::cout << Display::ErrorStr("SEGMENTATION FAULT") << std::endl;
762+
Close();
763+
exit(EXIT_FAILURE);
764+
}
765+
else if(cmd == "CTRL_D"){
761766
std::cout << sys_message_head << "Received EOF (ctrl-d) signal. Exiting...\n";
762767
cmd = "quit";
763768
}

0 commit comments

Comments
 (0)