diff --git a/src/main.cc b/src/main.cc index 44937271..66b2bbdc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -112,7 +112,9 @@ main(int argc, char** argv) { torrent::log_initialize(); - torrent::runtime::initialize_worker_process_and_main_thread(); + torrent::runtime::initialize_worker_process_and_main_thread([argc, argv]() { + parse_config_file(argc, argv, [](auto& path) { parse_config_file_comments("worker", path); }); + }); // Block SIGCHLD until all threads are created, then unblock on main-thread, to avoid SIGCHLD // interrupting other threads. @@ -135,12 +137,10 @@ main(int argc, char** argv) { // # do:log.open_file=system,/usr/rakshasa/system.log // # do:log.add_output=system,system // - parse_config_file(argc, argv, [](auto& path) { - if (path.empty()) - return; - - parse_config_file_comments(path); - }); + // # do-worker:log.open_file=system,/usr/rakshasa/system-worker.log + // # do-worker:log.add_output=system,system + // + parse_config_file(argc, argv, [](auto& path) { parse_config_file_comments("", path); }); control = new Control; diff --git a/src/option_parser.cc b/src/option_parser.cc index d8bc1c59..f8aff7c0 100644 --- a/src/option_parser.cc +++ b/src/option_parser.cc @@ -108,6 +108,6 @@ OptionParser::call_int_pair(slot_int_pair slot, const std::string& arg) { if (a < 0 || b < 0) throw std::runtime_error("Invalid argument, \"" + arg + "\" should be positive numbers"); - + slot(a, b); } diff --git a/src/setup.cc b/src/setup.cc index 7e9b6bc7..2562d00e 100644 --- a/src/setup.cc +++ b/src/setup.cc @@ -108,18 +108,22 @@ config_comment_log(const std::string& command, const std::string& raw_args) { throw torrent::input_error("Unknown log command: " + command); } -// Call special commands in the format "# do:command=args" in the config file. +// Call special commands in the format "# do:command=args" or "# do-:command=args" in the config file. void -parse_config_file_comments(const std::string& path) { +parse_config_file_comments(const std::string& category, const std::string& path) { + if (path.empty()) + return; + std::fstream file(path, std::ios::in); if (!file.is_open()) return; std::string line; + std::string prefix = category.empty() ? "# do:" : "# do-" + category + ":"; while (std::getline(file, line)) { - if (line.size() <= 5 || line.compare(0, 5, "# do:") != 0) + if (line.size() <= prefix.size() || line.compare(0, prefix.size(), prefix) != 0) continue; auto equal_pos = line.find('='); diff --git a/src/setup.h b/src/setup.h index fe105c3b..bd009135 100644 --- a/src/setup.h +++ b/src/setup.h @@ -6,7 +6,7 @@ int parse_main_options(int argc, char** argv); void parse_config_file(int argc, char** argv, std::function parse_fn); -void parse_config_file_comments(const std::string& path); +void parse_config_file_comments(const std::string& category, const std::string& path); void load_session_torrents(const std::string& path); void load_arg_torrents(char** first, char** last);