From 9093c227345c4db06cc5b09c68c53ca27c46a4b7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 29 Sep 2017 12:27:11 +0100 Subject: [PATCH 5/5] unix: Condition Linux-specific abstract sockets on __linux__ This is nicer for cross-compiling, because AC_RUN_IFELSE can't work there. In practice abstract sockets are supported on Linux since 2.2 (so, all relevant versions), and on no other platform; so it seems futile to keep this complexity. Signed-off-by: Simon McVittie --- README.cmake | 4 -- cmake/CMakeLists.txt | 1 - cmake/ConfigureChecks.cmake | 10 ----- cmake/config.h.cmake | 4 -- cmake/modules/CheckForAbstractSockets.c | 33 --------------- configure.ac | 73 --------------------------------- dbus/dbus-server-unix.c | 2 +- dbus/dbus-sysdeps-unix.c | 12 +++--- 8 files changed, 7 insertions(+), 132 deletions(-) delete mode 100644 cmake/modules/CheckForAbstractSockets.c diff --git a/README.cmake b/README.cmake index facfaf09..69012fbe 100644 --- a/README.cmake +++ b/README.cmake @@ -158,10 +158,6 @@ DBUS_BUS_ENABLE_INOTIFY:BOOL=ON // enable kqueue as dir watch backend DBUS_BUS_ENABLE_KQUEUE:BOOL=ON -not available on windows: -// enable abstract socket transport -DBUS_ENABLE_ABSTRACT_SOCKETS:BOOL=ON - x11 only: // Build with X11 auto launch support DBUS_BUILD_X11:BOOL=ON diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index a003f282..a9f53780 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -121,7 +121,6 @@ if (WIN32) endif (WIN32) if(NOT WIN32) - option (DBUS_ENABLE_ABSTRACT_SOCKETS "enable support for abstract sockets" ON) set (CMAKE_THREAD_PREFER_PTHREAD ON) include (FindThreads) endif(NOT WIN32) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index 6815178b..d83810a7 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -66,7 +66,6 @@ check_symbol_exists(raise "signal.h" HAVE_RAISE) check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c # missing: -# HAVE_ABSTRACT_SOCKETS # DBUS_HAVE_GCC33_GCOV check_type_size("short" SIZEOF_SHORT) @@ -168,12 +167,3 @@ else(DBUS_HAVE_VA_COPY) endif(DBUS_HAVE___VA_COPY) endif(DBUS_HAVE_VA_COPY) endif(MSVC) # _not_ MSVC -#### Abstract sockets - -if (DBUS_ENABLE_ABSTRACT_SOCKETS) - - try_compile(HAVE_ABSTRACT_SOCKETS - ${CMAKE_BINARY_DIR} - ${CMAKE_SOURCE_DIR}/modules/CheckForAbstractSockets.c) - -endif(DBUS_ENABLE_ABSTRACT_SOCKETS) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index 154353b7..202c0ab0 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -49,10 +49,6 @@ /* doxygen */ #cmakedefine DBUS_GCOV_ENABLED 1 -/* abstract-sockets */ - -#cmakedefine HAVE_ABSTRACT_SOCKETS 1 - /* selinux */ /* kqueue */ #cmakedefine HAVE_CONSOLE_OWNER_FILE 1 diff --git a/cmake/modules/CheckForAbstractSockets.c b/cmake/modules/CheckForAbstractSockets.c deleted file mode 100644 index 062b846c..00000000 --- a/cmake/modules/CheckForAbstractSockets.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main() { - int listen_fd; - struct sockaddr_un addr; - - listen_fd = socket (PF_UNIX, SOCK_STREAM, 0); - - if (listen_fd < 0) - { - fprintf (stderr, "socket() failed: %s\n", strerror (errno)); - exit (1); - } - - memset (&addr, '\0', sizeof (addr)); - addr.sun_family = AF_UNIX; - strcpy (addr.sun_path, "X/tmp/dbus-fake-socket-path-used-in-configure-test"); - addr.sun_path[0] = '\0'; /* this is what makes it abstract */ - - if (bind (listen_fd, (struct sockaddr*) &addr, SUN_LEN (&addr)) < 0) - { - fprintf (stderr, "Abstract socket namespace bind() failed: %s\n", - strerror (errno)); - exit (1); - } - else - exit (0); -} \ No newline at end of file diff --git a/configure.ac b/configure.ac index 98ee1bcf..7802aa52 100644 --- a/configure.ac +++ b/configure.ac @@ -196,7 +196,6 @@ AC_ARG_ENABLE([ducktype-docs], AS_HELP_STRING([--enable-ducktype-docs], [build Ducktype documentation (requires Ducktype)]), [enable_ducktype_docs=$enableval], [enable_ducktype_docs=auto]) -AC_ARG_ENABLE(abstract-sockets, AS_HELP_STRING([--enable-abstract-sockets],[use abstract socket namespace (linux only)]),enable_abstract_sockets=$enableval,enable_abstract_sockets=auto) AC_ARG_ENABLE(selinux, AS_HELP_STRING([--enable-selinux],[build with SELinux support]),enable_selinux=$enableval,enable_selinux=auto) AC_ARG_ENABLE([apparmor], [AS_HELP_STRING([--enable-apparmor], [build with AppArmor support])], @@ -848,77 +847,6 @@ AC_CHECK_FUNCS(getpeerucred getpeereid) AC_CHECK_FUNCS(pipe2 accept4) -#### Abstract sockets - -if test x$enable_abstract_sockets = xauto; then -AC_LANG_PUSH(C) -warn_on_xcompile=no -AC_CACHE_CHECK([abstract socket namespace], - ac_cv_have_abstract_sockets, - [AC_RUN_IFELSE([AC_LANG_PROGRAM( -[[ -#include -#include -#include -#include -#include -#include -#include -]], -[[ - size_t slen; - int listen_fd; - struct sockaddr_un addr; - - listen_fd = socket (PF_UNIX, SOCK_STREAM, 0); - - if (listen_fd < 0) - { - fprintf (stderr, "socket() failed: %s\n", strerror (errno)); - exit (1); - } - - memset (&addr, '\0', sizeof (addr)); - addr.sun_family = AF_UNIX; - strcpy (addr.sun_path, "X/tmp/dbus-fake-socket-path-used-in-configure-test"); - /* SUN_LEN uses strlen() so need to calculate it before adding \0 at the - * beginning. - */ - slen = SUN_LEN(&addr); - addr.sun_path[0] = '\0'; /* this is what makes it abstract */ - - if (bind (listen_fd, (struct sockaddr*) &addr, slen) < 0) - { - fprintf (stderr, "Abstract socket namespace bind() failed: %s\n", - strerror (errno)); - exit (1); - } - else - exit (0); -]])], - [ac_cv_have_abstract_sockets=yes], - [ac_cv_have_abstract_sockets=no], - [ - ac_cv_have_abstract_sockets=no - warn_on_xcompile=yes - ] -)]) -if test x$warn_on_xcompile = xyes ; then - AC_MSG_WARN([Cannot check for abstract sockets when cross-compiling, please use --enable-abstract-sockets]) -fi -AC_LANG_POP(C) -fi - -if test x$enable_abstract_sockets = xyes; then - if test x$ac_cv_have_abstract_sockets = xno; then - AC_MSG_ERROR([Abstract sockets explicitly required, and support not detected.]) - fi -fi - -if test x$enable_abstract_sockets = xno; then - ac_cv_have_abstract_sockets=no; -fi - PKG_CHECK_MODULES([EXPAT], [expat]) save_cflags="$CFLAGS" @@ -1921,7 +1849,6 @@ echo " Building Ducktype docs: ${enable_ducktype_docs} Building XML docs: ${enable_xml_docs} Building launchd support: ${have_launchd} - Abstract socket names: ${ac_cv_have_abstract_sockets} System bus socket: ${DBUS_SYSTEM_SOCKET} System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} System bus PID file: ${DBUS_SYSTEM_PID_FILE} diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index fd9348ab..534e1d5f 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -145,7 +145,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, { dir = tmpdir; -#ifdef HAVE_ABSTRACT_SOCKETS +#ifdef __linux__ /* Use abstract sockets for tmpdir if supported, so that it * never needs to be cleaned up. Use dir instead if you want a * path-based socket. */ diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index ea1a4b76..bebf2073 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -933,7 +933,7 @@ _dbus_connect_unix_socket (const char *path, if (abstract) { -#ifdef HAVE_ABSTRACT_SOCKETS +#ifdef __linux__ addr.sun_path[0] = '\0'; /* this is what says "use abstract" */ path_len++; /* Account for the extra nul byte added to the start of sun_path */ @@ -947,12 +947,12 @@ _dbus_connect_unix_socket (const char *path, strncpy (&addr.sun_path[1], path, path_len); /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ -#else /* HAVE_ABSTRACT_SOCKETS */ +#else /* !__linux__ */ dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED, "Operating system does not support abstract socket namespace\n"); _dbus_close (fd, NULL); return -1; -#endif /* ! HAVE_ABSTRACT_SOCKETS */ +#endif /* !__linux__ */ } else { @@ -1134,7 +1134,7 @@ _dbus_listen_unix_socket (const char *path, if (abstract) { -#ifdef HAVE_ABSTRACT_SOCKETS +#ifdef __linux__ /* remember that abstract names aren't nul-terminated so we rely * on sun_path being filled in with zeroes above. */ @@ -1151,12 +1151,12 @@ _dbus_listen_unix_socket (const char *path, strncpy (&addr.sun_path[1], path, path_len); /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ -#else /* HAVE_ABSTRACT_SOCKETS */ +#else /* !__linux__ */ dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED, "Operating system does not support abstract socket namespace\n"); _dbus_close (listen_fd, NULL); return -1; -#endif /* ! HAVE_ABSTRACT_SOCKETS */ +#endif /* !__linux__ */ } else { -- 2.14.2