Browse Source

Port Bitcoin PR#13131 to fig Windows SIGTERM bug

pull/32/head
Duke Leto 3 years ago
parent
commit
a9477ea5a1
  1. 46
      src/init.cpp

46
src/init.cpp

@ -56,7 +56,6 @@
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
#include "wallet/asyncrpcoperation_saplingconsolidation.h"
#endif
#include <stdint.h>
#include <stdio.h>
@ -291,6 +290,7 @@ void Shutdown()
}
// Signal handlers are very limited in what they are allowed to do, so:
#ifndef WIN32
void HandleSIGTERM(int)
{
fprintf(stderr,"%s\n",__FUNCTION__);
@ -302,6 +302,26 @@ void HandleSIGHUP(int)
fprintf(stderr,"%s\n",__FUNCTION__);
fReopenDebugLog = true;
}
#else
static BOOL WINAPI consoleCtrlHandler(DWORD dwCtrlType)
{
fRequestShutdown = true;
// This signal now sleeps with the fishes
Sleep(INFINITE);
return true;
}
#endif
#ifndef WIN32
static void registerSignalHandler(int signal, void(*handler)(int))
{
struct sigaction sa;
sa.sa_handler = handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(signal, &sa, nullptr);
}
#endif
bool static InitError(const std::string &str)
{
@ -356,7 +376,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 288));
strUsage += HelpMessageOpt("-checklevel=<n>", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), 3));
strUsage += HelpMessageOpt("-clientname=<SomeName>", _("Full node client name, default 'MagicBean'"));
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "komodo.conf"));
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "HUSH3.conf"));
if (mode == HMM_BITCOIND)
{
#if !defined(WIN32)
@ -979,21 +999,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
umask(077);
}
//fprintf(stderr,"%s tik1\n", __FUNCTION__);
// Clean shutdown on SIGTERM
struct sigaction sa;
sa.sa_handler = HandleSIGTERM;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
registerSignalHandler(SIGTERM, HandleSIGTERM);
registerSignalHandler(SIGINT, HandleSIGTERM);
// Reopen debug.log on SIGHUP
struct sigaction sa_hup;
sa_hup.sa_handler = HandleSIGHUP;
sigemptyset(&sa_hup.sa_mask);
sa_hup.sa_flags = 0;
sigaction(SIGHUP, &sa_hup, NULL);
registerSignalHandler(SIGHUP, HandleSIGHUP);
// Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly
signal(SIGPIPE, SIG_IGN);
@ -1487,8 +1499,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string warningString;
std::string errorString;
if (!CWallet::Verify(strWalletFile, warningString, errorString))
if (!CWallet::Verify(strWalletFile, warningString, errorString)) {
uiInterface.InitMessage(_("Verification failed!"));
return false;
}
if (!warningString.empty())
InitWarning(warningString);
@ -1510,7 +1524,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
return InitError(strprintf("User Agent comment (%s) contains unsafe characters.", cmt));
uacomments.push_back(SanitizeString(cmt, SAFE_CHARS_UA_COMMENT));
}
strSubVersion = FormatSubVersion(GetArg("-clientname","MagicBean"), CLIENT_VERSION, uacomments);
strSubVersion = FormatSubVersion(GetArg("-clientname","jl777sRemorse"), CLIENT_VERSION, uacomments);
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
return InitError(strprintf("Total length of network version string %i exceeds maximum of %i characters. Reduce the number and/or size of uacomments.",
strSubVersion.size(), MAX_SUBVERSION_LENGTH));

Loading…
Cancel
Save