From: Timo Sirainen Date: Fri, 24 May 2024 13:02:40 +0000 (+0300) Subject: lib, global: timeval_diff_msecs() - Return long long X-Git-Tag: 2.4.0~1652 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=48b54ed2a6f70fd036d31a72e4d7650f08d4ab6b;p=thirdparty%2Fdovecot%2Fcore.git lib, global: timeval_diff_msecs() - Return long long This makes it less likely to hit accidental bugs due to comparing timestamps with large differences. --- diff --git a/src/auth/auth-master-connection.c b/src/auth/auth-master-connection.c index a19e5857e7..1fb15ca0de 100644 --- a/src/auth/auth-master-connection.c +++ b/src/auth/auth-master-connection.c @@ -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)); } diff --git a/src/auth/db-ldap.c b/src/auth/db-ldap.c index 5ae3a90414..5059978661 100644 --- a/src/auth/db-ldap.c +++ b/src/auth/db-ldap.c @@ -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); diff --git a/src/auth/userdb-passwd.c b/src/auth/userdb-passwd.c index d94346a05b..2623dff58a 100644 --- a/src/auth/userdb-passwd.c +++ b/src/auth/userdb-passwd.c @@ -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; } diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 1b330f3ede..8d67996514 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -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)."); diff --git a/src/imap/imap-storage-callbacks.c b/src/imap/imap-storage-callbacks.c index 254fa0ba65..7cd31007ff 100644 --- a/src/imap/imap-storage-callbacks.c +++ b/src/imap/imap-storage-callbacks.c @@ -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); diff --git a/src/lib-dict-extra/dict-client.c b/src/lib-dict-extra/dict-client.c index cb62c4bd83..0f4d432350 100644 --- a/src/lib-dict-extra/dict-client.c +++ b/src/lib-dict-extra/dict-client.c @@ -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)", diff --git a/src/lib-dns/dns-lookup.c b/src/lib-dns/dns-lookup.c index ff578a739d..f9b83fd92a 100644 --- a/src/lib-dns/dns-lookup.c +++ b/src/lib-dns/dns-lookup.c @@ -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); diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index fe080fbba4..c3e788c7c9 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -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); diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 9af88af2c9..706c102e48 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -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 diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index 5a80215942..fc18496f35 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -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)); } diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index 5c7915a7ec..0bd1694e15 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -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, diff --git a/src/lib-http/http-client-request.c b/src/lib-http/http-client-request.c index 9b4ab7c55e..3643d19053 100644 --- a/src/lib-http/http-client-request.c +++ b/src/lib-http/http-client-request.c @@ -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); } diff --git a/src/lib-http/test-http-client-errors.c b/src/lib-http/test-http-client-errors.c index d6a485613a..35c6b207cc 100644 --- a/src/lib-http/test-http-client-errors.c +++ b/src/lib-http/test-http-client-errors.c @@ -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); } } diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index 346c770029..8ead6c3c8d 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -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. */ diff --git a/src/lib-login/login-client.c b/src/lib-login/login-client.c index bfeb805f6f..d801a7bb15 100644 --- a/src/lib-login/login-client.c +++ b/src/lib-login/login-client.c @@ -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), diff --git a/src/lib-login/login-server-auth.c b/src/lib-login/login-server-auth.c index 142a4e3b67..25cbb9b84e 100644 --- a/src/lib-login/login-server-auth.c +++ b/src/lib-login/login-server-auth.c @@ -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); diff --git a/src/lib-login/login-server.c b/src/lib-login/login-server.c index be1d7bf464..d8ce13d373 100644 --- a/src/lib-login/login-server.c +++ b/src/lib-login/login-server.c @@ -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)); diff --git a/src/lib-master/master-service.c b/src/lib-master/master-service.c index 7b3c8b4f3b..4d1af2b871 100644 --- a/src/lib-master/master-service.c +++ b/src/lib-master/master-service.c @@ -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); diff --git a/src/lib-master/stats-client.c b/src/lib-master/stats-client.c index 6622320e95..d54f9e3f01 100644 --- a/src/lib-master/stats-client.c +++ b/src/lib-master/stats-client.c @@ -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); } diff --git a/src/lib-program-client/program-client-local.c b/src/lib-program-client/program-client-local.c index 328b0d6a97..97fb5f1a64 100644 --- a/src/lib-program-client/program-client-local.c +++ b/src/lib-program-client/program-client-local.c @@ -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) diff --git a/src/lib-sql/driver-cassandra.c b/src/lib-sql/driver-cassandra.c index f93d090910..aebf3726a9 100644 --- a/src/lib-sql/driver-cassandra.c +++ b/src/lib-sql/driver-cassandra.c @@ -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 ? "" : diff --git a/src/lib-sql/driver-pgsql.c b/src/lib-sql/driver-pgsql.c index 9c293e2a58..0a0c257ecb 100644 --- a/src/lib-sql/driver-pgsql.c +++ b/src/lib-sql/driver-pgsql.c @@ -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); } diff --git a/src/lib-sql/sql-api.c b/src/lib-sql/sql-api.c index 1a5f499d51..dd0528aab9 100644 --- a/src/lib-sql/sql-api.c +++ b/src/lib-sql/sql-api.c @@ -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; } diff --git a/src/lib-storage/mail-duplicate.c b/src/lib-storage/mail-duplicate.c index 831545748e..f6635b30c5 100644 --- a/src/lib-storage/mail-duplicate.c +++ b/src/lib-storage/mail-duplicate.c @@ -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); } diff --git a/src/lib/connection.c b/src/lib/connection.c index 952c85cf96..0271fa134b 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -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); } } diff --git a/src/lib/cpu-limit.c b/src/lib/cpu-limit.c index 754717aed5..8457109d90 100644 --- a/src/lib/cpu-limit.c +++ b/src/lib/cpu-limit.c @@ -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; } diff --git a/src/lib/file-lock.c b/src/lib/file-lock.c index a9369b8f1b..9d37bb52d7 100644 --- a/src/lib/file-lock.c +++ b/src/lib/file-lock.c @@ -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); } } diff --git a/src/lib/istream-timeout.c b/src/lib/istream-timeout.c index 4fcced1758..d3e8d2524f 100644 --- a/src/lib/istream-timeout.c +++ b/src/lib/istream-timeout.c @@ -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( diff --git a/src/lib/test-cpu-limit.c b/src/lib/test-cpu-limit.c index b6d99a39cb..327a88fb6c 100644 --- a/src/lib/test-cpu-limit.c +++ b/src/lib/test-cpu-limit.c @@ -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)); diff --git a/src/lib/test-time-util.c b/src/lib/test-time-util.c index 375f8b8194..966851d311 100644 --- a/src/lib/test-time-util.c +++ b/src/lib/test-time-util.c @@ -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) { diff --git a/src/lib/time-util.c b/src/lib/time-util.c index 3f4cd01c9e..1d8da1f634 100644 --- a/src/lib/time-util.c +++ b/src/lib/time-util.c @@ -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) { diff --git a/src/lib/time-util.h b/src/lib/time-util.h index 437144cb42..c3c94f5416 100644 --- a/src/lib/time-util.h +++ b/src/lib/time-util.h @@ -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) diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index 72781925c5..a3239c78b7 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -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), diff --git a/src/login-common/login-proxy.c b/src/login-common/login-proxy.c index cff32e2301..d20d4b4423 100644 --- a/src/login-common/login-proxy.c +++ b/src/login-common/login-proxy.c @@ -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; diff --git a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc index 36f3f031cf..f4bb2650f3 100644 --- a/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc +++ b/src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc @@ -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; diff --git a/src/plugins/fts-flatcurve/fts-backend-flatcurve.c b/src/plugins/fts-flatcurve/fts-backend-flatcurve.c index 76d2871a5b..ef0bdabfd7 100644 --- a/src/plugins/fts-flatcurve/fts-backend-flatcurve.c +++ b/src/plugins/fts-flatcurve/fts-backend-flatcurve.c @@ -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);