Pol  Revision:4b29d2b
esignal.cpp
Go to the documentation of this file.
1 
7 #include "esignal.h"
8 #ifdef WINDOWS
9 #include "Header_Windows.h"
10 #include "logfacility.h"
11 #else
12 #include <signal.h>
13 #endif
14 namespace Pol
15 {
16 namespace Clib
17 {
18 std::atomic<bool> exit_signalled( false );
19 
20 #ifdef WINDOWS
21 BOOL WINAPI control_handler( DWORD dwCtrlType )
22 {
23  switch ( dwCtrlType )
24  {
25  case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate
26  case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode
27  ERROR_PRINT << "Ctrl-C detected. Stopping...\n";
28  exit_signalled = true;
29  return TRUE;
30 
31 // Consider these three new signals?
32 #if 0
33  case CTRL_CLOSE_EVENT: // console window closing
34  ERROR_PRINT << "Console window closing. Stopping...\n";
35  exit_signalled = true;
36  return TRUE;
37 
38  case CTRL_LOGOFF_EVENT: // User logging off system
39  ERROR_PRINT << "User logging off system. Stopping...\n";
40  exit_signalled = true;
41  return TRUE;
42 
43  case CTRL_SHUTDOWN_EVENT: // User shutting down system
44  ERROR_PRINT << "System shutting down. Stopping...\n";
45  exit_signalled = true;
46  return TRUE;
47 #endif
48  }
49  return FALSE;
50 }
51 
53 {
54  SetConsoleCtrlHandler( control_handler, TRUE );
55 }
56 
57 #else
58 
59 
60 void ctrlc_handler( int x )
61 {
62  (void)x;
63  exit_signalled = true;
64 }
66 {
67  signal( SIGINT, ctrlc_handler );
68  signal( SIGQUIT, ctrlc_handler );
69  signal( SIGTERM, ctrlc_handler );
70 }
71 #endif
72 }
73 }
void ctrlc_handler(int x)
Definition: esignal.cpp:60
typedef DWORD(WINAPI *__SymGetOptions)(VOID)
typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess
void enable_exit_signaller()
Definition: esignal.cpp:65
#define ERROR_PRINT
Definition: logfacility.h:230
Definition: berror.cpp:12
std::atomic< bool > exit_signalled