X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ferror.hpp;h=23d840c2daafcd3870ba4445708921c1ea3b93ad;hb=HEAD;hp=885902bb9d19f7be22779f5c58f76f6302f7f2c7;hpb=28f23191dcbf047429d51950a337a57d7a3f866a;p=lttng-tools.git diff --git a/src/common/error.hpp b/src/common/error.hpp index 885902bb9..66f38bf2e 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -46,8 +46,8 @@ struct log_time { /* Format: 00:00:00.000000000 plus NULL byte. */ char str[19]; }; -extern LTTNG_EXPORT DECLARE_URCU_TLS(struct log_time, error_log_time); -extern DECLARE_URCU_TLS(const char *, logger_thread_name); + +extern thread_local const char *logger_thread_name; extern int lttng_opt_quiet; extern int lttng_opt_verbose; @@ -160,7 +160,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) msg " - %s [%s]: " fmt " (in %s() at " __FILE__ \ ":" XSTR(__LINE__) ")\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args, \ __func__); \ } \ @@ -180,7 +180,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) __lttng_print(type, \ msg " - %s [%s]: " fmt "\n", \ log_add_time(), \ - URCU_TLS(logger_thread_name) ?: generic_name, \ + logger_thread_name ?: generic_name, \ ##args); \ } \ } while (0) @@ -226,6 +226,7 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) } while (0); #define _PERROR(fmt, args...) _ERRMSG("PERROR", PRINT_ERR, fmt, ##args) +#define _PWARN(fmt, args...) _ERRMSG("PWARN", PRINT_WARN, fmt, ##args) #if !defined(__GLIBC__) || \ ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) @@ -239,6 +240,13 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) strerror_r(errno, _perror_buf, sizeof(_perror_buf)); \ _PERROR(call ": %s", ##args, _perror_buf); \ } while (0); + +#define PWARN(call, args...) \ + do { \ + char _perror_buf[200]; \ + strerror_r(errno, _perror_buf, sizeof(_perror_buf)); \ + _PWARN(call ": %s", ##args, _perror_buf); \ + } while (0); #else /* * Version using GNU strerror_r, for linux with appropriate defines. @@ -250,14 +258,56 @@ static inline void __lttng_print_check_abort(enum lttng_error_level type) _perror_buf = strerror_r(errno, _perror_tmp, sizeof(_perror_tmp)); \ _PERROR(call ": %s", ##args, _perror_buf); \ } while (0); +#define PWARN(call, args...) \ + do { \ + char *_perror_buf; \ + char _perror_tmp[200]; \ + _perror_buf = strerror_r(errno, _perror_tmp, sizeof(_perror_tmp)); \ + _PWARN(call ": %s", ##args, _perror_buf); \ + } while (0); #endif -#define DBG_FMT(format_str, args...) DBG("%s", fmt::format(format_str, ##args).c_str()) -#define WARN_FMT(format_str, args...) WARN("%s", fmt::format(format_str, ##args).c_str()) -#define ERR_FMT(format_str, args...) ERR("%s", fmt::format(format_str, ##args).c_str()) - const char *error_get_str(int32_t code); +namespace lttng { +namespace logging { +namespace details { +[[noreturn]] void die_formatting_exception(const char *format, + const std::exception& formatting_exception); +} /* namespace details */ +} /* namespace logging */ +} /* namespace lttng */ + +#define DBG_FMT(format_str, args...) \ + do { \ + try { \ + DBG("%s", lttng::format(format_str, ##args).c_str()); \ + } catch (const std::exception& _formatting_exception) { \ + lttng::logging::details::die_formatting_exception(format_str, \ + _formatting_exception); \ + } \ + } while (0); + +#define WARN_FMT(format_str, args...) \ + do { \ + try { \ + WARN("%s", lttng::format(format_str, ##args).c_str()); \ + } catch (const std::exception& _formatting_exception) { \ + lttng::logging::details::die_formatting_exception(format_str, \ + _formatting_exception); \ + } \ + } while (0); + +#define ERR_FMT(format_str, args...) \ + do { \ + try { \ + ERR("%s", lttng::format(format_str, ##args).c_str()); \ + } catch (const std::exception& _formatting_exception) { \ + lttng::logging::details::die_formatting_exception(format_str, \ + _formatting_exception); \ + } \ + } while (0); + /* * Function that format the time and return the reference of log_time.str to * the caller. On error, an empty string is returned thus no time will be