From d52b86d3e774ed515039f47b2a35ec645362a97b Mon Sep 17 00:00:00 2001 From: Jesper Dam Date: Fri, 28 Oct 2011 15:54:30 +0200 Subject: Find dbus-daemon executable next to dbus shared libaray on windows. If the dbus shared library and the daemon executable are both in a dir that is not part of the default search path and dbus-1.dll is dynamically loaded with LoadLibrary(), it will fail to locate and launch the daemon without this patch. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41558 Reviewed-by: Ralf Habacker --- dbus/dbus-sysdeps-win.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index a8c60bda..3bcf86ac 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -2861,11 +2861,25 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address, if (!SearchPathA(NULL, daemon_name, NULL, sizeof(dbus_exe_path), dbus_exe_path, &lpFile)) { - printf ("please add the path to %s to your PATH environment variable\n", daemon_name); - printf ("or start the daemon manually\n\n"); - goto out; + // Look in directory containing dbus shared library + HMODULE hmod = _dbus_win_get_dll_hmodule(); + char dbus_module_path[MAX_PATH]; + DWORD rc = GetModuleFileNameA(hmod, dbus_module_path, sizeof(dbus_module_path)); + if (rc > 0) + { + char *ext_idx = strrchr(dbus_module_path, '\\'); + if (ext_idx) + *ext_idx = '\0'; + if (!SearchPathA(dbus_module_path, daemon_name, NULL, sizeof(dbus_exe_path), dbus_exe_path, &lpFile)) + { + printf ("please add the path to %s to your PATH environment variable\n", daemon_name); + printf ("or start the daemon manually\n\n"); + goto out; + } + } } + // Create process ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); -- cgit v1.2.3 From 93e9941de6908f731e3f9b0fac1083f0e9a47dd5 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 28 Oct 2011 21:22:53 +0200 Subject: Optimized error handling of previous patch --- dbus/dbus-sysdeps-win.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 3bcf86ac..aea704d2 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -2862,20 +2862,35 @@ _dbus_get_autolaunch_address (const char *scope, DBusString *address, if (!SearchPathA(NULL, daemon_name, NULL, sizeof(dbus_exe_path), dbus_exe_path, &lpFile)) { // Look in directory containing dbus shared library - HMODULE hmod = _dbus_win_get_dll_hmodule(); + HMODULE hmod; char dbus_module_path[MAX_PATH]; - DWORD rc = GetModuleFileNameA(hmod, dbus_module_path, sizeof(dbus_module_path)); - if (rc > 0) + DWORD rc; + + _dbus_verbose( "did not found dbus daemon executable on default search path, " + "trying path where dbus shared library is located"); + + hmod = _dbus_win_get_dll_hmodule(); + rc = GetModuleFileNameA(hmod, dbus_module_path, sizeof(dbus_module_path)); + if (rc <= 0) + { + dbus_set_error_const (error, DBUS_ERROR_FAILED, "could not retrieve dbus shared library file name"); + retval = FALSE; + goto out; + } + else { char *ext_idx = strrchr(dbus_module_path, '\\'); if (ext_idx) *ext_idx = '\0'; if (!SearchPathA(dbus_module_path, daemon_name, NULL, sizeof(dbus_exe_path), dbus_exe_path, &lpFile)) { + dbus_set_error_const (error, DBUS_ERROR_FAILED, "could not find dbus-daemon executable"); + retval = FALSE; printf ("please add the path to %s to your PATH environment variable\n", daemon_name); printf ("or start the daemon manually\n\n"); goto out; } + _dbus_verbose( "found dbus daemon executable at %s",dbus_module_path); } } -- cgit v1.2.3 From 7aed4eb923b3c6a8aafcdb9a4e35a0924005c833 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 29 Oct 2011 00:25:18 +0200 Subject: refactored cmake version extracting from configure.ac --- cmake/CMakeLists.txt | 19 ++++++------------ cmake/modules/MacrosAutotools.cmake | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 cmake/modules/MacrosAutotools.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 51d27cd1..98f1d5c6 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,18 +1,5 @@ project(dbus) -######################################################################### -# detect version -######################################################################### -file (READ ../configure.ac configure_ac) -string (REGEX REPLACE ".*dbus_major_version], .([0-9]+).*" "\\1" DBUS_MAJOR_VERSION ${configure_ac}) -string (REGEX REPLACE ".*dbus_minor_version], .([0-9]+).*" "\\1" DBUS_MINOR_VERSION ${configure_ac}) -string (REGEX REPLACE ".*dbus_micro_version], .([0-9]+).*" "\\1" DBUS_MICRO_VERSION ${configure_ac}) -# used by file version info -set (DBUS_PATCH_VERSION "0") -set (DBUS_VERSION ${DBUS_MAJOR_VERSION}.${DBUS_MINOR_VERSION}.${DBUS_MICRO_VERSION}) - -set (DBUS_VERSION_STRING "${DBUS_VERSION}") - # we need to be up to date CMAKE_MINIMUM_REQUIRED(VERSION 2.4.4 FATAL_ERROR) if(COMMAND cmake_policy) @@ -22,6 +9,12 @@ endif(COMMAND cmake_policy) # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules") +# detect version +include(MacrosAutotools) +autoversion(../configure.ac dbus) +# used by file version info +set (DBUS_PATCH_VERSION "0") + include(Macros) TIMESTAMP(DBUS_BUILD_TIMESTAMP) diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake new file mode 100644 index 00000000..ff30eaf9 --- /dev/null +++ b/cmake/modules/MacrosAutotools.cmake @@ -0,0 +1,40 @@ +# +# @Author Ralf Habacker +# +# extracts version information from autoconf config file +# and set related cmake variables +# +# returns +# ${prefix}_VERSION +# ${prefix}_VERSION_STRING +# ${prefix}_MAJOR_VERSION +# ${prefix}_MINOR_VERSION +# ${prefix}_MICRO_VERSION +# +macro(autoversion config prefix) + file (READ ${config} _configure_ac) + string(TOUPPER ${prefix} prefix_upper) + string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac}) + string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac}) + string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac}) + set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION}) + set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}") + +endmacro() + +# +# parses config.h template and create cmake equivalent +# not implemented yet +# +macro(autoconfig template output) + file(READ ${template} contents) + # Convert file contents into a CMake list (where each element in the list + # is one line of the file) + STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}") + STRING(REGEX REPLACE "\n" ";" contents "${contents}") + foreach(line contents) + message(STATUS ${line}) + # find #undef lines + # append to config.h #define + endforeach() +endmacro() -- cgit v1.2.3 From ec350d8d06f5b55fa42834f4d651ea9018e02650 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 3 Feb 2011 17:59:07 +0000 Subject: _dbus_listen_tcp_socket: avoid leaking listen_fd in unlikely circumstances If getaddrinfo (with port == 0) succeeds, the kernel gives us a port when we first listen on a socket, we jump back to redo_lookup_with_port, and getaddrinfo (with the nonzero port) fails, we leak listen_fd and all the fds in it. From the department of "without static analysis we'd never have spotted this", or possibly "backward goto considered harmful". Bug: https://bugs.freedesktop.org/show_bug.cgi?id=29881 Bug-NB: NB#180486 CID-2389 Reviewed-by: Will Thompson --- dbus/dbus-sysdeps-unix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index f51f6fcb..98667f24 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -1331,13 +1331,14 @@ _dbus_listen_tcp_socket (const char *host, hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; redo_lookup_with_port: + ai = NULL; if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai) { dbus_set_error (error, _dbus_error_from_errno (errno), "Failed to lookup host/port: \"%s:%s\": %s (%d)", host ? host : "*", port, gai_strerror(res), res); - return -1; + goto failed; } tmp = ai; -- cgit v1.2.3 From c587e56b8ab5b89dff443863a6067a0d11e8c6ae Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 16 Sep 2011 15:01:40 +0100 Subject: Set DBUS_TEST_HOMEDIR when running installcheck This avoids spamming ~/.dbus and ~/.dbus-keyrings with filesystem activity while running the tests. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41218 Reviewed-by: Lennart Poettering --- test/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Makefile.am b/test/Makefile.am index 0981d1f0..b890c638 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -124,6 +124,7 @@ installable_tests = \ installcheck_tests = installcheck_environment = \ DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT) \ + DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \ DBUS_TEST_SYSCONFDIR=$(DESTDIR)$(sysconfdir) TESTS_ENVIRONMENT = \ -- cgit v1.2.3 From a36d4918a6f646e085fd91c7cdb41b093feef7ac Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 15 Sep 2011 18:27:27 +0100 Subject: corrupt test: compile successfully against older GLib (Debian stable) We don't really need g_socket_send_with_blocking here. Also, don't leak the GLib socket objects. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41219 Reviewed-by: Lennart Poettering --- test/corrupt.c | 60 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/test/corrupt.c b/test/corrupt.c index ef9951af..02495901 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -160,6 +160,38 @@ test_message (Fixture *f, dbus_message_unref (outgoing); } +static void +send_n_bytes (GSocket *socket, + const gchar *blob, + gssize blob_len) +{ + gssize len, total_sent; + GError *gerror = NULL; + + total_sent = 0; + + while (total_sent < blob_len) + { + len = g_socket_send (socket, + blob + total_sent, + blob_len - total_sent, + NULL, &gerror); + + /* this is NULL-safe: a NULL error does not match */ + if (g_error_matches (gerror, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) + { + /* we could wait for G_IO_OUT, but life's too short; just sleep */ + g_clear_error (&gerror); + g_usleep (G_USEC_PER_SEC / 10); + continue; + } + + g_assert_no_error (gerror); + g_assert (len >= 0); + total_sent += len; + } +} + /* Enough bytes for it to be obvious that this connection is broken */ #define CORRUPT_LEN 1024 @@ -174,7 +206,6 @@ test_corrupt (Fixture *f, GSocket *socket; GError *gerror = NULL; int fd; - gssize len, total_sent; DBusMessage *incoming; test_message (f, addr); @@ -191,17 +222,7 @@ test_corrupt (Fixture *f, g_assert_no_error (gerror); g_assert (socket != NULL); - total_sent = 0; - - while (total_sent < CORRUPT_LEN) - { - len = g_socket_send_with_blocking (socket, - not_a_dbus_message + total_sent, CORRUPT_LEN - total_sent, - TRUE, NULL, &gerror); - g_assert_no_error (gerror); - g_assert (len >= 0); - total_sent += len; - } + send_n_bytes (socket, not_a_dbus_message, CORRUPT_LEN); /* Now spin on the client connection: the server just sent it complete * rubbish, so it should disconnect */ @@ -225,6 +246,7 @@ test_corrupt (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (incoming); + g_object_unref (socket); } static void @@ -237,7 +259,7 @@ test_byte_order (Fixture *f, char *blob; const gchar *arg = not_a_dbus_message; const gchar * const *args = &arg; - int blob_len, len, total_sent; + int blob_len; DBusMessage *message; dbus_bool_t mem; @@ -277,16 +299,7 @@ test_byte_order (Fixture *f, g_assert_no_error (gerror); g_assert (socket != NULL); - total_sent = 0; - - while (total_sent < blob_len) - { - len = g_socket_send_with_blocking (socket, blob + total_sent, - blob_len - total_sent, TRUE, NULL, &gerror); - g_assert_no_error (gerror); - g_assert (len >= 0); - total_sent += len; - } + send_n_bytes (socket, blob, blob_len); dbus_free (blob); @@ -312,6 +325,7 @@ test_byte_order (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (message); + g_object_unref (socket); } static void -- cgit v1.2.3 From 25d6d2d42975e5d88c89be7afdcb94c7b4bcb78f Mon Sep 17 00:00:00 2001 From: Siraj Razick Date: Wed, 21 Dec 2011 13:25:35 -0500 Subject: Adds a configure time key --with-dbus-session-bus-default-address With this key we can specifiy the default session bus address at compile time with autotool builds made with mingw32. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=43639 Reviewed-by: Ralf Habacker --- configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 23e886f9..86205be9 100644 --- a/configure.ac +++ b/configure.ac @@ -149,6 +149,7 @@ AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filen AC_ARG_WITH(launchd-agent-dir, AS_HELP_STRING([--with-launchd-agent-dir=[dirname]],[directory to put the launchd agent (default: /Library/LaunchAgents)])) AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=],[User for running the DBUS daemon (messagebus)])) AC_ARG_WITH(dbus_daemondir, AS_HELP_STRING([--with-dbus-daemondir=[dirname]],[Directory for installing the DBUS daemon])) +AC_ARG_WITH(dbus_session_bus_default_address, AS_HELP_STRING([--with-dbus-session-bus-default-address=[nonce-tcp:/autolaunch:/tcp:host:port]],[Transport Type to be used (default: nonce-tcp:)]),with_dbus_session_bus_default_address=$withval,with_dbus_session_bus_default_address=nonce-tcp:) AC_ARG_ENABLE([embedded-tests], AS_HELP_STRING([--enable-embedded-tests], @@ -1550,7 +1551,7 @@ AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where p AC_SUBST(DBUS_SESSION_SOCKET_DIR) if test x$dbus_win = xyes; then - DBUS_SESSION_BUS_DEFAULT_ADDRESS="nonce-tcp:" + DBUS_SESSION_BUS_DEFAULT_ADDRESS="$with_dbus_session_bus_default_address" elif test x$have_launchd = xyes; then DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET" else -- cgit v1.2.3