Mercurial > hg > bitcoin
changeset 268:f7d27372246c draft
Gavin Andresen: clean shutdown on SIGTERM
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@149 1a98c847-1fd6-4fd8-948a-caf3550aa51b
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> |
---|---|
date | Wed, 08 Sep 2010 19:24:32 +0000 |
parents | 32694c9fc1c5 |
children | ae8c8d8f84bf |
files | headers.h init.cpp net.cpp util.cpp util.h |
diffstat | 5 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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>
--- a/init.cpp +++ b/init.cpp @@ -10,7 +10,6 @@ - ////////////////////////////////////////////////////////////////////////////// // // Shutdown @@ -57,6 +56,11 @@ } } +void HandleSIGTERM(int) +{ + fRequestShutdown = true; +} + @@ -130,6 +134,14 @@ #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
--- a/net.cpp +++ b/net.cpp @@ -1163,6 +1163,8 @@ // Wait and allow messages to bunch up vnThreadsRunning[2]--; Sleep(100); + if (fRequestShutdown) + Shutdown(NULL); vnThreadsRunning[2]++; if (fShutdown) return;