Skip to content
Permalink
Browse files

tools: always handle signals, don't block in signal handling

  • Loading branch information...
aberaud committed Jun 8, 2019
1 parent 18c3161 commit 777505434ca565d510c99df3079067b3a6eaaff7
Showing with 5 additions and 9 deletions.
  1. +3 −4 tools/dhtnode.cpp
  2. +2 −5 tools/tools_common.h
@@ -503,9 +503,8 @@ main(int argc, char **argv)

if (params.daemonize) {
daemonize();
} else if (params.service) {
setupSignals();
}
setupSignals();

auto node = std::make_shared<DhtRunner>();

@@ -576,7 +575,7 @@ main(int argc, char **argv)

std::condition_variable cv;
std::mutex m;
std::atomic_bool done {false};
bool done {false};

node->shutdown([&]()
{
@@ -587,7 +586,7 @@ main(int argc, char **argv)

// wait for shutdown
std::unique_lock<std::mutex> lk(m);
cv.wait(lk, [&](){ return done.load(); });
cv.wait(lk, [&](){ return done; });

node->join();
#ifdef WIN32_NATIVE
@@ -282,18 +282,17 @@ readLine(const char* prefix = PROMPT)
struct ServiceRunner {
bool wait() {
std::unique_lock<std::mutex> lock(m);
cv.wait(lock, [&]{return terminate;});
cv.wait(lock, [&]{return terminate.load();});
return !terminate;
}
void kill() {
std::lock_guard<std::mutex> lock(m);
terminate = true;
cv.notify_all();
}
private:
std::condition_variable cv;
std::mutex m;
bool terminate = false;
std::atomic_bool terminate {false};
};

ServiceRunner runner;
@@ -340,7 +339,5 @@ void daemonize()
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

setupSignals();
#endif
}

0 comments on commit 7775054

Please sign in to comment.
You can’t perform that action at this time.