Merge branch 'dbus-1.6'
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 3 Apr 2013 11:22:24 +0000 (12:22 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 3 Apr 2013 11:22:24 +0000 (12:22 +0100)
1  2 
NEWS
configure.ac
dbus/dbus-sysdeps-unix.c

diff --combined NEWS
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
 -D-Bus 1.6.10 (UNRELEASED)
 +D-Bus 1.7.2 (UNRELEASED)
  ==
  
++• Unix-specific:
++  · Under systemd, log to syslog only, not stderr, avoiding duplication
++    (fd.o #61399, #39987; Colin Walters, Dagobert Michelsen)
++  · Include alloca.h for alloca() if available, fixing compilation on
++    Solaris 10 (fd.o #63071, Dagobert Michelsen)
++  · Allow use of systemd-logind without the rest of systemd
++    (fd.o #62585, Martin Pitt)
++  · When built with CMake, link to librt and use the right path for
++    meinproc's XSLT stylesheets (fd.o #61637, Ralf Habacker)
++
++• Windows-specific:
++  · Do not claim that all bus clients have the dbus-daemon's credentials
++    (fd.o #61787, Ralf Habacker)
++
 +D-Bus 1.7.0 (2013-02-22)
 +==
 +
 +The "Disingenuous Assertions" release.
 +
 +This is a new development release, starting the 1.7.x branch. D-Bus 1.6
 +remains the recommended version for long-term-supported distributions
 +or the upcoming GNOME 3.8 release.
 +
 +Build-time configuration changes:
 +
 +• The --with-dbus-session-bus-default-address configure option is no longer
 +  supported. Use the new --with-dbus-session-bus-connect-address and
 +  --with-dbus-session-bus-listen-address options instead. On Windows, you
 +  usually want them to have the same argument; on Unix, the defaults are
 +  usually correct.
 +
 +• Similarly, the DBUS_SESSION_BUS_DEFAULT_ADDRESS CMake variable is no longer
 +  supported; use the new DBUS_SESSION_BUS_LISTEN_ADDRESS and
 +  DBUS_SESSION_BUS_CONNECT_ADDRESS variables instead.
 +
 +• cmake/cross-compile.sh has been removed. Instead, please use a
 +  cross-toolchain file (-DCMAKE_TOOLCHAIN_FILE) as documented at
 +  <http://www.vtk.org/Wiki/CMake_Cross_Compiling>; or use Autotools
 +  as documented in "info automake Cross-Compilation", and set
 +  PKG_CONFIG_PATH appropriately.
 +
 +Requirements:
 +
 +• Man pages now require xmlto (or either xmlto or meinproc, if using CMake).
 +• man2html is no longer used.
 +
 +Enhancements:
 +
 +• D-Bus Specification 0.20
 +  · actually say that /org/freedesktop/DBus is the object that
 +    implements o.fd.DBus (fd.o #51865, Colin Walters)
 +  · various reorganisation for better clarity (fd.o #38252, Simon McVittie)
 +  · stop claiming that all basic types work just like INT32 (strings don't!)
 +
 +• The "source code" for the man pages is now Docbook XML, eliminating
 +  the outdated duplicate copies used when building with CMake.
 +  (fd.o #59805; Ralf Habacker, Simon McVittie)
 +
 +Fixes:
 +
  • In the activation helper, when compiled for tests, do not reset the system
    bus address, fixing the regression tests. (fd.o #52202, Simon)
  
  • Fix building with Valgrind 3.8, at the cost of causing harmless warnings
    with Valgrind 3.6 on some compilers (fd.o #55932, Arun Raghavan)
  
 -• Don't leak temporary fds pointing to /dev/null (fd.o #56927, Michel HERMIER)
 +• Merge <servicehelper> from system-local.conf if necessary (fd.o #51560,
 +  Krzysztof Konopko)
  
 -• Create session.d, system.d directories under CMake (fd.o #41319,
 +• Under CMake, prefer xmlto over meinproc (fd.o #59733, Ralf Habacker)
 +
 +• Stop duplicating CMake's own logic to find libexpat
 +  (fd.o #59733, Ralf Habacker)
 +
 +• Don't assume CMake host and build system are the same (fd.o #59733,
    Ralf Habacker)
  
 +• Avoid deprecation warnings for GLib 2.35 (fd.o #59971, Simon McVittie)
 +
  • Unix-specific:
 -  · Include alloca.h for alloca() if available, fixing compilation on
 -    Solaris 10 (fd.o #63071, Dagobert Michelsen)
 +  · Check for functions in libpthread correctly, fixing compilation on
 +    (at least) OpenBSD (fd.o #47239, Simon)
 +  · Don't leak temporary fds pointing to /dev/null (fd.o #56927,
 +    Michel HERMIER)
 +  · Update sd-daemon.[ch] from systemd (fd.o #60681)
 +  · Add partial support for QNX (fd.o #60339, fd.o #61176; Matt Fischer)
 +
 +• Windows-specific:
 +  · The default session bus listening and connecting address is now
 +    "autolaunch:", which makes D-Bus on Windows interoperate with itself
 +    and GDBus "out of the box". Use the configure options and cmake variables
 +    described above if you require a different autolaunch scope.
 +    (fd.o #38201, Simon McVittie)
 +  · Avoid a CMake warning under Cygwin (fd.o #59401, Ralf Habacker)
 +
 +• Create session.d, system.d directories under CMake (fd.o #41319,
 +  Ralf Habacker)
  
  D-Bus 1.6.8 (2012-09-28)
  ==
diff --combined configure.ac
@@@ -2,8 -2,8 +2,8 @@@ dnl -*- mode: m4 -*
  AC_PREREQ([2.63])
  
  m4_define([dbus_major_version], [1])
 -m4_define([dbus_minor_version], [6])
 -m4_define([dbus_micro_version], [9])
 +m4_define([dbus_minor_version], [7])
 +m4_define([dbus_micro_version], [1])
  m4_define([dbus_version],
            [dbus_major_version.dbus_minor_version.dbus_micro_version])
  AC_INIT([dbus],[dbus_version],[https://bugs.freedesktop.org/enter_bug.cgi?product=dbus],[dbus])
@@@ -33,16 -33,16 +33,16 @@@ AC_DEFINE_UNQUOTED(DBUS_DAEMON_NAME,"db
  #
  
  ## increment if the interface has additions, changes, removals.
 -LT_CURRENT=10
 +LT_CURRENT=11
  
  ## increment any time the source changes; set to
  ##  0 if you increment CURRENT
 -LT_REVISION=2
 +LT_REVISION=0
  
  ## increment if any interfaces have been added; set to 0
  ## if any interfaces have been changed or removed. removal has
  ## precedence over adding, so set to 0 if both happened.
 -LT_AGE=7
 +LT_AGE=8
  
  AC_SUBST(LT_CURRENT)
  AC_SUBST(LT_REVISION)
@@@ -169,6 -169,7 +169,6 @@@ AC_ARG_WITH(console-owner-file, AS_HELP
  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>],[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],
@@@ -211,9 -212,6 +211,9 @@@ f
  # default (unless you don't have GLib), because they don't bloat the library
  # or binaries.
  
 +AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_26], [Ignore post-2.26 deprecations])
 +AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_26], [Prevent post-2.26 APIs])
 +
  with_glib=yes
  
  if test "x$enable_modular_tests" != xno; then
@@@ -688,6 -686,8 +688,8 @@@ AC_CHECK_HEADERS(ws2tcpip.h
  
  AC_CHECK_HEADERS(wspiapi.h)
  
+ AC_CHECK_HEADERS(alloca.h)
  # Add -D_POSIX_PTHREAD_SEMANTICS if on Solaris
  #
  case $host_os in
@@@ -955,53 -955,15 +957,53 @@@ AC_SUBST([XML_CFLAGS]
  AC_SUBST([XML_LIBS])
  
  # Thread lib detection
 -AC_CHECK_FUNC(pthread_cond_timedwait,[AC_CHECK_LIB(pthread,pthread_cond_timedwait,
 -                                                    [THREAD_LIBS="-lpthread"])])
 +AC_ARG_VAR([THREAD_LIBS])
  save_libs="$LIBS"
  LIBS="$LIBS $THREAD_LIBS"
 -AC_CHECK_FUNC(pthread_condattr_setclock,have_pthread_condattr_setclock=true,have_pthread_condattr_setclock=false)
 -if test x$have_pthread_condattr_setclock = xtrue; then
 -    AC_SEARCH_LIBS([clock_getres],[rt],[THREAD_LIBS="$THREAD_LIBS -lrt"])
 -    AC_MSG_CHECKING([for CLOCK_MONOTONIC])
 -    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <time.h>
 +
 +is_missing_pthread_function="is required when compiling D-Bus on Unix platforms, but is not in your libc or libpthread. Please open a bug on https://bugs.freedesktop.org/enter_bug.cgi?product=dbus with details of your platform."
 +
 +# Don't do these automatic checks if the user set THREAD_LIBS on the
 +# configure command-line. If they did, we assume they're right.
 +#
 +# We also don't do these checks on Windows, because you don't need magical
 +# linker flags to have threading support there.
 +AS_IF([test "x$dbus_unix" = xyes && test "x$THREAD_LIBS" = x],
 +  [
 +    # Mandatory pthread functions. In principle, some of these could be made
 +    # optional if there are platforms that don't have them.
 +    #
 +    # Currently, we only look in -lpthread.
 +    # In principle we might need to look in -lpthreads, -lthreads, ...
 +    # as well - please file a bug if your platform needs this.
 +    AC_SEARCH_LIBS([pthread_cond_timedwait],
 +        [pthread],
 +        [THREAD_LIBS="$LIBS"],
 +        [AC_MSG_ERROR([pthread_cond_timedwait $is_missing_pthread_function])],
 +        [])
 +    AC_SEARCH_LIBS([pthread_mutexattr_init],
 +        [pthread],
 +        [THREAD_LIBS="$LIBS"],
 +        [AC_MSG_ERROR([pthread_mutexattr_init $is_missing_pthread_function])],
 +        [])
 +    AC_SEARCH_LIBS([pthread_mutexattr_settype],
 +        [pthread],
 +        [THREAD_LIBS="$LIBS"],
 +        [AC_MSG_ERROR([pthread_mutexattr_settype $is_missing_pthread_function])],
 +        [])
 +
 +    # Optional, for monotonic clocks. Because it's optional, this check
 +    # is non-fatal if we don't find it.
 +    AC_SEARCH_LIBS([pthread_condattr_setclock],
 +        [pthread],
 +        [THREAD_LIBS="$LIBS"])
 +
 +    AS_IF([test "x$ac_cv_search_pthread_condattr_setclock" != xno],
 +      [
 +        AC_SEARCH_LIBS([clock_getres], [rt], [THREAD_LIBS="$LIBS"])
 +        AC_MSG_CHECKING([for CLOCK_MONOTONIC])
 +        AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
 +[[#include <time.h>
  #include <pthread.h>
  ]], [[
  struct timespec monotonic_timer;
@@@ -1010,17 -972,15 +1012,17 @@@ pthread_condattr_init (&attr)
  pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
  clock_getres (CLOCK_MONOTONIC,&monotonic_timer);
  ]])],
 -[have_clock_monotonic=true],
 -[have_clock_monotonic=false])
 -if test x$have_clock_monotonic = xtrue; then
 -    AC_MSG_RESULT([found])
 -    AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1, [Define if we have CLOCK_MONOTONIC])
 -else
 -    AC_MSG_RESULT([not found])
 -fi
 -fi
 +            [have_clock_monotonic=true],
 +            [have_clock_monotonic=false])
 +        AS_IF([test x$have_clock_monotonic = xtrue],
 +        [
 +            AC_MSG_RESULT([found])
 +            AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1, [Define if we have CLOCK_MONOTONIC])
 +        ],
 +          [AC_MSG_RESULT([not found])])
 +      ]) dnl have pthread_condattr_setclock
 +  ]) dnl on Unix
 +
  LIBS="$save_libs"
  
  AC_SUBST([THREAD_LIBS])
  AM_CONDITIONAL(DBUS_XML_DOCS_ENABLED, test x$enable_xml_docs = xyes)
  AC_MSG_RESULT($enable_xml_docs)
  
 -AC_PATH_PROG([MAN2HTML], [man2html])
 -AC_ARG_VAR([MAN2HTML], [Path to man2html (optional)])
 -AM_CONDITIONAL(DBUS_HAVE_MAN2HTML, test x$MAN2HTML != x)
 -
  AM_CONDITIONAL(DBUS_CAN_UPLOAD_DOCS,
 -    test x$enable_doxygen_docs = xyes -a x$enable_xml_docs = xyes -a \
 -         x$MAN2HTML != x)
 +    [test x$enable_doxygen_docs = xyes && test x$enable_xml_docs = xyes])
  
  #### Have to go $localstatedir->$prefix/var->/usr/local/var
  
  AC_SUBST(DBUS_SYSTEM_SOCKET)
  AC_DEFINE_UNQUOTED(DBUS_SYSTEM_SOCKET,"$DBUS_SYSTEM_SOCKET",[The name of the socket the system bus listens on by default])
  
 -## system bus only listens on local domain sockets, and never
 -## on an abstract socket (so only root can create the socket)
 +## System bus only listens on local domain sockets, and never
 +## on an abstract socket (so only root can create the socket).
 +##
 +## This won't work on Windows. It's not meant to - the system bus is
 +## meaningless on Windows anyway.
 +##
 +## This has to be suitable for hard-coding in client libraries as well as
 +## in the dbus-daemon's configuration, so it has to be valid to listen on
 +## and also to connect to. If this ever changes, it'll need to be split into
 +## two variables, one for the listening address and one for the connecting
 +## address.
  DBUS_SYSTEM_BUS_DEFAULT_ADDRESS="unix:path=$DBUS_SYSTEM_SOCKET"
  AC_SUBST(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS)
  AC_DEFINE_UNQUOTED(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS, "$DBUS_SYSTEM_BUS_DEFAULT_ADDRESS",[The default D-Bus address of the system bus])
  AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets])
  AC_SUBST(DBUS_SESSION_SOCKET_DIR)
  
 -if test x$dbus_win = xyes; then
 -        DBUS_SESSION_BUS_DEFAULT_ADDRESS="$with_dbus_session_bus_default_address"
 +# This must be a listening address. It doesn't necessarily need to be an
 +# address you can connect to - it can be something vague like
 +# "nonce-tcp:".
 +#
 +# The default varies by platform.
 +AC_ARG_WITH([dbus_session_bus_listen_address],
 +            AS_HELP_STRING([--with-dbus-session-bus-listen-address=[ADDRESS]],
 +                           [default address for a session bus to listen on (see configure.ac)]),
 +            [with_dbus_session_bus_listen_address=$withval],
 +            [with_dbus_session_bus_listen_address=])
 +
 +if test "x$with_dbus_session_bus_listen_address" != "x"; then
 +        # the user specified something, trust them
 +        DBUS_SESSION_BUS_LISTEN_ADDRESS="$with_dbus_session_bus_listen_address"
 +elif test x$dbus_win = xyes; then
 +        # On Windows, you can (and should) listen on autolaunch addresses,
 +        # because autolaunching is different.
 +        # See https://bugs.freedesktop.org/show_bug.cgi?id=38201
 +        DBUS_SESSION_BUS_LISTEN_ADDRESS="autolaunch:"
  elif test x$have_launchd = xyes; then
 -        DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
 +        # Mac OS X default is to use launchd
 +        DBUS_SESSION_BUS_LISTEN_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
 +else
 +        # The default on all other Unix platforms (notably Linux)
 +        # is to create a randomly named socket in /tmp or similar
 +        DBUS_SESSION_BUS_LISTEN_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
 +fi
 +AC_SUBST([DBUS_SESSION_BUS_LISTEN_ADDRESS])
 +
 +# This must be an address you can connect to. It doesn't necessarily
 +# need to be an address you can listen on - it can be "autolaunch:",
 +# even on Unix.
 +#
 +# The default varies by platform.
 +AC_ARG_WITH([dbus_session_bus_connect_address],
 +            AS_HELP_STRING([--with-dbus-session-bus-connect-address=[ADDRESS]],
 +                           [fallback address for a session bus client to connect to (see configure.ac)]),
 +            [with_dbus_session_bus_connect_address=$withval],
 +            [with_dbus_session_bus_connect_address=])
 +
 +if test "x$with_dbus_session_bus_connect_address" != "x"; then
 +        # the user specified something, trust them
 +        DBUS_SESSION_BUS_CONNECT_ADDRESS="$with_dbus_session_bus_connect_address"
 +elif test x$dbus_win = xyes; then
 +        # Windows autolaunching is a bit different; leaving it in its own
 +        # branch of the conditional because the default might conceivably
 +        # change (see #38201)
 +        DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:"
  else
 -        DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
 +        # The default on all other Unix platforms (notably Linux)
 +        # is to use auto-launching - this works a bit differently on Mac OS X
 +        # but comes out basically the same in the end
 +        DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:"
  fi
 -AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS)
 +AC_SUBST([DBUS_SESSION_BUS_CONNECT_ADDRESS])
 +AC_DEFINE_UNQUOTED([DBUS_SESSION_BUS_CONNECT_ADDRESS],
 +  ["$DBUS_SESSION_BUS_CONNECT_ADDRESS"],
 +  [Fallback address for session bus clients])
  
  # darwin needs this to initialize the environment
  AC_CHECK_HEADERS(crt_externs.h)
@@@ -1813,12 -1719,7 +1815,12 @@@ tools/Makefil
  test/Makefile
  test/name-test/Makefile
  doc/Makefile
 -doc/dbus-daemon.1
 +doc/dbus-cleanup-sockets.1.xml
 +doc/dbus-daemon.1.xml
 +doc/dbus-launch.1.xml
 +doc/dbus-monitor.1.xml
 +doc/dbus-send.1.xml
 +doc/dbus-uuidgen.1.xml
  dbus-1.pc
  dbus-1-uninstalled.pc
  test/data/valid-config-files/debug-allow-all.conf
@@@ -1863,7 -1764,8 +1865,7 @@@ echo 
        32-bit int:               ${DBUS_INT32_TYPE}
        16-bit int:               ${DBUS_INT16_TYPE}
          Doxygen:                  ${DOXYGEN:-not found}
 -        xmlto:                    ${XMLTO:-not found}
 -        man2html:                 ${MAN2HTML:-not found}"
 +        xmlto:                    ${XMLTO:-not found}"
  
  echo "
          Rebuilding generated files: ${USE_MAINTAINER_MODE}
          System bus socket:        ${DBUS_SYSTEM_SOCKET}
          System bus address:       ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS}
          System bus PID file:      ${DBUS_SYSTEM_PID_FILE}
 -        Session bus address:      ${DBUS_SESSION_BUS_DEFAULT_ADDRESS}
 +        Session bus listens on:   ${DBUS_SESSION_BUS_LISTEN_ADDRESS}
 +        Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS}
          Console auth dir:         ${DBUS_CONSOLE_AUTH_DIR}
          Console owner file:       ${have_console_owner_file}
          Console owner file path:  ${DBUS_CONSOLE_OWNER_FILE}
diff --combined dbus/dbus-sysdeps-unix.c
@@@ -55,7 -55,6 +55,7 @@@
  #include <netinet/in.h>
  #include <netdb.h>
  #include <grp.h>
 +#include <arpa/inet.h>
  
  #ifdef HAVE_ERRNO_H
  #include <errno.h>
@@@ -72,6 -71,9 +72,9 @@@
  #ifdef HAVE_GETPEERUCRED
  #include <ucred.h>
  #endif
+ #ifdef HAVE_ALLOCA_H
+ #include <alloca.h>
+ #endif
  
  #ifdef HAVE_ADT
  #include <bsm/adt.h>
@@@ -1863,7 -1865,7 +1866,7 @@@ _dbus_read_credentials_socket  (in
  
    if (pid_read != DBUS_PID_UNSET)
      {
 -      if (!_dbus_credentials_add_unix_pid (credentials, pid_read))
 +      if (!_dbus_credentials_add_pid (credentials, pid_read))
          {
            _DBUS_SET_OOM (error);
            return FALSE;
@@@ -2318,7 -2320,7 +2321,7 @@@ _dbus_credentials_add_from_current_proc
    _dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
    _dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
  
 -  if (!_dbus_credentials_add_unix_pid(credentials, _dbus_getpid()))
 +  if (!_dbus_credentials_add_pid(credentials, _dbus_getpid()))
      return FALSE;
    if (!_dbus_credentials_add_unix_uid(credentials, _dbus_geteuid()))
      return FALSE;
@@@ -3300,12 -3302,15 +3303,12 @@@ _read_subprocess_line_argv (const char 
        /* set-up stdXXX */
        close (result_pipe[READ_END]);
        close (errors_pipe[READ_END]);
 -      close (0);                /* close stdin */
 -      close (1);                /* close stdout */
 -      close (2);                /* close stderr */
  
 -      if (dup2 (fd, 0) == -1)
 +      if (dup2 (fd, 0) == -1) /* setup stdin */
          _exit (1);
 -      if (dup2 (result_pipe[WRITE_END], 1) == -1)
 +      if (dup2 (result_pipe[WRITE_END], 1) == -1) /* setup stdout */
          _exit (1);
 -      if (dup2 (errors_pipe[WRITE_END], 2) == -1)
 +      if (dup2 (errors_pipe[WRITE_END], 2) == -1) /* setup stderr */
          _exit (1);
  
        _dbus_close_all ();
@@@ -4158,71 -4163,4 +4161,71 @@@ _dbus_check_setuid (void
  #endif
  }
  
 +/**
 + * Read the address from the socket and append it to the string
 + *
 + * @param fd the socket
 + * @param address
 + * @param error return location for error code
 + */
 +dbus_bool_t
 +_dbus_append_address_from_socket (int         fd,
 +                                  DBusString *address,
 +                                  DBusError  *error)
 +{
 +  union {
 +      struct sockaddr sa;
 +      struct sockaddr_storage storage;
 +      struct sockaddr_un un;
 +      struct sockaddr_in ipv4;
 +      struct sockaddr_in6 ipv6;
 +  } socket;
 +  char hostip[INET6_ADDRSTRLEN];
 +  int size = sizeof (socket);
 +
 +  if (getsockname (fd, &socket.sa, &size))
 +    goto err;
 +
 +  switch (socket.sa.sa_family)
 +    {
 +    case AF_UNIX:
 +      if (socket.un.sun_path[0]=='\0')
 +        {
 +          if (_dbus_string_append_printf (address, "unix:abstract=%s", &(socket.un.sun_path[1])))
 +            return TRUE;
 +        }
 +      else
 +        {
 +          if (_dbus_string_append_printf (address, "unix:path=%s", socket.un.sun_path))
 +            return TRUE;
 +        }
 +      break;
 +    case AF_INET:
 +      if (inet_ntop (AF_INET, &socket.ipv4.sin_addr, hostip, sizeof (hostip)))
 +        if (_dbus_string_append_printf (address, "tcp:family=ipv4,host=%s,port=%u",
 +                   hostip, ntohs (socket.ipv4.sin_port)))
 +          return TRUE;
 +      break;
 +#ifdef AF_INET6
 +    case AF_INET6:
 +      if (inet_ntop (AF_INET6, &socket.ipv6.sin6_addr, hostip, sizeof (hostip)))
 +        if (_dbus_string_append_printf (address, "tcp:family=ipv6,host=%s,port=%u",
 +                   hostip, ntohs (socket.ipv6.sin6_port)))
 +          return TRUE;
 +      break;
 +#endif
 +    default:
 +      dbus_set_error (error,
 +                      _dbus_error_from_errno (EINVAL),
 +                      "Failed to read address from socket: Unknown socket type.");
 +      return FALSE;
 +    }
 + err:
 +  dbus_set_error (error,
 +                  _dbus_error_from_errno (errno),
 +                  "Failed to open socket: %s",
 +                  _dbus_strerror (errno));
 +  return FALSE;
 +}
 +
  /* tests in dbus-sysdeps-util.c */