Changeset 26211 in vbox for trunk/src/VBox
- Timestamp:
- Feb 3, 2010 4:55:52 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 57236
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp
r26114 r26211 438 438 { 439 439 /* 440 * Query the current time, ad d the adjustment, then tryit.440 * Query the current time, adjust it by adding the drift and set it. 441 441 */ 442 int rc; 443 #ifdef RT_OS_WINDOWS 444 RTTIMESPEC hostNow; 445 rc = VbglR3GetHostTime(&hostNow); 446 if (RT_FAILURE(rc)) 447 { 448 if (g_cTimeSyncErrors++ < 10) 449 VBoxServiceError("VbglR3GetHostTime failed; rc=%Rrc\n", rc); 450 } 451 else 452 { 453 FILETIME ft; 454 RTTimeSpecGetNtFileTime(&hostNow, &ft); 455 SYSTEMTIME st; 456 if (FileTimeToSystemTime(&ft, &st)) 457 { 458 if (!SetSystemTime(&st)) 459 { 460 rc = RTErrConvertFromWin32(GetLastError()); 461 VBoxServiceError("SetSystemTime failed, error=%Rrc\n", rc); 462 } 463 else rc = VINF_SUCCESS; 464 } 465 else 466 { 467 rc = RTErrConvertFromWin32(GetLastError()); 468 VBoxServiceError("Cannot convert system times, error=%Rrc\n", rc); 469 } 470 } 471 #else /* !RT_OS_WINDOWS */ 472 struct timeval tv; 473 errno = 0; 474 if (!gettimeofday(&tv, NULL)) 475 { 476 RTTIMESPEC Tmp; 477 RTTimeSpecAdd(RTTimeSpecSetTimeval(&Tmp, &tv), pDrift); 478 if (!settimeofday(RTTimeSpecGetTimeval(&Tmp, &tv), NULL)) 479 { 480 char sz[64]; 481 RTTIME Time; 482 if (g_cVerbosity >= 1) 483 VBoxServiceVerbose(1, "settimeofday to %s\n", 484 RTTimeToString(RTTimeExplode(&Time, &Tmp), sz, sizeof(sz))); 485 # ifdef DEBUG 442 RTTIMESPEC NewGuestTime; 443 int rc = RTTimeSet(RTTimeSpecAdd(RTTimeNow(&NewGuestTime), pDrift)); 444 if (RT_SUCCESS(rc)) 445 { 446 /* Succeeded - reset the error count and log the change. */ 447 g_cTimeSyncErrors = 0; 448 449 if (g_cVerbosity >= 1) 450 { 451 char sz[64]; 452 RTTIME Time; 453 VBoxServiceVerbose(1, "time set to %s\n", 454 RTTimeToString(RTTimeExplode(&Time, &NewGuestTime), sz, sizeof(sz))); 455 #ifdef DEBUG 456 RTTIMESPEC Tmp; 486 457 if (g_cVerbosity >= 3) 487 VBoxServiceVerbose( 2, " new time%s\n",458 VBoxServiceVerbose(3, " now %s\n", 488 459 RTTimeToString(RTTimeExplode(&Time, RTTimeNow(&Tmp)), sz, sizeof(sz))); 489 # endif 490 g_cTimeSyncErrors = 0; 491 rc = VINF_SUCCESS; 492 } 493 else 494 { 495 rc = RTErrConvertFromErrno(errno); 496 if (g_cTimeSyncErrors++ < 10) 497 VBoxServiceError("settimeofday failed; errno=%d: %s\n", errno, strerror(errno)); 498 } 499 } 500 else 501 { 502 rc = RTErrConvertFromErrno(errno); 503 if (g_cTimeSyncErrors++ < 10) 504 VBoxServiceError("gettimeofday failed; errno=%d: %s\n", errno, strerror(errno)); 505 } 506 #endif /* !RT_OS_WINDOWS */ 507 return RT_SUCCESS(rc) ? true : false; 460 #endif 461 } 462 463 return true; 464 } 465 466 if (g_cTimeSyncErrors++ < 10) 467 VBoxServiceError("RTTimeSet(%RDtimespec) failed: %Rrc\n", &NewGuestTime, rc); 468 return false; 508 469 } 509 470
Note:
See TracChangeset
for help on using the changeset viewer.