aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-03-13 17:15:34 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-03-13 17:15:34 -0400
commit1bf9b3b06f483d908bb70ba3736ec347b72d90c8 (patch)
tree53dbc1ae3ec3d5b2b8a48bb33d9e5cd4b7539f03
parentdfd059173d911f173e67d8a384265663fb5537b0 (diff)
parente1205e4d15403fdbb9b8d081aa7a9c3190529262 (diff)
Merge branch 'daemon-mode' of https://github.com/tcatm/bitcoin
-rw-r--r--init.cpp65
-rw-r--r--util.cpp1
-rw-r--r--util.h1
3 files changed, 41 insertions, 26 deletions
diff --git a/init.cpp b/init.cpp
index 9c84dca166..ac2721db63 100644
--- a/init.cpp
+++ b/init.cpp
@@ -74,32 +74,11 @@ void HandleSIGTERM(int)
#ifndef GUI
int main(int argc, char* argv[])
{
- for (int i = 1; i < argc; i++)
- if (!IsSwitchChar(argv[i][0]))
- fCommandLine = true;
- fDaemon = !fCommandLine;
-
-#ifdef __WXGTK__
- if (!fCommandLine)
- {
- // Daemonize
- pid_t pid = fork();
- if (pid < 0)
- {
- fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
- return 1;
- }
- if (pid > 0)
- pthread_exit((void*)0);
- }
-#endif
-
- if (!AppInit(argc, argv))
- return 1;
+ bool fRet = false;
+ fRet = AppInit(argc, argv);
- while (!fShutdown)
- Sleep(1000000);
- return 0;
+ if (fRet && fDaemon)
+ pthread_exit((void*)0);
}
#endif
@@ -177,8 +156,10 @@ bool AppInit2(int argc, char* argv[])
" -connect=<ip> \t\t " + _("Connect only to the specified node\n") +
" -nolisten \t " + _("Don't accept connections from outside\n") +
" -paytxfee=<amt> \t " + _("Fee per KB to add to transactions you send\n") +
+#ifdef GUI
" -server \t\t " + _("Accept command line and JSON-RPC commands\n") +
" -daemon \t\t " + _("Run in the background as a daemon and accept commands\n") +
+#endif
" -testnet \t\t " + _("Use the test network\n") +
" -rpcuser=<user> \t " + _("Username for JSON-RPC connections\n") +
" -rpcpassword=<pw>\t " + _("Password for JSON-RPC connections\n") +
@@ -213,6 +194,19 @@ bool AppInit2(int argc, char* argv[])
fDebug = GetBoolArg("-debug");
+ fDaemon = GetBoolArg("-daemon");
+
+ if (fDaemon)
+ fServer = true;
+ else
+ fServer = GetBoolArg("-server");
+
+ /* force fServer and fDaemon when running without GUI */
+#ifndef GUI
+ fServer = true;
+ fDaemon = true;
+#endif
+
fPrintToConsole = GetBoolArg("-printtoconsole");
fPrintToDebugger = GetBoolArg("-printtodebugger");
@@ -220,12 +214,31 @@ bool AppInit2(int argc, char* argv[])
fNoListen = GetBoolArg("-nolisten");
+ for (int i = 1; i < argc; i++)
+ if (!IsSwitchChar(argv[i][0]))
+ fCommandLine = true;
+
if (fCommandLine)
{
int ret = CommandLineRPC(argc, argv);
exit(ret);
}
+#ifndef GUI
+ 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)
+ return true;
+ }
+#endif
+
if (!fDebug && !pszSetDataDir[0])
ShrinkDebugFile();
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
@@ -443,7 +456,7 @@ bool AppInit2(int argc, char* argv[])
if (!CreateThread(StartNode, NULL))
wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin");
- if (GetBoolArg("-server") || fDaemon)
+ if (fServer)
CreateThread(ThreadRPCServer, NULL);
#if defined(__WXMSW__) && defined(GUI)
diff --git a/util.cpp b/util.cpp
index 8a2f9d525e..124174bd9d 100644
--- a/util.cpp
+++ b/util.cpp
@@ -14,6 +14,7 @@ char pszSetDataDir[MAX_PATH] = "";
bool fRequestShutdown = false;
bool fShutdown = false;
bool fDaemon = false;
+bool fServer = false;
bool fCommandLine = false;
string strMiscWarning;
bool fTestNet = false;
diff --git a/util.h b/util.h
index c69bf1ce17..1b780d5520 100644
--- a/util.h
+++ b/util.h
@@ -143,6 +143,7 @@ extern char pszSetDataDir[MAX_PATH];
extern bool fRequestShutdown;
extern bool fShutdown;
extern bool fDaemon;
+extern bool fServer;
extern bool fCommandLine;
extern string strMiscWarning;
extern bool fTestNet;