From 1c12bb0f86bc02dec60d78c5d9861262fb14bf9b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 17 Nov 2015 16:24:06 +0000 Subject: [PATCH 3/3] Windows _dbus_get_autolaunch_address: use DBUS_TEST_DATA etc. The Unix equivalent is in tools/dbus-launch.c, because X11 autolaunching works differently. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Signed-off-by: Simon McVittie --- cmake/modules/Macros.cmake | 1 + dbus/dbus-sysdeps-win.c | 58 +++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index fd3f62c..ff5ac1c 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -50,6 +50,7 @@ macro(add_test_executable _target _source) add_test(NAME ${_target} COMMAND $) endif() list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") + list(APPEND _env "DBUS_USE_TEST_BINARY=1") list(APPEND _env "DBUS_FATAL_WARNINGS=1") list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data") list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus") diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index cce9741..e0ff35c 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -3099,10 +3099,11 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address, PROCESS_INFORMATION pi; dbus_bool_t retval = FALSE; LPSTR lpFile; - char dbus_exe_path[MAX_PATH]; - char dbus_args[MAX_PATH * 2]; + char dbus_exe_path[MAX_PATH] = { 0 }; const char * daemon_name = DBUS_DAEMON_NAME ".exe"; DBusString shm_name; + DBusString dbus_args; + dbus_bool_t dbus_args_inited = FALSE; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -3122,6 +3123,21 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address, goto out; } +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL) + { + const char *dbus_daemon = _dbus_getenv ("DBUS_TEST_DAEMON"); + + if (dbus_daemon != NULL) + strncpy (dbus_exe_path, dbus_daemon, sizeof (dbus_exe_path) - 1); + } + + if (dbus_exe_path[0] != '\0') + { + /* nothing more to do */ + } + else +#endif if (!SearchPathA(NULL, daemon_name, NULL, sizeof(dbus_exe_path), dbus_exe_path, &lpFile)) { // Look in directory containing dbus shared library @@ -3163,11 +3179,38 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address, si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); - _snprintf(dbus_args, sizeof(dbus_args) - 1, "\"%s\" %s", dbus_exe_path, " --session"); + if (!_dbus_string_init (&dbus_args)) + { + _DBUS_SET_OOM (error); + goto out; + } + + dbus_args_inited = TRUE; -// argv[i] = "--config-file=bus\\session.conf"; -// printf("create process \"%s\" %s\n", dbus_exe_path, dbus_args); - if(CreateProcessA(dbus_exe_path, dbus_args, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) + if (!_dbus_string_append_printf (&dbus_args, "\"%s\" ", dbus_exe_path)) + goto out; + +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + { + const char *test_data = _dbus_getenv ("DBUS_TEST_DATA"); + + if (test_data == NULL) + { + if (!_dbus_string_append (&dbus_args, "--session")) + goto out; + } + else + { + if (!_dbus_string_append_printf (&dbus_args, + "--config-file \"%s/valid-config-files/session.conf\"", + test_data)) + goto out; + } + } +#endif + + 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); @@ -3190,6 +3233,9 @@ out: _dbus_global_unlock (mutex); _dbus_string_free (&shm_name); + if (dbus_args_inited) + _dbus_string_free (&dbus_args); + return retval; } -- 2.6.2