Merge pull request #4631 from computezrmle/forward_rtcuseutc

forward rtc setting from host to guest
This commit is contained in:
Vitalii Koshura 2022-02-22 13:23:13 +01:00 committed by GitHub
commit 1efd5aaa69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

View File

@ -247,6 +247,11 @@ namespace vboxmanage {
command = "modifyvm \"" + vm_name + "\" ";
command += "--acpi on ";
command += "--ioapic on ";
if (is_hostrtc_set_to_utc()) {
command += "--rtcuseutc on ";
} else {
command += "--rtcuseutc off ";
}
retval = vbm_popen(command, output, "modifychipset");
if (retval) return retval;
@ -2147,6 +2152,46 @@ namespace vboxmanage {
if (vm_pid) {
setpriority(PRIO_PROCESS, vm_pid, PROCESS_NORMAL_PRIORITY);
}
#endif
}
bool VBOX_VM::is_hostrtc_set_to_utc() {
#ifdef _WIN32
bool rtc_is_set_to_utc = false;
LONG lReturnValue;
HKEY hkSetupHive;
// If the key is present and set to "1" assume the host's rtc is set to UTC.
// Otherwise or in case of an error assume the host's rtc is set to localtime.
lReturnValue = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
_T("SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"),
0,
KEY_READ,
&hkSetupHive
);
if (lReturnValue == ERROR_SUCCESS) {
DWORD dwvalue = 0;
DWORD dwsize = sizeof(DWORD);
lReturnValue = RegQueryValueEx(
hkSetupHive,
_T("RealTimeIsUniversal"),
NULL,
NULL,
(LPBYTE)&dwvalue,
&dwsize
);
if (lReturnValue == ERROR_SUCCESS && dwvalue == 1) rtc_is_set_to_utc = true;
}
if (hkSetupHive) RegCloseKey(hkSetupHive);
return rtc_is_set_to_utc;
#else
// Non-Windows Systems usually set their rtc to UTC.
return true;
#endif
}
}

View File

@ -52,6 +52,7 @@ namespace vboxmanage {
bool is_disk_image_registered();
bool is_extpack_installed();
bool is_virtualbox_installed();
bool is_hostrtc_set_to_utc();
int get_install_directory(std::string& dir);
int get_version_information(std::string& version_raw, std::string& version_display);