-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (56 loc) · 1.58 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <csignal>
#include <exception>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include "collector.h"
#include "processor.h"
using namespace std;
using namespace blah;
int main( int argc, char* argv[] )
{
log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("main"));
int result = -1;
try
{
log4cxx::BasicConfigurator::configure();
LOG4CXX_INFO( logger, "Starting file snooper" );
sigset_t signal_set;
// block all signals
sigfillset( &signal_set );
sigdelset( &signal_set, SIGINT );
pthread_sigmask( SIG_BLOCK, &signal_set, NULL );
//Start collector and processor threads
Processor processor;
Collector collector( processor );
LOG4CXX_INFO( logger, "Completed startup of file snooper" );
int sig;
sigemptyset( &signal_set );
sigaddset( &signal_set, SIGTERM );
//sigaddset( &signal_set, SIGINT );
sigwait( &signal_set, &sig );
switch( sig )
{
case SIGINT:
case SIGTERM:
LOG4CXX_INFO( logger, "Clean shutdown" );
break;
default:
break;
}
result = 0;
LOG4CXX_INFO( logger, "Shutting down file snooper" );
}
catch( const std::exception& exp )
{
LOG4CXX_ERROR(logger, exp.what());
}
catch( int i )
{
LOG4CXX_ERROR( logger, "Caught integer exception: " << i );
}
catch( ... )
{
LOG4CXX_ERROR( logger, "Caught unknown exception" );
}
return result;
}