X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ferror.cpp;h=26d69f48b2f9130e15ba13e9fb54764067e9cfb0;hb=4e845c10b7b0549cdd0ad400509454399150c061;hp=150d2e53fbfe75ef02517a766356eea7db809f7d;hpb=c9e313bc594f40a86eed237dce222c0fc99c957f;p=lttng-tools.git diff --git a/src/common/error.cpp b/src/common/error.cpp index 150d2e53f..26d69f48b 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -6,30 +6,35 @@ */ #define _LGPL_SOURCE -#include -#include -#include -#include +#include "error.hpp" #include -#include #include #include +#include + #include -#include "error.hpp" +#include +#include +#include +#include +#include +namespace { /* * lttng_opt_abort_on_error: unset: -1, disabled: 0, enabled: 1. * Controlled by the LTTNG_ABORT_ON_ERROR environment variable. */ -static int lttng_opt_abort_on_error = -1; +int lttng_opt_abort_on_error = -1; /* TLS variable that contains the time of one single log entry. */ -DEFINE_URCU_TLS(struct log_time, error_log_time); -DEFINE_URCU_TLS(const char *, logger_thread_name); +thread_local struct log_time error_log_time; +} /* namespace */ + +thread_local const char *logger_thread_name; -const char *log_add_time(void) +const char *log_add_time() { int ret; struct tm tm, *res; @@ -49,15 +54,19 @@ const char *log_add_time(void) } /* Format time in the TLS variable. */ - ret = snprintf(URCU_TLS(error_log_time).str, sizeof(URCU_TLS(error_log_time).str), - "%02d:%02d:%02d.%09ld", - tm.tm_hour, tm.tm_min, tm.tm_sec, tp.tv_nsec); + ret = snprintf(error_log_time.str, + sizeof(error_log_time.str), + "%02d:%02d:%02d.%09ld", + tm.tm_hour, + tm.tm_min, + tm.tm_sec, + tp.tv_nsec); if (ret < 0) { goto error; } errno = errsv; - return URCU_TLS(error_log_time).str; + return error_log_time.str; error: /* Return an empty string on error so logging is not affected. */ @@ -70,7 +79,7 @@ void logger_set_thread_name(const char *name, bool set_pthread_name) int ret; LTTNG_ASSERT(name); - URCU_TLS(logger_thread_name) = name; + logger_thread_name = name; if (set_pthread_name) { ret = lttng_thread_setname(name); @@ -84,8 +93,7 @@ void logger_set_thread_name(const char *name, bool set_pthread_name) /* * Human readable error message. */ -static -const char *lttng_error_code_str(lttng_error_code code) +static const char *lttng_error_code_str(lttng_error_code code) { switch (code) { case LTTNG_OK: @@ -445,3 +453,12 @@ void lttng_abort_on_error(void) abort(); } } + +[[noreturn]] void +lttng::logging::details::die_formatting_exception(const char *format, + const std::exception& formatting_exception) +{ + std::cerr << "Error occurred while formatting logging message: msg=`" << format + << "`: " << formatting_exception.what(); + abort(); +}