aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/main.cpp')
-rw-r--r--src/daemon/main.cpp95
1 files changed, 46 insertions, 49 deletions
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 0895e1bf1..19dd02171 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2016, The Monero Project
+// Copyright (c) 2014-2017, The Monero Project
//
// All rights reserved.
//
@@ -30,9 +30,10 @@
#include "common/command_line.h"
#include "common/scoped_message_writer.h"
+#include "common/password.h"
#include "common/util.h"
#include "cryptonote_core/cryptonote_core.h"
-#include "cryptonote_core/miner.h"
+#include "cryptonote_basic/miner.h"
#include "daemon/command_server.h"
#include "daemon/daemon.h"
#include "daemon/executor.h"
@@ -40,6 +41,7 @@
#include "misc_log_ex.h"
#include "p2p/net_node.h"
#include "rpc/core_rpc_server.h"
+#include "rpc/rpc_args.h"
#include "daemon/command_line_args.h"
#include "blockchain_db/db_types.h"
@@ -47,6 +49,9 @@
#include "common/stack_trace.h"
#endif // STACK_TRACE
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
+
namespace po = boost::program_options;
namespace bf = boost::filesystem;
@@ -54,7 +59,6 @@ int main(int argc, char const * argv[])
{
try {
- _note_c("dbg/main", "Begin of main()");
// TODO parse the debug options like set log level right here at start
tools::sanitize_locale();
@@ -79,7 +83,6 @@ int main(int argc, char const * argv[])
bf::path default_conf = default_data_dir / std::string(CRYPTONOTE_NAME ".conf");
command_line::add_arg(visible_options, daemon_args::arg_config_file, default_conf.string());
command_line::add_arg(visible_options, command_line::arg_test_dbg_lock_sleep);
- cryptonote::core::init_options(core_settings);
// Settings
bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log");
@@ -165,7 +168,6 @@ int main(int argc, char const * argv[])
// Create data dir if it doesn't exist
boost::filesystem::path data_dir = boost::filesystem::absolute(
command_line::get_arg(vm, data_dir_arg));
- tools::create_directories_if_necessary(data_dir.string());
// FIXME: not sure on windows implementation default, needs further review
//bf::path relative_path_base = daemonizer::get_relative_path_base(vm);
@@ -196,19 +198,39 @@ int main(int argc, char const * argv[])
}
po::notify(vm);
+ // log_file_path
+ // default: <data_dir>/<CRYPTONOTE_NAME>.log
+ // if log-file argument given:
+ // absolute path
+ // relative path: relative to data_dir
+ bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
+ if (! vm["log-file"].defaulted())
+ log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
+ log_file_path = bf::absolute(log_file_path, relative_path_base);
+ mlog_configure(log_file_path.string(), true);
+
+ // Set log level
+ if (!vm["log-level"].defaulted())
+ {
+ mlog_set_log(command_line::get_arg(vm, daemon_args::arg_log_level).c_str());
+ }
+
+ // after logs initialized
+ tools::create_directories_if_necessary(data_dir.string());
+
// If there are positional options, we're running a daemon command
{
auto command = command_line::get_arg(vm, daemon_args::arg_command);
if (command.size())
{
- auto rpc_ip_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_ip);
+ const cryptonote::rpc_args::descriptors arg{};
+ auto rpc_ip_str = command_line::get_arg(vm, arg.rpc_bind_ip);
auto rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_rpc_bind_port);
if (testnet_mode)
{
rpc_port_str = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_testnet_rpc_bind_port);
}
- auto user_agent = command_line::get_arg(vm, cryptonote::core_rpc_server::arg_user_agent);
uint32_t rpc_ip;
uint16_t rpc_port;
@@ -223,7 +245,20 @@ int main(int argc, char const * argv[])
return 1;
}
- daemonize::t_command_server rpc_commands{rpc_ip, rpc_port, user_agent};
+ boost::optional<tools::login> login{};
+ if (command_line::has_arg(vm, arg.rpc_login))
+ {
+ login = tools::login::parse(
+ command_line::get_arg(vm, arg.rpc_login), false, "Daemon client password"
+ );
+ if (!login)
+ {
+ std::cerr << "Failed to obtain password" << std::endl;
+ return 1;
+ }
+ }
+
+ daemonize::t_command_server rpc_commands{rpc_ip, rpc_port, std::move(login)};
if (rpc_commands.process_command_vec(command))
{
return 0;
@@ -236,55 +271,17 @@ int main(int argc, char const * argv[])
}
}
- // Start with log level 0
- epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0);
-
- // Set log level
- {
- int new_log_level = command_line::get_arg(vm, daemon_args::arg_log_level);
- if(new_log_level < LOG_LEVEL_MIN || new_log_level > LOG_LEVEL_MAX)
- {
- LOG_PRINT_L0("Wrong log level value: " << new_log_level);
- }
- else if (epee::log_space::get_set_log_detalisation_level(false) != new_log_level)
- {
- epee::log_space::get_set_log_detalisation_level(true, new_log_level);
- int otshell_utils_log_level = 100 - (new_log_level * 20);
- gCurrentLogger.setDebugLevel(otshell_utils_log_level);
- LOG_PRINT_L0("LOG_LEVEL set to " << new_log_level);
- }
- }
-
- // log_file_path
- // default: <data_dir>/<CRYPTONOTE_NAME>.log
- // if log-file argument given:
- // absolute path
- // relative path: relative to data_dir
-
- // Set log file
- {
- bf::path log_file_path {data_dir / std::string(CRYPTONOTE_NAME ".log")};
- if (! vm["log-file"].defaulted())
- log_file_path = command_line::get_arg(vm, daemon_args::arg_log_file);
- log_file_path = bf::absolute(log_file_path, relative_path_base);
-
- epee::log_space::log_singletone::add_logger(
- LOGGER_FILE
- , log_file_path.filename().string().c_str()
- , log_file_path.parent_path().string().c_str()
- );
#ifdef STACK_TRACE
- tools::set_stack_trace_log(log_file_path.filename().string());
+ tools::set_stack_trace_log(log_file_path.filename().string());
#endif // STACK_TRACE
- }
if (command_line::has_arg(vm, daemon_args::arg_max_concurrency))
tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency));
// logging is now set up
- LOG_PRINT_L0("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
+ MGINFO("Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")");
- _note_c("dbg/main", "Moving from main() into the daemonize now.");
+ MINFO("Moving from main() into the daemonize now.");
return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm);
}