0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-02-27 14:10:13 +01:00

construct/ircd: Use hostname-based init from command line params.

This commit is contained in:
Jason Volk 2018-08-13 14:36:12 -07:00
parent 6dec6dca3e
commit d1944c6006
3 changed files with 27 additions and 26 deletions

View file

@ -19,7 +19,7 @@ namespace fs = ircd::fs;
static void sigfd_handler(const boost::system::error_code &, int) noexcept; static void sigfd_handler(const boost::system::error_code &, int) noexcept;
static bool startup_checks(); static bool startup_checks();
static void enable_coredumps(); static void enable_coredumps();
static void print_version(); static int print_version();
const char *const fatalerrstr const char *const fatalerrstr
{R"( {R"(
@ -75,31 +75,40 @@ int main(int argc, char *const *argv)
try try
{ {
umask(077); // better safe than sorry --SRB umask(077); // better safe than sorry --SRB
// '-' switched arguments come first; this function incs argv and decs argc
parseargs(&argc, &argv, opts); parseargs(&argc, &argv, opts);
if(!startup_checks())
return 1;
// cores are not dumped without consent of the user to maintain the privacy // cores are not dumped without consent of the user to maintain the privacy
// of cryptographic key material in memory at the time of the crash. // of cryptographic key material in memory at the time of the crash.
if(RB_DEBUG_LEVEL || ircd::debugmode) if(RB_DEBUG_LEVEL || ircd::debugmode)
enable_coredumps(); enable_coredumps();
if(printversion) if(!startup_checks())
{ return EXIT_FAILURE;
print_version();
return 0;
}
// Determine the configuration file from either the user's command line if(printversion)
// argument or fall back to the default. return print_version();
const std::string confpath
// The matrix origin (i.e hostname) is the first positional argument after any
// switched arguments. All other information about configuration and database
// location is found using this string.
const ircd::string_view hostname
{ {
configfile?: "" argc? *argv : nullptr // where parseargs() left off
}; };
// at least one hostname argument is required for now.
if(!hostname)
throw ircd::user_error
{
"Must specify the origin (i.e hostname) after any switched parameters."
};
// Associates libircd with our io_context and posts the initial routines // Associates libircd with our io_context and posts the initial routines
// to that io_context. Execution of IRCd will then occur during ios::run() // to that io_context. Execution of IRCd will then occur during ios::run()
ircd::init(*ios, confpath); // note: only supports service for one hostname at this time.
ircd::init(*ios, hostname);
// libircd does no signal handling (or at least none that you ever have to // libircd does no signal handling (or at least none that you ever have to
// care about); reaction to all signals happens out here instead. Handling // care about); reaction to all signals happens out here instead. Handling
@ -172,7 +181,7 @@ catch(const std::exception &e)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
void int
print_version() print_version()
{ {
printf("VERSION :%s\n", printf("VERSION :%s\n",
@ -183,6 +192,8 @@ print_version()
PACKAGE_NAME, PACKAGE_NAME,
PACKAGE_VERSION); PACKAGE_VERSION);
#endif #endif
return EXIT_SUCCESS;
} }
bool bool

View file

@ -85,8 +85,7 @@ namespace ircd
seconds uptime(); seconds uptime();
void init(boost::asio::io_context &ios, const std::string &conf); void init(boost::asio::io_context &ios, const string_view &hostname);
void init(boost::asio::io_context &ios);
bool quit() noexcept; bool quit() noexcept;
} }

View file

@ -39,12 +39,6 @@ std::thread::id
ircd::thread_id ircd::thread_id
{}; {};
void
ircd::init(boost::asio::io_context &ios)
{
init(ios, std::string{});
}
/// Sets up the IRCd and its main context, then returns without blocking. /// Sets up the IRCd and its main context, then returns without blocking.
// //
/// Pass your io_context instance, it will share it with the rest of your program. /// Pass your io_context instance, it will share it with the rest of your program.
@ -56,7 +50,7 @@ ircd::init(boost::asio::io_context &ios)
/// init() can only be called from a runlevel::HALT state /// init() can only be called from a runlevel::HALT state
void void
ircd::init(boost::asio::io_context &ios, ircd::init(boost::asio::io_context &ios,
const std::string &configfile) const string_view &hostname)
try try
{ {
if(runlevel != runlevel::HALT) if(runlevel != runlevel::HALT)
@ -83,9 +77,6 @@ try
info::init(); info::init();
info::dump(); info::dump();
// The conf supplied by the user is read in; see: ircd::conf.
conf::init(configfile);
// Setup the main context, which is a new stack executing the function // Setup the main context, which is a new stack executing the function
// ircd::main(). The main_context is the first ircd::ctx to be spawned // ircd::main(). The main_context is the first ircd::ctx to be spawned
// and will be the last to finish. // and will be the last to finish.