diff options
Diffstat (limited to 'src/init.cpp')
-rw-r--r-- | src/init.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/init.cpp b/src/init.cpp index 7e9230a228..2e4740602f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -13,6 +13,7 @@ #include "amount.h" #include "checkpoints.h" #include "compat/sanity.h" +#include "consensus/validation.h" #include "key.h" #include "main.h" #include "miner.h" @@ -39,7 +40,9 @@ #include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/replace.hpp> +#include <boost/bind.hpp> #include <boost/filesystem.hpp> +#include <boost/function.hpp> #include <boost/interprocess/sync/file_lock.hpp> #include <boost/thread.hpp> #include <openssl/crypto.h> @@ -188,7 +191,11 @@ void Shutdown() pwalletMain->Flush(true); #endif #ifndef WIN32 - boost::filesystem::remove(GetPidFile()); + try { + boost::filesystem::remove(GetPidFile()); + } catch (const boost::filesystem::filesystem_error& e) { + LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); + } #endif UnregisterAllValidationInterfaces(); #ifdef ENABLE_WALLET @@ -661,6 +668,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // to protect privacy, do not listen by default if a default proxy server is specified if (SoftSetBoolArg("-listen", false)) LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__); + // to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1 + // to listen locally, so don't rely on this happening through -listen below. + if (SoftSetBoolArg("-upnp", false)) + LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__); // to protect privacy, do not discover addresses by default if (SoftSetBoolArg("-discover", false)) LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__); @@ -863,9 +874,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) boost::filesystem::path pathLockFile = GetDataDir() / ".lock"; FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist. if (file) fclose(file); - static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); - if (!lock.try_lock()) - return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir)); + + try { + static boost::interprocess::file_lock lock(pathLockFile.string().c_str()); + if (!lock.try_lock()) + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir)); + } catch(const boost::interprocess::interprocess_exception& e) { + return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running.") + " %s.", strDataDir, e.what())); + } + #ifndef WIN32 CreatePidFile(GetPidFile(), getpid()); #endif @@ -1382,6 +1399,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) StartNode(threadGroup, scheduler); + // Monitor the chain, and alert if we get blocks much quicker or slower than expected + int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing; + CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload, + boost::ref(cs_main), boost::cref(chainActive), nPowTargetSpacing); + scheduler.scheduleEvery(f, nPowTargetSpacing); + #ifdef ENABLE_WALLET // Generate coins in the background if (pwalletMain) |