[W32TIME] Remember date/time sync settings (#5866)

Based on KRosUser's patch.
- In the W32TmServiceMain function, the
  time check loop does check the registry value.
CORE-19292
This commit is contained in:
Katayama Hirofumi MZ 2023-11-03 22:56:58 +09:00 committed by GitHub
parent eb4d13c823
commit e627c3b00e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -230,8 +230,6 @@ ControlHandler(DWORD request)
default: default:
break; break;
} }
return;
} }
@ -239,8 +237,12 @@ VOID
WINAPI WINAPI
W32TmServiceMain(DWORD argc, LPWSTR *argv) W32TmServiceMain(DWORD argc, LPWSTR *argv)
{ {
int result; LONG error;
DWORD dwInterval; DWORD dwInterval;
HKEY hKey;
WCHAR szData[8];
DWORD cbData;
BOOL bNoSync;
UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv); UNREFERENCED_PARAMETER(argv);
@ -279,29 +281,44 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv)
ServiceStatus.dwCurrentState = SERVICE_RUNNING; ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus, &ServiceStatus); SetServiceStatus(hStatus, &ServiceStatus);
/* The worker loop of a service */ /* The service's worker loop */
for (;;) for (;;)
{ {
result = SetTime(); /* The default is NoSync */
bNoSync = TRUE;
if (result) /* TODO: Use RegNotifyChangeKeyValue() when implemented */
DPRINT("W32Time Service failed to set clock.\n"); if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
else L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters",
DPRINT("W32Time Service successfully set clock.\n"); 0,
KEY_QUERY_VALUE,
if (result) &hKey) == ERROR_SUCCESS)
{ {
/* In general we do not want to stop this service for a single cbData = sizeof(szData);
* Internet read failure but there may be other reasons for which RegQueryValueExW(hKey, L"Type", NULL, NULL, (LPBYTE)szData, &cbData);
* we really might want to stop it. szData[ARRAYSIZE(szData) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
* Therefore this code is left here to make it easy to stop this bNoSync = (_wcsicmp(szData, L"NoSync") == 0);
* service when the correct conditions can be determined, but it RegCloseKey(hKey);
* is left commented out. }
ServiceStatus.dwCurrentState = SERVICE_STOPPED;
ServiceStatus.dwWin32ExitCode = result; if (!bNoSync)
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) if (WaitForSingleObject(hStopEvent, dwInterval * 1000) == WAIT_OBJECT_0)
@ -317,11 +334,9 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv)
return; return;
} }
} }
return;
} }
BOOL WINAPI BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DllMain(HINSTANCE hinstDLL,
DWORD fdwReason, DWORD fdwReason,