]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib, global: timeval_diff_msecs() - Return long long
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 24 May 2024 13:02:40 +0000 (16:02 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 24 May 2024 13:38:55 +0000 (16:38 +0300)
This makes it less likely to hit accidental bugs due to comparing timestamps
with large differences.

36 files changed:
src/auth/auth-master-connection.c
src/auth/db-ldap.c
src/auth/userdb-passwd.c
src/imap/imap-client.c
src/imap/imap-storage-callbacks.c
src/lib-dict-extra/dict-client.c
src/lib-dns/dns-lookup.c
src/lib-http/http-client-connection.c
src/lib-http/http-client-host.c
src/lib-http/http-client-peer.c
src/lib-http/http-client-queue.c
src/lib-http/http-client-request.c
src/lib-http/test-http-client-errors.c
src/lib-lda/mail-deliver.c
src/lib-login/login-client.c
src/lib-login/login-server-auth.c
src/lib-login/login-server.c
src/lib-master/master-service.c
src/lib-master/stats-client.c
src/lib-program-client/program-client-local.c
src/lib-sql/driver-cassandra.c
src/lib-sql/driver-pgsql.c
src/lib-sql/sql-api.c
src/lib-storage/mail-duplicate.c
src/lib/connection.c
src/lib/cpu-limit.c
src/lib/file-lock.c
src/lib/istream-timeout.c
src/lib/test-cpu-limit.c
src/lib/test-time-util.c
src/lib/time-util.c
src/lib/time-util.h
src/lmtp/lmtp-proxy.c
src/login-common/login-proxy.c
src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc
src/plugins/fts-flatcurve/fts-backend-flatcurve.c

index a19e5857e7b6f2b2c8e3338de283b5359797dbe9..1fb15ca0de5d52c35f17aa5d2ae5db5e4308f78c 100644 (file)
@@ -90,11 +90,11 @@ auth_master_event_log_callback(struct auth_master_connection *conn,
 {
        string_t *str = t_str_new(128);
 
-       str_printfa(str, "auth-master client: %s (created %d msecs ago",
+       str_printfa(str, "auth-master client: %s (created %lld msecs ago",
                    message,
                    timeval_diff_msecs(&ioloop_timeval, &conn->conn.connect_finished));
        if (conn->conn.handshake_finished.tv_sec != 0) {
-               str_printfa(str, ", handshake %d msecs ago",
+               str_printfa(str, ", handshake %lld msecs ago",
                            timeval_diff_msecs(&ioloop_timeval,
                                               &conn->conn.handshake_finished));
        }
index 5ae3a904142ec787b409f62a026c425f7db04060..5059978661ec7b3586ad2deda8cfec7487bcef9b 100644 (file)
@@ -1278,8 +1278,8 @@ int db_ldap_connect(struct ldap_connection *conn)
                return -1;
 
        i_gettimeofday(&end);
-       int msecs = timeval_diff_msecs(&end, &start);
-       e_debug(conn->event, "LDAP initialization took %d msecs", msecs);
+       e_debug(conn->event, "LDAP initialization took %lld msecs",
+               timeval_diff_msecs(&end, &start));
 
        db_ldap_get_fd(conn);
        conn->io = io_add(conn->fd, IO_READ, ldap_input, conn);
index d94346a05b4e4e0dd45660081024024dab5a2133..2623dff58abc4636b5dc4252b240c097f589991d 100644 (file)
@@ -38,13 +38,14 @@ passwd_check_warnings(struct auth_request *auth_request,
                      const struct timeval *start_tv)
 {
        struct timeval end_tv;
-       unsigned int msecs, percentage;
+       unsigned int percentage;
+       long long msecs;
 
        i_gettimeofday(&end_tv);
 
        msecs = timeval_diff_msecs(&end_tv, start_tv);
        if (msecs >= PASSWD_SLOW_WARN_MSECS) {
-               e_warning(authdb_event(auth_request), "Lookup for %s took %u secs",
+               e_warning(authdb_event(auth_request), "Lookup for %s took %lld secs",
                          auth_request->fields.user, msecs/1000);
                return;
        }
index 1b330f3ede22fc8732478719a68ef46cdb450a52..8d67996514100f09153ef606058e96b5e683a166 100644 (file)
@@ -376,11 +376,11 @@ static const char *client_get_last_command_status(struct client *client)
        const struct client_command_stats *stats = &client->last_cmd_stats;
 
        string_t *str = t_str_new(128);
-       int last_run_secs = timeval_diff_msecs(&ioloop_timeval,
-                                              &stats->last_run_timeval);
-       str_printfa(str, " (%s finished %d.%03d secs ago",
-                   client->last_cmd_name, last_run_secs/1000,
-                   last_run_secs%1000);
+       long long last_run_msecs = timeval_diff_msecs(&ioloop_timeval,
+                                                     &stats->last_run_timeval);
+       str_printfa(str, " (%s finished %lld.%03lld secs ago",
+                   client->last_cmd_name, last_run_msecs/1000,
+                   last_run_msecs%1000);
 
        if (timeval_diff_msecs(&stats->last_run_timeval, &stats->start_time) >=
            IMAP_CLIENT_DISCONNECT_LOG_STATS_CMD_MIN_RUNNING_MSECS) {
@@ -624,7 +624,7 @@ client_cmd_append_timing_stats(struct client_command_context *cmd,
 {
        unsigned int msecs_in_cmd, msecs_in_ioloop;
        uint64_t ioloop_wait_usecs;
-       unsigned int msecs_since_cmd;
+       long long msecs_since_cmd;
 
        if (cmd->stats.start_time.tv_sec == 0)
                return;
@@ -643,7 +643,7 @@ client_cmd_append_timing_stats(struct client_command_context *cmd,
                    msecs_in_cmd / 1000, msecs_in_cmd % 1000,
                    msecs_in_ioloop / 1000, msecs_in_ioloop % 1000);
        if (msecs_since_cmd > 0) {
-               str_printfa(str, "+ %d.%03d ",
+               str_printfa(str, "+ %lld.%03lld ",
                            msecs_since_cmd / 1000, msecs_since_cmd % 1000);
        }
        str_append(str, "secs).");
index 254fa0ba65839604cf7d740a65ff9b1eb2fb35b3..7cd31007ffc87f22e6271617d8d180b87e2bd844 100644 (file)
@@ -97,8 +97,8 @@ imap_storage_callback_line(const struct mail_storage_progress_details *dtl,
                float percentage = processed * 100.0 / total;
                str_printfa(str, "%s %d%% of the mailbox", verb, (int)percentage);
 
-               unsigned int elapsed_ms = timeval_diff_msecs(&dtl->now,
-                                                            &dtl->start_time);
+               long long elapsed_ms = timeval_diff_msecs(&dtl->now,
+                                                         &dtl->start_time);
                if (percentage > 0 && elapsed_ms > 0) {
                        int eta_secs = elapsed_ms * (100 - percentage) /
                                            (1000 * percentage);
index cb62c4bd839a86eeea108f8a337945e8a5464720..0f4d432350916a07efa3f5ee7f8bf4e5e0260882 100644 (file)
@@ -260,10 +260,11 @@ static void client_dict_input_timeout(struct client_dict_cmd *cmd)
                return;
        }
 
-       int cmd_diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
+       long long cmd_diff = timeval_diff_msecs(&ioloop_timeval,
+                                               &cmd->start_time);
        (void)client_dict_reconnect(dict, t_strdup_printf(
                "Dict server timeout: %s "
-               "(%u commands pending, oldest sent %u.%03u secs ago: %s, %s)",
+               "(%u commands pending, oldest sent %lld.%03lld secs ago: %s, %s)",
                connection_input_timeout_reason(&dict->conn.conn),
                array_count(&dict->cmds),
                cmd_diff/1000, cmd_diff%1000, cmd->query,
@@ -885,26 +886,26 @@ static const char *dict_wait_warnings(const struct client_dict_cmd *cmd)
 }
 
 static const char *
-dict_warnings_sec(const struct client_dict_cmd *cmd, int msecs,
+dict_warnings_sec(const struct client_dict_cmd *cmd, long long msecs,
                  const char *const *extra_args)
 {
        string_t *str = t_str_new(64);
        struct timeval tv_start, tv_end;
        unsigned int tv_start_usec, tv_end_usec;
 
-       str_printfa(str, "%d.%03d secs (%s", msecs/1000, msecs%1000,
+       str_printfa(str, "%lld.%03lld secs (%s", msecs/1000, msecs%1000,
                    dict_wait_warnings(cmd));
        if (cmd->reconnected) {
-               int reconnected_msecs =
+               long long reconnected_msecs =
                        timeval_diff_msecs(&ioloop_timeval,
                                &cmd->dict->conn.conn.connect_started);
-               str_printfa(str, ", reconnected %u.%03u secs ago",
+               str_printfa(str, ", reconnected %lld.%03lld secs ago",
                            reconnected_msecs/1000, reconnected_msecs%1000);
        }
        if (cmd->async_id != 0) {
-               int async_reply_msecs =
+               long long async_reply_msecs =
                        timeval_diff_msecs(&ioloop_timeval, &cmd->async_id_received_time);
-               str_printfa(str, ", async-id reply %u.%03u secs ago",
+               str_printfa(str, ", async-id reply %lld.%03lld secs ago",
                            async_reply_msecs/1000, async_reply_msecs%1000);
        }
        if (extra_args != NULL &&
@@ -916,11 +917,11 @@ dict_warnings_sec(const struct client_dict_cmd *cmd, int msecs,
                tv_start.tv_usec = tv_start_usec;
                tv_end.tv_usec = tv_end_usec;
 
-               int server_msecs_since_start =
+               long long server_msecs_since_start =
                        timeval_diff_msecs(&ioloop_timeval, &tv_start);
-               int server_msecs = timeval_diff_msecs(&tv_end, &tv_start);
-               str_printfa(str, ", started on dict-server %u.%03d secs ago, "
-                           "took %u.%03d secs",
+               long long server_msecs = timeval_diff_msecs(&tv_end, &tv_start);
+               str_printfa(str, ", started on dict-server %lld.%03lld secs ago, "
+                           "took %lld.%03lld secs",
                            server_msecs_since_start/1000,
                            server_msecs_since_start%1000,
                            server_msecs/1000, server_msecs%1000);
@@ -978,7 +979,7 @@ client_dict_lookup_async_callback(struct client_dict_cmd *cmd,
                break;
        }
 
-       int diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
+       long long diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
        if (result.error != NULL) {
                /* include timing info always in error messages */
                result.error = t_strdup_printf("%s (reply took %s)",
@@ -1090,7 +1091,8 @@ client_dict_iter_api_callback(struct client_dict_iterate_context *ctx,
                return;
        }
        if (ctx->finished) {
-               int diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
+               long long diff = timeval_diff_msecs(&ioloop_timeval,
+                                                   &cmd->start_time);
                if (ctx->error != NULL) {
                        /* include timing info always in error messages */
                        char *new_error = i_strdup_printf("%s (reply took %s)",
@@ -1368,7 +1370,7 @@ client_dict_transaction_commit_callback(struct client_dict_cmd *cmd,
                break;
        }
 
-       int diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
+       long long diff = timeval_diff_msecs(&ioloop_timeval, &cmd->start_time);
        if (result.error != NULL) {
                /* include timing info always in error messages */
                result.error = t_strdup_printf("%s (reply took %s)",
index ff578a739d5b5ebb655f81e0e6a4f8fbc950d9c9..f9b83fd92ab1d0cffc77c209531b4312359a3bcf 100644 (file)
@@ -385,7 +385,7 @@ static int dns_lookup_input_args(struct dns_lookup *lookup, const char *const *a
 static void dns_lookup_save_msecs(struct dns_lookup *lookup)
 {
        struct timeval now;
-       int diff;
+       long long diff;
 
        i_gettimeofday(&now);
 
@@ -425,11 +425,11 @@ static int dns_client_input_args(struct connection *conn, const char *const *arg
 
 static void dns_lookup_timeout(struct dns_lookup *lookup)
 {
-       int duration_msecs = timeval_diff_msecs(&ioloop_timeval,
-                                               &lookup->start_time);
-       lookup->result.error = t_strdup_printf("Lookup timed out in %u.%03u secs",
-                                              duration_msecs / 1000,
-                                              duration_msecs % 1000);
+       long long duration_msecs = timeval_diff_msecs(&ioloop_timeval,
+                                                     &lookup->start_time);
+       lookup->result.error =
+               t_strdup_printf("Lookup timed out in %lld.%03lld secs",
+                               duration_msecs / 1000, duration_msecs % 1000);
 
        dns_lookup_callback(lookup);
        dns_lookup_free(&lookup);
index fe080fbba414559dfec7576d80b9e5d721ba1a39..c3e788c7c9532b1a03ce47b69b301d2d1860a4b2 100644 (file)
@@ -236,7 +236,7 @@ static const char *
 http_client_connection_get_timing_info(struct http_client_connection *conn)
 {
        struct http_client_request *const *requestp;
-       unsigned int connected_msecs;
+       long long connected_msecs;
        string_t *str = t_str_new(64);
 
        if (array_count(&conn->request_wait_list) > 0) {
@@ -253,7 +253,7 @@ http_client_connection_get_timing_info(struct http_client_connection *conn)
        }
        connected_msecs = timeval_diff_msecs(&ioloop_timeval,
                                             &conn->connected_timestamp);
-       str_printfa(str, ", connected %u.%03u secs ago",
+       str_printfa(str, ", connected %lld.%03lld secs ago",
                    connected_msecs/1000, connected_msecs%1000);
        return str_c(str);
 }
@@ -723,7 +723,7 @@ static void http_client_connection_destroy(struct connection *_conn)
        struct http_client_connection *conn =
                (struct http_client_connection *)_conn;
        const char *error;
-       unsigned int msecs;
+       long long msecs;
 
        switch (_conn->disconnect_reason) {
        case CONNECTION_DISCONNECT_CONNECT_TIMEOUT:
@@ -733,14 +733,14 @@ static void http_client_connection_destroy(struct connection *_conn)
                                &conn->connect_start_timestamp);
                        error = t_strdup_printf(
                                "connect(%s) failed: "
-                               "Connection timed out in %u.%03u secs",
+                               "Connection timed out in %lld.%03lld secs",
                                _conn->name, msecs/1000, msecs%1000);
                } else {
                        msecs = timeval_diff_msecs(&ioloop_timeval,
                                                   &conn->connected_timestamp);
                        error = t_strdup_printf(
                                "SSL handshaking with %s failed: "
-                               "Connection timed out in %u.%03u secs",
+                               "Connection timed out in %lld.%03lld secs",
                                _conn->name, msecs/1000, msecs%1000);
                }
                e_debug(conn->event, "%s", error);
@@ -794,7 +794,7 @@ static void http_client_payload_destroyed(struct http_client_request *req)
 
        e_debug(conn->event,
                "Response payload stream destroyed "
-               "(%u ms after initial response)",
+               "(%lld ms after initial response)",
                timeval_diff_msecs(&ioloop_timeval, &req->response_time));
 
        /* Caller is allowed to change the socket fd to blocking while reading
@@ -1157,7 +1157,7 @@ static void http_client_connection_input(struct connection *_conn)
                        http_client_request_add_event_headers(req, &response);
                e_debug(conn->event,
                        "Got %u response for request %s: %s%s "
-                       "(took %u ms + %u ms in queue)",
+                       "(took %lld ms + %lld ms in queue)",
                        response.status, http_client_request_label(req),
                        response.reason, suffix,
                        timeval_diff_msecs(&req->response_time, &req->sent_time),
@@ -1644,12 +1644,12 @@ http_client_connect_tunnel_timeout(struct http_client_connection *conn)
 {
        struct http_client_peer_shared *pshared = conn->ppool->peer;
        const char *error, *name = http_client_peer_addr2str(&pshared->addr);
-       unsigned int msecs;
+       long long msecs;
 
        msecs = timeval_diff_msecs(&ioloop_timeval,
                                   &conn->connect_start_timestamp);
        error = t_strdup_printf("Tunnel connect(%s) failed: "
-                               "Connection timed out in %u.%03u secs",
+                               "Connection timed out in %lld.%03lld secs",
                                name, msecs/1000, msecs%1000);
 
        e_debug(conn->event, "%s", error);
index 9af88af2c9da3c3b7cc4bff6f8882fb702cd9237..706c102e489a634f14c2331cf2497b0cf437213a 100644 (file)
@@ -39,7 +39,7 @@ static void
 http_client_host_shared_check_idle(struct http_client_host_shared *hshared)
 {
        struct http_client_host *host;
-       int timeout = 0;
+       long long timeout = 0;
 
        if (hshared->destroyed)
                return;
@@ -66,7 +66,7 @@ http_client_host_shared_check_idle(struct http_client_host_shared *hshared)
                                          http_client_host_shared_idle_timeout,
                                          hshared);
 
-       e_debug(hshared->event, "Host is idle (timeout = %u msecs)", timeout);
+       e_debug(hshared->event, "Host is idle (timeout = %lld msecs)", timeout);
 }
 
 static void
index 5a80215942cba037fccc7121e4e285145675593e..fc18496f35343021ae52022bd20bc323a5a6991c 100644 (file)
@@ -441,7 +441,7 @@ http_client_peer_shared_start_backoff_timer(
                return TRUE;
 
        if (pshared->last_failure.tv_sec > 0) {
-               int backoff_time_spent =
+               long long backoff_time_spent =
                        timeval_diff_msecs(&ioloop_timeval,
                                           &pshared->last_failure);
 
@@ -458,7 +458,7 @@ http_client_peer_shared_start_backoff_timer(
                }
 
                e_debug(pshared->event,
-                       "Backoff time already exceeded by %d msecs",
+                       "Backoff time already exceeded by %lld msecs",
                        (backoff_time_spent -
                         pshared->backoff_current_time_msecs));
        }
index 5c7915a7ec08120587e6b883c5f1969b38a98bb1..0bd1694e153cf032a7b34bd1d955ee3fc46c6b70 100644 (file)
@@ -588,11 +588,11 @@ void http_client_queue_connection_failure(struct http_client_queue *queue,
                                "Failed to set up any connection; "
                                "failing all queued requests");
                        if (queue->connect_attempts > 1) {
-                               unsigned int total_msecs =
+                               long long total_msecs =
                                        timeval_diff_msecs(&ioloop_timeval,
                                                           &queue->first_connect_time);
                                reason = t_strdup_printf(
-                                       "%s (%u attempts in %u.%03u secs)",
+                                       "%s (%u attempts in %lld.%03lld secs)",
                                        reason, queue->connect_attempts,
                                        total_msecs/1000, total_msecs%1000);
                        }
@@ -976,7 +976,7 @@ void http_client_queue_submit_request(struct http_client_queue *queue,
                                       TIMEOUT_CMP_MARGIN_USECS) > 0) {
                        e_debug(queue->event,
                                "Delayed request %s%s submitted "
-                               "(time remaining: %d msecs)",
+                               "(time remaining: %lld msecs)",
                                http_client_request_label(req),
                                (req->urgent ? " (urgent)" : ""),
                                timeval_diff_msecs(&req->release_time,
index 9b4ab7c55e333ba00bdc2b190cde938bdf225a64..3643d19053533afb2b8bc7eda284af6674385083 100644 (file)
@@ -763,7 +763,7 @@ void http_client_request_get_stats(struct http_client_request *req,
                                   struct http_client_request_stats *stats_r)
 {
        struct http_client *client = req->client;
-       int diff_msecs;
+       long long diff_msecs;
        uint64_t wait_usecs;
 
        i_zero(stats_r);
@@ -1544,11 +1544,11 @@ bool http_client_request_callback(struct http_client_request *req,
                struct http_response response_copy = *response;
 
                if (req->attempts > 0 && !req->preserve_exact_reason) {
-                       unsigned int total_msecs =
+                       long long total_msecs =
                                timeval_diff_msecs(&ioloop_timeval,
                                                   &req->submit_time);
                        response_copy.reason = t_strdup_printf(
-                               "%s (%u retries in %u.%03u secs)",
+                               "%s (%u retries in %lld.%03lld secs)",
                                response_copy.reason, req->attempts,
                                total_msecs/1000, total_msecs%1000);
                }
index d6a485613a12ec08c5b90c25c99f3a5bf7d61b0e..35c6b207cc3f60085bb447e78852713992ee2ca4 100644 (file)
@@ -2273,7 +2273,7 @@ test_client_retry_with_delay_response(
        const struct http_response *resp,
        struct _client_retry_with_delay_ctx *ctx)
 {
-       int real_delay, exp_delay;
+       long long real_delay, exp_delay;
 
        test_client_assert_response(resp, resp->status == 500);
 
@@ -2282,7 +2282,7 @@ test_client_retry_with_delay_response(
                real_delay = timeval_diff_msecs(&ioloop_timeval, &ctx->time);
                exp_delay = (1 << (ctx->retries-1)) * 50;
                if (real_delay < exp_delay-2) {
-                       i_fatal("Retry delay is too short %d < %d",
+                       i_fatal("Retry delay is too short %lld < %lld",
                                real_delay, exp_delay);
                }
        }
index 346c770029d8b01c8b682946edc6b3b989052181..8ead6c3c8d84271fb8cac9bc92ef5a95f58524bf 100644 (file)
@@ -147,7 +147,7 @@ const struct var_expand_table *
 mail_deliver_ctx_get_log_var_expand_table(struct mail_deliver_context *ctx,
                                          const char *message)
 {
-       unsigned int delivery_time_msecs;
+       long long delivery_time_msecs;
 
        /* If a mail was saved/copied, the fields are already filled and the
           following call is ignored. Otherwise, only the source mail exists. */
index bfeb805f6fc88b29f2d4d9d860093505fc3e68b6..d801a7bb154ecc7076c2a9e196cf1ce15a37d52b 100644 (file)
@@ -92,7 +92,7 @@ login_connection_event_callback(struct login_connection *conn,
                                const char *message)
 {
        string_t *str = t_str_new(128);
-       str_printfa(str, "%s (client-pid=%u, client-id=%u, rip=%s, created %u msecs ago, received %u/%zu bytes)",
+       str_printfa(str, "%s (client-pid=%u, client-id=%u, rip=%s, created %lld msecs ago, received %u/%zu bytes)",
                message, conn->client_pid, conn->auth_id,
                net_ip2addr(&conn->remote_ip),
                timeval_diff_msecs(&ioloop_timeval, &conn->create_time),
index 142a4e3b67f40c88527c553d2d27799dc82038aa..25cbb9b84e85850293f0193781b3d6b448bcfc57 100644 (file)
@@ -134,13 +134,13 @@ static void request_failure(struct login_server_auth *auth,
 {
        string_t *str = t_str_new(128);
 
-       str_printfa(str, "auth connected %u msecs ago",
+       str_printfa(str, "auth connected %lld msecs ago",
                    timeval_diff_msecs(&ioloop_timeval, &auth->connect_time));
        if (auth->handshake_time.tv_sec != 0) {
-               str_printfa(str, ", handshake %u msecs ago",
+               str_printfa(str, ", handshake %lld msecs ago",
                            timeval_diff_msecs(&ioloop_timeval, &auth->handshake_time));
        }
-       str_printfa(str, ", request took %u msecs, client-pid=%u client-id=%u",
+       str_printfa(str, ", request took %lld msecs, client-pid=%u client-id=%u",
                    timeval_diff_msecs(&ioloop_timeval, &request->create_stamp),
                    request->client_pid, request->auth_id);
 
@@ -266,7 +266,7 @@ static void login_server_auth_destroy(struct connection *_conn)
 static unsigned int auth_get_next_timeout_msecs(struct login_server_auth *auth)
 {
        struct timeval expires;
-       int diff;
+       long long diff;
 
        expires = auth->request_head->create_stamp;
        timeval_add_msecs(&expires, auth->timeout_msecs);
@@ -282,7 +282,7 @@ static void login_server_auth_timeout(struct login_server_auth *auth)
 
        while (auth->request_head != NULL &&
               auth_get_next_timeout_msecs(auth) == 0) {
-               int msecs;
+               long long msecs;
 
                request = auth->request_head;
                DLLIST2_REMOVE(&auth->request_head,
@@ -292,7 +292,7 @@ static void login_server_auth_timeout(struct login_server_auth *auth)
                msecs = timeval_diff_msecs(&ioloop_timeval,
                                           &request->create_stamp);
                reason = t_strdup_printf(
-                       "Auth server request timed out after %u.%03u secs",
+                       "Auth server request timed out after %lld.%03lld secs",
                        msecs/1000, msecs%1000);
                request_internal_failure(auth, request, reason);
                request_free(&request);
index be1d7bf464a0071d6b58dd0fc6df0e58bbc9a85f..d8ce13d373045e0a5714fa02a6b55b7f513b8842 100644 (file)
@@ -130,7 +130,7 @@ login_server_event_log_callback(struct login_server_connection *conn,
                                const char *message)
 {
        string_t *str = t_str_new(128);
-       str_printfa(str, "%s (connection created %d msecs ago", message,
+       str_printfa(str, "%s (connection created %lld msecs ago", message,
                timeval_diff_msecs(&ioloop_timeval, &conn->create_time));
        if (conn->requests != NULL) {
                struct login_server_request *request = conn->requests;
@@ -138,7 +138,7 @@ login_server_event_log_callback(struct login_server_connection *conn,
                str_append(str, ", ");
                if (request->next != NULL)
                        str_printfa(str, "%u requests, first ", conn->refcount-1);
-               str_printfa(str, "request created %d msecs ago: ",
+               str_printfa(str, "request created %lld msecs ago: ",
                            timeval_diff_msecs(&ioloop_timeval,
                                               &request->create_time));
                str_printfa(str, "session=%s, rip=%s, auth_pid=%ld, "
@@ -151,7 +151,7 @@ login_server_event_log_callback(struct login_server_connection *conn,
                if (request->postlogin_request != NULL) {
                        struct login_server_postlogin *pl =
                                request->postlogin_request;
-                       str_printfa(str, ", post-login script %s started %d msecs ago",
+                       str_printfa(str, ", post-login script %s started %lld msecs ago",
                                    pl->socket_path,
                                    timeval_diff_msecs(&ioloop_timeval,
                                                       &pl->create_time));
index 7b3c8b4f3be640b99cbccbb076c27789835c1dec..4d1af2b8714b3fcc0bb99b1aa855161ebd2d830b 100644 (file)
@@ -1715,7 +1715,7 @@ master_service_overflow_timeout_msecs(const struct timeval *created)
           this code treats all clients older than 10 seconds the same. */
        const unsigned int max_wait = 100;
        const int max_since = 10*1000;
-       int created_since = timeval_diff_msecs(&ioloop_timeval, created);
+       long long created_since = timeval_diff_msecs(&ioloop_timeval, created);
        unsigned int msecs;
 
        created_since = I_MAX(created_since, 0);
index 6622320e95767e6c563de896f38c66fe861477bc..d54f9e3f018e4476fe871d9f060d81bfae9c3d79 100644 (file)
@@ -112,7 +112,7 @@ static void stats_client_destroy(struct connection *conn)
                /* waiting for stats handshake to finish */
                io_loop_stop(client->ioloop);
        } else if (conn->connect_finished.tv_sec != 0) {
-               int msecs_since_connected =
+               long long msecs_since_connected =
                        timeval_diff_msecs(&ioloop_timeval,
                                           &conn->connect_finished);
                if (msecs_since_connected >= STATS_CLIENT_RECONNECT_INTERVAL_MSECS) {
@@ -317,20 +317,21 @@ static void stats_global_deinit(void)
 
 static void stats_client_handshake_timeout(struct stats_client *client)
 {
-       int diff_msecs = timeval_diff_msecs(&ioloop_timeval,
-                                           &client->wait_started);
+       long long diff_msecs = timeval_diff_msecs(&ioloop_timeval,
+                                                 &client->wait_started);
        e_error(client->conn.event, "Timeout waiting for handshake response "
-               "(waited %d.%03d secs%s)", diff_msecs / 1000, diff_msecs % 1000,
+               "(waited %lld.%03lld secs%s)",
+               diff_msecs / 1000, diff_msecs % 1000,
                client->conn.version_received ? ", version received" : "");
        io_loop_stop(client->ioloop);
 }
 
 static void stats_client_deinit_timeout(struct stats_client *client)
 {
-       int diff_msecs = timeval_diff_msecs(&ioloop_timeval,
-                                           &client->wait_started);
+       long long diff_msecs = timeval_diff_msecs(&ioloop_timeval,
+                                                 &client->wait_started);
        e_error(client->conn.event, "Timeout waiting for flushing outputs"
-               "(waited %d.%03d secs) - discarding the rest of the queued statistics",
+               "(waited %lld.%03lld secs) - discarding the rest of the queued statistics",
                diff_msecs / 1000, diff_msecs % 1000);
        io_loop_stop(client->ioloop);
 }
index 328b0d6a971b87ab4bea85c1630b8db49ba4a2e6..97fb5f1a6406dc17548246d38db3603c9a240854 100644 (file)
@@ -457,7 +457,8 @@ program_client_local_disconnect(struct program_client *pclient, bool force)
        struct program_client_local *plclient =
                (struct program_client_local *) pclient;
        pid_t pid = plclient->pid;
-       unsigned long runtime, timeout = 0;
+       long long runtime;
+       unsigned long timeout = 0;
 
        if (plclient->exited) {
                program_client_local_exited(plclient);
@@ -493,11 +494,11 @@ program_client_local_disconnect(struct program_client *pclient, bool force)
                return;
        }
 
-       if (runtime < pclient->set.input_idle_timeout_msecs)
+       if (runtime > 0 && runtime < pclient->set.input_idle_timeout_msecs)
                timeout = pclient->set.input_idle_timeout_msecs - runtime;
 
        e_debug(pclient->event,
-               "Waiting for program to finish after %lu msecs "
+               "Waiting for program to finish after %lld msecs "
                "(timeout = %lu msecs)", runtime, timeout);
 
        if (timeout == 0)
index f93d090910b6e2a9e1d4a3bf22004ae8e1dbab61..aebf3726a97553b3bd7e5bf4f0aac52307a4ae0e 100644 (file)
@@ -1487,7 +1487,7 @@ static void query_callback(CassFuture *future, void *context)
        if (error != CASS_OK) {
                const char *errmsg;
                size_t errsize;
-               int msecs;
+               long long msecs;
 
                cass_future_error_message(future, &errmsg, &errsize);
                i_free(result->error);
@@ -1499,7 +1499,7 @@ static void query_callback(CassFuture *future, void *context)
                   enough copies of the data for the query to succeed. */
                result->api.error_type = driver_cassandra_error_is_uncertain(error);
                result->error = i_strdup_printf(
-                       "Query '%s' failed: %.*s (in %u.%03u secs%s%s)",
+                       "Query '%s' failed: %.*s (in %lld.%03lld secs%s%s)",
                        result->log_query, (int)errsize, errmsg, msecs/1000, msecs%1000,
                        result->page_num == 0 ?
                                "" :
index 9c293e2a58edc1cee16860452d360c37a558c414..0a0c257ecba2743e5021512e57f04e95c292e17d 100644 (file)
@@ -240,7 +240,7 @@ static int driver_pgsql_connect(struct sql_db *_db)
 {
        struct pgsql_db *db = (struct pgsql_db *)_db;
        struct timeval tv_start;
-       int msecs;
+       long long msecs;
 
        i_assert(db->api.state == SQL_DB_STATE_DISCONNECTED);
 
@@ -268,7 +268,7 @@ static int driver_pgsql_connect(struct sql_db *_db)
        io_loop_time_refresh();
        msecs = timeval_diff_msecs(&ioloop_timeval, &tv_start);
        if (msecs > PGSQL_DNS_WARN_MSECS) {
-               e_warning(_db->event, "DNS lookup took %d.%03d s",
+               e_warning(_db->event, "DNS lookup took %lld.%03lld s",
                          msecs/1000, msecs % 1000);
        }
 
index 1a5f499d517261a4f75b1660e6ee89539858c6cb..dd0528aab90b9533dd8bb8a375c30953d2555d94 100644 (file)
@@ -834,7 +834,7 @@ struct event_passthrough *
 sql_query_finished_event(struct sql_db *db, struct event *event, const char *query,
                         bool success, int *duration_r)
 {
-       int diff;
+       long long diff;
        struct timeval tv;
        event_get_create_time(event, &tv);
        struct event_passthrough *e = event_create_passthrough(event)->
@@ -852,7 +852,8 @@ sql_query_finished_event(struct sql_db *db, struct event *event, const char *que
                e->add_str("slow_query", "y");
                db->slow_queries++;
        }
-       *duration_r = diff;
+       i_assert(diff <= INT_MAX);
+       *duration_r = (int)diff;
 
        return e;
 }
index 831545748ec7b24ea5882e93270e546970557f73..f6635b30c58db751dbc9269cd310ca8776d47fec 100644 (file)
@@ -127,7 +127,7 @@ duplicate_lock_failed(struct mail_duplicate_transaction *trans,
 {
        struct mail_duplicate_lock *lock = &dup->lock;
        enum mail_duplicate_lock_result result;
-       int diff;
+       long long diff;
 
        i_assert(lock->fd == -1);
        i_assert(lock->lock == NULL);
@@ -141,7 +141,7 @@ duplicate_lock_failed(struct mail_duplicate_transaction *trans,
        } else {
                diff = timeval_diff_msecs(&ioloop_timeval,
                                          &lock->start_time);
-               error = t_strdup_printf("Lock timeout in %d.%03d secs",
+               error = t_strdup_printf("Lock timeout in %lld.%03lld secs",
                                        diff/1000, diff%1000);
                result = MAIL_DUPLICATE_LOCK_TIMEOUT;
        }
@@ -175,7 +175,7 @@ mail_duplicate_lock(struct mail_duplicate_transaction *trans,
        const char *error;
        unsigned char id_md5[MD5_RESULTLEN];
        bool created;
-       int diff;
+       long long diff;
 
        if (mail_duplicate_is_locked(dup)) {
                e_debug(trans->event, "Duplicate ID already locked");
@@ -214,7 +214,7 @@ mail_duplicate_lock(struct mail_duplicate_transaction *trans,
 
        diff = timeval_diff_msecs(&ioloop_timeval, &lock->start_time);
        if (diff >= (DUPLICATE_LOCK_WARN_SECS * 1000)) {
-               e_warning(trans->event, "Locking %s took %d.%03d secs",
+               e_warning(trans->event, "Locking %s took %lld.%03lld secs",
                          lock->path, diff/1000, diff%1000);
        }
 
index 952c85cf967130990de659fd28e2dc4a428dbf05..0271fa134b0dbc3681ee5db965a47bea0cf8b86f 100644 (file)
@@ -983,21 +983,22 @@ const char *connection_disconnect_reason(struct connection *conn)
 const char *connection_input_timeout_reason(struct connection *conn)
 {
        if (conn->last_input_tv.tv_sec != 0) {
-               int diff = timeval_diff_msecs(&ioloop_timeval,
-                                             &conn->last_input_tv);
-               return t_strdup_printf("No input for %u.%03u secs",
+               long long diff = timeval_diff_msecs(&ioloop_timeval,
+                                                   &conn->last_input_tv);
+               return t_strdup_printf("No input for %lld.%03lld secs",
                                       diff/1000, diff%1000);
        } else if (conn->connect_finished.tv_sec != 0) {
-               int diff = timeval_diff_msecs(&ioloop_timeval,
-                                             &conn->connect_finished);
+               long long diff = timeval_diff_msecs(&ioloop_timeval,
+                                                   &conn->connect_finished);
                return t_strdup_printf(
-                       "No input since connected %u.%03u secs ago",
+                       "No input since connected %lld.%03lld secs ago",
                        diff/1000, diff%1000);
        } else {
-               int diff = timeval_diff_msecs(&ioloop_timeval,
-                                             &conn->connect_started);
-               return t_strdup_printf("connect(%s) timed out after %u.%03u secs",
-                                      conn->name, diff/1000, diff%1000);
+               long long diff = timeval_diff_msecs(&ioloop_timeval,
+                                                   &conn->connect_started);
+               return t_strdup_printf(
+                       "connect(%s) timed out after %lld.%03lld secs",
+                       conn->name, diff/1000, diff%1000);
        }
 }
 
index 754717aed58ffc265946b7e3ab99894056698130..8457109d90e6c6a1ad5064c9d5607df5c4f91b26 100644 (file)
@@ -36,7 +36,7 @@ cpu_limit_get_usage_msecs_with(struct cpu_limit *climit,
                               const struct rusage *rusage)
 {
        struct timeval cpu_usage = { 0, 0 };
-       int usage_diff;
+       long long usage_diff;
 
        if ((type & CPU_LIMIT_TYPE_USER) != 0)
                timeval_add(&cpu_usage, &rusage->ru_utime);
@@ -50,6 +50,7 @@ cpu_limit_get_usage_msecs_with(struct cpu_limit *climit,
                timeval_add(&initial_total, &climit->initial_usage.ru_stime);
        usage_diff = timeval_diff_msecs(&cpu_usage, &initial_total);
        i_assert(usage_diff >= 0);
+       i_assert(usage_diff <= UINT_MAX);
 
        return (unsigned int)usage_diff;
 }
index a9369b8f1bb2385304137218969dec9a434cafb2..9d37bb52d7ee933cf7a5ee267905eecb8f0b4382 100644 (file)
@@ -486,9 +486,9 @@ static void file_lock_log_warning_if_slow(struct file_lock *lock)
        struct timeval now;
        i_gettimeofday(&now);
 
-       int diff = timeval_diff_msecs(&now, &lock->locked_time);
+       long long diff = timeval_diff_msecs(&now, &lock->locked_time);
        if (diff > file_lock_slow_warning_usecs/1000) {
-               i_warning("Lock %s kept for %d.%03d secs", lock->path,
+               i_warning("Lock %s kept for %lld.%03lld secs", lock->path,
                          diff / 1000, diff % 1000);
        }
 }
index 4fcced1758128207a490cdf3d6294f8ad4b16a77..d3e8d2524f09ea343a498194991b1c018e216336 100644 (file)
@@ -42,7 +42,7 @@ static void i_stream_timeout(struct timeout_istream *tstream)
 {
        struct iostream_private *iostream = &tstream->istream.iostream;
        unsigned int over_msecs;
-       int diff;
+       long long diff;
 
        if (tstream->update_timestamp) {
                /* we came here after a long-running code. timeouts are handled
@@ -66,7 +66,7 @@ static void i_stream_timeout(struct timeout_istream *tstream)
        over_msecs = diff - tstream->timeout_msecs;
 
        io_stream_set_error(&tstream->istream.iostream,
-                           "Read timeout in %u.%03u s after %"PRIuUOFF_T" bytes%s",
+                           "Read timeout in %lld.%03lld s after %"PRIuUOFF_T" bytes%s",
                            diff/1000, diff%1000,
                            tstream->istream.istream.v_offset,
                            over_msecs < 1000 ? "" : t_strdup_printf(
index b6d99a39cb3869a8703bea50df601f63a566aa1e..327a88fb6c077b135c1990b07c12afa1dc2161ca 100644 (file)
@@ -52,7 +52,7 @@ test_cpu_limit_simple(enum cpu_limit_type type, const char *type_str)
 {
        struct cpu_limit *climit;
        struct timeval usage, cpu;
-       int diff_msecs;
+       long long diff_msecs;
 
        test_begin(t_strdup_printf("cpu limit - simple (%s)", type_str));
 
@@ -77,7 +77,7 @@ static void test_cpu_limit_nested(enum cpu_limit_type type, const char *type_str
        struct cpu_limit *climit1, *climit2;
        struct timeval usage1, cpu;
        unsigned int n;
-       int diff_msecs;
+       long long diff_msecs;
 
        test_begin(t_strdup_printf("cpu limit - nested (%s)", type_str));
 
index 375f8b81940d4de8a5d31c8cd785856acf9ffc0c..966851d311cfaa066f0fe04cb9ad97355bfff31b 100644 (file)
@@ -208,8 +208,7 @@ static void test_timeval_diff(void)
                999999
        };
        unsigned int i;
-       long long udiff;
-       int mdiff;
+       long long udiff, mdiff;
 
        test_begin("timeval_diff_*()");
        for (i = 0; i < N_ELEMENTS(input); i += 2) {
index 3f4cd01c9eda7e8cbc620cb29215b7b9a414ad45..1d8da1f634d6c6b433470fcc52a496b569a34c3c 100644 (file)
@@ -68,16 +68,6 @@ int timeval_cmp_margin(const struct timeval *tv1, const struct timeval *tv2,
        return (unsigned long long)usecs_diff > usec_margin ? ret : 0;
 }
 
-int timeval_diff_msecs(const struct timeval *tv1, const struct timeval *tv2)
-{
-       long long diff = timeval_diff_usecs(tv1, tv2) / 1000LL;
-#ifdef DEBUG
-       /* FIXME v2.4: Remove the ifdef */
-       i_assert(diff <= INT_MAX);
-#endif
-       return (int)diff;
-}
-
 long long timeval_diff_usecs(const struct timeval *tv1,
                             const struct timeval *tv2)
 {
index 437144cb42d6b81f563150103facf427541cee2d..c3c94f5416c16965862aacb79ed552f2595d4fa0 100644 (file)
@@ -17,11 +17,14 @@ int timeval_cmp(const struct timeval *tv1, const struct timeval *tv2);
 /* Same as timeval_cmp, but tv->usecs must differ by at least usec_margin */
 int timeval_cmp_margin(const struct timeval *tv1, const struct timeval *tv2,
                       unsigned int usec_margin);
-/* Returns tv1-tv2 in milliseconds. */
-int timeval_diff_msecs(const struct timeval *tv1, const struct timeval *tv2);
 /* Returns tv1-tv2 in microseconds. */
 long long timeval_diff_usecs(const struct timeval *tv1,
                             const struct timeval *tv2);
+/* Returns tv1-tv2 in milliseconds. */
+static inline long long timeval_diff_msecs(const struct timeval *tv1,
+                                          const struct timeval *tv2) {
+       return timeval_diff_usecs(tv1, tv2) / 1000;
+}
 
 static inline void
 timeval_from_usecs(struct timeval *tv_r, unsigned long long usecs)
index 72781925c556bebbaff591adc688f78b24c90140..a3239c78b7ace80767e3ee65900d9b5e152823c5 100644 (file)
@@ -1079,7 +1079,7 @@ lmtp_proxy_data_cb(const struct smtp_reply *proxy_reply,
                str_append(msg, "Sent message to");
        else
                str_append(msg, "Failed to send message to");
-       str_printfa(msg, " <%s> at %s:%u: %s (%u/%u at %u ms)",
+       str_printfa(msg, " <%s> at %s:%u: %s (%u/%u at %lld ms)",
                    smtp_address_encode(address),
                    conn->set.set.host, conn->set.set.port,
                    smtp_reply_log(proxy_reply),
index cff32e23017c5e6a393be6bdee806c9fdb4515b6..d20d4b44239d5496d161c4e55ef3c03d0263b439 100644 (file)
@@ -220,8 +220,8 @@ static void proxy_fail_connect(struct login_proxy *proxy)
 void login_proxy_append_success_log_info(struct login_proxy *proxy,
                                         string_t *str)
 {
-       int msecs = timeval_diff_msecs(&ioloop_timeval, &proxy->created);
-       str_printfa(str, " (%d.%03d secs", msecs/1000, msecs%1000);
+       long long msecs = timeval_diff_msecs(&ioloop_timeval, &proxy->created);
+       str_printfa(str, " (%lld.%03lld secs", msecs/1000, msecs%1000);
        if (proxy->reconnect_count > 0)
                str_printfa(str, ", %u reconnects", proxy->reconnect_count);
        str_append_c(str, ')');
@@ -284,7 +284,7 @@ static void proxy_reconnect_timeout(struct login_proxy *proxy)
 
 static bool proxy_try_reconnect(struct login_proxy *proxy)
 {
-       int since_started_msecs, left_msecs;
+       long long since_started_msecs, left_msecs;
 
        if (proxy->reconnect_count >= proxy->client->set->login_proxy_max_reconnects)
                return FALSE;
@@ -592,7 +592,7 @@ static unsigned int login_proxy_delay_disconnect(struct login_proxy *proxy)
                proxy->client->set->login_proxy_max_disconnect_delay;
        struct timeval disconnect_time_offset;
        unsigned int max_disconnects_per_sec, delay_msecs_since_ts, max_conns;
-       int delay_msecs;
+       long long delay_msecs;
 
        if (rec->num_disconnects_since_ts == 0) {
                rec->disconnect_timestamp = ioloop_timeval;
index 36f3f031cf8bfb5508efd210b0053b5323c8320f..f4bb2650f305cf9a41dec43d992928b7cbe5bec4 100644 (file)
@@ -1387,11 +1387,10 @@ fts_flatcurve_xapian_close_db(struct flatcurve_fts_backend *backend,
        if (commit) {
                struct timeval now;
                i_gettimeofday(&now);
-               unsigned int elapsed =
-                       (unsigned int) timeval_diff_msecs(&now, &start);
+               long long elapsed = timeval_diff_msecs(&now, &start);
                if (xdb->changes > 0)
                        e_debug(backend->event, "Committed %u changes to DB "
-                               "(RW, %s) in %u.%03u secs", xdb->changes,
+                               "(RW, %s) in %lld.%03lld secs", xdb->changes,
                                xdb->dbpath->fname, elapsed / 1000, elapsed % 1000);
 
                xdb->changes = 0;
@@ -1902,8 +1901,8 @@ fts_flatcurve_xapian_optimize_box_do(struct flatcurve_fts_backend *backend,
 
        struct timeval now;
        i_gettimeofday(&now);
-       unsigned int elapsed = (unsigned int) timeval_diff_msecs(&now, &start);
-       e_debug(backend->event, "Optimized DB in %u.%03u secs",
+       long long elapsed = timeval_diff_msecs(&now, &start);
+       e_debug(backend->event, "Optimized DB in %lld.%03lld secs",
                                elapsed / 1000, elapsed % 1000);
 
        return 0;
index 76d2871a5bbfa104d7112e8baf2e14f0c4ef36b8..ef0bdabfd79b5f7b9199941e456b9239a0ad3969 100644 (file)
@@ -181,7 +181,8 @@ fts_backend_flatcurve_update_deinit(struct fts_backend_update_context *_ctx)
 {
        struct flatcurve_fts_backend_update_context *ctx =
                (struct flatcurve_fts_backend_update_context *)_ctx;
-       int diff, ret = _ctx->failed ? -1 : 0;
+       int ret = _ctx->failed ? -1 : 0;
+       long long diff;
        struct timeval now;
 
        if (ret == 0) {
@@ -189,7 +190,7 @@ fts_backend_flatcurve_update_deinit(struct fts_backend_update_context *_ctx)
                diff = timeval_diff_msecs(&now, &ctx->start);
 
                e_debug(ctx->backend->event, "Update transaction completed in "
-                       "%u.%03u secs", diff/1000, diff%1000);
+                       "%lld.%03lld secs", diff/1000, diff%1000);
        }
 
        str_free(&ctx->hdr_name);