MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / AppInit

Function AppInit

src/coind.cpp:54–123  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////// Start

Source from the content-addressed store, hash-verified

52// Start
53//
54bool AppInit(int argc, char* argv[], boost::thread_group& threadGroup) {
55 // boost::thread* detectShutdownThread = nullptr;
56
57 bool fRet = false;
58 try {
59 //
60 // Parameters
61 //
62 // If Qt is used, parameters/coin.conf are parsed in qt/Coin.cpp's main()
63 CBaseParams::LoadParamsFromConfigFile(argc, argv);
64
65 if (SysCfg().IsArgCount("-?") || SysCfg().IsArgCount("--help")) {
66 // First part of help message is specific to coind / RPC client
67 std::string strUsage = _("WaykiChain Coin Daemon") + " " + _("version") + " " + FormatFullVersion() +
68 "\n\n" + _("Usage:") + "\n" + " coind [options] " +
69 _("Start Coin Core Daemon") + "\n" + _("Usage (deprecated, use Coin-cli):") + "\n" +
70 " coin [options] <command> [params] " + _("Send command to Coin Core") + "\n" +
71 " coin [options] help " + _("List commands") + "\n" +
72 " coin [options] help <command> " + _("Get help for a command") + "\n";
73
74 strUsage += "\n" + HelpMessage();
75 strUsage += "\n" + HelpMessageCli(false);
76
77 fprintf(stdout, "%s", strUsage.c_str());
78 return false;
79 }
80
81 // Command-line RPC
82 bool fCommandLine = false;
83 for (int i = 1; i < argc; i++)
84 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "Coin:"))
85 fCommandLine = true;
86
87 if (fCommandLine) {
88 int ret = CommandLineRPC(argc, argv);
89 exit(ret);
90 }
91#ifndef WIN32
92 fDaemon = SysCfg().GetBoolArg("-daemon", false);
93 if (fDaemon) {
94 fprintf(stdout, "Coin server starting\n");
95
96 // Daemonize
97 pid_t pid = fork();
98 if (pid < 0) {
99 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
100 return false;
101 }
102 if (pid > 0) // Parent process, pid is child process id
103 {
104 CreatePidFile(GetPidFile(), pid);
105 return true;
106 }
107 // Child process falls through to rest of initialization
108
109 pid_t sid = setsid();
110 if (sid < 0) fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
111 }

Callers 1

RunCoinFunction · 0.70

Calls 13

_Function · 0.85
FormatFullVersionFunction · 0.85
HelpMessageFunction · 0.85
HelpMessageCliFunction · 0.85
IsSwitchCharFunction · 0.85
CommandLineRPCFunction · 0.85
CreatePidFileFunction · 0.85
GetPidFileFunction · 0.85
InitLoggingFunction · 0.85
PrintExceptionContinueFunction · 0.85
IsArgCountMethod · 0.80
GetBoolArgMethod · 0.80

Tested by

no test coverage detected