From: Jérémie Galarneau Date: Thu, 13 Apr 2023 18:34:31 +0000 (-0400) Subject: Coverity warning: sessiond: uncaught exception in main X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=64f8e4936e6d54cff9c1f6d642a1b6745b7984d9;p=lttng-tools.git Coverity warning: sessiond: uncaught exception in main Coverity reports: 1508778 Uncaught exception If the exception is ever thrown, the program will crash. In main: A C++ exception is thrown but never caught (CWE-248) In particular, Coverity reports that pthread_mutex_lock can error-out, which would cause an lttng::posix_error exception to be thrown. This isn't particularly likely to happen, but it is nonetheless preferable to catch exceptions at the top-level and log them before exiting. Change-Id: I4f7a52db3c9cd19764e7d12fd62afa60af99dabd Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/main.cpp b/src/bin/lttng-sessiond/main.cpp index 8d59952d6..7f0995a9b 100644 --- a/src/bin/lttng-sessiond/main.cpp +++ b/src/bin/lttng-sessiond/main.cpp @@ -1403,7 +1403,7 @@ static void sessiond_uuid_log() /* * main */ -int main(int argc, char **argv) +static int _main(int argc, char **argv) { int ret = 0, retval = 0; const char *env_app_timeout; @@ -1975,3 +1975,13 @@ exit_set_signal_handler: exit(EXIT_FAILURE); } } + +int main(int argc, char **argv) +{ + try { + return _main(argc, argv); + } catch (const std::exception& e) { + ERR_FMT("Unhandled exception caught by main thread: %s", e.what()); + abort(); + } +}