From 3ca855f2642239ea83c424d8bae5c2a514e55e3b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 18 May 2022 15:23:01 +0100 Subject: [PATCH 1/6] build: Use AS_IF for system bus socket Signed-off-by: Simon McVittie --- configure.ac | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ecff6a04..c15ee151 100644 --- a/configure.ac +++ b/configure.ac @@ -1330,14 +1330,15 @@ AS_HELP_STRING([--with-systemduserunitdir=DIR], [Directory for systemd user serv AC_SUBST([systemduserunitdir], [$with_systemduserunitdir]) ##### Set up location for system bus socket -if ! test -z "$with_system_socket"; then - DBUS_SYSTEM_SOCKET=$with_system_socket -else + +AS_IF([! test -z "$with_system_socket"], + [DBUS_SYSTEM_SOCKET=$with_system_socket], + [ # We don't use runstatedir for this (yet?), because /var/run has been the # interoperable system bus socket for 10+ years. # See https://bugs.freedesktop.org/show_bug.cgi?id=101628 DBUS_SYSTEM_SOCKET=${EXPANDED_LOCALSTATEDIR}/run/dbus/system_bus_socket -fi + ]) 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]) From ba6fb129bdb57320f84032e02f34a98d433caf14 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 18 May 2022 16:04:40 +0100 Subject: [PATCH 2/6] build: Update a comment with the release status of Autoconf It took a while, but Autoconf 2.70 was eventually released. Signed-off-by: Simon McVittie --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index c15ee151..3abbafc5 100644 --- a/configure.ac +++ b/configure.ac @@ -1286,8 +1286,8 @@ AM_CONDITIONAL(DBUS_CAN_UPLOAD_DOCS, [test x$enable_doxygen_docs = xyes && test x$enable_xml_docs = xyes && test x$enable_ducktype_docs = xyes]) -# Autoconf 2.70 will support this, and many distros patch this option in, -# but Autoconf 2.70 hasn't actually been released yet. +# Autoconf 2.70 supports this, and many distros patched this option in +# before Autoconf 2.70 was released AS_IF([test -z "${runstatedir}"], [runstatedir='${localstatedir}/run']) AC_SUBST([runstatedir]) From e5d8d0c19ad932dad44b3302c90ba692d3a9017a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 18 May 2022 16:13:36 +0100 Subject: [PATCH 3/6] build: Show a warning if the system bus socket is not interoperable We would like to start using ${runstatedir}/dbus/system_bus_socket, so that distributors who make /var/run a symbolic link to /run will usually get their dbus-daemon listening on /run/dbus/system_bus_socket, which has some advantages in corner cases, such as when /var is mediated by an automounter or is unmounted during system shutdown. Unfortunately, the interoperable path in the D-Bus Specification is /var/run/dbus/system_bus_socket for historical reasons (D-Bus is older than /run), and older versions of Slackware are known to have had /run and /var/run as distinct directories. Do a check during configuration to catch systems configured like this and show a warning. When cross-compiling, this assumes that the system where dbus is built (the build system in Autotools/Meson, or the "host" in CMake terminology) has its /var/run and /run set up in a way that is compatible with the system where dbus will run (the host system in Autotools/Meson, or the "target" in CMake terminology). This is not 100% correct, but seems good enough for a warning that will hopefully only trigger for misguided OS distributors. Signed-off-by: Simon McVittie --- CMakeLists.txt | 12 ++++++ Makefile.am | 1 + configure.ac | 4 ++ meson.build | 19 ++++++++++ tools/check-runstatedir.sh | 77 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100755 tools/check-runstatedir.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 28017a4e..6996f61e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -599,6 +599,18 @@ set(DBUS_SYSTEM_PID_FILE ${DBUS_RUNSTATEDIR}/dbus/pid) # address. set(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=${DBUS_RUNSTATEDIR}/dbus/system_bus_socket" CACHE STRING "system bus default address") +# This check assumes that the disposition of /run and /var/run on the +# system where we're building is the same as on the system we're building +# for, so we can't usefully do this check if we're building for Windows, +# or if we're cross-building for Unix on a Windows machine. +# +# The check is shared between Autotools and CMake. +# Because we only run it on Unix, it's fine to make it a shell script. +if(UNIX AND (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")) + execute_process( + COMMAND "${CMAKE_SOURCE_DIR}/tools/check-runstatedir.sh" "${DBUS_RUNSTATEDIR}/dbus/system_bus_socket") +endif() + if(WIN32) set(DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address") set(DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients") diff --git a/Makefile.am b/Makefile.am index ae2d648d..81f3c91e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,6 +37,7 @@ EXTRA_DIST = \ test/CMakeLists.txt \ test/name-test/CMakeLists.txt \ tools/CMakeLists.txt \ + tools/check-runstatedir.sh \ cmake \ $(NULL) diff --git a/configure.ac b/configure.ac index 3abbafc5..ca704344 100644 --- a/configure.ac +++ b/configure.ac @@ -1340,6 +1340,10 @@ AS_IF([! test -z "$with_system_socket"], DBUS_SYSTEM_SOCKET=${EXPANDED_LOCALSTATEDIR}/run/dbus/system_bus_socket ]) +dnl The actual check script is shared between Autotools and CMake. +AS_IF([test "$dbus_win" != yes], + [${CONFIG_SHELL-/bin/sh} "${srcdir}/tools/check-runstatedir.sh" "$DBUS_SYSTEM_SOCKET"]) + 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]) diff --git a/meson.build b/meson.build index 20e9dbc6..caaaccf2 100644 --- a/meson.build +++ b/meson.build @@ -831,6 +831,25 @@ if system_socket == '' /'run'/'dbus'/'system_bus_socket' ) endif + +# This check assumes that the disposition of /run and /var/run on the +# system where we're building is the same as on the system we're building +# for, so we can't usefully do this check if we're building for Windows, +# or if we're cross-building for Unix on a Windows machine. +# +# The check is shared between Autotools, CMake and Meson. +# Because we only run it on Unix, it's fine to make it a shell script. +if platform_unix and build_machine.system() != 'windows' + msg = run_command( + find_program('tools/check-runstatedir.sh'), + system_socket, + check: false, + ).stdout() + if msg != '' + warning(msg) + endif +endif + data_config.set('DBUS_SYSTEM_SOCKET', system_socket) ## System bus only listens on local domain sockets, and never diff --git a/tools/check-runstatedir.sh b/tools/check-runstatedir.sh new file mode 100755 index 00000000..75eb713d --- /dev/null +++ b/tools/check-runstatedir.sh @@ -0,0 +1,77 @@ +#!/bin/sh +# Copyright 2022 Collabora Ltd. +# SPDX-License-Identifier: MIT + +# Usage: check-runstatedir.sh /run/dbus/system_bus_socket + +set -e +set -u + +same_file () { + # Many shells implement test -ef (test whether two names point to + # the same file), but POSIX doesn't require it, so fall back to + # comparing realpath output if necessary. We prefer test -ef if + # available, since it does the right thing for bind-mounts, not just + # symlinks + if test / -ef / 2>/dev/null; then + test "$1" -ef "$2" + else + test "$(realpath "$1")" = "$(realpath "$2")" + fi +} + +if [ -e /run ] && [ -e /var/run ] && ! same_file /run /var/run; then + echo + echo "WARNING: /run and /var/run are not the same directory." + echo "| Tools that do not agree on whether a socket is in /run or in" + echo "| /var/run will fail to interoperate." + echo "| Ask your OS distributor to make these two directories equivalent" + echo "| via a symbolic link or bind mount: there is no useful reason to" + echo "| make them different." + echo +fi + +system_socket="$1" + +case "$system_socket" in + (/run/dbus/system_bus_socket) + # --with-system-socket=/run/dbus/system_bus_socket + if ! same_file /run /var/run; then + echo + echo "WARNING: system bus socket: /run/dbus/system_bus_socket" + echo "| The system bus has been configured to listen on" + echo "| /run/dbus/system_bus_socket, but /run is not the same" + echo "| as /var/run on this system." + echo "|" + echo "| Most D-Bus implementations will expect to find the D-Bus" + echo "| system bus socket at /var/run/dbus/system_bus_socket." + echo "| Consider creating a symbolic link." + echo + fi + ;; + + (/var/run/dbus/system_bus_socket) + # e.g. --localstatedir=/var + if ! same_file /run /var/run; then + echo + echo "NOTE: system bus socket: /var/run/dbus/system_bus_socket" + echo "| The system bus has been configured to listen on" + echo "| /var/run/dbus/system_bus_socket, but /run is not the same" + echo "| as /var/run on this system." + echo "|" + echo "| Some D-Bus implementations might expect to find the" + echo "| D-Bus system bus socket at /run/dbus/system_bus_socket." + echo "| Consider creating a symbolic link." + echo + fi + ;; + + (*) + # e.g. --prefix=/opt/dbus + echo + echo "NOTE: system bus listens on $system_socket" + echo "| This build of dbus will not interoperate with the well-known" + echo "| system bus socket, /var/run/dbus/system_bus_socket." + echo + ;; +esac From 91fe77904acf01b9845c52affdaf49e7b0d2fff7 Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Fri, 18 Jun 2021 21:20:21 -0400 Subject: [PATCH 4/6] build: Put system bus socket in runstatedir by default This lets OS distributors configure --runstatedir=/run if they want to, although for interoperability, they should only do this if they can guarantee that their /run and /var/run are equivalent. A previous commit adds a warning if we are using the default path on a system where /run and /var/run are not synoymous, mitigating the compatibility impact of this change. For CMake, this requires version 3.9, released in 2017. For Meson, this is currently controlled by the runtime_dir option, which defaults to /run if the prefix is /usr. The rationale for this is that /run is correct for modern Unix systems, and distributors who switch from Autotools or CMake to Meson need to review all their build options at that time, which is an ideal opportunity to check that they are doing the right thing around /run. Helps: https://gitlab.freedesktop.org/dbus/dbus/-/issues/180 Co-authored-by: Simon McVittie --- CMakeLists.txt | 4 ++-- bus/Makefile.am | 2 +- bus/meson.build | 2 +- configure.ac | 9 ++------- meson.build | 7 +------ 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6996f61e..2dd95e98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.4) +cmake_minimum_required(VERSION 3.9) # we do not need to have WIN32 defined set(CMAKE_LEGACY_CYGWIN_WIN32 0) @@ -71,7 +71,7 @@ set(DBUS_MACHINE_UUID_FILE ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dbus/machin set(DBUS_BINDIR ${CMAKE_INSTALL_FULL_BINDIR}) set(DBUS_DAEMONDIR ${CMAKE_INSTALL_FULL_BINDIR}) set(DBUS_LOCALSTATEDIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}) -set(DBUS_RUNSTATEDIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run) +set(DBUS_RUNSTATEDIR ${CMAKE_INSTALL_FULL_RUNSTATEDIR}) # On Windows this is relative to where we put the bus setup, in # ${datadir}/dbus-1. For simplicity, we only do this if diff --git a/bus/Makefile.am b/bus/Makefile.am index 51a8de81..1f5017c5 100644 --- a/bus/Makefile.am +++ b/bus/Makefile.am @@ -185,7 +185,7 @@ install-data-hook: $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/session.d $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/services if DBUS_UNIX - $(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus + $(mkinstalldirs) $(DESTDIR)$(runstatedir)/dbus $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system.d $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system-services endif diff --git a/bus/meson.build b/bus/meson.build index 1aaaf48d..058e3b25 100644 --- a/bus/meson.build +++ b/bus/meson.build @@ -191,7 +191,7 @@ install_emptydirs += [ if platform_unix install_emptydirs += [ - get_option('localstatedir') / 'run' / 'dbus', + runstatedir / 'dbus', get_option('datadir') / 'dbus-1' / 'system.d', get_option('datadir') / 'dbus-1' / 'system-services', ] diff --git a/configure.ac b/configure.ac index ca704344..7da53d5d 100644 --- a/configure.ac +++ b/configure.ac @@ -1331,14 +1331,9 @@ AC_SUBST([systemduserunitdir], [$with_systemduserunitdir]) ##### Set up location for system bus socket -AS_IF([! test -z "$with_system_socket"], +AS_IF([test -n "$with_system_socket"], [DBUS_SYSTEM_SOCKET=$with_system_socket], - [ - # We don't use runstatedir for this (yet?), because /var/run has been the - # interoperable system bus socket for 10+ years. - # See https://bugs.freedesktop.org/show_bug.cgi?id=101628 - DBUS_SYSTEM_SOCKET=${EXPANDED_LOCALSTATEDIR}/run/dbus/system_bus_socket - ]) + [DBUS_SYSTEM_SOCKET=${EXPANDED_RUNSTATEDIR}/dbus/system_bus_socket]) dnl The actual check script is shared between Autotools and CMake. AS_IF([test "$dbus_win" != yes], diff --git a/meson.build b/meson.build index caaaccf2..33294e2e 100644 --- a/meson.build +++ b/meson.build @@ -822,13 +822,8 @@ config.set_quoted('DBUS_SESSION_CONFIG_FILE', system_socket = get_option('system_socket') if system_socket == '' - # We don't use runstatedir for this (yet?), because /var/run has been the - # interoperable system bus socket for 10+ years. - # See https://bugs.freedesktop.org/show_bug.cgi?id=101628 system_socket = ( - get_option('prefix') - / get_option('localstatedir') - /'run'/'dbus'/'system_bus_socket' + get_option('prefix') / runstatedir / 'dbus' / 'system_bus_socket' ) endif From cc0544cd36919adffa7d16df2297c9c2805be3d2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 15 Jul 2022 17:10:57 +0100 Subject: [PATCH 5/6] spec: Mention that the system bus address might actually be in /run The interoperable address is unix:path=/var/run/dbus/system_bus_socket. However, in most (perhaps all) current Linux distributions, /var/run is guaranteed to be a symbolic link to /run, and using the path in /run has some advantages (particularly if automounters are used). Implementations that intend to be interoperable are not required to listen on exactly /var/run/dbus/system_bus_socket, as long as clients that connect to that socket will work correctly. Similarly, clients are not required to connect to exactly /var/run/dbus/system_bus_socket, as long as the overall system (consisting of the client and the OSs that it supports) ensures that it ends up connecting to the same well-known system bus that is available at /var/run/dbus/system_bus_socket. Because of the Unix conventions for how software installs into a prefix, building a D-Bus implementation with its default build-time configuration options will not necessarily result in an interoperable system bus. The system bus is normally shipped by OS distributors, who should ensure that they have configured it in a way that is interoperable. Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/180 Signed-off-by: Simon McVittie --- doc/dbus-specification.xml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/dbus-specification.xml b/doc/dbus-specification.xml index 9b02f5cd..3b0f4cab 100644 --- a/doc/dbus-specification.xml +++ b/doc/dbus-specification.xml @@ -5783,13 +5783,27 @@ variable. If that variable is not set, applications should try to connect to the well-known address unix:path=/var/run/dbus/system_bus_socket. - - - The D-Bus reference implementation actually honors the - $(localstatedir) configure option - for this address, on both client and server side. - - + Implementations of the well-known system bus should listen on + an address that will result in that connection being successful. + + + On systems where /var/run/ is known to be + synonymous with /run/ (such as most Linux + operating system distributions), implementations might prefer + to make use of that knowledge to connect to or listen on + unix:path=/run/dbus/system_bus_socket instead, + which has some minor technical advantages, particularly during + early startup and late shutdown. + + + In practice, implementations of D-Bus often have build-time + configuration options for the system bus address, whose defaults + often depend on other build-time options such as the installation + prefix (in particular, this is the case for dbus, the reference + implementation of D-Bus). + Distributors intending to provide access to the well-known + system bus should verify that they are using an interoperable + address. On Unix systems, the system bus should default to searching From 5bef1d3d135019af64145878bf7e3bf03e6128b0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 26 Jul 2022 11:38:05 +0100 Subject: [PATCH 6/6] Add NEWS entries for #180 Signed-off-by: Simon McVittie --- NEWS | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/NEWS b/NEWS index 15c119f0..085a4cf8 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,31 @@ dbus 1.15.4 (UNRELEASED) ======================== +Dependencies: + +• Building with CMake now requires CMake ≥ 3.9. + +Build-time configuration changes: + +• On Unix platforms, a path in the runtime state directory (often /run) + is now used for the well-known system bus socket by default. OS + distributors should check that the path used is equivalent to the + interoperable path /var/run/dbus/system_bus_socket, especially if + running on an OS where /var/run is not guaranteed to be a symbolic + link to /run. + (dbus#180; Issam E. Maghni, Simon McVittie) + · With Autotools, this is controlled by --runstatedir, which defaults + to ${localstatedir}/run but is often set to /run by OS distributors. + The path to the system bus socket can be overridden with the + --with-system-socket option if required. + · With CMake, this is controlled by the RUNSTATEDIR option, which has + behaviour similar to Autotools. There is no separate option for the + path to the system bus socket. + · With Meson, this is controlled by the runtime_dir option, which + defaults to /run if the installation prefix is set to /usr, or has + behaviour similar to Autotools otherwise. The path to the system bus + socket can be overridden with the system_socket option if required. + New API: • Add dbus_connection_set_builtin_filters_enabled(), intended to be called