From: Ralf Habacker Date: Mon, 20 Dec 2021 13:41:06 +0000 (+0100) Subject: sysdeps-win: Let tests access autostarted dbus-daemon's handle X-Git-Tag: dbus-1.15.0~35^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62ccb35996449a8786beacc343646480556d66a5;p=thirdparty%2Fdbus.git sysdeps-win: Let tests access autostarted dbus-daemon's handle 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 --- diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index a7396427d..19e832b4f 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -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"); diff --git a/dbus/dbus-sysdeps-win.h b/dbus/dbus-sysdeps-win.h index 284bc7965..5027f180f 100644 --- a/dbus/dbus-sysdeps-win.h +++ b/dbus/dbus-sysdeps-win.h @@ -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 */