aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-09-08 19:24:32 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-09-08 19:24:32 +0000
commit3f647537790e02e892701f4bb2586ccd964c2631 (patch)
treebdbaf24dfcf13214803ba6416871b91b2b7a39ef
parentf1e1fb4bdef878c8fc1564fa418d44e7541a7e83 (diff)
downloadbitcoin-3f647537790e02e892701f4bb2586ccd964c2631.tar.xz
Gavin Andresen: clean shutdown on SIGTERM
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@149 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--headers.h1
-rw-r--r--init.cpp14
-rw-r--r--net.cpp2
-rw-r--r--util.cpp1
-rw-r--r--util.h1
5 files changed, 18 insertions, 1 deletions
diff --git a/headers.h b/headers.h
index 682f7ab1a8..31e6712017 100644
--- a/headers.h
+++ b/headers.h
@@ -99,6 +99,7 @@
#include <net/if.h>
#include <ifaddrs.h>
#include <fcntl.h>
+#include <signal.h>
#endif
#ifdef BSD
#include <netinet/in.h>
diff --git a/init.cpp b/init.cpp
index 43a672f5ae..95204ad3a0 100644
--- a/init.cpp
+++ b/init.cpp
@@ -10,7 +10,6 @@
-
//////////////////////////////////////////////////////////////////////////////
//
// Shutdown
@@ -57,6 +56,11 @@ void Shutdown(void* parg)
}
}
+void HandleSIGTERM(int)
+{
+ fRequestShutdown = true;
+}
+
@@ -130,6 +134,14 @@ bool AppInit2(int argc, char* argv[])
#ifndef __WXMSW__
umask(077);
#endif
+#ifndef __WXMSW__
+ // Clean shutdown on SIGTERM
+ struct sigaction sa;
+ sa.sa_handler = HandleSIGTERM;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sigaction(SIGTERM, &sa, NULL);
+#endif
//
// Parameters
diff --git a/net.cpp b/net.cpp
index d1fdd241bc..1a64a82c14 100644
--- a/net.cpp
+++ b/net.cpp
@@ -1163,6 +1163,8 @@ void ThreadMessageHandler2(void* parg)
// Wait and allow messages to bunch up
vnThreadsRunning[2]--;
Sleep(100);
+ if (fRequestShutdown)
+ Shutdown(NULL);
vnThreadsRunning[2]++;
if (fShutdown)
return;
diff --git a/util.cpp b/util.cpp
index ef2e68344d..9efa20ede8 100644
--- a/util.cpp
+++ b/util.cpp
@@ -11,6 +11,7 @@ bool fDebug = false;
bool fPrintToConsole = false;
bool fPrintToDebugger = false;
char pszSetDataDir[MAX_PATH] = "";
+bool fRequestShutdown = false;
bool fShutdown = false;
bool fDaemon = false;
bool fCommandLine = false;
diff --git a/util.h b/util.h
index 22ace616b4..42d1fe460b 100644
--- a/util.h
+++ b/util.h
@@ -140,6 +140,7 @@ extern bool fDebug;
extern bool fPrintToConsole;
extern bool fPrintToDebugger;
extern char pszSetDataDir[MAX_PATH];
+extern bool fRequestShutdown;
extern bool fShutdown;
extern bool fDaemon;
extern bool fCommandLine;