From 8f68163f90ae4d2e79b5e9c67b8718b7d5ada620 Mon Sep 17 00:00:00 2001 From: Proddy Date: Mon, 30 Jan 2023 17:04:10 +0100 Subject: [PATCH] fix exit not exiting in standalone mode --- src/console.cpp | 43 +++---------------------------------------- src/console.h | 4 ---- src/emsesp.cpp | 5 +++++ 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/console.cpp b/src/console.cpp index 1eb4ee71d..cfaf7af01 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -70,28 +70,13 @@ static void setup_commands(std::shared_ptr & commands) { // log, exit, help for (unsigned int context = ShellContext::MAIN; context < ShellContext::END; context++) { commands->add_command(context, CommandFlags::USER, {F_(log)}, {F_(log_level_optional)}, console_log_level, log_level_autocomplete); - - commands->add_command(context, - CommandFlags::USER, - {F_(exit)}, - context == ShellContext::MAIN ? EMSESPShell::main_exit_function : EMSESPShell::generic_exit_context_function); - + commands->add_command(context, CommandFlags::USER, {F_(exit)}, EMSESPShell::main_exit_function); commands->add_command(context, CommandFlags::USER, {F_(help)}, EMSESPShell::main_help_function); - - // commands->add_command(context, CommandFlags::USER, {F_(logout)}, EMSESPShell::main_logout_function); } - /* example of going into a new context - commands->add_command(ShellContext::MAIN, CommandFlags::ADMIN, flash_string_vector{F_(fs)}, - [] (Shell &shell, const std::vector &arguments) { - shell.enter_context(ShellContext::FILESYSTEM); - }); - */ - // // Show commands // - commands->add_command(ShellContext::MAIN, CommandFlags::USER, string_vector{F_(show), F_(system)}, @@ -721,39 +706,17 @@ std::string EMSESPShell::prompt_suffix() { void EMSESPShell::end_of_transmission() { invoke_command(F_(exit)); - // if (context() != ShellContext::MAIN || has_flags(CommandFlags::ADMIN)) { - // invoke_command(F_(exit)); - // } else { - // invoke_command(F_(logout)); - // } } -void EMSESPShell::generic_exit_context_function(Shell & shell, const std::vector & arguments) { - shell.exit_context(); -}; - void EMSESPShell::main_help_function(Shell & shell, const std::vector & arguments) { shell.print_all_available_commands(); } void EMSESPShell::main_exit_function(Shell & shell, const std::vector & arguments) { - if (shell.has_flags(CommandFlags::ADMIN)) { - EMSESPShell::main_exit_admin_function(shell, NO_ARGUMENTS); - } else { - EMSESPShell::main_exit_user_function(shell, NO_ARGUMENTS); - } + shell.stop(); } -void EMSESPShell::main_exit_user_function(Shell & shell, const std::vector & arguments) { - shell.stop(); -}; - -void EMSESPShell::main_exit_admin_function(Shell & shell, const std::vector & arguments) { - shell.logger().log(LogLevel::INFO, LogFacility::AUTH, "Admin session closed on console %s", to_shell(shell).console_name().c_str()); - shell.remove_flags(CommandFlags::ADMIN); -}; - - // **** EMSESPConsole ***** +// **** EMSESPConsole ***** #ifndef EMSESP_STANDALONE std::vector EMSESPConsole::ptys_; diff --git a/src/console.h b/src/console.h index e8bddfeb4..fd1d89336 100644 --- a/src/console.h +++ b/src/console.h @@ -44,7 +44,6 @@ class EMSESPShell : public uuid::console::Shell { virtual std::string console_name() = 0; - static void generic_exit_context_function(Shell & shell, const std::vector & arguments); static void main_help_function(Shell & shell, const std::vector & arguments); static void main_exit_function(Shell & shell, const std::vector & arguments); @@ -65,9 +64,6 @@ class EMSESPShell : public uuid::console::Shell { void end_of_transmission() override; private: - static void main_exit_user_function(Shell & shell, const std::vector & arguments); - static void main_exit_admin_function(Shell & shell, const std::vector & arguments); - std::string console_hostname_; }; diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 9cfd7f606..bc91fa947 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -1528,8 +1528,13 @@ void EMSESP::loop() { if (system_.telnet_enabled()) { telnet_.loop(); } +#else + if (!shell_->running()) { + ::exit(0); + } #endif + Shell::loop_all(); }