From 30c4bef6335fbc58432e62923d37d4617a6d9637 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Fri, 25 Feb 2022 14:10:05 -0800 Subject: [PATCH] config: option to use UTC/localtime for RTC Default to UTC unless Windows is chosen in the wizard. Existing VMs get localtime since that was the previous default. Fixes #3104 --- Configuration/UTMQemuConfiguration+System.h | 1 + Configuration/UTMQemuConfiguration+System.m | 13 +++++++++++++ Managers/UTMQemuSystem.m | 8 +++++--- Platform/Shared/VMConfigQEMUView.swift | 9 ++++++--- Platform/Shared/VMWizardState.swift | 1 + 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Configuration/UTMQemuConfiguration+System.h b/Configuration/UTMQemuConfiguration+System.h index 0b819d56c..c457176df 100644 --- a/Configuration/UTMQemuConfiguration+System.h +++ b/Configuration/UTMQemuConfiguration+System.h @@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL useHypervisor; @property (nonatomic, readonly) BOOL isTargetArchitectureMatchHost; @property (nonatomic, readonly) BOOL defaultUseHypervisor; +@property (nonatomic, assign) BOOL rtcUseLocalTime; - (void)migrateSystemConfigurationIfNecessary; diff --git a/Configuration/UTMQemuConfiguration+System.m b/Configuration/UTMQemuConfiguration+System.m index c48ae211b..2e8d04f39 100644 --- a/Configuration/UTMQemuConfiguration+System.m +++ b/Configuration/UTMQemuConfiguration+System.m @@ -36,6 +36,7 @@ static const NSString *const kUTMConfigSystemUUIDKey = @"SystemUUID"; static const NSString *const kUTMConfigMachinePropertiesKey = @"MachineProperties"; static const NSString *const kUTMConfigUseHypervisorKey = @"UseHypervisor"; +static const NSString *const kUTMConfigRTCUseLocalTimeKey = @"RTCUseLocalTime"; @interface UTMQemuConfiguration () @@ -93,6 +94,9 @@ - (void)migrateSystemConfigurationIfNecessary { if (self.rootDict[kUTMConfigSystemKey][kUTMConfigRngEnabledKey] == nil) { self.systemRngEnabled = [self.systemTarget hasPrefix:@"pc"] || [self.systemTarget hasPrefix:@"q35"] || [self.systemTarget hasPrefix:@"virt"]; } + if (self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] == nil) { + self.rtcUseLocalTime = YES; // used to be default, now only for Windows + } } #pragma mark - System Properties @@ -214,6 +218,15 @@ - (void)setUseHypervisor:(BOOL)useHypervisor { self.rootDict[kUTMConfigSystemKey][kUTMConfigUseHypervisorKey] = @(useHypervisor); } +- (BOOL)rtcUseLocalTime { + return [self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] boolValue]; +} + +- (void)setRtcUseLocalTime:(BOOL)rtcUseLocalTime { + [self propertyWillChange]; + self.rootDict[kUTMConfigSystemKey][kUTMConfigRTCUseLocalTimeKey] = @(rtcUseLocalTime); +} + #pragma mark - Additional arguments array handling - (NSInteger)countArguments { diff --git a/Managers/UTMQemuSystem.m b/Managers/UTMQemuSystem.m index 91803ef21..d62de6815 100644 --- a/Managers/UTMQemuSystem.m +++ b/Managers/UTMQemuSystem.m @@ -692,9 +692,11 @@ - (void)argsFromConfiguration { [self pushArgv:self.configuration.systemUUID]; } - // fix windows time issues - [self pushArgv:@"-rtc"]; - [self pushArgv:@"base=localtime"]; + if (self.configuration.rtcUseLocalTime) { + // fix windows time issues + [self pushArgv:@"-rtc"]; + [self pushArgv:@"base=localtime"]; + } } - (void)argsFromUser { diff --git a/Platform/Shared/VMConfigQEMUView.swift b/Platform/Shared/VMConfigQEMUView.swift index dd9f8bedc..c5c3d0b08 100644 --- a/Platform/Shared/VMConfigQEMUView.swift +++ b/Platform/Shared/VMConfigQEMUView.swift @@ -39,13 +39,16 @@ struct VMConfigQEMUView: View { var body: some View { VStack { Form { - #if os(macOS) - Section(header: Text("Hypervisor")) { + Section(header: Text("Tweaks")) { + #if os(macOS) Toggle(isOn: $config.useHypervisor, label: { Text("Use Hypervisor") }).disabled(!config.isTargetArchitectureMatchHost) + #endif + Toggle(isOn: $config.rtcUseLocalTime, label: { + Text("Use local time for base clock") + }).help(Text("If checked, use local time for RTC which is required for Windows. Otherwise, use UTC clock.")) } - #endif Section(header: Text("Logging")) { Toggle(isOn: $config.debugLogEnabled, label: { Text("Debug Logging") diff --git a/Platform/Shared/VMWizardState.swift b/Platform/Shared/VMWizardState.swift index 6413ea3ef..b2b57145e 100644 --- a/Platform/Shared/VMWizardState.swift +++ b/Platform/Shared/VMWizardState.swift @@ -402,6 +402,7 @@ enum VMWizardOS: String, Identifiable { } case .Windows: config.icon = "windows" + config.rtcUseLocalTime = true if let windowsBootVhdx = windowsBootVhdx { config.newDrive("drive0", path: destinationFilename(forExisting: windowsBootVhdx), type: .disk, interface: mainDriveInterface) generateRemovableDrive() // order matters here