Skip to content

Commit

Permalink
Handle OS signals
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Mar 31, 2020
1 parent ccb32c5 commit 2ef6f6e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cpp/scenario/gazebo/src/GazeboSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "scenario/gazebo/components/SimulatedTime.h"
#include "scenario/gazebo/components/Timestamp.h"
#include "scenario/gazebo/helpers.h"
#include "scenario/gazebo/signals.h"
#include "scenario/gazebo/utils.h"
#include "scenario/plugins/gazebo/ECMSingleton.h"

Expand All @@ -50,6 +51,7 @@
#include <cassert>
#include <chrono>
#include <cmath>
#include <csignal>
#include <limits>
#include <optional>
#include <thread>
Expand Down Expand Up @@ -171,6 +173,18 @@ bool GazeboSimulator::initialize()
return false;
}

auto cb = [&](int sig) {
this->close();
exit(sig);
};

// Setup signals callbacks.
// It must be done after the creation of the simulator since
// we oveeride override their callbacks.
base::SignalManager::Instance().setCallback(SIGINT, cb);
base::SignalManager::Instance().setCallback(SIGTERM, cb);
base::SignalManager::Instance().setCallback(SIGABRT, cb);

return true;
}

Expand Down

0 comments on commit 2ef6f6e

Please sign in to comment.