Add sanity checks for system clock changes.
authorZac Medico <zmedico@gentoo.org>
Sat, 23 Oct 2010 23:19:24 +0000 (16:19 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 23 Oct 2010 23:19:24 +0000 (16:19 -0700)
pym/_emerge/PollScheduler.py
pym/_emerge/QueueScheduler.py

index 68826e28edc7bb5c315c1c58d4832cc84481b506..e71350e5bb182d94acea6128e1ef94b99e0a02e7 100644 (file)
@@ -235,7 +235,13 @@ class PollScheduler(object):
                                        break
                                if timeout is not None:
                                        elapsed_time = time.time() - start_time
-                                       remaining_timeout = (timeout - 1000 * elapsed_time)
+                                       if elapsed_time < 0:
+                                               # The system clock has changed such that start_time
+                                               # is now in the future, so just assume that the
+                                               # timeout has already elapsed.
+                                               timed_out = True
+                                               break
+                                       remaining_timeout = timeout - 1000 * elapsed_time
                                        if remaining_timeout <= 0:
                                                timed_out = True
                                                break
index 1379ffc6f73a636a8bc1c529042189f0b0c40f7e..8a7ea300a55f04f1ceb9aa5f72b4f1d4ddc82f27 100644 (file)
@@ -46,7 +46,13 @@ class QueueScheduler(PollScheduler):
                        self._schedule_wait(timeout=remaining_timeout)
                        if timeout is not None:
                                elapsed_time = time.time() - start_time
-                               remaining_timeout = (timeout - 1000 * elapsed_time)
+                               if elapsed_time < 0:
+                                       # The system clock has changed such that start_time
+                                       # is now in the future, so just assume that the
+                                       # timeout has already elapsed.
+                                       timed_out = True
+                                       break
+                               remaining_timeout = timeout - 1000 * elapsed_time
                                if remaining_timeout <= 0:
                                        timed_out = True
                                        break
@@ -56,7 +62,13 @@ class QueueScheduler(PollScheduler):
                                self._schedule_wait(timeout=remaining_timeout)
                                if timeout is not None:
                                        elapsed_time = time.time() - start_time
-                                       remaining_timeout = (timeout - 1000 * elapsed_time)
+                                       if elapsed_time < 0:
+                                               # The system clock has changed such that start_time
+                                               # is now in the future, so just assume that the
+                                               # timeout has already elapsed.
+                                               timed_out = True
+                                               break
+                                       remaining_timeout = timeout - 1000 * elapsed_time
                                        if remaining_timeout <= 0:
                                                timed_out = True
                                                break