Wrap main functions to handle uncaught exceptions
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Jun 2023 18:20:09 +0000 (14:20 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Jun 2023 18:42:18 +0000 (14:42 -0400)
Coverity reports multiple instances where formatting facilities can
throw (e.g. invalid format string).

A wrapper to handle formatting exceptions is added in a follow-up
change, but it is a good practice to catch exceptions at the top level
nonetheless.

Reported-by: Coverity Scan
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ie55af338b9ef1f7d6e8825055cfc2e7037cdd80e

src/bin/lttng/commands/start.cpp
src/bin/lttng/commands/stop.cpp
src/bin/lttng/lttng.cpp
tests/regression/tools/trigger/utils/notification-client.cpp
tests/unit/test_action.cpp

index 2552062e5bff43e6f0f8c4d9418b50cc741fdcd9..29cff53c2fb1cc0cd3457cde5066159b0e6ba21f 100644 (file)
@@ -103,7 +103,7 @@ cmd_error_code start_tracing(const char *session_name)
        return CMD_SUCCESS;
 }
 
-cmd_error_code start_tracing(const lttng::cli::session_spec& spec) noexcept
+cmd_error_code start_tracing(const lttng::cli::session_spec& spec)
 {
        bool had_warning = false;
        bool had_error = false;
index d2e0bee14e5bc2f504e5a22bcadfaac1dd09de20..8b33bd7f4af5e7dc46c2c5b231432c059a0befe2 100644 (file)
@@ -132,7 +132,7 @@ cmd_error_code stop_tracing(const char *session_name)
        return CMD_SUCCESS;
 }
 
-cmd_error_code stop_tracing(const lttng::cli::session_spec& spec) noexcept
+cmd_error_code stop_tracing(const lttng::cli::session_spec& spec)
 {
        bool had_warning = false;
        bool had_error = false;
index 5f6e0f66e73477952472aa034f5f4c77ae759f72..b84fe3407069613d0c345956876d6dce73f76008 100644 (file)
@@ -460,7 +460,7 @@ error:
 /*
  *  main
  */
-int main(int argc, char *argv[])
+static int _main(int argc, char *argv[])
 {
        int ret;
 
@@ -478,3 +478,13 @@ int main(int argc, char *argv[])
 
        return 0;
 }
+
+int main(int argc, char **argv)
+{
+       try {
+               return _main(argc, argv);
+       } catch (const std::exception& e) {
+               ERR_FMT("Unhandled exception caught by client: %s", e.what());
+               abort();
+       }
+}
index f733821588a63995846cb709e7e903ab2ac8cf25..58ac01e6cbb078d688fb811aa22991c9e3bf1a12 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "utils.h"
 
+#include <common/error.hpp>
+
 #include <lttng/action/list-internal.hpp>
 #include <lttng/condition/event-rule-matches.h>
 #include <lttng/lttng.h>
@@ -81,7 +83,7 @@ end:
        return names_match;
 }
 
-int main(int argc, char **argv)
+static int _main(int argc, char **argv)
 {
        int ret;
        int option;
@@ -279,3 +281,13 @@ end:
        free(expected_trigger_name);
        return !!ret;
 }
+
+int main(int argc, char **argv)
+{
+       try {
+               return _main(argc, argv);
+       } catch (const std::exception& e) {
+               ERR_FMT("Unhandled exception caught by notification client: %s", e.what());
+               abort();
+       }
+}
index 7d0727eda237894bb3fa2b66e9b035548b179258..c46b8fcea665fa177dbaa27c8b85a7027bec5096 100644 (file)
@@ -9,6 +9,7 @@
  *
  */
 
+#include <common/error.hpp>
 #include <common/payload-view.hpp>
 #include <common/payload.hpp>
 
@@ -541,7 +542,7 @@ static void test_action_snapshot_session()
        lttng_payload_reset(&payload);
 }
 
-int main()
+static int _main()
 {
        plan_tests(NUM_TESTS);
        test_action_notify();
@@ -552,3 +553,13 @@ int main()
        test_action_snapshot_session();
        return exit_status();
 }
+
+int main()
+{
+       try {
+               return _main();
+       } catch (const std::exception& e) {
+               ERR_FMT("Unhandled exception caught by action unit test: %s", e.what());
+               abort();
+       }
+}
This page took 0.028796 seconds and 4 git commands to generate.