From eaff3b421033ae891041319ae072d823303cd554 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Wed, 21 Dec 2016 13:34:45 +0100 Subject: [PATCH] Make a hard reset of named barrier mutexes on signal --- src/tools/store.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tools/store.cpp b/src/tools/store.cpp index 80b514560..8d1782af1 100644 --- a/src/tools/store.cpp +++ b/src/tools/store.cpp @@ -1,3 +1,4 @@ +#include "storage/shared_barriers.hpp" #include "storage/storage.hpp" #include "util/exception.hpp" #include "util/log.hpp" @@ -7,6 +8,9 @@ #include #include +#include +#include + using namespace osrm; // generate boost::program_options object for the routing part @@ -87,8 +91,20 @@ bool generateDataStoreOptions(const int argc, return true; } +[[ noreturn ]] void CleanupSharedBarriers(int signum) +{ // Here the lock state of named mutexes is unknown, make a hard cleanup + osrm::storage::SharedBarriers::resetCurrentRegions(); + std::_Exit(128 + signum); +} + int main(const int argc, const char *argv[]) try { + int signals[] = {SIGTERM, SIGSEGV, SIGINT, SIGILL, SIGABRT, SIGFPE}; + for (auto sig : signals) + { + std::signal(sig, CleanupSharedBarriers); + } + util::LogPolicy::GetInstance().Unmute(); boost::filesystem::path base_path; @@ -135,4 +151,4 @@ catch (const std::bad_alloc &e) util::Log(logERROR) << "Please provide more memory or disable locking the virtual " "address space (note: this makes OSRM swap, i.e. slow)"; return EXIT_FAILURE; -} \ No newline at end of file +}