From: Kienan Stewart Date: Fri, 17 May 2024 17:15:25 +0000 (-0400) Subject: lttng: Add PWARN macro X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ac559d09a23994f9f52014b0efba3a3c566dcfea;p=lttng-tools.git lttng: Add PWARN macro Change-Id: Id6d15e094b8fe7ef779022e44d8414214af3444a Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/error.hpp b/src/common/error.hpp index 23d840c2d..66f38bf2e 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -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,6 +258,13 @@ 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 const char *error_get_str(int32_t code);