Module: tools Branch: master Commit: ba9cb31d7418e896a8fc95f4cbc4af312631e197 URL: https://gitlab.winehq.org/winehq/tools/-/commit/ba9cb31d7418e896a8fc95f4cbc4...
Author: Francois Gouget fgouget@codeweavers.com Date: Fri Nov 18 12:56:38 2022 +0100
testbot/LibvirtTool: Re-set the locale and country when preparing Windows VMs.
On Windows a call to SetSystemTime() reverts UserDefaultLCID and ThreadLocale to their pre-SetWinLocale values. But only if the time is 24 hours after SetWinLocale was run!!! Setting the locale is normally done when preparing the VM's live snapshot (some of the locale settings require a reboot) so part of the locale settings are lost if the snapshot is used more than 24 hours later. Fortunately the lost settings take don't require a reboot to take effect so re-set without rebooting right before using the VM to work around this issue.
---
testbot/bin/LibvirtTool.pl | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index 0c070da6..60559ebd 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -588,9 +588,9 @@ sub ResetBootCount($) $TA->SetProperty("start.count", 0); }
-sub PrepareVM($) +sub PrepareVM($$) { - my ($TA) = @_; + my ($TA, $Config) = @_;
Debug(Elapsed($Start), " Setting up the $VMKey TestAgent server\n"); LogMsg "Setting up the $VMKey TestAgent server\n"; @@ -611,6 +611,22 @@ sub PrepareVM($) { FatalError("Setting the $VMKey system time failed: ". $PTA->GetLastError() ."\n"); } + + if ($VM->Type =~ /^win(?:32|64)$/ and $Config->{locale}) + { + # Moving the time forward by more than 24 hours reverts UserDefaultLCID and + # ThreadLocale to their pre-SetWinLocale values!!! So restore the locale. + my $Country = $Config->{locale}; + $Country =~ s/^.*-//; + my @Cmd = ("$BinDir/SetWinLocale", "--vm", $VMKey, "--locale", $Config->{locale}, "--country", $Country, "--no-reboot"); + $TA->Disconnect(); + + Debug("Running: @Cmd\n"); + if (system(@Cmd)) + { + FatalError("Could not restore the $VMKey locale to $Config->{locale}\n"); + } + } }
sub GetSnapshotConfig($$) @@ -885,6 +901,11 @@ sub Revert() $VM->ChildDeadline($Deadline + $ExtraTimeout); $VM->Save(); } + else + { + GetSnapshotConfig($Domain, $Config); + $Config->{base} = $VM->IdleSnapshot; + }
# Before reverting, try to perform a clean shutdown if requested. # After a shutdown a small wait is also sometimes required, at least when @@ -924,7 +945,7 @@ sub Revert()
my $TA = $VM->GetAgent(); WaitForBoot($TA) if ($Booting); - PrepareVM($TA); + PrepareVM($TA, $Config);
if ($Config->{create}) {