mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
Merge #8813: bitcoind: Daemonize using daemon(3)
a92bf4a
bitcoind: Daemonize using daemon(3) (Matthew King)
This commit is contained in:
parent
2f3abc62ee
commit
210242e5c0
@ -518,6 +518,9 @@ AC_SEARCH_LIBS([inet_pton], [nsl resolv], [AC_DEFINE(HAVE_INET_PTON, 1, [Define
|
||||
|
||||
AC_CHECK_DECLS([strnlen])
|
||||
|
||||
# Check for daemon(3), unrelated to --with-daemon (although used by it)
|
||||
AC_CHECK_DECLS([daemon])
|
||||
|
||||
AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
|
||||
[#if HAVE_ENDIAN_H
|
||||
#include <endian.h>
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "chainparams.h"
|
||||
#include "clientversion.h"
|
||||
#include "compat.h"
|
||||
#include "rpc/server.h"
|
||||
#include "init.h"
|
||||
#include "noui.h"
|
||||
@ -142,29 +143,21 @@ bool AppInit(int argc, char* argv[])
|
||||
fprintf(stderr, "Error: There is no RPC client functionality in dashd anymore. Use the dash-cli utility instead.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifndef WIN32
|
||||
if (GetBoolArg("-daemon", false))
|
||||
{
|
||||
#if HAVE_DECL_DAEMON
|
||||
fprintf(stdout, "Dash Core 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
|
||||
|
@ -395,7 +395,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
|
||||
if (mode == HMM_BITCOIND)
|
||||
{
|
||||
#ifndef WIN32
|
||||
#if HAVE_DECL_DAEMON
|
||||
strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands"));
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user