Browse Source

Gavin Andresen: clean shutdown on SIGTERM

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@149 1a98c847-1fd6-4fd8-948a-caf3550aa51b
0.8
s_nakamoto 14 years ago
parent
commit
14002c8eba
  1. 1
      headers.h
  2. 14
      init.cpp
  3. 2
      net.cpp
  4. 1
      util.cpp
  5. 1
      util.h

1
headers.h

@ -99,6 +99,7 @@
#include <net/if.h> #include <net/if.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h>
#endif #endif
#ifdef BSD #ifdef BSD
#include <netinet/in.h> #include <netinet/in.h>

14
init.cpp

@ -10,7 +10,6 @@
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// Shutdown // 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__ #ifndef __WXMSW__
umask(077); umask(077);
#endif #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 // Parameters

2
net.cpp

@ -1163,6 +1163,8 @@ void ThreadMessageHandler2(void* parg)
// Wait and allow messages to bunch up // Wait and allow messages to bunch up
vnThreadsRunning[2]--; vnThreadsRunning[2]--;
Sleep(100); Sleep(100);
if (fRequestShutdown)
Shutdown(NULL);
vnThreadsRunning[2]++; vnThreadsRunning[2]++;
if (fShutdown) if (fShutdown)
return; return;

1
util.cpp

@ -11,6 +11,7 @@ bool fDebug = false;
bool fPrintToConsole = false; bool fPrintToConsole = false;
bool fPrintToDebugger = false; bool fPrintToDebugger = false;
char pszSetDataDir[MAX_PATH] = ""; char pszSetDataDir[MAX_PATH] = "";
bool fRequestShutdown = false;
bool fShutdown = false; bool fShutdown = false;
bool fDaemon = false; bool fDaemon = false;
bool fCommandLine = false; bool fCommandLine = false;

1
util.h

@ -140,6 +140,7 @@ extern bool fDebug;
extern bool fPrintToConsole; extern bool fPrintToConsole;
extern bool fPrintToDebugger; extern bool fPrintToDebugger;
extern char pszSetDataDir[MAX_PATH]; extern char pszSetDataDir[MAX_PATH];
extern bool fRequestShutdown;
extern bool fShutdown; extern bool fShutdown;
extern bool fDaemon; extern bool fDaemon;
extern bool fCommandLine; extern bool fCommandLine;

Loading…
Cancel
Save