Francois Gouget : testbot/LibvirtTool: Add GetPrivilegedTA().

Alexandre Julliard julliard at winehq.org
Thu Feb 3 16:02:54 CST 2022


Module: tools
Branch: master
Commit: caafd9d1d6896b43d70762cfbf1254ead45680f1
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=caafd9d1d6896b43d70762cfbf1254ead45680f1

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Thu Feb  3 19:26:05 2022 +0100

testbot/LibvirtTool: Add GetPrivilegedTA().

This simplifies getting a connection to the TestAgent server with
elevated privileges.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/bin/LibvirtTool.pl | 60 ++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 28 deletions(-)

diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index b186e19..51ed8e7 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -257,6 +257,28 @@ sub ChangeStatus($$;$)
   return 0;
 }
 
+=pod
+=over 12
+
+=item C<GetPrivilegedTA()>
+
+Returns a connection to a TestAgent server with elevated privileges.
+
+If the server running on the regular port does not have elevated privileges
+this assumes that the one on the alternate port will. It is up to the caller
+to report an error if that's not the case.
+
+=back
+=cut
+
+sub GetPrivilegedTA($)
+{
+  my ($TA) = @_;
+
+  # Use SetTime() to detect if privileged operations are allowed.
+  return $TA->SetTime() ? $TA : $VM->GetAgent(1);
+}
+
 sub ShutDown()
 {
   my $Domain = $VM->GetDomain();
@@ -270,30 +292,15 @@ sub ShutDown()
   Debug(Elapsed($Start), " Performing a clean shutdown of $VMKey $CurrentSnapshot\n");
   LogMsg "Performing a clean shutdown of $VMKey $CurrentSnapshot\n";
 
-  # Use SetTime() to detect if privileged operations are allowed.
-  my $TA = $VM->GetAgent();
-  if (!$TA->SetTime())
-  {
-    # Not a fatal error. Try the next port in case the VM runs a privileged
-    # TestAgentd daemon there.
-    $TA->Disconnect();
-    $TA = $VM->GetAgent(1);
-    if (!$TA->SetTime())
-    {
-      Error "Unable to get a privileged TestAgent: ". $TA->GetLastError() ."\n";
-      $TA->Disconnect();
-      return 0;
-    }
-  }
-
   my $Success = 1;
   my $Cmd = $VM->Type =~ /^win(?:32|64)$/ ?
             ["shutdown.exe", "/p", "/d", "00:00"] :
             ["/sbin/shutdown", "--poweroff", "now"];
   Debug(Elapsed($Start), " Running @$Cmd\n");
-  if (!$TA->Run($Cmd, 0))
+  my $PTA = GetPrivilegedTA($VM->GetAgent());
+  if (!$PTA->Run($Cmd, 0))
   {
-    Error "Could not run @$Cmd: ". $TA->GetLastError() ."\n";
+    Error "Could not run @$Cmd: ". $PTA->GetLastError() ."\n";
     $Success = 0;
   }
   else
@@ -311,7 +318,8 @@ sub ShutDown()
       sleep(1);
     }
   }
-  $TA->Disconnect();
+  $PTA->Disconnect();
+
   Debug(Elapsed($Start), " Successfully shut down $VMKey\n");
   LogMsg "Successfully shut down $VMKey\n";
   return $Success;
@@ -496,16 +504,11 @@ sub SetupTestAgentd($$$$)
   # This is needed not only for the tests (date is important when checking
   # HTTPS certificates), but also for the build (if the time moves forward
   # during the build some ccache versions will return a compilation error).
-  if (!$TA->SetTime())
+  my $PTA = GetPrivilegedTA($TA);
+  FatalError("Cannot set the VM system time\n") if (!$PTA);
+  if (!$PTA->SetTime())
   {
-    # Not a fatal error. Try the next port in case the VM runs a privileged
-    # TestAgentd daemon there.
-    my $PrivilegedTA = $VM->GetAgent(1);
-    if (!$PrivilegedTA->SetTime())
-    {
-      FatalError("Unable to set the VM system time: ". $PrivilegedTA->GetLastError() ."\n");
-    }
-    $PrivilegedTA->Disconnect();
+    FatalError("Setting the VM system time failed: ". $PTA->GetLastError() ."\n");
   }
 
   if ($Booting and $VM->Type eq "wine")
@@ -543,6 +546,7 @@ sub SetupTestAgentd($$$$)
       FatalError("The VM has been rebooted too many times: start.count=$Count > 1");
     }
   }
+  $PTA->Disconnect();
   $TA->Disconnect();
 }
 




More information about the wine-cvs mailing list