]> xenbits.xensource.com Git - pvdrivers/win/xeniface.git/commitdiff
Set local time to UTC if Windows has "RealTimeIsUniversal"
authorPaul Durrant <paul.durrant@citrix.com>
Mon, 1 Apr 2019 10:25:09 +0000 (11:25 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Mon, 1 Apr 2019 10:25:09 +0000 (11:25 +0100)
Commit 3b8723b1 "Set VM's time based on host's time exposed by Xen"
modified the guest agent to adjust Xen time to UTC before setting the
system time (i.e. the emulated RTC) if a vendor specific registry value
was set.

Windows' idea of whether the RTC is programmed in UTC is actually
controlled by:

[HKLM\System\CurrentControlSet\Control\TimeZoneInformation]
DWORD:RealTimeIsUniversal

If this value is present and non-zero then the RTC is set in UTC otherwise
it is in local time. So, there is no need for a vendor specific key.

This patch removes use of the vendor specific key and checks
"RealTimeIsUniversal" directly to determine how to set the system time.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
build.py
src/xenagent/service.cpp
src/xenagent/service.h

index 3bd17b110d786fee14b9a563c690aba73ec39d60..20a3ff42b2c7fb28c2b8caf672507b4e0d4be439 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -70,9 +70,6 @@ def make_header():
     file.write('#define DAY_STR\t\t\t"' + str(now.day) + '"\n')
     file.write('\n')
 
-    file.write('#define REG_KEY_NAME\t\t\t"' + os.environ['REG_KEY_NAME'] + '"\n')
-    file.write('\n')
-
     file.close()
 
 
@@ -418,9 +415,6 @@ def main():
     if 'OBJECT_PREFIX' not in os.environ.keys():
         os.environ['OBJECT_PREFIX'] = 'XenProject'
 
-    if 'REG_KEY_NAME' not in os.environ.keys():
-        os.environ['REG_KEY_NAME'] = 'Windows PV Drivers'
-
     os.environ['MAJOR_VERSION'] = '9'
     os.environ['MINOR_VERSION'] = '0'
     os.environ['MICRO_VERSION'] = '0'
@@ -441,7 +435,6 @@ def main():
 
     print("PRODUCT_NAME\t\t'%s'" % os.environ['PRODUCT_NAME'])
     print("OBJECT_PREFIX\t\t'%s'" % os.environ['OBJECT_PREFIX'])
-    print("REG_KEY_NAME\t\t'%s'" % os.environ['REG_KEY_NAME'])
     print("MAJOR_VERSION\t\t%s" % os.environ['MAJOR_VERSION'])
     print("MINOR_VERSION\t\t%s" % os.environ['MINOR_VERSION'])
     print("MICRO_VERSION\t\t%s" % os.environ['MICRO_VERSION'])
index a8d45fc30c9e47f0d2c78baa22cfbab887f22490..dfcf8a597bea099cd40aa31059c05b0656bd1583 100644 (file)
@@ -371,18 +371,29 @@ void CXenIfaceCreator::AcquireShutdownPrivilege()
     CloseHandle(token);
 }
 
-bool CXenIfaceCreator::IsHostTimeUTC()
+bool CXenIfaceCreator::IsRTCInUTC()
 {
-#ifdef _WIN64
-    // Check SOFTWARE\Wow6432Node\$(VENDOR_NAME_STR)\$(REG_KEY_NAME) $(REG_UTC_NAME) == UTC
-    if (RegCheckIsUTC("SOFTWARE\\Wow6432Node"))
-        return true;
-#endif
-    // Check SOFTWARE\$(VENDOR_NAME_STR)\$(REG_KEY_NAME) $(REG_UTC_NAME) == UTC
-    if (RegCheckIsUTC("SOFTWARE"))
-        return true;
+    HKEY key;
+    std::string path;
+    DWORD val = 0;
+    DWORD length = sizeof(val);
+    LRESULT lr;
 
-    return false;
+    path = "SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation";
+
+    lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_READ, &key);
+    if (lr != ERROR_SUCCESS)
+        return false;
+
+    lr = RegQueryValueEx(key, "RealTimeIsUniversal", NULL, NULL,
+                         (LPBYTE)&val, &length);
+    RegCloseKey(key);
+
+    // A non-present value -> false
+    if (lr != ERROR_SUCCESS)
+        return false;
+
+    return val;
 }
 
 void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
@@ -407,62 +418,14 @@ void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
     now->dwHighDateTime = lnow.HighPart;
 }
 
-bool CXenIfaceCreator::RegCheckIsUTC(const char* rootpath)
-{
-    HKEY    key;
-    LRESULT lr;
-    std::string path;
-    bool    match = false;
-
-    path = rootpath;
-    path += "\\";
-    path += VENDOR_NAME_STR;
-    path += "\\";
-    path += REG_KEY_NAME;
-
-    lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), 0, KEY_READ, &key);
-    if (lr != ERROR_SUCCESS)
-        goto fail1;
-
-    DWORD size = 32;
-    DWORD length;
-    char* buffer = NULL;
-
-    do {
-        length = size;
-        if (buffer)
-            delete [] buffer;
-
-        buffer = new char[size];
-        if (buffer == NULL)
-            goto fail2;
-
-        lr = RegQueryValueEx(key, "HostTime", NULL, NULL, (LPBYTE)buffer, &length);
-        size *= 2;
-    } while (lr == ERROR_MORE_DATA);
-    if (lr != ERROR_SUCCESS)
-        goto fail3;
-
-    if (!_strnicoll("UTC", buffer, length))
-        match = true;
-
-fail3:
-    delete [] buffer;
-fail2:
-    RegCloseKey(key);
-fail1:
-
-    return match;
-}
-
 void CXenIfaceCreator::SetXenTime()
 {
-    // Set VM's time to Xen's time (adjust for UTC settings of VM and guest)
+    // Set VM's time to Xen's time (adjust for UTC setting)
     FILETIME now = { 0 };
     if (!m_device->SharedInfoGetTime(&now))
         return;
 
-    bool IsUTC = IsHostTimeUTC();
+    bool IsUTC = IsRTCInUTC();
     if (IsUTC)
         AdjustXenTimeToUTC(&now);
 
@@ -473,6 +436,7 @@ void CXenIfaceCreator::SetXenTime()
     SYSTEMTIME cur = { 0 };
     GetLocalTime(&cur);
 
+    CXenAgent::Log("RTC is in %s\n", IsUTC ? "UTC" : "local time");
     CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d\n",
                    cur.wYear, cur.wMonth, cur.wDay,
                    cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds);
index 47b735290050fb1d0772ea0da207a0d16ce8a540..2f1bbd2544f4db19285cbb2d9497dd1cb88a346c 100644 (file)
@@ -84,9 +84,8 @@ private:
     void StartSlateModeWatch();
     void StopSlateModeWatch();
     void AcquireShutdownPrivilege();
-    bool IsHostTimeUTC();
+    bool IsRTCInUTC();
     void AdjustXenTimeToUTC(FILETIME* time);
-    bool RegCheckIsUTC(const char* path);
     void SetXenTime();
 
 private: