From d87f00c4d5e9f547481ccb3977febdc6f740828e Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 10 Jan 2017 16:33:41 +0100 Subject: [PATCH 1/2] Throw an error if zcash.conf is missing An empty zcash.conf is sufficient to bypass this error. --- src/util.cpp | 2 +- src/util.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index b667acc5e..8fbdfc65b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -534,7 +534,7 @@ void ReadConfigFile(map& mapSettingsRet, { boost::filesystem::ifstream streamConfig(GetConfigFile()); if (!streamConfig.good()) - return; // No zcash.conf file is OK + throw missing_zcash_conf(); set setOptions; setOptions.insert("*"); diff --git a/src/util.h b/src/util.h index ef3a347fa..b7d255e4d 100644 --- a/src/util.h +++ b/src/util.h @@ -127,6 +127,10 @@ boost::filesystem::path GetConfigFile(); boost::filesystem::path GetPidFile(); void CreatePidFile(const boost::filesystem::path &path, pid_t pid); #endif +class missing_zcash_conf : public std::runtime_error { +public: + missing_zcash_conf() : std::runtime_error("Missing zcash.conf") { } +}; void ReadConfigFile(std::map& mapSettingsRet, std::map >& mapMultiSettingsRet); #ifdef WIN32 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); From 24f4e3365bb3aed558fe0baa80d17715aad5b3db Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 11 Jan 2017 12:55:35 +0100 Subject: [PATCH 2/2] Show a friendly message explaining why zcashd needs a zcash.conf --- src/bitcoind.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 2ec14ccc6..8634be211 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -97,6 +97,24 @@ bool AppInit(int argc, char* argv[]) try { ReadConfigFile(mapArgs, mapMultiArgs); + } catch (const missing_zcash_conf& e) { + fprintf(stderr, + (_("Before starting zcashd, you need to create a configuration file:\n" + "%s\n" + "It can be completely empty! That indicates you are happy with the default\n" + "configuration of zcashd. But requiring a configuration file to start ensures\n" + "that zcashd won't accidentally compromise your privacy if there was a default\n" + "option you needed to change.\n" + "\n" + "You can look at the example configuration file for suggestions of default\n" + "options that you may want to change. It should be in one of these locations,\n" + "depending on how you installed Zcash:\n") + + _("- Source code: %s\n" + "- .deb package: %s\n")).c_str(), + GetConfigFile().string().c_str(), + "contrib/DEBIAN/examples/zcash.conf", + "/usr/share/doc/zcash/examples/zcash.conf"); + return false; } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); return false;