Fix: logging: log_add_time() save/restore errno
[lttng-tools.git] / src / common / error.c
index 2215886db1be67d5c93e3b89233c8e101f26a96d..a13320f6857714eaf4cd123185dc7befa1ef0802 100644 (file)
@@ -20,6 +20,7 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <lttng/lttng-error.h>
 #include <common/common.h>
@@ -45,6 +46,7 @@ const char *log_add_time(void)
        struct tm tm, *res;
        struct timespec tp;
        time_t now;
+       int errsv = errno;
 
        ret = lttng_clock_gettime(CLOCK_REALTIME, &tp);
        if (ret < 0) {
@@ -59,16 +61,18 @@ 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.%06ld",
+                       "%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;
 
 error:
        /* Return an empty string on error so logging is not affected. */
+       errno = errsv;
        return "";
 }
 
@@ -190,6 +194,13 @@ static const char *error_string_array[] = {
        [ ERROR_INDEX(LTTNG_ERR_TRIGGER_EXISTS) ] = "Trigger already registered",
        [ ERROR_INDEX(LTTNG_ERR_TRIGGER_NOT_FOUND) ] = "Trigger not found",
        [ ERROR_INDEX(LTTNG_ERR_COMMAND_CANCELLED) ] = "Command cancelled",
+       [ ERROR_INDEX(LTTNG_ERR_AGENT_TRACING_DISABLED) ] = "Session daemon agent tracing is disabled",
+       [ ERROR_INDEX(LTTNG_ERR_USER_NOT_FOUND) ] = "User not found.",
+       [ ERROR_INDEX(LTTNG_ERR_GROUP_NOT_FOUND) ] = "Group not found.",
+       [ ERROR_INDEX(LTTNG_ERR_CLEAR_RELAY_DISALLOW) ] = "Relayd daemon peer does not allow lttng clear command",
+       [ ERROR_INDEX(LTTNG_ERR_CLEAR_NOT_AVAILABLE) ] = "Clear feature is not available for the session type",
+       [ ERROR_INDEX(LTTNG_ERR_CLEAR_NOT_AVAILABLE_RELAY) ] = "Clear feature is not available on the relay",
+       [ ERROR_INDEX(LTTNG_ERR_CLEAR_FAIL_CONSUMER) ] = "Clear failure on the consumer",
 
        /* Last element */
        [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code"
This page took 0.024769 seconds and 5 git commands to generate.