]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ioloop: Make the callback for io_loop_set_time_moved_callback() use struct timeval.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 16 Dec 2018 12:55:34 +0000 (13:55 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 10 Sep 2019 07:01:47 +0000 (10:01 +0300)
This allows reporting sub-second glitches.

src/lib-storage/mail-storage-service.c
src/lib/ioloop.c
src/lib/ioloop.h
src/master/main.c

index fd4dfcc9ae396f75a56cc771e4bfe2b2c7828aac..14ee82390b9969e13401dda235b790380fdb620b 100644 (file)
@@ -900,9 +900,11 @@ mail_storage_service_init_log(struct mail_storage_service_ctx *ctx,
                i_set_failure_send_prefix(user->log_prefix);
 }
 
-static void mail_storage_service_time_moved(time_t old_time, time_t new_time)
+static void
+mail_storage_service_time_moved(const struct timeval *old_time,
+                               const struct timeval *new_time)
 {
-       long diff = new_time - old_time;
+       long diff = new_time->tv_sec - old_time->tv_sec;
 
        if (diff > 0) {
                if (diff > MAX_NOWARN_FORWARD_SECS)
@@ -927,7 +929,7 @@ static void mail_storage_service_time_moved(time_t old_time, time_t new_time)
                        /* don't use sleep()'s return value, because
                           it could get us to a long loop in case
                           interrupts just keep coming */
-                       diff = old_time - time(NULL) + 1;
+                       diff = old_time->tv_sec - time(NULL) + 1;
                }
        }
 }
index 6f1ab7b86ef6c2acc2bbf131741d15e4bd59ccec..20016eac1a721b3d17913ebd640d61dd8b93be51 100644 (file)
@@ -550,11 +550,14 @@ static int timeout_cmp(const void *p1, const void *p2)
        return timeval_cmp(&to1->next_run, &to2->next_run);
 }
 
-static void io_loop_default_time_moved(time_t old_time, time_t new_time)
+static void
+io_loop_default_time_moved(const struct timeval *old_time,
+                          const struct timeval *new_time)
 {
-       if (old_time > new_time) {
-               i_warning("Time moved backwards by %ld seconds.",
-                         (long)(old_time - new_time));
+       long long diff = timeval_diff_usecs(old_time, new_time);
+       if (diff > 0) {
+               i_warning("Time moved backwards by %lld.%06lld seconds.",
+                         diff / 1000000, diff % 1000000);
        }
 }
 
@@ -634,10 +637,7 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
        if (unlikely(diff_usecs < 0)) {
                /* time moved backwards */
                io_loops_timeouts_update(diff_usecs);
-               if (unlikely(ioloop_time > ioloop_timeval.tv_sec)) {
-                       ioloop->time_moved_callback(ioloop_time,
-                                                   ioloop_timeval.tv_sec);
-               }
+               ioloop->time_moved_callback(&tv_old, &ioloop_timeval);
                i_assert(ioloop == current_ioloop);
                /* the callback may have slept, so check the time again. */
                if (gettimeofday(&ioloop_timeval, NULL) < 0)
@@ -648,12 +648,8 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
                if (unlikely(diff_usecs < 0)) {
                        io_loops_timeouts_update(-diff_usecs);
                        /* time moved forwards */
-                       if (unlikely(ioloop_timeval.tv_sec >
-                                    ioloop->next_max_time.tv_sec)) {
-                               ioloop->time_moved_callback(
-                                       ioloop->next_max_time.tv_sec,
-                                       ioloop_timeval.tv_sec);
-                       }
+                       ioloop->time_moved_callback(&ioloop->next_max_time,
+                                                   &ioloop_timeval);
                        i_assert(ioloop == current_ioloop);
                }
                ioloop_add_wait_time(ioloop);
index 5178d135f1e1e2e934d4f82daa1540f904a138a1..9f60b2f9d615d1376550f68d4c6001eb37d4dc6c 100644 (file)
@@ -32,7 +32,8 @@ enum io_notify_result {
 
 typedef void io_callback_t(void *context);
 typedef void timeout_callback_t(void *context);
-typedef void io_loop_time_moved_callback_t(time_t old_time, time_t new_time);
+typedef void io_loop_time_moved_callback_t(const struct timeval *old_time,
+                                          const struct timeval *new_time);
 typedef void io_switch_callback_t(struct ioloop *prev_ioloop);
 
 /* Time when the I/O loop started calling handlers.
index 869a2b612fbb9e1cff7526a2a5d4a24c4a2b0830..477a9fb09fc350cf32fddd5f815a1296d163c31a 100644 (file)
@@ -589,16 +589,18 @@ static const char *get_full_config_path(struct service_list *list)
        return p_strdup(list->pool, abspath);
 }
 
-static void master_time_moved(time_t old_time, time_t new_time)
+static void
+master_time_moved(const struct timeval *old_time,
+                const struct timeval *new_time)
 {
        time_t secs;
 
-       if (new_time >= old_time)
+       if (new_time->tv_sec >= old_time->tv_sec)
                return;
 
        /* time moved backwards. disable launching new service processes
           until  */
-       secs = old_time - new_time + 1;
+       secs = old_time->tv_sec - new_time->tv_sec + 1;
        if (secs > SERVICE_TIME_MOVED_BACKWARDS_MAX_THROTTLE_SECS)
                secs = SERVICE_TIME_MOVED_BACKWARDS_MAX_THROTTLE_SECS;
        services_throttle_time_sensitives(services, secs);