diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-09-30 18:02:53 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2016-09-30 18:19:31 +0200 |
commit | fb24d7eeb47e6caeef7b4ce62a1c35130d42f67f (patch) | |
tree | ab18d1dc0bf05d05c6e283165b963f01681bd358 /src/bitcoind.cpp | |
parent | 9bc6a6bd7b0ddb12cbafdd6d3b70fb6b10c0d2ba (diff) | |
parent | a92bf4af66f8b5a2e6bc28baa6670065ce76daf2 (diff) |
Merge #8813: bitcoind: Daemonize using daemon(3)
a92bf4a bitcoind: Daemonize using daemon(3) (Matthew King)
Diffstat (limited to 'src/bitcoind.cpp')
-rw-r--r-- | src/bitcoind.cpp | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 322298d1b3..25d720e1e8 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -9,6 +9,7 @@ #include "chainparams.h" #include "clientversion.h" +#include "compat.h" #include "rpc/server.h" #include "init.h" #include "noui.h" @@ -127,29 +128,21 @@ bool AppInit(int argc, char* argv[]) fprintf(stderr, "Error: There is no RPC client functionality in bitcoind anymore. Use the bitcoin-cli utility instead.\n"); exit(1); } -#ifndef WIN32 if (GetBoolArg("-daemon", false)) { +#if HAVE_DECL_DAEMON fprintf(stdout, "Bitcoin server starting\n"); // Daemonize - pid_t pid = fork(); - if (pid < 0) - { - fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); + if (daemon(1, 0)) { // don't chdir (1), do close FDs (0) + fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno)); return false; } - if (pid > 0) // Parent process, pid is child process id - { - 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); +#else + fprintf(stderr, "Error: -daemon is not supported on this operating system\n"); + return false; +#endif // HAVE_DECL_DAEMON } -#endif SoftSetBoolArg("-server", true); // Set this early so that parameter interactions go to console |