From: Simon McVittie Date: Mon, 28 Apr 2025 13:06:39 +0000 (+0100) Subject: build: Don't use build-time TMPDIR, TEMP, TMP as socket directory X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7afc131bf9f211f09ca9dbb2279933e8803ee19;p=thirdparty%2Fdbus.git build: Don't use build-time TMPDIR, TEMP, TMP as socket directory When the ancestor of this code was introduced in 2003 (commit e45e4382), it was presumably most common to have these variables either unset, or set to a value that is system-wide and remains valid in the long term, such as /tmp or /var/tmp. However, on modern systems they are sometimes set to a value that is itself temporary, for example /var/folders/${some_long_path}/T on macOS, or user-specific, for example /tmp/user/$(id -u) on Linux with libpam-tmpdir. These values are certainly not useful to hard-code into libdbus and dbus-daemon during installation: they will not be usable when running dbus-related programs after a reboot or as a different user. So, instead of assuming TMPDIR, TEMP and TMP remain valid long-term, we now hard-code /tmp as our default. As before, system integrators can override this default with `-Dsession_socket_dir=...` (Meson) or `-DDBUS_SESSION_SOCKET_DIR=...` (CMake) if a different directory is more appropriate than /tmp. However, system integrators should note that because AF_UNIX paths have a relatively short length limit (typically 108 bytes), a short path is better than a long path in this context. Resolves: dbus/dbus#551 Signed-off-by: Simon McVittie --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 49ae125b3..82c1493a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -562,23 +562,9 @@ if(MSVC_IDE) file(REMOVE ${PROJECT_BINARY_DIR}/data/dbus-1/services) endif() -#### Find socket directories -set(DBUS_SESSION_SOCKET_DIR "" CACHE STRING "Default directory for session socket") -if(UNIX) - if (CMAKE_CROSSCOMPILING) - if (NOT DBUS_SESSION_SOCKET_DIR) - message(FATAL_ERROR "cannot autodetect session socket directory " - "when crosscompiling, pass -DDBUS_SESSION_SOCKET_DIR=...") - endif() - elseif(NOT $ENV{TMPDIR} STREQUAL "") - set(DBUS_SESSION_SOCKET_DIR $ENV{TMPDIR}) - elseif(NOT $ENV{TEMP} STREQUAL "") - set(DBUS_SESSION_SOCKET_DIR $ENV{TEMP}) - elseif(NOT $ENV{TMP} STREQUAL "") - set(DBUS_SESSION_SOCKET_DIR $ENV{TMP}) - else() - set(DBUS_SESSION_SOCKET_DIR /tmp) - endif() +set(DBUS_SESSION_SOCKET_DIR "" CACHE STRING "Default directory for session socket on Unix") +if(UNIX AND NOT DBUS_SESSION_SOCKET_DIR) + set(DBUS_SESSION_SOCKET_DIR /tmp) endif() # Not used on Windows, where there is no system bus diff --git a/meson.build b/meson.build index 65bb9d0d8..451da9114 100644 --- a/meson.build +++ b/meson.build @@ -1070,19 +1070,11 @@ endif data_config.set('SYSCONFDIR_FROM_PKGDATADIR', sysconfdir_from_pkgdatadir) data_config.set('DATADIR_FROM_PKGSYSCONFDIR', datadir_from_pkgsysconfdir) -#### Find socket directories -values = run_command(python, '-c', - 'import os; [print(os.getenv(e, "")) for e in ["TMPDIR", "TEMP", "TMP"]]', - check: true, -).stdout() -values += '/tmp' -default_socket_dir = values.strip().split('\n')[0] - if platform_unix session_socket_dir = get_option('session_socket_dir') if session_socket_dir == '' - session_socket_dir = default_socket_dir + session_socket_dir = '/tmp' endif config.set_quoted('DBUS_SESSION_SOCKET_DIR', session_socket_dir)