From a9380c72bee0fc134a2215d7919b52936bd8158d Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 28 May 2013 16:00:17 -0400 Subject: [PATCH 1/8] build: prepare to move DetectShutdownThread --- src/init.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 78f838f7c..6777f48d5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -123,13 +123,15 @@ void Shutdown() // void DetectShutdownThread(boost::thread_group* threadGroup) { + bool shutdown = ShutdownRequested(); // Tell the main threads to shutdown. - while (!fRequestShutdown) + while (!shutdown) { MilliSleep(200); - if (fRequestShutdown) - threadGroup->interrupt_all(); + shutdown = ShutdownRequested(); } + if (threadGroup) + threadGroup->interrupt_all(); } void HandleSIGTERM(int) From c862d2ff22f06cb15fb9492b9f0b69e3d91a7e44 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 13:48:30 -0400 Subject: [PATCH 2/8] build: split the non-gui startup routines into a new file This will allow each to have its own main(), meaning that we can build a common base client and simply link in the correct startup object to create the appropriate binary. --- src/bitcoind.cpp | 136 +++++++++++++++++++++++++++++++++++++++ src/init.cpp | 134 -------------------------------------- src/makefile.linux-mingw | 3 +- src/makefile.mingw | 3 +- src/makefile.osx | 3 +- src/makefile.unix | 3 +- 6 files changed, 144 insertions(+), 138 deletions(-) create mode 100644 src/bitcoind.cpp diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp new file mode 100644 index 000000000..81f67802d --- /dev/null +++ b/src/bitcoind.cpp @@ -0,0 +1,136 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-2012 The Bitcoin developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "init.h" +#include "bitcoinrpc.h" +#include + +void DetectShutdownThread(boost::thread_group* threadGroup) +{ + bool shutdown = ShutdownRequested(); + // Tell the main threads to shutdown. + while (!shutdown) + { + MilliSleep(200); + shutdown = ShutdownRequested(); + } + if (threadGroup) + threadGroup->interrupt_all(); +} + +////////////////////////////////////////////////////////////////////////////// +// +// Start +// +bool AppInit(int argc, char* argv[]) +{ + boost::thread_group threadGroup; + boost::thread* detectShutdownThread = NULL; + + bool fRet = false; + try + { + // + // Parameters + // + // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() + ParseParameters(argc, argv); + if (!boost::filesystem::is_directory(GetDataDir(false))) + { + fprintf(stderr, "Error: Specified directory does not exist\n"); + Shutdown(); + } + ReadConfigFile(mapArgs, mapMultiArgs); + + if (mapArgs.count("-?") || mapArgs.count("--help")) + { + // First part of help message is specific to bitcoind / RPC client + std::string strUsage = _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" + + _("Usage:") + "\n" + + " bitcoind [options] " + "\n" + + " bitcoind [options] [params] " + _("Send command to -server or bitcoind") + "\n" + + " bitcoind [options] help " + _("List commands") + "\n" + + " bitcoind [options] help " + _("Get help for a command") + "\n"; + + strUsage += "\n" + HelpMessage(); + + fprintf(stdout, "%s", strUsage.c_str()); + return false; + } + + // Command-line RPC + for (int i = 1; i < argc; i++) + if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:")) + fCommandLine = true; + + if (fCommandLine) + { + int ret = CommandLineRPC(argc, argv); + exit(ret); + } +#if !defined(WIN32) + fDaemon = GetBoolArg("-daemon", false); + if (fDaemon) + { + // Daemonize + pid_t pid = fork(); + if (pid < 0) + { + fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); + return false; + } + if (pid > 0) // Parent process, pid is child process id + { + CreatePidFile(GetPidFile(), pid); + return true; + } + // Child process falls through to rest of initialization + + pid_t sid = setsid(); + if (sid < 0) + fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); + } +#endif + + detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup)); + fRet = AppInit2(threadGroup); + } + catch (std::exception& e) { + PrintExceptionContinue(&e, "AppInit()"); + } catch (...) { + PrintExceptionContinue(NULL, "AppInit()"); + } + if (!fRet) { + if (detectShutdownThread) + detectShutdownThread->interrupt(); + threadGroup.interrupt_all(); + } + + if (detectShutdownThread) + { + detectShutdownThread->join(); + delete detectShutdownThread; + detectShutdownThread = NULL; + } + Shutdown(); + + return fRet; +} + +extern void noui_connect(); +int main(int argc, char* argv[]) +{ + bool fRet = false; + + // Connect bitcoind signal handlers + noui_connect(); + + fRet = AppInit(argc, argv); + + if (fRet && fDaemon) + return 0; + + return (fRet ? 0 : 1); +} diff --git a/src/init.cpp b/src/init.cpp index 6777f48d5..e9e5e278b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -121,19 +121,6 @@ void Shutdown() // // Signal handlers are very limited in what they are allowed to do, so: // -void DetectShutdownThread(boost::thread_group* threadGroup) -{ - bool shutdown = ShutdownRequested(); - // Tell the main threads to shutdown. - while (!shutdown) - { - MilliSleep(200); - shutdown = ShutdownRequested(); - } - if (threadGroup) - threadGroup->interrupt_all(); -} - void HandleSIGTERM(int) { fRequestShutdown = true; @@ -144,127 +131,6 @@ void HandleSIGHUP(int) fReopenDebugLog = true; } - - - - -////////////////////////////////////////////////////////////////////////////// -// -// Start -// -#if !defined(QT_GUI) -bool AppInit(int argc, char* argv[]) -{ - boost::thread_group threadGroup; - boost::thread* detectShutdownThread = NULL; - - bool fRet = false; - try - { - // - // Parameters - // - // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() - ParseParameters(argc, argv); - if (!boost::filesystem::is_directory(GetDataDir(false))) - { - fprintf(stderr, "Error: Specified directory does not exist\n"); - Shutdown(); - } - ReadConfigFile(mapArgs, mapMultiArgs); - - if (mapArgs.count("-?") || mapArgs.count("--help")) - { - // First part of help message is specific to bitcoind / RPC client - std::string strUsage = _("Bitcoin version") + " " + FormatFullVersion() + "\n\n" + - _("Usage:") + "\n" + - " bitcoind [options] " + "\n" + - " bitcoind [options] [params] " + _("Send command to -server or bitcoind") + "\n" + - " bitcoind [options] help " + _("List commands") + "\n" + - " bitcoind [options] help " + _("Get help for a command") + "\n"; - - strUsage += "\n" + HelpMessage(); - - fprintf(stdout, "%s", strUsage.c_str()); - return false; - } - - // Command-line RPC - for (int i = 1; i < argc; i++) - if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "bitcoin:")) - fCommandLine = true; - - if (fCommandLine) - { - int ret = CommandLineRPC(argc, argv); - exit(ret); - } -#if !defined(WIN32) - fDaemon = GetBoolArg("-daemon", false); - if (fDaemon) - { - // Daemonize - pid_t pid = fork(); - if (pid < 0) - { - fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); - return false; - } - if (pid > 0) // Parent process, pid is child process id - { - CreatePidFile(GetPidFile(), pid); - return true; - } - // Child process falls through to rest of initialization - - pid_t sid = setsid(); - if (sid < 0) - fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); - } -#endif - - detectShutdownThread = new boost::thread(boost::bind(&DetectShutdownThread, &threadGroup)); - fRet = AppInit2(threadGroup); - } - catch (std::exception& e) { - PrintExceptionContinue(&e, "AppInit()"); - } catch (...) { - PrintExceptionContinue(NULL, "AppInit()"); - } - if (!fRet) { - if (detectShutdownThread) - detectShutdownThread->interrupt(); - threadGroup.interrupt_all(); - } - - if (detectShutdownThread) - { - detectShutdownThread->join(); - delete detectShutdownThread; - detectShutdownThread = NULL; - } - Shutdown(); - - return fRet; -} - -extern void noui_connect(); -int main(int argc, char* argv[]) -{ - bool fRet = false; - - // Connect bitcoind signal handlers - noui_connect(); - - fRet = AppInit(argc, argv); - - if (fRet && fDaemon) - return 0; - - return (fRet ? 0 : 1); -} -#endif - bool static InitError(const std::string &str) { uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR); diff --git a/src/makefile.linux-mingw b/src/makefile.linux-mingw index 7719cd263..114a9491b 100644 --- a/src/makefile.linux-mingw +++ b/src/makefile.linux-mingw @@ -71,6 +71,7 @@ OBJS= \ obj/key.o \ obj/db.o \ obj/init.o \ + obj/bitcoind.o \ obj/keystore.o \ obj/main.o \ obj/net.o \ @@ -116,7 +117,7 @@ TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) obj-test/%.o: test/%.cpp $(HEADERS) $(CXX) -c $(TESTDEFS) $(xCXXFLAGS) -o $@ $< -test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) +test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o obj/bitcoind.o,$(OBJS:obj/%=obj/%)) $(CXX) $(xCXXFLAGS) $(xLDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework-mt-s $(LIBS) diff --git a/src/makefile.mingw b/src/makefile.mingw index 8b5a5dccd..34ddc3eec 100644 --- a/src/makefile.mingw +++ b/src/makefile.mingw @@ -79,6 +79,7 @@ OBJS= \ obj/key.o \ obj/db.o \ obj/init.o \ + obj/bitcoind.o \ obj/keystore.o \ obj/main.o \ obj/net.o \ @@ -127,7 +128,7 @@ TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp)) obj-test/%.o: test/%.cpp $(HEADERS) $(CXX) -c $(TESTDEFS) $(CFLAGS) -o $@ $< -test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) +test_bitcoin.exe: $(TESTOBJS) $(filter-out obj/init.o obj/bitcoind.o,$(OBJS:obj/%=obj/%)) $(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(LIBPATHS) $^ -lboost_unit_test_framework$(BOOST_SUFFIX) $(LIBS) clean: diff --git a/src/makefile.osx b/src/makefile.osx index 50279fdb0..4ee0edcb9 100644 --- a/src/makefile.osx +++ b/src/makefile.osx @@ -82,6 +82,7 @@ OBJS= \ obj/key.o \ obj/db.o \ obj/init.o \ + obj/bitcoind.o \ obj/keystore.o \ obj/main.o \ obj/net.o \ @@ -162,7 +163,7 @@ obj-test/%.o: test/%.cpp -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) +test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o obj/bitcoind.o,$(OBJS:obj/%=obj/%)) $(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS) $(TESTLIBS) clean: diff --git a/src/makefile.unix b/src/makefile.unix index 811023564..f8042b293 100644 --- a/src/makefile.unix +++ b/src/makefile.unix @@ -121,6 +121,7 @@ OBJS= \ obj/key.o \ obj/db.o \ obj/init.o \ + obj/bitcoind.o \ obj/keystore.o \ obj/main.o \ obj/net.o \ @@ -187,7 +188,7 @@ obj-test/%.o: test/%.cpp -e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \ rm -f $(@:%.o=%.d) -test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o,$(OBJS:obj/%=obj/%)) +test_bitcoin: $(TESTOBJS) $(filter-out obj/init.o obj/bitcoind.o,$(OBJS:obj/%=obj/%)) $(LINK) $(xCXXFLAGS) -o $@ $(LIBPATHS) $^ $(TESTLIBS) $(xLDFLAGS) $(LIBS) clean: From 13c84b3bd550f93bf6c2bf57677a08a1ea858c60 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:00:16 -0400 Subject: [PATCH 3/8] build: add global var for whether or not the gui is enabled --- src/bitcoind.cpp | 1 + src/main.cpp | 1 + src/main.h | 1 + src/qt/bitcoin.cpp | 2 ++ 4 files changed, 5 insertions(+) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 81f67802d..682a214fb 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -123,6 +123,7 @@ extern void noui_connect(); int main(int argc, char* argv[]) { bool fRet = false; + fHaveGUI = false; // Connect bitcoind signal handlers noui_connect(); diff --git a/src/main.cpp b/src/main.cpp index a98b83b6a..b8b777161 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,7 @@ bool fReindex = false; bool fBenchmark = false; bool fTxIndex = false; unsigned int nCoinCacheSize = 5000; +bool fHaveGUI = false; /** Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) */ int64 CTransaction::nMinTxFee = 10000; // Override with -mintxfee diff --git a/src/main.h b/src/main.h index 679ae75a4..fae37ea51 100644 --- a/src/main.h +++ b/src/main.h @@ -94,6 +94,7 @@ extern bool fBenchmark; extern int nScriptCheckThreads; extern bool fTxIndex; extern unsigned int nCoinCacheSize; +extern bool fHaveGUI; // Settings extern int64 nTransactionFee; diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 73a5a12ef..76e88b36a 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -113,6 +113,8 @@ static void handleRunawayException(std::exception *e) #ifndef BITCOIN_QT_TEST int main(int argc, char *argv[]) { + fHaveGUI = true; + // Command-line options take precedence: ParseParameters(argc, argv); From c98c88b3abf35d04c2058bd50ae50f2496e09594 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:05:53 -0400 Subject: [PATCH 4/8] build: cosmetic: split usage string for easier formatting --- src/init.cpp | 136 +++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e9e5e278b..75229a3d6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -158,89 +158,89 @@ bool static Bind(const CService &addr, unsigned int flags) { // Core-specific options shared between UI and daemon std::string HelpMessage() { - string strUsage = _("Options:") + "\n" + - " -? " + _("This help message") + "\n" + - " -conf= " + _("Specify configuration file (default: bitcoin.conf)") + "\n" + - " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n" + - " -gen " + _("Generate coins (default: 0)") + "\n" + - " -datadir= " + _("Specify data directory") + "\n" + - " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n" + - " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" + - " -proxy= " + _("Connect through socks proxy") + "\n" + - " -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" + - " -tor= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n" - " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" + - " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n" + - " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n" + - " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n" + - " -connect= " + _("Connect only to the specified node(s)") + "\n" + - " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n" + - " -externalip= " + _("Specify your own public address") + "\n" + - " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n" + - " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n" + - " -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n" + - " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n" + - " -bind= " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n" + - " -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n" + - " -banscore= " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n" + - " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n" + - " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n" + - " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n" + + string strUsage = _("Options:") + "\n"; + strUsage += " -? " + _("This help message") + "\n"; + strUsage += " -conf= " + _("Specify configuration file (default: bitcoin.conf)") + "\n"; + strUsage += " -pid= " + _("Specify pid file (default: bitcoind.pid)") + "\n"; + strUsage += " -gen " + _("Generate coins (default: 0)") + "\n"; + strUsage += " -datadir= " + _("Specify data directory") + "\n"; + strUsage += " -dbcache= " + _("Set database cache size in megabytes (default: 25)") + "\n"; + strUsage += " -timeout= " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n"; + strUsage += " -proxy= " + _("Connect through socks proxy") + "\n"; + strUsage += " -socks= " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n"; + strUsage += " -tor= " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"; + strUsage += " -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n"; + strUsage += " -port= " + _("Listen for connections on (default: 8333 or testnet: 18333)") + "\n"; + strUsage += " -maxconnections= " + _("Maintain at most connections to peers (default: 125)") + "\n"; + strUsage += " -addnode= " + _("Add a node to connect to and attempt to keep the connection open") + "\n"; + strUsage += " -connect= " + _("Connect only to the specified node(s)") + "\n"; + strUsage += " -seednode= " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n"; + strUsage += " -externalip= " + _("Specify your own public address") + "\n"; + strUsage += " -onlynet= " + _("Only connect to nodes in network (IPv4, IPv6 or Tor)") + "\n"; + strUsage += " -discover " + _("Discover own IP address (default: 1 when listening and no -externalip)") + "\n"; + strUsage += " -checkpoints " + _("Only accept block chain matching built-in checkpoints (default: 1)") + "\n"; + strUsage += " -listen " + _("Accept connections from outside (default: 1 if no -proxy or -connect)") + "\n"; + strUsage += " -bind= " + _("Bind to given address and always listen on it. Use [host]:port notation for IPv6") + "\n"; + strUsage += " -dnsseed " + _("Find peers using DNS lookup (default: 1 unless -connect)") + "\n"; + strUsage += " -banscore= " + _("Threshold for disconnecting misbehaving peers (default: 100)") + "\n"; + strUsage += " -bantime= " + _("Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") + "\n"; + strUsage += " -maxreceivebuffer= " + _("Maximum per-connection receive buffer, *1000 bytes (default: 5000)") + "\n"; + strUsage += " -maxsendbuffer= " + _("Maximum per-connection send buffer, *1000 bytes (default: 1000)") + "\n"; #ifdef USE_UPNP #if USE_UPNP - " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n" + + strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 1 when listening)") + "\n"; #else - " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n" + + strUsage += " -upnp " + _("Use UPnP to map the listening port (default: 0)") + "\n"; #endif #endif - " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\n" + + strUsage += " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\n"; #ifdef QT_GUI - " -server " + _("Accept command line and JSON-RPC commands") + "\n" + + strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n"; #endif #if !defined(WIN32) && !defined(QT_GUI) - " -daemon " + _("Run in the background as a daemon and accept commands") + "\n" + + strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n"; #endif - " -testnet " + _("Use the test network") + "\n" + - " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n" + - " -debugnet " + _("Output extra network debugging information") + "\n" + - " -logtimestamps " + _("Prepend debug output with timestamp") + "\n" + - " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n" + - " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n" + + strUsage += " -testnet " + _("Use the test network") + "\n"; + strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n"; + strUsage += " -debugnet " + _("Output extra network debugging information") + "\n"; + strUsage += " -logtimestamps " + _("Prepend debug output with timestamp") + "\n"; + strUsage += " -shrinkdebugfile " + _("Shrink debug.log file on client startup (default: 1 when no -debug)") + "\n"; + strUsage += " -printtoconsole " + _("Send trace/debug info to console instead of debug.log file") + "\n"; #ifdef WIN32 - " -printtodebugger " + _("Send trace/debug info to debugger") + "\n" + + strUsage += " -printtodebugger " + _("Send trace/debug info to debugger") + "\n"; #endif - " -rpcuser= " + _("Username for JSON-RPC connections") + "\n" + - " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n" + - " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n" + - " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n" + + strUsage += " -rpcuser= " + _("Username for JSON-RPC connections") + "\n"; + strUsage += " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n"; + strUsage += " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n"; + strUsage += " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n"; #ifndef QT_GUI - " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n" + + strUsage += " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; #endif - " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n" + - " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n" + - " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n" + - " -alertnotify= " + _("Execute command when a relevant alert is received (%s in cmd is replaced by message)") + "\n" + - " -upgradewallet " + _("Upgrade wallet to latest format") + "\n" + - " -keypool= " + _("Set key pool size to (default: 100)") + "\n" + - " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" + - " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" + - " -checkblocks= " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n" + - " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n" + - " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n" + - " -loadblock= " + _("Imports blocks from external blk000??.dat file") + "\n" + - " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + "\n" + - " -par= " + _("Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)") + "\n" + + strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n"; + strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; + strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; + strUsage += " -alertnotify= " + _("Execute command when a relevant alert is received (%s in cmd is replaced by message)") + "\n"; + strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; + strUsage += " -keypool= " + _("Set key pool size to (default: 100)") + "\n"; + strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; + strUsage += " -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n"; + strUsage += " -checkblocks= " + _("How many blocks to check at startup (default: 288, 0 = all)") + "\n"; + strUsage += " -checklevel= " + _("How thorough the block verification is (0-4, default: 3)") + "\n"; + strUsage += " -txindex " + _("Maintain a full transaction index (default: 0)") + "\n"; + strUsage += " -loadblock= " + _("Imports blocks from external blk000??.dat file") + "\n"; + strUsage += " -reindex " + _("Rebuild block chain index from current blk000??.dat files") + "\n"; + strUsage += " -par= " + _("Set the number of script verification threads (up to 16, 0 = auto, <0 = leave that many cores free, default: 0)") + "\n"; - "\n" + _("Block creation options:") + "\n" + - " -blockminsize= " + _("Set minimum block size in bytes (default: 0)") + "\n" + - " -blockmaxsize= " + _("Set maximum block size in bytes (default: 250000)") + "\n" + - " -blockprioritysize= " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n" + + strUsage += "\n"; _("Block creation options:") + "\n"; + strUsage += " -blockminsize= " + _("Set minimum block size in bytes (default: 0)") + "\n"; + strUsage += " -blockmaxsize= " + _("Set maximum block size in bytes (default: 250000)") + "\n"; + strUsage += " -blockprioritysize= " + _("Set maximum size of high-priority/low-fee transactions in bytes (default: 27000)") + "\n"; - "\n" + _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n" + - " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n" + - " -rpcsslcertificatechainfile= " + _("Server certificate file (default: server.cert)") + "\n" + - " -rpcsslprivatekeyfile= " + _("Server private key (default: server.pem)") + "\n" + - " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n"; + strUsage += "\n"; _("SSL options: (see the Bitcoin Wiki for SSL setup instructions)") + "\n"; + strUsage += " -rpcssl " + _("Use OpenSSL (https) for JSON-RPC connections") + "\n"; + strUsage += " -rpcsslcertificatechainfile= " + _("Server certificate file (default: server.cert)") + "\n"; + strUsage += " -rpcsslprivatekeyfile= " + _("Server private key (default: server.pem)") + "\n"; + strUsage += " -rpcsslciphers= " + _("Acceptable ciphers (default: TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)") + "\n"; return strUsage; } From 7f61f1ac78039d713f034e648f4efad3649e04c3 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:10:38 -0400 Subject: [PATCH 5/8] build: use runtime setting for displaying the help message rather than QT_GUI define --- src/init.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 75229a3d6..dcc43d836 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -194,11 +194,11 @@ std::string HelpMessage() #endif #endif strUsage += " -paytxfee= " + _("Fee per KB to add to transactions you send") + "\n"; -#ifdef QT_GUI - strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n"; -#endif -#if !defined(WIN32) && !defined(QT_GUI) - strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n"; + if (fHaveGUI) + strUsage += " -server " + _("Accept command line and JSON-RPC commands") + "\n"; +#if !defined(WIN32) + if (fHaveGUI) + strUsage += " -daemon " + _("Run in the background as a daemon and accept commands") + "\n"; #endif strUsage += " -testnet " + _("Use the test network") + "\n"; strUsage += " -debug " + _("Output extra debugging information. Implies all other -debug* options") + "\n"; @@ -213,9 +213,8 @@ std::string HelpMessage() strUsage += " -rpcpassword= " + _("Password for JSON-RPC connections") + "\n"; strUsage += " -rpcport= " + _("Listen for JSON-RPC connections on (default: 8332 or testnet: 18332)") + "\n"; strUsage += " -rpcallowip= " + _("Allow JSON-RPC connections from specified IP address") + "\n"; -#ifndef QT_GUI - strUsage += " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; -#endif + if (!fHaveGUI) + strUsage += " -rpcconnect= " + _("Send commands to node running on (default: 127.0.0.1)") + "\n"; strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n"; strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; @@ -435,9 +434,8 @@ bool AppInit2(boost::thread_group& threadGroup) fServer = GetBoolArg("-server", false); /* force fServer when running without GUI */ -#if !defined(QT_GUI) - fServer = true; -#endif + if (!fHaveGUI) + fServer = true; fPrintToConsole = GetBoolArg("-printtoconsole", false); fPrintToDebugger = GetBoolArg("-printtodebugger", false); fLogTimestamps = GetBoolArg("-logtimestamps", false); From ee4b170c929b0f0d0b5a9fcaa0c35c79e9ac157c Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:17:18 -0400 Subject: [PATCH 6/8] build: use runtime setting for wallet rather than QT_GUI define --- src/wallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 27aab08ec..17a35d940 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -459,7 +459,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) if (fInsertedNew || fUpdated) if (!wtx.WriteToDisk()) return false; -#ifndef QT_GUI + + if (!fHaveGUI) { // If default receiving address gets used, replace it with a new one if (vchDefaultKey.IsValid()) { CScript scriptDefaultKey; @@ -477,7 +478,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) } } } -#endif + } // since AddToWallet is called directly for self-originating transactions, check for consumption of own coins WalletUpdateSpent(wtx); From 34994ebcb0cb5164f515266ebc5524a9608cb1c8 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:18:33 -0400 Subject: [PATCH 7/8] build: cosmetics after last commit --- src/wallet.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index 17a35d940..549d9bbf4 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -461,24 +461,24 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) return false; if (!fHaveGUI) { - // If default receiving address gets used, replace it with a new one - if (vchDefaultKey.IsValid()) { - CScript scriptDefaultKey; - scriptDefaultKey.SetDestination(vchDefaultKey.GetID()); - BOOST_FOREACH(const CTxOut& txout, wtx.vout) - { - if (txout.scriptPubKey == scriptDefaultKey) + // If default receiving address gets used, replace it with a new one + if (vchDefaultKey.IsValid()) { + CScript scriptDefaultKey; + scriptDefaultKey.SetDestination(vchDefaultKey.GetID()); + BOOST_FOREACH(const CTxOut& txout, wtx.vout) { - CPubKey newDefaultKey; - if (GetKeyFromPool(newDefaultKey, false)) + if (txout.scriptPubKey == scriptDefaultKey) { - SetDefaultKey(newDefaultKey); - SetAddressBookName(vchDefaultKey.GetID(), ""); + CPubKey newDefaultKey; + if (GetKeyFromPool(newDefaultKey, false)) + { + SetDefaultKey(newDefaultKey); + SetAddressBookName(vchDefaultKey.GetID(), ""); + } } } } } - } // since AddToWallet is called directly for self-originating transactions, check for consumption of own coins WalletUpdateSpent(wtx); From 6887bb9ad7f6722a64e9fbdf0a780f362dc796a1 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sun, 26 May 2013 14:19:04 -0400 Subject: [PATCH 8/8] build: kill off the QT_GUI define --- bitcoin-qt.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin-qt.pro b/bitcoin-qt.pro index 05fb5545a..ec9f5e4a1 100644 --- a/bitcoin-qt.pro +++ b/bitcoin-qt.pro @@ -5,7 +5,7 @@ VERSION = 0.8.2 INCLUDEPATH += src src/json src/qt QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets -DEFINES += QT_GUI BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE +DEFINES += BOOST_THREAD_USE_LIB BOOST_SPIRIT_THREADSAFE CONFIG += no_include_pwd CONFIG += thread