From 6da02915627fb15a08fae932884af37d12861be2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 9 Apr 2021 18:37:18 -0700 Subject: [PATCH] construct::console: Improve main sequence; extension module unload related. --- construct/console.cc | 79 ++++++++++++++++++++++++++++---------------- construct/console.h | 2 ++ construct/signals.cc | 1 - 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/construct/console.cc b/construct/console.cc index fae03ffc7..95ac494ba 100644 --- a/construct/console.cc +++ b/construct/console.cc @@ -92,7 +92,7 @@ construct::console::interrupt() construct::console->context.interrupt(); return true; } - return false; + else return false; } bool @@ -103,7 +103,7 @@ construct::console::terminate() construct::console->context.terminate(); return true; } - return false; + else return false; } bool @@ -137,10 +137,10 @@ construct::console::console() void construct::console::main() -try { - const unwind destruct{[] + const unwind dtor{[] { + assert(construct::console); construct::console->context.detach(); delete construct::console; construct::console = nullptr; @@ -149,30 +149,22 @@ try if(!wait_running()) return; - ircd::module module{"console"}; - this->module = &module; - - if(next_command()) + ircd::module module { - while(handle_line()) - if(!next_command()) - break; + "console" + }; - if(unlikely(quit_when_done)) - { - static ircd::ios::descriptor descriptor - { - "construct.console.quit" - }; + this->module = &module; + loop(); +} - ircd::dispatch - { - descriptor, ios::defer, ircd::quit - }; - } - - return; - } +void +construct::console::loop() +try +{ + if(next_command()) + if(handle_queued()) + return; show_message(); do { @@ -194,6 +186,39 @@ catch(const std::exception &e) "The console session has ended: %s", e.what() }; } +catch(...) +{ + log::debug + { + "The console session has terminated." + }; +} + +bool +construct::console::handle_queued() +{ + while(handle_line()) + if(!next_command()) + break; + + if(!quit_when_done) + return true; + + if(run::level != run::level::RUN) + return true; + + static ircd::ios::descriptor descriptor + { + "construct.console.quit" + }; + + ircd::dispatch + { + descriptor, ios::defer, ircd::quit + }; + + return true; +} bool construct::console::handle_line() @@ -513,10 +538,6 @@ construct::console::on_runlevel(const enum ircd::run::level &runlevel) switch(runlevel) { case ircd::run::level::QUIT: - if(terminate()) - context.join(); - break; - case ircd::run::level::HALT: terminate(); break; diff --git a/construct/console.h b/construct/console.h index a857be5ca..8a234caa2 100644 --- a/construct/console.h +++ b/construct/console.h @@ -41,6 +41,8 @@ struct construct::console bool cmd__watch(); int handle_line_bymodule(); bool handle_line(); + bool handle_queued(); + void loop(); void main(); console(); diff --git a/construct/signals.cc b/construct/signals.cc index 43f77aef5..32bb53e65 100644 --- a/construct/signals.cc +++ b/construct/signals.cc @@ -190,7 +190,6 @@ void construct::handle_quit() try { - console::terminate(); ircd::quit(); } catch(const std::exception &e)