Changeset 13101 in vbox for trunk/src/VBox/Additions/linux/daemon
- Timestamp:
- Oct 8, 2008 6:33:59 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 37593
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/linux/daemon/vboxadd_timesync.c
r10554 r13101 90 90 for (;;) 91 91 { 92 c = getopt_long(argc, argv, " ", options, NULL);92 c = getopt_long(argc, argv, "i:dh", options, NULL); 93 93 if (c == -1) 94 94 break; … … 151 151 if (VBOX_SUCCESS(req.header.rc)) 152 152 { 153 /** Set the system time. 154 * @@todo r=frank: This is too choppy. Adapt time smoother and try 155 * to prevent negative time differences. */ 153 /* Adapt time smoothly and try to prevent negative time differences. */ 154 uint64_t u64Now; 155 int64_t i64Diff; 156 int64_t i64AbsDiff; 156 157 struct timeval tv; 157 tv.tv_sec = req.time / (uint64_t)1000; 158 tv.tv_usec = (req.time % (uint64_t)1000) * 1000; 159 settimeofday(&tv, NULL); 158 159 gettimeofday(&tv, NULL); 160 #if 0 161 u64Now = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000; 162 i64Diff = (int64_t)(req.time - u64Now); 163 i64AbsDiff = i64Diff < 0 ? -i64Diff : i64Diff; 164 165 if (i64AbsDiff < 300000) 166 { 167 /* difference less than 5 minutes => smoothly adapt the guest time */ 168 int32_t i32Diff = (int32_t)i64Diff; 169 int32_t i32Sec, i32Micro; 170 struct timeval delta; 171 172 i32Sec = i32Diff / 1000; 173 i32Micro = (i32Diff % 1000) * 1000; 174 175 if (i32Micro < 0) 176 i32Micro = -i32Micro; 177 delta.tv_sec = i32Sec; 178 delta.tv_usec = i32Micro; 179 180 /* adjtime on Linux adjusts the time about 5 ms per 10 seconds, even 181 * for very huge differences */ 182 adjtime(&delta, NULL); 183 } 184 else 185 #endif 186 { 187 /* difference more than 5 minutes => set the time with all consequences */ 188 tv.tv_sec = req.time / (uint64_t)1000; 189 tv.tv_usec = (req.time % (uint64_t)1000) * 1000; 190 settimeofday(&tv, NULL); 191 } 160 192 } 161 193 else 162 {163 194 printf("Error querying host time! header.rc = %d\n", req.header.rc); 164 }165 195 } 166 196 else 167 {168 197 printf("Error performing VMM request! errno = %d\n", errno); 169 } 170 198 199 /* wait for the next run */ 171 200 safe_sleep(secInterval); 172 201
Note:
See TracChangeset
for help on using the changeset viewer.