From 734445f78de5e36bb7b8df91349b35e9fa42d66b Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 30 May 2022 20:30:33 +0300 Subject: [PATCH] mu-server: add a bit more debugging info --- lib/utils/mu-readline.cc | 7 +++++++ lib/utils/mu-readline.hh | 8 ++++++++ mu/mu-cmd-server.cc | 16 +++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/utils/mu-readline.cc b/lib/utils/mu-readline.cc index 0858cf1c..2f9c72a9 100644 --- a/lib/utils/mu-readline.cc +++ b/lib/utils/mu-readline.cc @@ -64,6 +64,13 @@ static bool is_a_tty{}; static std::string hist_path; static size_t max_lines{}; +bool +Mu::have_readline() +{ + return HAVE_READLINE != 0; +} + + void Mu::setup_readline(const std::string& histpath, size_t maxlines) { diff --git a/lib/utils/mu-readline.hh b/lib/utils/mu-readline.hh index feb0a15b..ca0455fc 100644 --- a/lib/utils/mu-readline.hh +++ b/lib/utils/mu-readline.hh @@ -50,4 +50,12 @@ std::string read_line(bool& do_quit); */ void save_line(const std::string& line); + +/** + * Do we have the non-shim readline? + * + * @return true or failse + */ +bool have_readline(); + } // namespace Mu diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index 8185e31d..779b9cb3 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -35,13 +35,13 @@ #include "utils/mu-readline.hh" using namespace Mu; -static std::atomic MuTerminate{false}; +static std::atomic MuTerminate{0}; static bool tty; static void sig_handler(int sig) { - MuTerminate = true; + MuTerminate = sig; } static void @@ -50,7 +50,7 @@ install_sig_handler(void) static struct sigaction action; int i, sigs[] = {SIGINT, SIGHUP, SIGTERM, SIGPIPE}; - MuTerminate = false; + MuTerminate = 0; action.sa_handler = sig_handler; sigemptyset(&action.sa_mask); @@ -123,10 +123,12 @@ Mu::mu_cmd_server(const MuConfig* opts) try { return Err(store.error()); Server server{*store, output_sexp_stdout}; - g_message("created server with store @ %s; maildir @ %s; debug-mode %s", + g_message("created server with store @ %s; maildir @ %s; debug-mode %s" + "readline: %s", store->properties().database_path.c_str(), store->properties().root_maildir.c_str(), - opts->debug ? "yes" : "no"); + opts->debug ? "yes" : "no", + have_readline() ? "yes" : "no"); tty = ::isatty(::fileno(stdout)); const auto eval = std::string{opts->commands ? "(help :full t)" @@ -155,6 +157,10 @@ Mu::mu_cmd_server(const MuConfig* opts) try { do_quit = server.invoke(line) ? false : true; save_line(line); } + + if (MuTerminate != 0) + g_message ("shutting down due to signal %d", MuTerminate.load()); + shutdown_readline(); return Ok();