The debugging logging macros (e.g. DBG()) are used as printf in the
lttng-tools source files. The printf() implementation does not alter the
errno value, so the fact that log_add_time() (through clock_gettime())
can alter errno is unexpected. For instance, adding a logging statement
for debugging purposes within a function for which errno is expected to
stay unchanged on return will change the behavior between execution with
-vvv and non-verbose.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <lttng/lttng-error.h>
#include <common/common.h>
struct tm tm, *res;
struct timespec tp;
time_t now;
+ const int errsv = errno;
ret = lttng_clock_gettime(CLOCK_REALTIME, &tp);
if (ret < 0) {
goto error;
}
+ errno = errsv;
return URCU_TLS(error_log_time).str;
error:
/* Return an empty string on error so logging is not affected. */
+ errno = errsv;
return "";
}