]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
sysdeps-win: Let tests access autostarted dbus-daemon's handle
authorRalf Habacker <ralf.habacker@freenet.de>
Mon, 20 Dec 2021 13:41:06 +0000 (14:41 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Mon, 27 Jun 2022 13:32:07 +0000 (15:32 +0200)
This will allow automated tests to kill the autostarted dbus-daemon
before continuing to the next test-case, which wasn't previously
possible.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
dbus/dbus-sysdeps-win.c
dbus/dbus-sysdeps-win.h

index a7396427d0302e434ba9c841a9d367f77ad3949e..19e832b4f2effca6dd6cb155f3ffc6f885ece90d 100644 (file)
@@ -2915,6 +2915,24 @@ void _dbus_test_win_autolaunch_set_command_line_parameter (const char *path)
   autolaunch_custom_command_line_parameter = path;
 }
 
+static HANDLE *autolaunch_handle_location;
+
+/**
+ * Set location where to store process handle of an autostarted server
+ *
+ * This function is not thread-safe, and can only be called from a
+ * single-threaded unit test.
+ *
+ * After using the handle it must be closed with @ref CloseHandle().
+ *
+ * @param location Pointer where to store the handle
+ */
+void
+_dbus_test_win_set_autolaunch_handle_location (HANDLE *location)
+{
+  autolaunch_handle_location = location;
+}
+
 /**
  * Return the hash of the installation root directory, which can be
  * used to construct a per-installation-root scope for autolaunching
@@ -3452,7 +3470,15 @@ _dbus_get_autolaunch_address (const char *scope,
   if (CreateProcessA (dbus_exe_path, _dbus_string_get_data (&dbus_args), NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
     {
       CloseHandle (pi.hThread);
-      CloseHandle (pi.hProcess);
+      if (autolaunch_handle_location != NULL)
+        {
+          *autolaunch_handle_location = pi.hProcess;
+          _dbus_verbose ("Returning process handle of started server (handle=%p)\n", pi.hProcess);
+        }
+      else
+        {
+          CloseHandle (pi.hProcess);
+        }
       retval = _dbus_get_autolaunch_shm (address, &shm_name);
       if (retval == FALSE)
         dbus_set_error_const (error, DBUS_ERROR_FAILED, "Failed to get autolaunch address from launched dbus-daemon");
index 284bc79650cc83a8964893aa32f673f9fac31b7e..5027f180f6b0fd9f94dd90e0cb91e349b29fd578 100644 (file)
@@ -117,6 +117,10 @@ dbus_bool_t _dbus_daemon_publish_session_bus_address (const char *address,
 DBUS_PRIVATE_EXPORT
 DBusRMutex  *_dbus_win_rmutex_named_new (const char* name);
 
+DBUS_PRIVATE_EXPORT
+void _dbus_test_win_autolaunch_set_command_line_parameter (const char *path);
+DBUS_PRIVATE_EXPORT
+void _dbus_test_win_set_autolaunch_handle_location (HANDLE *location);
 #endif
 
 /** @} end of sysdeps-win.h */