souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
souffle::SignalHandler Class Reference

Class SignalHandler captures signals and reports the context where the signal occurs. More...

#include <SignalHandler.h>

Collaboration diagram for souffle::SignalHandler:
Collaboration graph

Public Member Functions

void enableLogging ()
 
void error (const std::string &error)
 
void reset ()
 
void set ()
 
void setMsg (const char *m)
 

Static Public Member Functions

static SignalHandlerinstance ()
 

Private Member Functions

 SignalHandler ()
 

Static Private Member Functions

static void handler (int signal)
 Signal handler for various types of signals. More...
 

Private Attributes

bool isSet = false
 
bool logMessages = false
 
std::atomic< const char * > msg
 
void(* prevFpeHandler )(int) = nullptr
 
void(* prevIntHandler )(int) = nullptr
 
void(* prevSegVHandler )(int) = nullptr
 

Detailed Description

Class SignalHandler captures signals and reports the context where the signal occurs.

The signal handler is implemented as a singleton.

Definition at line 41 of file SignalHandler.h.

Constructor & Destructor Documentation

◆ SignalHandler()

souffle::SignalHandler::SignalHandler ( )
inlineprivate

Definition at line 181 of file SignalHandler.h.

Member Function Documentation

◆ enableLogging()

void souffle::SignalHandler::enableLogging ( )
inline

Definition at line 56 of file SignalHandler.h.

56  {
57  if (sameLine) {
58  sameLine = false;

◆ error()

void souffle::SignalHandler::error ( const std::string &  error)
inline

Definition at line 138 of file SignalHandler.h.

152  {

◆ handler()

static void souffle::SignalHandler::handler ( int  signal)
inlinestaticprivate

Signal handler for various types of signals.

Definition at line 164 of file SignalHandler.h.

169  : msg(nullptr) {}
170 };
171 
172 } // namespace souffle

◆ instance()

static SignalHandler* souffle::SignalHandler::instance ( )
inlinestatic

Definition at line 50 of file SignalHandler.h.

53  {

◆ reset()

void souffle::SignalHandler::reset ( )
inline

Definition at line 113 of file SignalHandler.h.

114  {
115  perror("Failed to reset SIGSEGV signal handler.");
116  exit(1);
117  }
118  isSet = false;
119  }
120  }
121 
122  /***
123  * error handling routine that prints the rule context.
124  */
125 
126  void error(const std::string& error) {
127  if (msg != nullptr) {
128  std::cerr << error << " in rule:\n" << msg << std::endl;
129  } else {
130  std::cerr << error << std::endl;
131  }
132  exit(1);

◆ set()

void souffle::SignalHandler::set ( )
inline

Definition at line 88 of file SignalHandler.h.

90  {
91  perror("Failed to set SIGSEGV signal handler.");
92  exit(1);
93  }
94  isSet = true;
95  }
96  }
97 
98  /***
99  * reset signal handlers
100  */
101  void reset() {
102  if (isSet) {
103  // reset floating point exception
104  if (signal(SIGFPE, prevFpeHandler) == SIG_ERR) {
105  perror("Failed to reset SIGFPE signal handler.");
106  exit(1);
107  }
108  // user interrupts

◆ setMsg()

void souffle::SignalHandler::setMsg ( const char *  m)
inline

Definition at line 60 of file SignalHandler.h.

62  : outputMessage) {
63  if (c == '\n' || c == '\t') {
64  c = ' ';
65  }
66  }
67  std::cout << "Starting work on " << outputMessage << std::endl;
68  }
69  }
70  msg = m;
71  }
72 
73  /***
74  * set signal handlers
75  */
76  void set() {
77  if (!isSet && std::getenv("SOUFFLE_ALLOW_SIGNALS") == nullptr) {
78  // register signals
79  // floating point exception
80  if ((prevFpeHandler = signal(SIGFPE, handler)) == SIG_ERR) {
81  perror("Failed to set SIGFPE signal handler.");
82  exit(1);
83  }

Field Documentation

◆ isSet

bool souffle::SignalHandler::isSet = false
private

Definition at line 152 of file SignalHandler.h.

◆ logMessages

bool souffle::SignalHandler::logMessages = false
private

Definition at line 154 of file SignalHandler.h.

◆ msg

std::atomic<const char*> souffle::SignalHandler::msg
private

Definition at line 149 of file SignalHandler.h.

◆ prevFpeHandler

void(* souffle::SignalHandler::prevFpeHandler) (int) = nullptr
private

Definition at line 157 of file SignalHandler.h.

◆ prevIntHandler

void(* souffle::SignalHandler::prevIntHandler) (int) = nullptr
private

Definition at line 158 of file SignalHandler.h.

◆ prevSegVHandler

void(* souffle::SignalHandler::prevSegVHandler) (int) = nullptr
private

Definition at line 159 of file SignalHandler.h.


The documentation for this class was generated from the following file:
souffle::SignalHandler::error
void error(const std::string &error)
Definition: SignalHandler.h:138
m
var m
Definition: htmlJsChartistMin.h:15
souffle::SignalHandler::msg
std::atomic< const char * > msg
Definition: SignalHandler.h:149
souffle::SignalHandler::set
void set()
Definition: SignalHandler.h:88
souffle::SignalHandler::isSet
bool isSet
Definition: SignalHandler.h:152
souffle::SignalHandler::handler
static void handler(int signal)
Signal handler for various types of signals.
Definition: SignalHandler.h:164
souffle::SignalHandler::prevFpeHandler
void(* prevFpeHandler)(int)
Definition: SignalHandler.h:157
souffle::SignalHandler::reset
void reset()
Definition: SignalHandler.h:113