Merge branch 'enable-unix-domain-support' into 'main'

dbus/win: use a unix domain socket on windows for autolaunch: protocol by default if supported by host

See merge request dbus/dbus!391
This commit is contained in:
Ralf Habacker 2026-01-10 04:23:20 +00:00
commit 16ca945689
14 changed files with 461 additions and 91 deletions

View file

@ -182,7 +182,8 @@ endif()
find_package(EXPAT)
find_package(X11)
find_package(GLIB2)
set(GLIB_MIN_VERSION 2.72) # for AF_UNIX
find_package(GLIB2 ${GLIB_MIN_VERSION})
if(GLIB2_FOUND)
option(DBUS_WITH_GLIB "build with glib" ON)
endif()

View file

@ -1,6 +1,6 @@
option(DBUS_USE_WINE "set to 1 or ON to support running test cases with Wine" OFF)
if((DBUS_ENABLE_MODULAR_TESTS OR DBUS_ENABLE_INTRUSIVE_TESTS) AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
find_file(WINE_EXECUTABLE
NAMES wine
@ -35,6 +35,7 @@ if((DBUS_ENABLE_MODULAR_TESTS OR DBUS_ENABLE_INTRUSIVE_TESTS) AND CMAKE_CROSSCOM
set(Z_DRIVE_IF_WINE "z:")
if(DBUS_USE_WINE AND WINE_EXECUTABLE)
set(TEST_WRAPPER "${WINE_EXECUTABLE}")
message(STATUS "Using wrapper for running tests: ${TEST_WRAPPER}")
endif()
endif()
@ -114,10 +115,18 @@ endmacro()
# create executable and add an associated unit test
#
# see @ref add_helper_executable for supported parameters
# @param ARGS <args> additional arguments added to the test command in front of the target file
# @param ENV <env> additional environment variables to provide to the running test
# @param LIBS <libs> additional libraries to link the executable with
#
macro(add_test_executable _target _source)
add_helper_executable(${_target} "${_source}" ${ARGN})
add_unit_test(${_target} ${_target})
set(options)
set(oneValueArgs)
set(multiValueArgs ARGS ENV LIBS)
cmake_parse_arguments(ATE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_helper_executable(${_target} "${_source}" LIBS ${ATE_LIBS})
add_unit_test(${_target} ${_target} ARGS ${ATE_ARGS} ENV ${ATE_ENV})
endmacro()
#
@ -133,31 +142,45 @@ endmacro()
#
# @param _target target name
# @param _source sources to add to this target
# @param LIBS <libs> additional libraries to link the executable with
#
macro(add_helper_executable _target _source)
set(options)
set(oneValueArgs)
set(multiValueArgs LIBS)
cmake_parse_arguments(AHE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(_sources "${_source}")
if(WIN32 AND NOT MSVC)
# avoid triggering UAC
add_uac_manifest(_sources)
endif()
add_executable(${_target} ${_sources})
target_link_libraries(${_target} ${ARGN})
target_link_libraries(${_target} ${AHE_LIBS})
endmacro()
#
# create executable and add an associated unit test with dbus session setup
#
# see @ref add_helper_executable for supported parameters
# see @ref add_unit_test for supported parameters
#
macro(add_session_test_executable _target _source)
add_helper_executable(${_target} "${_source}" ${ARGN})
set(options)
set(oneValueArgs)
set(multiValueArgs ARGS ENV LIBS)
cmake_parse_arguments(ASTE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_helper_executable(${_target} "${_source}" LIBS ${ASTE_LIBS})
add_unit_test(${_target} ${_target}
ARGS
${DBUS_TEST_RUN_SESSION}
--config-file=${DBUS_TEST_DATA}/valid-config-files/tmp-session.conf
--dbus-daemon=${DBUS_TEST_DAEMON}
${ASTE_ARGS}
ENV
"DBUS_SESSION_BUS_PID="
${ASTE_ENV}
)
endmacro()

View file

@ -689,7 +689,7 @@ _dbus_server_new_for_domain_socket (const char *path,
* @param error location to store reason for failure.
* @returns the new server, or #NULL on failure.
*/
static DBusServer *
DBusServer *
_dbus_server_new_for_dir (const char *dir,
DBusError *error)
{

View file

@ -39,6 +39,9 @@ DBusServer* _dbus_server_new_for_socket (DBusSocket *fds,
DBusServer* _dbus_server_new_for_autolaunch (const DBusString *address,
DBusError *error);
DBUS_PRIVATE_EXPORT
DBusServer* _dbus_server_new_for_dir (const char *dir,
DBusError *error);
DBUS_PRIVATE_EXPORT
DBusServer* _dbus_server_new_for_tcp_socket (const char *host,
const char *bind,
const char *port,

View file

@ -66,12 +66,25 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
const char *port = "0";
const char *family = "ipv4";
const char *scope = dbus_address_entry_get_value (entry, "scope");
dbus_bool_t supported = FALSE;
if (_dbus_daemon_is_session_bus_address_published (scope))
return DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED;
*server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
family, error, FALSE);
if (!_dbus_win_check_af_unix_support (&supported, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
}
if (supported)
{
const char *tmp = _dbus_get_tmpdir ();
*server_p = _dbus_server_new_for_dir (tmp, error);
}
else
*server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
family, error, FALSE);
if (*server_p)
{
_DBUS_ASSERT_ERROR_IS_CLEAR(error);

View file

@ -4517,5 +4517,37 @@ _dbus_listen_unix_socket (const char *path,
return s;
}
/**
* Checks and returns result for availability of unix domain sockets on Windows
*
* @param supported returns whether unix domain sockets are supported
* @param error return location for an error
* @returns #FALSE if error is set
*/
dbus_bool_t
_dbus_win_check_af_unix_support (dbus_bool_t *supported,
DBusError *error)
{
SOCKET temp;
if (!_dbus_win_startup_winsock ())
{
_DBUS_SET_OOM (error);
return FALSE;
}
*supported = FALSE;
temp = socket (AF_UNIX, SOCK_STREAM, 0);
if (temp != INVALID_SOCKET)
{
*supported = TRUE;
closesocket (temp);
}
return TRUE;
}
/** @} end of sysdeps-win */
/* tests in dbus-sysdeps-util.c */

View file

@ -589,6 +589,9 @@ DBusSocket _dbus_listen_unix_socket (const char *path,
dbus_bool_t abstract,
DBusError *error);
dbus_bool_t _dbus_win_check_af_unix_support (dbus_bool_t *supported,
DBusError *error);
DBusSocket _dbus_connect_exec (const char *path,
char *const argv[],
DBusError *error);

View file

@ -397,11 +397,12 @@ endif
# a running dbus-daemon will be disabled if message_bus is not set.
message_bus = get_option('message_bus')
minimum_glib = '2.72' # for AF_UNIX
if get_option('modular_tests').disabled()
glib = dependency('', required: false)
else
glib = dependency(
'glib-2.0', version: '>=2.40',
'glib-2.0', version: '>=' + minimum_glib,
required: get_option('modular_tests'),
fallback: ['glib', 'libglib_dep'],
default_options: fallback_subproject_options + [

View file

@ -74,35 +74,36 @@ set(manual-paths_SOURCES
manual-paths.c
)
add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_test_executable(test-string internals/strings.c dbus-testutils)
add_test_executable(test-printf internals/printf.c dbus-testutils)
add_helper_executable(test-privserver test-privserver.c dbus-testutils)
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-service ${test-service_SOURCES} LIBS dbus-testutils)
add_helper_executable(test-names ${test-names_SOURCES} LIBS dbus-testutils)
add_test_executable(test-shell ${test-shell_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
add_test_executable(test-string internals/strings.c LIBS dbus-testutils)
add_test_executable(test-printf internals/printf.c LIBS dbus-testutils)
add_helper_executable(test-privserver test-privserver.c LIBS dbus-testutils)
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} LIBS dbus-testutils)
if(NOT WINCE AND ENABLE_TRADITIONAL_ACTIVATION)
add_test_executable(test-spawn-oom internals/spawn-oom.c dbus-testutils)
add_test_executable(test-spawn-oom internals/spawn-oom.c LIBS dbus-testutils)
endif()
if(ENABLE_TRADITIONAL_ACTIVATION)
add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-spawn ${test-spawn_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
endif()
add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(test-exit ${test-exit_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
# the second argument of add_helper_executable() is a whitespace-separated
# list of source files and the third and subsequent arguments are libraries
# to link, hence the quoting here
add_helper_executable(test-segfault "${test-segfault_SOURCES}")
add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-tcp ${manual-tcp_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-backtrace manual-backtrace.c dbus-1)
add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-socket-afunix manual-socket-afunix.c LIBS dbus-testutils)
add_helper_executable(manual-tcp ${manual-tcp_SOURCES} LIBS ${DBUS_INTERNAL_LIBRARIES})
add_helper_executable(manual-backtrace manual-backtrace.c LIBS dbus-1)
if(WIN32)
add_helper_executable(manual-paths ${manual-paths_SOURCES} dbus-testutils)
add_helper_executable(manual-paths ${manual-paths_SOURCES} LIBS dbus-testutils)
endif()
if(DBUS_ENABLE_INTRUSIVE_TESTS)
add_test_executable(test-atomic ${test-atomic_SOURCES} dbus-testutils)
add_test_executable(test-hash internals/hash.c dbus-testutils)
add_test_executable(test-atomic ${test-atomic_SOURCES} LIBS dbus-testutils)
add_test_executable(test-hash internals/hash.c LIBS dbus-testutils)
set_target_properties(test-hash PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
set(SOURCES
@ -110,7 +111,7 @@ if(DBUS_ENABLE_INTRUSIVE_TESTS)
internals/dbus-marshal-recursive-util.h
internals/marshal-recursive.c
)
add_test_executable(test-marshal-recursive "${SOURCES}" dbus-testutils)
add_test_executable(test-marshal-recursive "${SOURCES}" LIBS dbus-testutils)
set_target_properties(test-marshal-recursive PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
set(SOURCES
@ -122,7 +123,7 @@ if(DBUS_ENABLE_INTRUSIVE_TESTS)
internals/dbus-message-util.h
internals/message-internals.c
)
add_test_executable(test-message-internals "${SOURCES}" dbus-testutils)
add_test_executable(test-message-internals "${SOURCES}" LIBS dbus-testutils)
set_target_properties(test-message-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
set(SOURCES
@ -142,39 +143,39 @@ if(DBUS_ENABLE_INTRUSIVE_TESTS)
internals/misc-internals.h
internals/sha.c
)
add_test_executable(test-misc-internals "${SOURCES}" dbus-testutils)
add_test_executable(test-misc-internals "${SOURCES}" LIBS dbus-testutils)
set_target_properties(test-misc-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
add_test_executable(test-platform-mutex test-platform-mutex.c ${DBUS_INTERNAL_LIBRARIES} dbus-testutils)
add_test_executable(test-platform-mutex test-platform-mutex.c LIBS ${DBUS_INTERNAL_LIBRARIES} dbus-testutils)
set(SOURCES bus/main.c bus/common.c bus/common.h)
add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
add_test_executable(test-bus "${SOURCES}" LIBS dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
if(ENABLE_TRADITIONAL_ACTIVATION)
set(SOURCES bus/normal-activation.c bus/common.c bus/common.h)
add_test_executable(test-bus-normal-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
add_test_executable(test-bus-normal-activation "${SOURCES}" LIBS dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
set_target_properties(test-bus-normal-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
endif()
set(SOURCES bus/dispatch-sha1.c bus/common.c bus/common.h)
add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" LIBS dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
set_target_properties(test-bus-dispatch-sha1 PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
if(NOT WIN32)
add_test_executable(test-bus-system bus/system.c launch-helper-internal dbus-testutils)
add_test_executable(test-counter internals/counter.c dbus-testutils)
add_test_executable(test-bus-system bus/system.c LIBS launch-helper-internal dbus-testutils)
add_test_executable(test-counter internals/counter.c LIBS dbus-testutils)
if(ENABLE_TRADITIONAL_ACTIVATION)
add_test_executable(test-bus-launch-helper-oom bus/launch-helper-oom.c launch-helper-internal dbus-testutils)
add_helper_executable(dbus-daemon-launch-helper-for-tests bus/launch-helper-for-tests.c launch-helper-internal)
add_test_executable(test-bus-launch-helper-oom bus/launch-helper-oom.c LIBS launch-helper-internal dbus-testutils)
add_helper_executable(dbus-daemon-launch-helper-for-tests bus/launch-helper-for-tests.c LIBS launch-helper-internal)
set(SOURCES bus/failed-helper-activation.c bus/common.c bus/common.h)
add_test_executable(test-bus-failed-helper-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
add_test_executable(test-bus-failed-helper-activation "${SOURCES}" LIBS dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
set_target_properties(test-bus-failed-helper-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
set(SOURCES bus/helper-activation.c bus/common.c bus/common.h)
add_test_executable(test-bus-helper-activation "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
add_test_executable(test-bus-helper-activation "${SOURCES}" LIBS dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
set_target_properties(test-bus-helper-activation PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
endif()
endif()
@ -198,26 +199,26 @@ if(DBUS_WITH_GLIB)
set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils dbus-testutils-glib ${GLIB2_LIBRARIES})
add_test_executable(test-assertions internals/assertions.c ${TEST_LIBRARIES})
add_test_executable(test-corrupt corrupt.c ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon dbus-daemon.c ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon-eavesdrop dbus-daemon-eavesdrop.c ${TEST_LIBRARIES})
add_test_executable(test-desktop-file internals/desktop-file.c ${TEST_LIBRARIES})
add_test_executable(test-fdpass fdpass.c ${TEST_LIBRARIES})
add_test_executable(test-header-fields header-fields.c ${TEST_LIBRARIES})
add_test_executable(test-loopback loopback.c ${TEST_LIBRARIES})
add_test_executable(test-marshal marshal.c ${TEST_LIBRARIES})
add_test_executable(test-monitor monitor.c ${TEST_LIBRARIES})
add_test_executable(test-refs internals/refs.c ${TEST_LIBRARIES})
add_test_executable(test-relay relay.c ${TEST_LIBRARIES})
add_test_executable(test-server-oom internals/server-oom.c ${TEST_LIBRARIES})
add_test_executable(test-syntax syntax.c ${TEST_LIBRARIES})
add_test_executable(test-sysdeps internals/sysdeps.c ${TEST_LIBRARIES})
add_test_executable(test-syslog internals/syslog.c ${TEST_LIBRARIES})
add_test_executable(test-uid-permissions uid-permissions.c ${TEST_LIBRARIES})
add_test_executable(test-userdb internals/userdb.c ${TEST_LIBRARIES})
add_helper_executable(manual-authz manual-authz.c ${TEST_LIBRARIES})
add_helper_executable(manual-test-thread-blocking thread-blocking.c ${TEST_LIBRARIES})
add_test_executable(test-assertions internals/assertions.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-corrupt corrupt.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon dbus-daemon.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-dbus-daemon-eavesdrop dbus-daemon-eavesdrop.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-desktop-file internals/desktop-file.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-fdpass fdpass.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-header-fields header-fields.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-loopback loopback.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-marshal marshal.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-monitor monitor.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-refs internals/refs.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-relay relay.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-server-oom internals/server-oom.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-syntax syntax.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-sysdeps internals/sysdeps.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-syslog internals/syslog.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-uid-permissions uid-permissions.c LIBS ${TEST_LIBRARIES})
add_test_executable(test-userdb internals/userdb.c LIBS ${TEST_LIBRARIES})
add_helper_executable(manual-authz manual-authz.c LIBS ${TEST_LIBRARIES})
add_helper_executable(manual-test-thread-blocking thread-blocking.c LIBS ${TEST_LIBRARIES})
endif()
### keep these in creation order, i.e. uppermost dirs first

298
test/manual-socket-afunix.c Normal file
View file

@ -0,0 +1,298 @@
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: 2025 Ralf Habacker <ralf.habacker@freenet.de>
*/
#include <config.h>
#include <dbus/dbus-test-tap.h>
#include <test/test-utils.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#ifdef DBUS_WIN
#include <io.h>
#include <winsock.h>
#include <winsock2.h>
#include <afunix.h>
#define close(a) closesocket(a)
#undef errno
#define errno WSAGetLastError()
#define strerror(a) ""
#define unlink _unlink
#define F_OK 0
#define access _access
#ifndef ERROR_NO_SUCH_DEVICE
#define ERROR_NO_SUCH_DEVICE 433
#endif
#else
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define INVALID_SOCKET -1
#define SOCKET int
#endif
#define SOCK_PATH "tpf_unix_sock.server"
#define DATA "Hello from server"
static char*
sock_path(void)
{
static DBusString path = _DBUS_STRING_INIT_INVALID;
static dbus_bool_t first = TRUE;
if (first)
{
if (!_dbus_string_init (&path))
goto out;
if (!_dbus_string_append (&path, _dbus_get_tmpdir ()))
goto out;
if (!_dbus_string_append (&path, "/" SOCK_PATH "-"))
goto out;
if (!_dbus_generate_random_ascii (&path, 6, NULL))
goto out;
first = FALSE;
}
return _dbus_string_get_data (&path);
out:
_dbus_test_fatal ("Could not setup socket path");
return NULL;
}
static dbus_bool_t
test_afunix_socket_raw (const char *test_data_dir _DBUS_GNUC_UNUSED)
{
SOCKET accept_sock = INVALID_SOCKET, server_sock = INVALID_SOCKET, client_sock = INVALID_SOCKET;
int rc;
int bytes_rec = 0;
int ret = FALSE;
socklen_t len;
struct sockaddr_un server_sockaddr;
struct sockaddr_un client_sockaddr;
char buf[256];
int backlog = 10;
_DBUS_ZERO (server_sockaddr);
_DBUS_ZERO (client_sockaddr);
_DBUS_ZERO (buf);
#ifdef DBUS_WIN
{
WSADATA data;
WORD version = MAKEWORD (2, 2);
rc = WSAStartup (version, &data);
if (rc == -1)
{
_dbus_test_fatal ("STARTUP ERROR: %d '%s'", WSAGetLastError(), "");
goto err;
}
}
#endif
server_sock = socket (AF_UNIX, SOCK_STREAM, 0);
if (server_sock == INVALID_SOCKET)
{
#ifdef DBUS_WIN
if (errno == WSAEAFNOSUPPORT)
{
_dbus_test_skip ("No AF_UNIX support available");
ret = TRUE;
goto err;
}
#endif
_dbus_test_fatal ("server SOCKET ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
{
_dbus_test_diag ("AF_UNIX stream socket created for server");
}
client_sock = socket (AF_UNIX, SOCK_STREAM, 0);
if (client_sock == INVALID_SOCKET)
{
#ifdef DBUS_WIN
if (errno == WSAEAFNOSUPPORT)
{
_dbus_test_skip ("No AF_UNIX support available");
ret = TRUE;
goto err;
}
#endif
_dbus_test_fatal ("client SOCKET ERROR = %d '%s'", errno, strerror(errno));
goto err;
}
else
_dbus_test_diag ("AF_UNIX stream socket created for client");
server_sockaddr.sun_family = AF_UNIX;
server_sockaddr.sun_path[0] = '\0';
strncat (server_sockaddr.sun_path, sock_path(), sizeof (server_sockaddr.sun_path) - 1);
len = sizeof (server_sockaddr);
rc = unlink (sock_path());
if (rc == -1)
{
#ifdef DBUS_WIN
if (errno == ERROR_NO_SUCH_DEVICE)
{
_dbus_test_diag ("got error ERROR_NO_SUCH_DEVICE on unlinking file, ignoring");
}
else
#endif
if (errno == ENOENT)
{
_dbus_test_diag ("AF_UNIX socket file did not exist");
}
else
{
_dbus_test_fatal ("Unlinking AF_UNIX socket file fails = %d '%s'", errno, strerror(errno));
goto err;
}
}
if (access (sock_path(), F_OK) == 0)
{
_dbus_test_fatal ("AF_UNIX socket file '%s' still present", sock_path());
}
rc = bind (server_sock, (struct sockaddr *) &server_sockaddr, len);
if (rc == -1)
{
#ifdef DBUS_WIN
if (errno == WSAEAFNOSUPPORT)
{
_dbus_test_skip ("Binding to AF_UNIX socket failed, no support available");
return FALSE;
}
else if (errno == WSAEADDRINUSE)
{
_dbus_test_diag ("Binding to AF_UNIX socket failed, address in use");
return FALSE;
}
#endif
_dbus_test_fatal ("BIND ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
rc = listen (server_sock, backlog);
if (rc == -1)
{
_dbus_test_fatal ("LISTEN ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
_dbus_test_diag ("Listening on AF_UNIX server socket");
rc = connect (client_sock, (struct sockaddr *) &server_sockaddr, len);
if(rc == -1)
{
_dbus_test_fatal ("CONNECT ERROR = %d '%s'", errno, strerror(errno));
goto err;
}
else
{
_dbus_test_diag ("Connected to AF_UNIX server socket");
}
accept_sock = accept (server_sock, (struct sockaddr *) &client_sockaddr, &len);
if (accept_sock == INVALID_SOCKET)
{
_dbus_test_fatal ("ACCEPT ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
{
_dbus_test_diag ("AF_UNIX server accepted connection");
}
len = sizeof (client_sockaddr);
rc = getsockname (server_sock, (struct sockaddr *) &client_sockaddr, &len);
if (rc == -1)
{
_dbus_test_fatal ("GETPEERNAME ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
_dbus_test_diag ("AF_UNIX server socket filepath: '%s'", client_sockaddr.sun_path);
len = sizeof (client_sockaddr);
rc = getsockname (accept_sock, (struct sockaddr *) &client_sockaddr, &len);
if (rc == -1)
{
_dbus_test_fatal ("GETSOCKNAME ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
_dbus_test_diag ("Accepted AF_UNIX socket filepath: '%s'", client_sockaddr.sun_path);
len = sizeof (client_sockaddr);
rc = getpeername (accept_sock, (struct sockaddr *) &client_sockaddr, &len);
if (rc == -1)
{
_dbus_test_fatal ("GETPEERNAME ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
_dbus_test_diag ("Client AF_UNIX socket filepath: '%s'", client_sockaddr.sun_path);
memset (buf, 0, sizeof (buf));
strcpy (buf, DATA);
_dbus_test_diag ("Sending data over AF_UNIX socket ...");
rc = send (client_sock, buf, strlen(buf) + 1, 0);
if (rc == -1)
{
_dbus_test_fatal ("SEND ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
{
_dbus_test_diag ("Data sent!");
}
_dbus_test_diag ("Waiting to read data from AF_UNIX socket ...");
bytes_rec = recv (accept_sock, buf, sizeof(buf), 0);
if (bytes_rec == -1 || bytes_rec != strlen(DATA) + 1)
{
_dbus_test_diag ("RECV ERROR: %d '%s'", errno, strerror(errno));
goto err;
}
else
{
_dbus_test_diag ("Data from AF_UNIX socket received = '%s'", buf);
}
ret = TRUE;
err:
if (server_sock != INVALID_SOCKET)
close (server_sock);
if (accept_sock != INVALID_SOCKET)
close (accept_sock);
if (client_sock != INVALID_SOCKET)
close (client_sock);
rc = unlink (sock_path());
if (rc == -1)
_dbus_test_diag ("unlink AF_UNIX socket file failure: %d '%s'", errno, strerror(errno));
return ret;
}
static DBusTestCase tests[] =
{
{ "test dbus unix socket raw", test_afunix_socket_raw },
{ NULL }
};
int
main (int argc, char **argv)
{
return _dbus_test_main (argc, argv, _DBUS_N_ELEMENTS (tests), tests,
DBUS_TEST_FLAGS_NONE,
NULL, NULL);
}

View file

@ -425,6 +425,12 @@ tests += [
'link': [ libdbus_testutils, ],
'test': false,
},
{
'name': 'manual-socket-afunix',
'srcs': [ 'manual-socket-afunix.c' ],
'link': [ libdbus_testutils ],
'test': false,
},
{
'name': 'manual-tcp',
'srcs': [ 'manual-tcp.c' ],

View file

@ -1,20 +1,20 @@
add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
if(WIN32)
add_test_executable(test-autolaunch-win test-autolaunch-win.c ${DBUS_INTERNAL_LIBRARIES} dbus-testutils)
add_test_executable(test-autolaunch-win test-autolaunch-win.c LIBS ${DBUS_INTERNAL_LIBRARIES} dbus-testutils)
else()
add_helper_executable(test-autolaunch test-autolaunch.c dbus-testutils)
add_helper_executable(test-autolaunch test-autolaunch.c LIBS dbus-testutils)
endif()
add_session_test_executable(test-ids test-ids.c ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-pending-call-disconnected test-pending-call-disconnected.c ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-ids test-ids.c LIBS ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-pending-call-disconnected test-pending-call-disconnected.c LIBS ${DBUS_INTERNAL_LIBRARIES})
if(ENABLE_TRADITIONAL_ACTIVATION)
add_session_test_executable(test-pending-call-dispatch test-pending-call-dispatch.c ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-pending-call-timeout test-pending-call-timeout.c ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-pending-call-dispatch test-pending-call-dispatch.c LIBS ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-pending-call-timeout test-pending-call-timeout.c LIBS ${DBUS_INTERNAL_LIBRARIES})
endif()
add_session_test_executable(test-shutdown test-shutdown.c dbus-testutils)
add_session_test_executable(test-shutdown test-shutdown.c LIBS dbus-testutils)
if(ENABLE_TRADITIONAL_ACTIVATION)
add_session_test_executable(test-privserver-client test-privserver-client.c dbus-testutils)
add_session_test_executable(test-thread-init test-threads-init.c ${DBUS_INTERNAL_LIBRARIES})
add_session_test_executable(test-privserver-client test-privserver-client.c LIBS dbus-testutils)
add_session_test_executable(test-thread-init test-threads-init.c LIBS ${DBUS_INTERNAL_LIBRARIES})
endif()

View file

@ -59,25 +59,8 @@ init_wine() {
addpath="$addpath$d$wb"
d=";"
done
# create registry file from template
local wineaddpath=$(echo "$addpath" | sed 's,\\,\\\\\\\\,g')
sed "s,@PATH@,$wineaddpath,g" ../tools/user-path.reg.in > user-path.reg
# add path to registry
wine regedit /C user-path.reg
# check if path(s) has been set and break if not
local o=$(wine cmd /C "echo %PATH%")
case "$o" in
(*z:* | *Z:*)
# OK
;;
(*)
echo "Failed to add Unix paths '$*' to path: Wine %PATH% = $o" >&2
exit 1
;;
esac
# setup paths for wine
export WINEPATH=$addpath
}
# ci_buildsys:

View file

@ -247,11 +247,17 @@ case "$ci_distro" in
# cross
packages=(
"${packages[@]}"
wine
xvfb-run
)
# add required repos
if ! zypper lr Emulators > /dev/null; then
$zypper ar --refresh --no-gpgcheck \
"https://download.opensuse.org/repositories/Emulators/$version/Emulators.repo"
fi
packages=(
"${packages[@]}"
wine-staging
wine-staging-32bit
)
if [ "${ci_host%%-*}" = x86_64 ]; then
bits="64"
else