summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hwclock/clock.h1
-rw-r--r--hwclock/hwclock.c2
-rw-r--r--hwclock/rtc.c23
3 files changed, 14 insertions, 12 deletions
diff --git a/hwclock/clock.h b/hwclock/clock.h
index 6e8a9b4ca..cbdf99917 100644
--- a/hwclock/clock.h
+++ b/hwclock/clock.h
@@ -33,6 +33,7 @@ extern void outsyserr(char *msg, ...)
#else
;
#endif
+extern double time_diff(struct timeval subtrahend, struct timeval subtractor);
/* cmos.c */
extern void set_cmos_epoch(int ARCconsole, int SRM);
extern void set_cmos_access(int Jensen, int funky_toy);
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index 82da273df..c08ae3f5e 100644
--- a/hwclock/hwclock.c
+++ b/hwclock/hwclock.c
@@ -182,7 +182,7 @@ read_date_from_file (struct tm *tm) {
write_date_to_file (tm);
}
-static double
+double
time_diff(struct timeval subtrahend, struct timeval subtractor) {
/*---------------------------------------------------------------------------
The difference in seconds between two times in "timeval" format.
diff --git a/hwclock/rtc.c b/hwclock/rtc.c
index 3eb1f4eb7..e59414fde 100644
--- a/hwclock/rtc.c
+++ b/hwclock/rtc.c
@@ -179,8 +179,8 @@ busywait_for_rtc_clock_tick(const int rtc_fd) {
struct tm start_time;
/* The time when we were called (and started waiting) */
struct tm nowtime;
- int i; /* local loop index */
int rc;
+ struct timeval begin, now;
if (debug)
printf(_("Waiting in loop for time from %s to change\n"),
@@ -191,25 +191,26 @@ busywait_for_rtc_clock_tick(const int rtc_fd) {
return 1;
/* Wait for change. Should be within a second, but in case something
- weird happens, we have a limit on this loop to reduce the impact
- of this failure.
- */
- for (i = 0;
- (rc = do_rtc_read_ioctl(rtc_fd, &nowtime)) == 0
- && start_time.tm_sec == nowtime.tm_sec;
- i++)
- if (i >= 1000000) {
+ * weird happens, we have a time limit (1.5s) on this loop to reduce the
+ * impact of this failure.
+ */
+ gettimeofday(&begin, NULL);
+ do {
+ rc = do_rtc_read_ioctl(rtc_fd, &nowtime);
+ if (rc || start_time.tm_sec != nowtime.tm_sec)
+ break;
+ gettimeofday(&now, NULL);
+ if (time_diff(now, begin) > 1.5) {
fprintf(stderr, _("Timed out waiting for time change.\n"));
return 2;
}
+ } while(1);
if (rc)
return 3;
return 0;
}
-
-
static int
synchronize_to_clock_tick_rtc(void) {
/*----------------------------------------------------------------------------