https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e627c3b00e7109b5110b9…
commit e627c3b00e7109b5110b94fb8253859a29f35d42
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Fri Nov 3 22:56:58 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Fri Nov 3 22:56:58 2023 +0900
[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
---
base/services/w32time/w32time.c | 63 +++++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 24 deletions(-)
diff --git a/base/services/w32time/w32time.c b/base/services/w32time/w32time.c
index 69c6bd15abe..0d5508a7b2c 100644
--- a/base/services/w32time/w32time.c
+++ b/base/services/w32time/w32time.c
@@ -230,8 +230,6 @@ ControlHandler(DWORD request)
default:
break;
}
-
- return;
}
@@ -239,8 +237,12 @@ 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);
@@ -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)
@@ -317,11 +334,9 @@ W32TmServiceMain(DWORD argc, LPWSTR *argv)
return;
}
}
- return;
}
-
BOOL WINAPI
DllMain(HINSTANCE hinstDLL,
DWORD fdwReason,