From 2e0d0467eef888b7afa4af4ebc6de090643dc56f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 23 Aug 2017 15:46:35 -0600 Subject: [PATCH] charybdis: Various improvements / fixes to console etc. --- charybdis/charybdis.cc | 41 ++++++++++++++++++++++++++++++++--------- charybdis/console.cc | 9 ++++----- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/charybdis/charybdis.cc b/charybdis/charybdis.cc index 098af4653..a90ef7a7a 100644 --- a/charybdis/charybdis.cc +++ b/charybdis/charybdis.cc @@ -84,7 +84,6 @@ int main(int argc, char *const *argv) try { umask(077); // better safe than sorry --SRB - parseargs(&argc, &argv, opts); if(!startup_checks()) return 1; @@ -95,9 +94,24 @@ try return 0; } - const std::string confpath(configfile?: fs::get(fs::IRCD_CONF)); + // Determine the configuration file from either the user's command line + // argument or fall back to the default. + const std::string confpath + { + configfile?: fs::get(fs::IRCD_CONF) + }; + + // Associates libircd with our io_service and posts the initial routines + // to that io_service. Execution of IRCd will then occur during ios::run() ircd::init(*ios, confpath); + // 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 + // is done properly through the io_service which registers the handler for + // the platform and then safely posts the received signal to the io_service + // event loop. This means we lose the true instant hardware-interrupt gratitude + // of signals but with the benefit of unconditional safety and cross- + // platformness with windows etc. sigs.add(SIGHUP); sigs.add(SIGINT); sigs.add(SIGTSTP); @@ -105,18 +119,26 @@ try sigs.add(SIGTERM); sigs.add(SIGUSR1); sigs.add(SIGUSR2); - ircd::at_main_exit([] - { - // Entered when IRCd's main context has finished. ios.run() won't - // return because our signal handler out here is still using it. - sigs.cancel(); - }); sigs.async_wait(sigfd_handler); + // Because we registered signal handlers with the io_service, ios->run() + // is now shared between those handlers and libircd. This means the run() + // won't return even if ircd::stop() is called. We use the callback to then + // cancel the handlers allowing run() to return and the program to exit. + ircd::at_main_exit([] + { + // Entered when IRCd's main context has finished. + sigs.cancel(); + }); + + // If the user wants to immediately drop to a command line without having to + // send a ctrl-c for it, that is provided here. if(cmdline) console_spawn(); - ios->run(); // Blocks until a clean exit or an exception comes out of it. + // Execution. + // Blocks until a clean exit from a stop() or an exception comes out of it. + ios->run(); } catch(const ircd::user_error &e) { @@ -156,6 +178,7 @@ void print_version() #endif printf("VERSION :boost %d\n", BOOST_VERSION); + printf("VERSION :RocksDB %s\n", ircd::db::version); } bool startup_checks() diff --git a/charybdis/console.cc b/charybdis/console.cc index 31a6d9cbb..7cb7acc21 100644 --- a/charybdis/console.cc +++ b/charybdis/console.cc @@ -252,7 +252,7 @@ try const auto args(tokens_after(line, " ", 0)); const params token{args, " ", {"host", "port"}}; const std::string host{token.at(0, "127.0.0.1"s)}; - const auto port{token.at(1, 6667)}; + const auto port{token.at(1, 8448)}; moi = new m::session{{host, port}}; break; } @@ -298,14 +298,13 @@ try } const auto args(tokens_after(line, " ", 0)); - const params token{args, " ", {"username", "pass"}}; + const params token{args, " ", {"username", "password"}}; m::request request { - "POST", "_matrix/client/r0/register", {}, + "POST", "_matrix/client/r0/register?kind=user", {}, { { "username", token.at(0) }, - { "pass", token.at(1) }, { "password", token.at(1) }, { "auth", @@ -332,7 +331,7 @@ try } const auto args(tokens_after(line, " ", 0)); - const params token{args, " ", {"user", "pass"}}; + const params token{args, " ", {"username", "password"}}; m::request request {