Commit 6a652174 authored by Simon McVittie's avatar Simon McVittie

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.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34905Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
parent 633a208c
......@@ -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
......
......@@ -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)
......
......@@ -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)
......@@ -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
......
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
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
......@@ -198,7 +198,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])],
......@@ -850,77 +849,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 <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
]],
[[
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"
......@@ -1923,7 +1851,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}
......
......@@ -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. */
......
......@@ -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
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment