[dovecot-cvs] dovecot/src/lib ioloop.c,1.35.2.4,1.35.2.5
tss at dovecot.org
tss at dovecot.org
Tue Mar 6 20:27:13 EET 2007
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv14606
Modified Files:
Tag: branch_1_0
ioloop.c
Log Message:
If time moves backwards only max. 5 seconds, sleep instead of killing
ourself.
Index: ioloop.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop.c,v
retrieving revision 1.35.2.4
retrieving revision 1.35.2.5
diff -u -d -r1.35.2.4 -r1.35.2.5
--- ioloop.c 28 Feb 2007 20:19:39 -0000 1.35.2.4
+++ ioloop.c 6 Mar 2007 18:27:11 -0000 1.35.2.5
@@ -1,8 +1,13 @@
-/* Copyright (c) 2002-2003 Timo Sirainen */
+/* Copyright (c) 2002-2007 Timo Sirainen */
#include "lib.h"
#include "ioloop-internal.h"
+#include <unistd.h>
+
+/* If time moves backwards more than this, kill ourself instead of sleeping. */
+#define IOLOOP_MAX_TIME_BACKWARDS_SLEEP 5
+
#define timer_is_larger(tvp, uvp) \
((tvp)->tv_sec > (uvp)->tv_sec || \
((tvp)->tv_sec == (uvp)->tv_sec && \
@@ -217,11 +222,25 @@
if (gettimeofday(&ioloop_timeval, &ioloop_timezone) < 0)
i_fatal("gettimeofday(): %m");
+ /* Don't bother comparing usecs. */
if (ioloop_time > ioloop_timeval.tv_sec) {
- i_fatal("Time just moved backwards (%s -> %s)! "
- "This might cause a lot of problems, "
- "so I'll just kill myself now.",
- dec2str(ioloop_time), dec2str(ioloop_timeval.tv_sec));
+ time_t diff = ioloop_time - ioloop_timeval.tv_sec;
+
+ if (diff > IOLOOP_MAX_TIME_BACKWARDS_SLEEP) {
+ i_fatal("Time just moved backwards by %ld seconds. "
+ "This might cause a lot of problems, "
+ "so I'll just kill myself now.", (long)diff);
+ } else {
+ i_error("Time just moved backwards by %ld seconds. "
+ "I'll sleep now until we're back in present.",
+ (long)diff);
+ /* Sleep extra second to make sure usecs also grows. */
+ if (sleep(diff + 1) != 0)
+ i_fatal("Sleep interrupted, byebye.");
+
+ /* Try again. */
+ io_loop_handle_timeouts(ioloop);
+ }
}
ioloop_time = ioloop_timeval.tv_sec;
More information about the dovecot-cvs
mailing list