VirtualBox

Changeset 21157 in vbox for trunk


Ignore:
Timestamp:
Jul 2, 2009 12:58:57 PM (16 years ago)
Author:
vboxsync
Message:

VBoxServiceTimeSync.cpp: r=bird: Some todos for the windows code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp

    r19374 r21157  
    198198            {
    199199                DWORD cbRet = sizeof(g_TkOldPrivileges);
    200                 if (!AdjustTokenPrivileges(g_hTokenProcess, FALSE, &tkPriv, sizeof(TOKEN_PRIVILEGES), &g_TkOldPrivileges, &cbRet))
     200                if (AdjustTokenPrivileges(g_hTokenProcess, FALSE, &tkPriv, sizeof(TOKEN_PRIVILEGES), &g_TkOldPrivileges, &cbRet))
     201                    rc = VINF_SUCCESS;
     202                else
    201203                {
    202204                    DWORD dwErr = GetLastError();
     
    211213                VBoxServiceError("Looking up token privileges (SE_SYSTEMTIME_NAME) failed with status code %u/%Rrc!\n", dwErr, rc);
    212214            }
    213 
    214215            if (RT_FAILURE(rc))
    215216            {
     
    227228    }
    228229
    229     if (!::GetSystemTimeAdjustment(&g_dwWinTimeAdjustment, &g_dwWinTimeIncrement, &g_bWinTimeAdjustmentDisabled))
     230    if (GetSystemTimeAdjustment(&g_dwWinTimeAdjustment, &g_dwWinTimeIncrement, &g_bWinTimeAdjustmentDisabled))
     231        VBoxServiceVerbose(3, "Windows time adjustment: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n",
     232                           g_dwWinTimeAdjustment, g_dwWinTimeIncrement, g_bWinTimeAdjustmentDisabled ? 1 : 0);
     233    else
    230234    {
    231235        DWORD dwErr = GetLastError();
     
    233237        VBoxServiceError("Could not get time adjustment values! Last error: %ld!\n", dwErr);
    234238    }
    235     else VBoxServiceVerbose(3, "Windows time adjustment: Initially %ld (100ns) units per %ld (100 ns) units interval, disabled=%d\n",
    236                             g_dwWinTimeAdjustment, g_dwWinTimeIncrement, g_bWinTimeAdjustmentDisabled ? 1 : 0);
    237239#endif /* RT_OS_WINDOWS */
    238240
     
    249251
    250252    /*
    251      * Tell the control thread that it can continue
    252      * spawning services.
     253     * Tell the control thread that it can continue spawning services.
    253254     */
    254255    RTThreadUserSignal(RTThreadSelf());
    255256
     257    /*
     258     * The Work Loop.
     259     */
    256260    unsigned cErrors = 0;
    257261    for (;;)
     
    303307                }
    304308
     309/** @todo move the adjustment code into two new functions, too much code
     310 *        here. */
    305311                uint32_t AbsDriftMilli = RTTimeSpecGetMilli(&AbsDrift);
    306312                if (AbsDriftMilli > MinAdjust)
     
    313319#ifdef RT_OS_WINDOWS
    314320                    DWORD dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwWinTimeIncrement;
    315                     BOOL bWinTimeAdjustmentDisabled;
    316                     if (!::GetSystemTimeAdjustment(&dwWinTimeAdjustment, &dwWinTimeIncrement, &bWinTimeAdjustmentDisabled))
    317                     {
    318                         VBoxServiceError("GetSystemTimeAdjustment failed, error=%ld\n", GetLastError());
    319                     }
    320                     else
     321                    BOOL  fWinTimeAdjustmentDisabled;
     322/** @todo r=bird: NT4 doesn't have GetSystemTimeAdjustment. */
     323                    if (GetSystemTimeAdjustment(&dwWinTimeAdjustment, &dwWinTimeIncrement, &fWinTimeAdjustmentDisabled))
    321324                    {
    322325                        DWORD dwDiffMax = g_dwWinTimeAdjustment * 0.50;
    323                         DWORD dwDiffNew = dwWinTimeAdjustment * 0.10;
     326                        DWORD dwDiffNew =   dwWinTimeAdjustment * 0.10;
    324327
    325328                        if (RTTimeSpecGetMilli(&Drift) > 0)
     
    327330                            dwWinNewTimeAdjustment = dwWinTimeAdjustment + dwDiffNew;
    328331                            if (dwWinNewTimeAdjustment > (g_dwWinTimeAdjustment + dwDiffMax))
    329                             {   
     332                            {
    330333                                dwWinNewTimeAdjustment = g_dwWinTimeAdjustment + dwDiffMax;
    331334                                dwDiffNew = dwDiffMax;
    332335                            }
    333336                        }
    334                         else 
     337                        else
    335338                        {
    336339                            dwWinNewTimeAdjustment = dwWinTimeAdjustment - dwDiffNew;
    337340                            if (dwWinNewTimeAdjustment < (g_dwWinTimeAdjustment - dwDiffMax))
    338                             {   
     341                            {
    339342                                dwWinNewTimeAdjustment = g_dwWinTimeAdjustment - dwDiffMax;
    340343                                dwDiffNew = dwDiffMax;
     
    342345                        }
    343346
    344                         VBoxServiceVerbose(3, "Windows time adjustment: Drift=%ldms\n", RTTimeSpecGetMilli(&Drift));
    345                         VBoxServiceVerbose(3, "Windows time adjustment: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n", 
     347                        VBoxServiceVerbose(3, "Windows time adjustment: Drift=%lldms\n", RTTimeSpecGetMilli(&Drift));
     348                        VBoxServiceVerbose(3, "Windows time adjustment: OrgTA=%ld, CurTA=%ld, NewTA=%ld, DiffNew=%ld, DiffMax=%ld\n",
    346349                                           g_dwWinTimeAdjustment, dwWinTimeAdjustment, dwWinNewTimeAdjustment, dwDiffNew, dwDiffMax);
    347                        
     350
    348351                        /* Is AbsDrift way too big? Then a minimum adjustment via SetSystemTimeAdjustment() would take ages.
    349352                           So set the time in a hard manner. */
    350353                        if (AbsDriftMilli > (60 * 1000 * 20)) /** @todo 20 minutes here hardcoded here. Needs configurable parameter later. */
    351354                        {
    352                             SYSTEMTIME st = {0};
    353                             FILETIME ft = {0};
    354 
    355355                            VBoxServiceVerbose(3, "Windows time adjustment: Setting system time directly.\n");
    356356
     357
     358/** @todo NT4 doesn't have GetSystemTimeAdjustment. */
     359                            FILETIME ft;
    357360                            RTTimeSpecGetNtFileTime(&HostNow, &ft);
    358                             if (FALSE == FileTimeToSystemTime(&ft,&st))
    359                                 VBoxServiceError("Cannot convert system times, error=%ld\n", GetLastError());
    360 
    361                             if (!::SetSystemTime(&st))
    362                                 VBoxServiceError("SetSystemTime failed, error=%ld\n", GetLastError());
     361                            SYSTEMTIME st;
     362                            if (FileTimeToSystemTime(&ft, &st))
     363                            {
     364                                if (!SetSystemTime(&st))
     365                                    VBoxServiceError("SetSystemTime failed, error=%u\n", GetLastError());
     366                            }
     367                            else
     368                                VBoxServiceError("Cannot convert system times, error=%u\n", GetLastError());
    363369                        }
    364370                        else
    365371                        {
    366                             if (!::SetSystemTimeAdjustment(dwWinNewTimeAdjustment, FALSE /* Periodic adjustments enabled. */))
    367                                 VBoxServiceError("SetSystemTimeAdjustment failed, error=%ld\n", GetLastError());       
     372                            if (!SetSystemTimeAdjustment(dwWinNewTimeAdjustment, FALSE /* Periodic adjustments enabled. */))
     373                                VBoxServiceError("SetSystemTimeAdjustment failed, error=%u\n", GetLastError());
    368374                        }
    369375                    }
     376                    else
     377                        VBoxServiceError("GetSystemTimeAdjustment failed, error=%ld\n", GetLastError());
    370378
    371379#else  /* !RT_OS_WINDOWS */
     
    410418                {
    411419#ifdef RT_OS_WINDOWS
    412                     if (::SetSystemTimeAdjustment(0, TRUE /* Periodic adjustments disabled. */))
     420                    if (SetSystemTimeAdjustment(0, TRUE /* Periodic adjustments disabled. */))
    413421                        VBoxServiceVerbose(3, "Windows Time Adjustment is now disabled.\n");
    414422#endif /* !RT_OS_WINDOWS */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette