Skip to content

Commit

Permalink
[W32TIME] Remember date/time sync settings (reactos#5866)
Browse files Browse the repository at this point in the history
Based on KRosUser's patch.
- In the W32TmServiceMain function, the
  time check loop does check the registry value.
CORE-19292
  • Loading branch information
katahiromz authored Nov 3, 2023
1 parent eb4d13c commit e627c3b
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions base/services/w32time/w32time.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,19 @@ ControlHandler(DWORD request)
default:
break;
}

return;
}


VOID
WINAPI
W32TmServiceMain(DWORD argc, LPWSTR *argv)
{
int result;
LONG error;
DWORD dwInterval;
HKEY hKey;
WCHAR szData[8];
DWORD cbData;
BOOL bNoSync;

UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
Expand Down Expand Up @@ -279,29 +281,44 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv)
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus, &ServiceStatus);

/* The worker loop of a service */
/* The service's worker loop */
for (;;)
{
result = SetTime();

if (result)
DPRINT("W32Time Service failed to set clock.\n");
else
DPRINT("W32Time Service successfully set clock.\n");
/* The default is NoSync */
bNoSync = TRUE;

/* TODO: Use RegNotifyChangeKeyValue() when implemented */
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters",
0,
KEY_QUERY_VALUE,
&hKey) == ERROR_SUCCESS)
{
cbData = sizeof(szData);
RegQueryValueExW(hKey, L"Type", NULL, NULL, (LPBYTE)szData, &cbData);
szData[ARRAYSIZE(szData) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
bNoSync = (_wcsicmp(szData, L"NoSync") == 0);
RegCloseKey(hKey);
}

if (result)
if (!bNoSync)
{
/* In general we do not want to stop this service for a single
* Internet read failure but there may be other reasons for which
* we really might want to stop it.
* Therefore this code is left here to make it easy to stop this
* service when the correct conditions can be determined, but it
* is left commented out.
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = result;
SetServiceStatus(hStatus, &ServiceStatus);
return;
*/
error = SetTime();
if (error != ERROR_SUCCESS)
{
DPRINT("W32Time Service failed to set clock: 0x%08lX\n", error);
#if 0
/*
* In general, we do not want to stop this service for a single
* Internet read failure but there may be other reasons for which
* we really might want to stop it. Therefore this code is left here.
*/
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = error;
SetServiceStatus(hStatus, &ServiceStatus);
return;
#endif
}
}

if (WaitForSingleObject(hStopEvent, dwInterval * 1000) == WAIT_OBJECT_0)
Expand All @@ -317,11 +334,9 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv)
return;
}
}
return;
}



BOOL WINAPI
DllMain(HINSTANCE hinstDLL,
DWORD fdwReason,
Expand Down

0 comments on commit e627c3b

Please sign in to comment.