]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm log errors: Add microseconds to timestamp
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sat, 14 Jan 2023 21:02:48 +0000 (23:02 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 23 Jan 2023 07:04:36 +0000 (07:04 +0000)
src/doveadm/doveadm-log.c
src/lib-master/log-error-buffer.c
src/lib-master/log-error-buffer.h
src/log/doveadm-connection.c
src/log/log-connection.c

index 680738958877a2c9b8366f172acd3db77d14c28d..8958e6f19c40842060eb7e480a9fd6b0ee1ad305 100644 (file)
@@ -304,7 +304,7 @@ static void cmd_log_error_write(const char *const *args, time_t min_timestamp,
        /* <type> <timestamp> <prefix> <text> */
        const char *type_prefix = "?";
        unsigned int type;
-       time_t t;
+       struct timeval tv;
 
        /* find type's prefix */
        for (type = 0; type < LOG_TYPE_COUNT; type++) {
@@ -314,12 +314,15 @@ static void cmd_log_error_write(const char *const *args, time_t min_timestamp,
                }
        }
 
-       if (str_to_time(args[1], &t) < 0) {
+       if (str_to_timeval(args[1], &tv) < 0) {
                e_error(event, "Invalid timestamp: %s", args[1]);
-               t = 0;
+               i_zero(&tv);
        }
-       if (t >= min_timestamp) {
-               doveadm_print(t_strflocaltime(LOG_TIMESTAMP_FORMAT, t));
+       if (tv.tv_sec >= min_timestamp) {
+               const char *ts_secs =
+                       t_strflocaltime(LOG_TIMESTAMP_FORMAT, tv.tv_sec);
+               doveadm_print(t_strdup_printf("%s.%06u", ts_secs,
+                                             (unsigned int)tv.tv_usec));
                doveadm_print(t_cmd_log_error_trim(args[2]));
                doveadm_print(t_cmd_log_error_trim(type_prefix));
                doveadm_print(args[3]);
index 608d1ad47df839bc56098711f6c96ef31c9f5650..ab2b1e6913051afaeae2ba9a00bc98b4281f5ab4 100644 (file)
@@ -9,7 +9,7 @@ struct log_error_data {
        struct log_error_data *next;
 
        enum log_type type;
-       time_t timestamp;
+       struct timeval timestamp;
        unsigned char prefix_text[FLEXIBLE_ARRAY_MEMBER];
 };
 
index e863c3565db2476ddbb9ff3100e88804055c0d83..7bf8f3bcd13a598a5e44c34ac55025ee7ef49b32 100644 (file)
@@ -5,7 +5,7 @@ struct log_error_buffer;
 
 struct log_error {
        enum log_type type;
-       time_t timestamp;
+       struct timeval timestamp;
        const char *prefix;
        const char *text;
 };
index a00ada03f730b6fcbf7907ac4e2429d98635adeb..f6bfdcb4802ddb455ffd2d623301adce6eb31172 100644 (file)
@@ -29,9 +29,10 @@ static int doveadm_connection_send_errors(struct doveadm_connection *conn)
        iter = log_error_buffer_iter_init(conn->errorbuf);
        while ((error = log_error_buffer_iter_next(iter)) != NULL) {
                str_truncate(str, 0);
-               str_printfa(str, "%s\t%ld\t",
+               str_printfa(str, "%s\t%"PRIdTIME_T".%06u\t",
                            failure_log_type_names[error->type],
-                           (long)error->timestamp);
+                           error->timestamp.tv_sec,
+                           (unsigned int)error->timestamp.tv_usec);
                str_append_tabescaped(str, error->prefix);
                str_append_c(str, '\t');
                str_append_tabescaped(str, error->text);
index 034010758671d6c8e0f17b5f3eb053ba049ff4a1..41fe8114313372be30783442e086e6cdfef98d37 100644 (file)
@@ -146,7 +146,7 @@ client_log_ctx(struct log_connection *log,
        case LOG_TYPE_PANIC:
                i_zero(&err);
                err.type = ctx->type;
-               err.timestamp = log_time->tv_sec;
+               err.timestamp = *log_time;
                err.prefix = ctx->log_prefix != NULL ? ctx->log_prefix : prefix;
                err.text = text;
                log_error_buffer_add(log->errorbuf, &err);