From a9477ea5a19e7c1012950965a45b8a7c622ba099 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 10 Jan 2021 12:49:58 -0500 Subject: [PATCH] Port Bitcoin PR#13131 to fig Windows SIGTERM bug --- src/init.cpp | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 7b2627030..ab3b5e778 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -56,7 +56,6 @@ #include "wallet/wallet.h" #include "wallet/walletdb.h" #include "wallet/asyncrpcoperation_saplingconsolidation.h" - #endif #include #include @@ -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=", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 288)); strUsage += HelpMessageOpt("-checklevel=", strprintf(_("How thorough the block verification of -checkblocks is (0-4, default: %u)"), 3)); strUsage += HelpMessageOpt("-clientname=", _("Full node client name, default 'MagicBean'")); - strUsage += HelpMessageOpt("-conf=", strprintf(_("Specify configuration file (default: %s)"), "komodo.conf")); + strUsage += HelpMessageOpt("-conf=", 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));