Commit aa50c30f authored by Alessio Netti's avatar Alessio Netti
Browse files

Changes to signal handlers

- The same signal handler is used for both SIGINT and SIGTERM signals
- Previously, the SIGTERM handler would not perform any cleanup,
leading to corruption and issues on the collect agent side
parent 718e4334
......@@ -52,9 +52,12 @@ HttpsServer* _httpsServer;
boost::shared_ptr<boost::asio::io_service::work> keepAliveWork;
void sigintHandler(int sig) {
void sigHandler(int sig) {
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
LOG(fatal) << "Received SIGINT";
if( sig == SIGINT )
LOG(fatal) << "Received SIGINT";
else if( sig == SIGTERM )
LOG(fatal) << "Received SIGTERM";
//Stop all sensors
LOG(info) << "Stopping sensors...";
for(auto& p : _configuration->getPlugins()) {
......@@ -75,13 +78,6 @@ void sigintHandler(int sig) {
_httpsServer->stop();
}
void sigtermHandler(int sig) {
boost::log::sources::severity_logger<boost::log::trivial::severity_level> lg;
LOG(fatal) << "Received SIGTERM. Terminating";
signal(SIGTERM, SIG_DFL);
kill(getpid(), SIGTERM);
}
void printSyntax()
{
/*
......@@ -321,8 +317,8 @@ int main(int argc, char** argv) {
LOG(info) << "Threads created!";
LOG(info) << "Registering signal handlers...";
signal(SIGINT, sigintHandler); //Handle Strg+C
signal(SIGTERM, sigtermHandler); //Handle termination
signal(SIGINT, sigHandler); //Handle Strg+C
signal(SIGTERM, sigHandler); //Handle termination
LOG(info) << "Signal handlers registered!";
LOG(info) << "Setup complete!";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment