X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fdestroy.cpp;h=78bbbaaad37e25a6e94648236860fe11a60252db;hb=HEAD;hp=0bffb30bdb86ac1399516eba05c6bc74bb787e11;hpb=42a11b8f4c8d98b33fa1eadcdcda96253e651f0b;p=lttng-tools.git diff --git a/src/bin/lttng/commands/destroy.cpp b/src/bin/lttng/commands/destroy.cpp index 0bffb30bd..ef4b914d3 100644 --- a/src/bin/lttng/commands/destroy.cpp +++ b/src/bin/lttng/commands/destroy.cpp @@ -7,6 +7,7 @@ #define _LGPL_SOURCE #include "../command.hpp" +#include "../exception.hpp" #include #include @@ -74,7 +75,7 @@ cmd_error_code destroy_session(const lttng_session& session) ret = lttng_stop_tracing_no_wait(session.name); if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) { - LTTNG_THROW_CTL(fmt::format("Failed to stop session `{}`", session.name), + LTTNG_THROW_CTL(lttng::format("Failed to stop session `{}`", session.name), static_cast(-ret)); } @@ -110,7 +111,8 @@ cmd_error_code destroy_session(const lttng_session& session) } while (ret != 0); } - std::unique_ptr::deleter> + std::unique_ptr::deleter> stats_str; if (!session_was_already_stopped) { char *raw_stats_str = nullptr; @@ -134,7 +136,8 @@ cmd_error_code destroy_session(const lttng_session& session) auto ctl_ret_code = lttng_destroy_session_ext(session.name, &raw_destruction_handle); if (ctl_ret_code != LTTNG_OK) { - LTTNG_THROW_CTL(fmt::format("Failed to destroy session `{}`", session.name), + LTTNG_THROW_CTL(lttng::format("Failed to destroy session `{}`", + session.name), ctl_ret_code); } @@ -184,7 +187,8 @@ cmd_error_code destroy_session(const lttng_session& session) } if (ctl_ret_code != LTTNG_OK) { - LTTNG_THROW_CTL(fmt::format("Failed to destroy session `{}`", session.name), + LTTNG_THROW_CTL(lttng::format("Failed to destroy session `{}`", + session.name), ctl_ret_code); } @@ -240,7 +244,7 @@ cmd_error_code destroy_session(const lttng_session& session) * destroy the file. */ const auto session_name = - lttng::make_unique_wrapper(get_session_name_quiet()); + lttng::make_unique_wrapper(get_session_name_quiet()); if (session_name && !strncmp(session.name, session_name.get(), NAME_MAX)) { config_destroy_default(); } @@ -255,13 +259,13 @@ cmd_error_code destroy_session(const lttng_session& session) return CMD_SUCCESS; } -cmd_error_code destroy_sessions(const session_spec& spec) +cmd_error_code destroy_sessions(const lttng::cli::session_spec& spec) { bool had_warning = false; bool had_error = false; bool listing_failed = false; - const auto sessions = [&listing_failed, &spec]() -> session_list { + const auto sessions = [&listing_failed, &spec]() -> lttng::cli::session_list { try { return list_sessions(spec); } catch (const lttng::ctl::error& ctl_exception) { @@ -269,10 +273,19 @@ cmd_error_code destroy_sessions(const session_spec& spec) lttng_strerror(-ctl_exception.code())); listing_failed = true; return {}; + } catch (const lttng::cli::no_default_session_error& cli_exception) { + /* + * The retrieval of the default session name already logs + * an error when it fails. There is no value in printing + * anything about this exception. + */ + listing_failed = true; + return {}; } }(); - if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) { + if (!listing_failed && sessions.size() == 0 && + spec.type_ == lttng::cli::session_spec::type::NAME) { ERR_FMT("Session `{}` not found", spec.value); return CMD_ERROR; } @@ -289,7 +302,7 @@ cmd_error_code destroy_sessions(const session_spec& spec) } catch (const lttng::ctl::error& ctl_exception) { switch (ctl_exception.code()) { case LTTNG_ERR_NO_SESSION: - if (spec.type_ != session_spec::type::NAME) { + if (spec.type_ != lttng::cli::session_spec::type::NAME) { /* Session destroyed during command, ignore and carry-on. */ sub_ret = CMD_SUCCESS; break; @@ -335,8 +348,8 @@ int cmd_destroy(int argc, const char **argv) bool success; static poptContext pc; const char *leftover = nullptr; - struct session_spec spec(session_spec::type::NAME); - session_list const sessions; + lttng::cli::session_spec spec(lttng::cli::session_spec::type::NAME); + lttng::cli::session_list const sessions; pc = poptGetContext(nullptr, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -355,10 +368,10 @@ int cmd_destroy(int argc, const char **argv) list_cmd_options(stdout, long_options); goto end; case OPT_ALL: - spec.type_ = session_spec::type::ALL; + spec.type_ = lttng::cli::session_spec::type::ALL; break; case OPT_ENABLE_GLOB: - spec.type_ = session_spec::type::GLOB_PATTERN; + spec.type_ = lttng::cli::session_spec::type::GLOB_PATTERN; break; default: command_ret = CMD_UNDEFINED;