summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-03-31 14:51:51 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2014-03-31 14:51:51 +0000
commitf2e4718bf42f507684949ebf484aa94df42abbbe (patch)
tree7f6266a7e45144490b18eb6c71a953e8e0196eb9
parenta0f3687d650c8c73134f318820f4978a4ff3e9e2 (diff)
parent6528b0973bb09b0b407a5e169fdcc519087cc58d (diff)
downloaddbus-baserock/v1.8.0.tar.gz
Merge tag 'dbus-1.8.0' into baserock/pedroalvarez/genivibaserock/v1.8.0
dbus-1.8.0
-rw-r--r--Doxyfile.in1
-rw-r--r--HACKING2
-rw-r--r--INSTALL6
-rw-r--r--Makefile.am3
-rw-r--r--NEWS642
-rw-r--r--README4
-rw-r--r--README.cmake34
-rw-r--r--README.valgrind24
-rw-r--r--README.win12
-rwxr-xr-xautogen.sh14
-rw-r--r--bus/.gitignore6
-rw-r--r--bus/Makefile.am31
-rw-r--r--bus/activation-helper-bin.c5
-rw-r--r--bus/activation-helper.c33
-rw-r--r--bus/activation.c42
-rw-r--r--bus/bus.c16
-rw-r--r--bus/config-loader-libxml.c324
-rw-r--r--bus/config-parser-trivial.c4
-rw-r--r--bus/config-parser.c31
-rw-r--r--bus/connection.c64
-rw-r--r--bus/connection.h3
-rw-r--r--bus/dbus.service.in1
-rw-r--r--bus/desktop-file.c6
-rw-r--r--bus/desktop-file.h1
-rw-r--r--bus/dir-watch-dnotify.c93
-rw-r--r--bus/dir-watch-inotify.c20
-rw-r--r--bus/dir-watch-kqueue.c175
-rw-r--r--bus/dispatch.c15
-rw-r--r--bus/driver.c253
-rw-r--r--bus/expirelist.c4
-rw-r--r--bus/main.c49
-rw-r--r--bus/policy.c4
-rw-r--r--bus/policy.h2
-rw-r--r--bus/selinux.c61
-rw-r--r--bus/services.c2
-rw-r--r--bus/session.conf.in4
-rw-r--r--bus/signals.c38
-rw-r--r--bus/stats.c242
-rw-r--r--bus/test-launch-helper.c13
-rw-r--r--bus/test-main.c8
-rw-r--r--bus/test-system.c8
-rw-r--r--bus/test.c2
-rw-r--r--bus/test.h2
-rw-r--r--cmake/CMakeLists.txt196
-rw-r--r--cmake/ConfigureChecks.cmake9
-rw-r--r--cmake/Doxyfile.cmake182
-rw-r--r--cmake/bus/CMakeLists.txt47
-rw-r--r--cmake/config.h.cmake37
-rwxr-xr-xcmake/cross-compile.sh110
-rw-r--r--cmake/dbus-env.bat.cmake4
-rw-r--r--cmake/dbus/CMakeLists.txt30
-rw-r--r--cmake/doc/CMakeLists.txt90
-rw-r--r--cmake/modules/COPYING-CMAKE-SCRIPTS22
-rw-r--r--cmake/modules/CPackInstallConfig.cmake9
-rw-r--r--cmake/modules/FindGLIB.cmake42
-rw-r--r--cmake/modules/FindGLib2.cmake60
-rw-r--r--cmake/modules/FindGObject.cmake52
-rw-r--r--cmake/modules/FindLibExpat.cmake61
-rw-r--r--cmake/modules/Macros.cmake35
-rw-r--r--cmake/modules/MacrosAutotools.cmake60
-rw-r--r--cmake/test/CMakeLists.txt77
-rw-r--r--cmake/test/name-test/CMakeLists.txt48
-rw-r--r--cmake/tools/CMakeLists.txt2
-rw-r--r--configure.ac420
-rw-r--r--dbus-1-uninstalled.pc.in2
-rw-r--r--dbus-1.pc.in2
-rw-r--r--dbus/.gitignore2
-rw-r--r--dbus/Makefile.am31
-rw-r--r--dbus/dbus-address.c12
-rw-r--r--dbus/dbus-arch-deps.h.in8
-rw-r--r--dbus/dbus-asv-util.c260
-rw-r--r--dbus/dbus-asv-util.h46
-rw-r--r--dbus/dbus-auth-script.c10
-rw-r--r--dbus/dbus-auth-util.c4
-rw-r--r--dbus/dbus-auth.c12
-rw-r--r--dbus/dbus-auth.h3
-rw-r--r--dbus/dbus-bus.c82
-rw-r--r--dbus/dbus-connection-internal.h2
-rw-r--r--dbus/dbus-connection.c122
-rw-r--r--dbus/dbus-credentials-util.c16
-rw-r--r--dbus/dbus-credentials.c32
-rw-r--r--dbus/dbus-credentials.h4
-rw-r--r--dbus/dbus-dataslot.c77
-rw-r--r--dbus/dbus-dataslot.h8
-rw-r--r--dbus/dbus-errors.c3
-rw-r--r--dbus/dbus-hash.c4
-rw-r--r--dbus/dbus-init-win.cpp52
-rw-r--r--dbus/dbus-internals.c58
-rw-r--r--dbus/dbus-internals.h77
-rw-r--r--dbus/dbus-keyring.c19
-rw-r--r--dbus/dbus-list.c21
-rw-r--r--dbus/dbus-macros.h10
-rw-r--r--dbus/dbus-mainloop.c25
-rw-r--r--dbus/dbus-marshal-basic.c77
-rw-r--r--dbus/dbus-marshal-basic.h39
-rw-r--r--dbus/dbus-marshal-byteswap-util.c4
-rw-r--r--dbus/dbus-marshal-byteswap.c4
-rw-r--r--dbus/dbus-marshal-header.c4
-rw-r--r--dbus/dbus-marshal-recursive-util.c36
-rw-r--r--dbus/dbus-marshal-validate-util.c4
-rw-r--r--dbus/dbus-memory.c59
-rw-r--r--dbus/dbus-mempool.c42
-rw-r--r--dbus/dbus-message-factory.c4
-rw-r--r--dbus/dbus-message-factory.h4
-rw-r--r--dbus/dbus-message-internal.h3
-rw-r--r--dbus/dbus-message-util.c249
-rw-r--r--dbus/dbus-message.c205
-rw-r--r--dbus/dbus-message.h12
-rw-r--r--dbus/dbus-misc.c2
-rw-r--r--dbus/dbus-misc.h4
-rw-r--r--dbus/dbus-nonce.c16
-rw-r--r--dbus/dbus-object-tree.c468
-rw-r--r--dbus/dbus-pending-call.c24
-rw-r--r--dbus/dbus-server-debug-pipe.c4
-rw-r--r--dbus/dbus-server-launchd.c3
-rw-r--r--dbus/dbus-server-socket.c7
-rw-r--r--dbus/dbus-server-unix.c38
-rw-r--r--dbus/dbus-server-win.c28
-rw-r--r--dbus/dbus-server.c36
-rw-r--r--dbus/dbus-sha.c4
-rw-r--r--dbus/dbus-shell.c12
-rw-r--r--dbus/dbus-signature.c2
-rw-r--r--dbus/dbus-socket-set-poll.c2
-rw-r--r--dbus/dbus-spawn-win.c47
-rw-r--r--dbus/dbus-spawn.c168
-rw-r--r--dbus/dbus-spawn.h1
-rw-r--r--dbus/dbus-string-util.c4
-rw-r--r--dbus/dbus-string.c61
-rw-r--r--dbus/dbus-string.h2
-rw-r--r--dbus/dbus-syntax.c8
-rw-r--r--dbus/dbus-sysdeps-pthread.c24
-rw-r--r--dbus/dbus-sysdeps-thread-win.c30
-rw-r--r--dbus/dbus-sysdeps-unix.c661
-rw-r--r--dbus/dbus-sysdeps-unix.h4
-rw-r--r--dbus/dbus-sysdeps-util-unix.c227
-rw-r--r--dbus/dbus-sysdeps-util-win.c214
-rw-r--r--dbus/dbus-sysdeps-util.c4
-rw-r--r--dbus/dbus-sysdeps-win.c602
-rw-r--r--dbus/dbus-sysdeps-win.h9
-rw-r--r--dbus/dbus-sysdeps-wince-glue.c2
-rw-r--r--dbus/dbus-sysdeps.c23
-rw-r--r--dbus/dbus-sysdeps.h34
-rw-r--r--dbus/dbus-test.c15
-rw-r--r--dbus/dbus-threads.c423
-rw-r--r--dbus/dbus-transport-protected.h2
-rw-r--r--dbus/dbus-transport-socket.c40
-rw-r--r--dbus/dbus-transport-unix.c2
-rw-r--r--dbus/dbus-transport-win.c35
-rw-r--r--dbus/dbus-transport.c50
-rw-r--r--dbus/dbus-transport.h3
-rw-r--r--dbus/dbus-types.h36
-rw-r--r--dbus/dbus-userdb-util.c33
-rw-r--r--dbus/dbus-userdb.c51
-rw-r--r--dbus/dbus-userdb.h2
-rw-r--r--dbus/dbus-valgrind-internal.h8
-rw-r--r--dbus/dbus-watch.c43
-rw-r--r--dbus/sd-daemon.c193
-rw-r--r--dbus/sd-daemon.h59
-rw-r--r--doc/.gitignore3
-rw-r--r--doc/Makefile.am72
-rw-r--r--doc/dbus-cleanup-sockets.143
-rw-r--r--doc/dbus-cleanup-sockets.1.xml.in65
-rw-r--r--doc/dbus-daemon.1.in766
-rw-r--r--doc/dbus-daemon.1.xml.in (renamed from cmake/bus/dbus-daemon.xml)625
-rw-r--r--doc/dbus-faq.xml4
-rw-r--r--doc/dbus-launch.1183
-rw-r--r--doc/dbus-launch.1.xml.in (renamed from cmake/tools/dbus-launch.xml)120
-rw-r--r--doc/dbus-monitor.178
-rw-r--r--doc/dbus-monitor.1.xml.in (renamed from cmake/tools/dbus-monitor.xml)19
-rw-r--r--doc/dbus-run-session.1.xml.in151
-rw-r--r--doc/dbus-send.1109
-rw-r--r--doc/dbus-send.1.xml.in (renamed from cmake/tools/dbus-send.xml)101
-rw-r--r--doc/dbus-specification.xml1570
-rw-r--r--doc/dbus-test-plan.xml18
-rw-r--r--doc/dbus-tutorial.xml4
-rw-r--r--doc/dbus-uuidgen.189
-rw-r--r--doc/dbus-uuidgen.1.xml.in126
-rw-r--r--m4/compiler.m42
-rw-r--r--test/.gitignore6
-rw-r--r--test/Makefile.am161
-rw-r--r--test/break-loader.c2
-rw-r--r--test/corrupt.c37
-rw-r--r--test/data/valid-config-files/incoming-limit.conf.in (renamed from test/data/valid-config-files/incoming-limit.conf)2
-rw-r--r--test/dbus-daemon-eavesdrop.c36
-rw-r--r--test/dbus-daemon.c163
-rw-r--r--test/internals/printf.c88
-rw-r--r--test/internals/refs.c1
-rw-r--r--test/internals/syslog.c10
-rw-r--r--test/loopback.c85
-rw-r--r--test/manual-authz.c409
-rw-r--r--test/marshal.c28
-rw-r--r--test/name-test/.gitignore2
-rw-r--r--test/name-test/Makefile.am23
-rwxr-xr-xtest/name-test/run-test-systemserver.sh5
-rwxr-xr-xtest/name-test/run-test.sh5
-rw-r--r--test/name-test/test-autolaunch.c11
-rw-r--r--test/name-test/test-threads-init.c14
-rw-r--r--test/relay.c25
-rw-r--r--test/shell-test.c2
-rw-r--r--test/spawn-test.c4
-rw-r--r--test/syntax.c6
-rw-r--r--test/test-exit.c2
-rw-r--r--test/test-utils.c93
-rw-r--r--test/test-utils.h39
-rw-r--r--tools/Makefile.am18
-rw-r--r--tools/dbus-launch-win.c11
-rw-r--r--tools/dbus-launch.c187
-rw-r--r--tools/dbus-monitor.c51
-rw-r--r--tools/dbus-print-message.c10
-rw-r--r--tools/dbus-run-session.c464
-rw-r--r--tools/dbus-send.c73
-rwxr-xr-xtools/run-with-tmp-session-bus.sh52
-rw-r--r--tools/strtoll.c1
-rw-r--r--tools/strtoull.c1
214 files changed, 9481 insertions, 6211 deletions
diff --git a/Doxyfile.in b/Doxyfile.in
index afac639b..f0a37eda 100644
--- a/Doxyfile.in
+++ b/Doxyfile.in
@@ -147,7 +147,6 @@ PREDEFINED = "DBUS_BEGIN_DECLS=" \
"DBUS_END_DECLS=" \
"DOXYGEN_SHOULD_SKIP_THIS" \
"DBUS_GNUC_DEPRECATED=" \
- "_DBUS_DEFINE_GLOBAL_LOCK(name)=" \
"_DBUS_GNUC_PRINTF(from,to)="
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
diff --git a/HACKING b/HACKING
index 805fd2e0..8c993b66 100644
--- a/HACKING
+++ b/HACKING
@@ -267,7 +267,7 @@ Tests
These are the test programs that are built if dbus is compiled using
--enable-tests.
-dbus/dbus-test
+dbus/test-dbus
This is the main unit test program that tests all aspects of the D-Bus
client library.
diff --git a/INSTALL b/INSTALL
index e182f985..f2f0122c 100644
--- a/INSTALL
+++ b/INSTALL
@@ -51,15 +51,11 @@ Core library
Requisite:
- Gettext
- - expat or libxml-2
-
- NB, expat is the recommended XML parser because it has more robust
- handling of OOM conditions.
+ - expat
Optional:
- libselinux (for SELinux integration)
- - dnotify (for automatic service file reload)
- doxygen (for API documentation)
- xmlto or meinproc4 (for Spec & other XML documentation)
diff --git a/Makefile.am b/Makefile.am
index 10b96703..756ab8b9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,6 +7,7 @@ DISTCLEANFILES = \
dbus-1.pc
EXTRA_DIST = \
+ autogen.sh \
HACKING \
dbus-1.pc.in \
cleanup-man-pages.sh \
@@ -14,6 +15,7 @@ EXTRA_DIST = \
NEWS.pre-1-0 \
ChangeLog.pre-1-2 \
NEWS.pre-1-2 \
+ README.valgrind \
README.win \
README.wince \
README.cygwin \
@@ -26,6 +28,7 @@ update-authors:
git shortlog -s -e | cut -c 8- | sort > AUTHORS
DISTCHECK_CONFIGURE_FLAGS = \
+ --enable-xml-docs \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
diff --git a/NEWS b/NEWS
index d0ad049d..0adbc00a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,645 @@
-D-Bus 1.5.14 (UNRELEASED)
+D-Bus 1.8.0 (2014-01-20)
==
-...
+The “Wolverine distrusts my printer” release.
+
+This starts a new stable branch. The 1.6.x branch is now considered to be
+outdated, and will only receive fixes for serious bugs such as security
+flaws. The 1.4.x and 1.2.x branches no longer have upstream support and
+are unlikely to get any more releases, but if distributors still need to
+support them, please share security patches via upstream.
+
+Summary of changes since 1.6.x:
+
+• libdbus always behaves as if dbus_threads_init_default() had been called
+ (thread-safety by default)
+• new dbus-run-session tool, replacing certain misuses of dbus-launch
+• dbus-monitor can talk to outdated versions of dbus-daemon again
+• new org.freedesktop.DBus.GetConnectionCredentials method
+• GetConnectionUnixProcessID also works correctly on Windows, returning
+ the Windows process ID
+• GetConnectionWindowsSID returns the correct SID on Windows
+• expat is required, libxml2 can no longer be used as a substitute
+• the userDB cache is required, and cannot be disabled
+• a 64-bit integer type (either int, long, long long or _int64) is required
+• better systemd-journald integration on Linux
+• fixed long-standing fd and array leaks when failing to parse a message
+• fixed referenced-but-never-freed parent nodes (effectively memory leaks)
+ when using certain object-path allocation patterns, notably in Avahi
+• better defaults for Windows support
+• better CMake support
+• better portability to mingw32, FreeBSD, NetBSD, QNX and Hurd
+• the source language for the man pages is now Docbook XML
+
+Enhancements since 1.7.10:
+
+• Enhance the CMake build system to check for GLib and compile/run
+ a subset of the regression tests (fd.o #41252, #73495; Ralf Habacker)
+
+Fixes since 1.7.10:
+
+• don't rely on va_copy(), use DBUS_VA_COPY() wrapper (fd.o #72840,
+ Ralf Habacker)
+
+• fix compilation of systemd journal support on older systemd versions where
+ sd-journal.h doesn't include syslog.h (fd.o #73455, Ralf Habacker)
+
+• fix compilation on older MSVC versions by including stdlib.h
+ (fd.o #73455, Ralf Habacker)
+
+• Allow <allow_anonymous/> to appear in an included configuration file
+ (fd.o #73475, Matt Hoosier)
+
+Test behaviour changes since 1.7.10:
+
+• If the tests crash with an assertion failure, they no longer default to
+ blocking for a debugger to be attached. Set DBUS_BLOCK_ON_ABORT in the
+ environment if you want the old behaviour.
+
+• To improve debuggability, the dbus-daemon and dbus-daemon-eavesdrop tests
+ can be run with an external dbus-daemon by setting
+ DBUS_TEST_DAEMON_ADDRESS in the environment. Test-cases that require
+ an unusually-configured dbus-daemon are skipped.
+
+D-Bus 1.7.10 (2014-01-06)
+==
+
+The “weighted companion cube” release.
+
+This is a release candidate for D-Bus 1.8.
+
+D-Bus Specification 0.23:
+
+• don't require messages with no INTERFACE to be dispatched
+ (fd.o #68597, Simon McVittie)
+
+• document "tcp:bind=..." and "nonce-tcp:bind=..." (fd.o #72301,
+ Chengwei Yang)
+
+• define "listenable" and "connectable" addresses, and discuss
+ the difference (fd.o #61303, Simon McVittie)
+
+Enhancements:
+
+• support printing Unix file descriptors in dbus-send, dbus-monitor
+ (fd.o #70592, Robert Ancell)
+
+• don't install systemd units if --disable-systemd is given
+ (fd.o #71818, Chengwei Yang)
+
+Fixes:
+
+• don't leak memory on out-of-memory while listing activatable or
+ active services (fd.o #71526, Radoslaw Pajak)
+
+• fix undefined behaviour in a regression test (fd.o #69924, DreamNik)
+
+• escape Unix socket addresses correctly (fd.o #46013, Chengwei Yang)
+
+• on SELinux systems, don't assume that SECCLASS_DBUS, DBUS__ACQUIRE_SVC
+ and DBUS__SEND_MSG are numerically equal to their values in the
+ reference policy (fd.o #88719, osmond sun)
+
+• define PROCESS_QUERY_LIMITED_INFORMATION if missing from MinGW < 4 headers
+ (fd.o #71366, Matt Fischer)
+
+• define WIN32_LEAN_AND_MEAN to avoid conflicts between winsock.h and
+ winsock2.h (fd.o #71405, Matt Fischer)
+
+• do not return failure from _dbus_read_nonce() with no error set,
+ preventing a potential crash (fd.o #72298, Chengwei Yang)
+
+• on BSD systems, avoid some O(1)-per-process memory and fd leaks in kqueue,
+ preventing test failures (fd.o #69332, fd.o #72213; Chengwei Yang)
+
+• fix warning spam on Hurd by not trying to set SO_REUSEADDR on Unix sockets,
+ which doesn't do anything anyway on at least Linux and FreeBSD
+ (fd.o #69492, Simon McVittie)
+
+• fix use of TCP sockets on FreeBSD and Hurd by tolerating EINVAL from
+ sendmsg() with SCM_CREDS (retrying with plain send()), and looking
+ for credentials more correctly (fd.o #69492, Simon McVittie)
+
+• ensure that tests run with a temporary XDG_RUNTIME_DIR to avoid
+ getting mixed up in XDG/systemd "user sessions" (fd.o #61301,
+ Simon McVittie)
+
+• refresh cached policy rules for existing connections when bus
+ configuration changes (fd.o #39463, Chengwei Yang)
+
+D-Bus 1.7.8 (2013-11-01)
+==
+
+The “extreme hills” release.
+
+Dependencies:
+
+• If systemd support is enabled, libsystemd-journal is now required.
+
+Enhancements:
+
+• When activating a non-systemd service under systemd, annotate its
+ stdout/stderr with its bus name in the Journal. Known limitation:
+ because the socket is opened before forking, the process will still be
+ logged as if it had dbus-daemon's process ID and user ID.
+ (fd.o #68559, Chengwei Yang)
+
+• Document more configuration elements in dbus-daemon(1)
+ (fd.o #69125, Chengwei Yang)
+
+Fixes:
+
+• Don't leak string arrays or fds if dbus_message_iter_get_args_valist()
+ unpacks them and then encounters an error (fd.o #21259, Chengwei Yang)
+
+• If compiled with libaudit, retain CAP_AUDIT_WRITE so we can write
+ disallowed method calls to the audit log, fixing a regression in 1.7.6
+ (fd.o #49062, Colin Walters)
+
+• path_namespace='/' in match rules incorrectly matched nothing; it
+ now matches everything. (fd.o #70799, Simon McVittie)
+
+D-Bus 1.7.6 (2013-10-09)
+==
+
+The “CSI Shrewsbury” release.
+
+Build-time configuration changes:
+
+• Directory change notification via dnotify on Linux is no longer
+ supported; it hadn't compiled successfully since 2010 in any case.
+ If you don't have inotify (Linux) or kqueue (*BSD), you will need
+ to send SIGHUP to the dbus-daemon when its configuration changes.
+ (fd.o #33001, Chengwei Yang)
+
+• Compiling with --disable-userdb-cache is no longer supported;
+ it didn't work since at least 2008, and would lead to an extremely
+ slow dbus-daemon even it worked. (fd.o #15589, #17133, #66947;
+ Chengwei Yang)
+
+• The DBUS_DISABLE_ASSERTS CMake option didn't actually disable most
+ assertions. It has been renamed to DBUS_DISABLE_ASSERT to be consistent
+ with the Autotools build system. (fd.o #66142, Chengwei Yang)
+
+• --with-valgrind=auto enables Valgrind instrumentation if and only if
+ valgrind headers are available. The default is still --with-valgrind=no.
+ (fd.o #56925, Simon McVittie)
+
+Dependencies:
+
+• Platforms with no 64-bit integer type are no longer supported.
+ (fd.o #65429, Simon McVittie)
+
+• GNU make is now (documented to be) required. (fd.o #48277, Simon McVittie)
+
+• Full test coverage no longer requires dbus-glib, although the tests do not
+ exercise the shared library (only a static copy) if dbus-glib is missing.
+ (fd.o #68852, Simon McVittie)
+
+Enhancements:
+
+• D-Bus Specification 0.22
+ · Document GetAdtAuditSessionData() and
+ GetConnectionSELinuxSecurityContext() (fd.o #54445, Simon)
+ · Fix example .service file (fd.o #66481, Chengwei Yang)
+ · Don't claim D-Bus is "low-latency" (lower than what?), just
+ give factual statements about it supporting async use
+ (fd.o #65141, Justin Lee)
+ · Document the contents of .service files, and the fact that
+ system services' filenames are constrained
+ (fd.o #66608; Simon McVittie, Chengwei Yang)
+
+• Be thread-safe by default on all platforms, even if
+ dbus_threads_init_default() has not been called. For compatibility with
+ older libdbus, library users should continue to call
+ dbus_threads_init_default(): it is harmless to do so.
+ (fd.o #54972, Simon McVittie)
+
+• Add GetConnectionCredentials() method (fd.o #54445, Simon)
+
+• New API: dbus_setenv(), a simple wrapper around setenv().
+ Note that this is not thread-safe. (fd.o #39196, Simon)
+
+• Add dbus-send --peer=ADDRESS (connect to a given peer-to-peer connection,
+ like --address=ADDRESS in previous versions) and dbus-send --bus=ADDRESS
+ (connect to a given bus, like dbus-monitor --address=ADDRESS).
+ dbus-send --address still exists for backwards compatibility,
+ but is no longer documented. (fd.o #48816, Andrey Mazo)
+
+• Windows-specific:
+ · "dbus-daemon --nofork" is allowed on Windows again. (fd.o #68852,
+ Simon McVittie)
+
+Fixes:
+
+• Avoid an infinite busy-loop if a signal interrupts waitpid()
+ (fd.o #68945, Simon McVittie)
+
+• Clean up memory for parent nodes when objects are unexported
+ (fd.o #60176, Thomas Fitzsimmons)
+
+• Make dbus_connection_set_route_peer_messages(x, FALSE) behave as
+ documented. Previously, it assumed its second parameter was TRUE.
+ (fd.o #69165, Chengwei Yang)
+
+• Escape addresses containing non-ASCII characters correctly
+ (fd.o #53499, Chengwei Yang)
+
+• Document <servicedir> search order correctly (fd.o #66994, Chengwei Yang)
+
+• Don't crash on "dbus-send --session / x.y.z" which regressed in 1.7.4.
+ (fd.o #65923, Chengwei Yang)
+
+• If malloc() returns NULL in _dbus_string_init() or similar, don't free
+ an invalid pointer if the string is later freed (fd.o #65959, Chengwei Yang)
+
+• If malloc() returns NULL in dbus_set_error(), don't va_end() a va_list
+ that was never va_start()ed (fd.o #66300, Chengwei Yang)
+
+• fix build failure with --enable-stats (fd.o #66004, Chengwei Yang)
+
+• fix a regression test on platforms with strict alignment (fd.o #67279,
+ Colin Walters)
+
+• Avoid calling function parameters "interface" since certain Windows headers
+ have a namespace-polluting macro of that name (fd.o #66493, Ivan Romanov)
+
+• Assorted Doxygen fixes (fd.o #65755, Chengwei Yang)
+
+• Various thread-safety improvements to static variables (fd.o #68610,
+ Simon McVittie)
+
+• Make "make -j check" work (fd.o #68852, Simon McVittie)
+
+• Fix a NULL pointer dereference on an unlikely error path
+ (fd.o #69327, Sviatoslav Chagaev)
+
+• Improve valgrind memory pool tracking (fd.o #69326,
+ Sviatoslav Chagaev)
+
+• Don't over-allocate memory in dbus-monitor (fd.o #69329,
+ Sviatoslav Chagaev)
+
+• dbus-monitor can monitor dbus-daemon < 1.5.6 again
+ (fd.o #66107, Chengwei Yang)
+
+• Unix-specific:
+ · If accept4() fails with EINVAL, as it can on older Linux kernels
+ with newer glibc, try accept() instead of going into a busy-loop.
+ (fd.o #69026, Chengwei Yang)
+ · If socket() or socketpair() fails with EINVAL or EPROTOTYPE,
+ for instance on Hurd or older Linux with a new glibc, try without
+ SOCK_CLOEXEC. (fd.o #69073; Pino Toscano, Chengwei Yang)
+ · Fix a file descriptor leak on an error code path.
+ (fd.o #69182, Sviatoslav Chagaev)
+ · dbus-run-session: clear some unwanted environment variables
+ (fd.o #39196, Simon)
+ · dbus-run-session: compile on FreeBSD (fd.o #66197, Chengwei Yang)
+ · Don't fail the autolaunch test if there is no DISPLAY (fd.o #40352, Simon)
+ · Use dbus-launch from the builddir for testing, not the installed copy
+ (fd.o #37849, Chengwei Yang)
+ · Fix compilation if writev() is unavailable (fd.o #69409,
+ Vasiliy Balyasnyy)
+ · Remove broken support for LOCAL_CREDS credentials passing, and
+ document where each credential-passing scheme is used (fd.o #60340,
+ Simon McVittie)
+ · Make autogen.sh work on *BSD by not assuming GNU coreutils functionality
+ (fd.o #35881, #69787; Chengwei Yang)
+ · dbus-monitor: be portable to NetBSD (fd.o #69842, Chengwei Yang)
+ · dbus-launch: stop using non-portable asprintf (fd.o #37849, Simon)
+ · Improve error reporting from the setuid activation helper (fd.o #66728,
+ Chengwei Yang)
+
+• Windows-specific:
+ · Remove unavailable command-line options from 'dbus-daemon --help'
+ (fd.o #42441, Ralf Habacker)
+ · Add support for looking up local TCPv4 clients' credentials on
+ Windows XP via the undocumented AllocateAndGetTcpExTableFromStack
+ function (fd.o #66060, Ralf Habacker)
+ · Fix insufficient dependency-tracking (fd.o #68505, Simon McVittie)
+ · Don't include wspiapi.h, fixing a compiler warning (fd.o #68852,
+ Simon McVittie)
+
+• Internal changes:
+ · add DBUS_ENABLE_ASSERT, DBUS_ENABLE_CHECKS for less confusing
+ conditionals (fd.o #66142, Chengwei Yang)
+ · improve verbose-mode output (fd.o #63047, Colin Walters)
+ · consolidate Autotools and CMake build (fd.o #64875, Ralf Habacker)
+ · fix various unused variables, unusual build configurations
+ etc. (fd.o #65712, #65990, #66005, #66257, #69165, #69410, #70218;
+ Chengwei Yang, Vasiliy Balyasnyy)
+
+D-Bus 1.7.4 (2013-06-13)
+==
+
+The “but is your thread-safety thread-safe?” release.
+
+Security fixes:
+
+• CVE-2013-2168: Fix misuse of va_list that could be used as a denial
+ of service for system services. Vulnerability reported by Alexandru Cornea.
+ (Simon)
+
+Dependencies:
+
+• The Windows version of libdbus now contains a C++ source file, used
+ to provide global initialization when the library is loaded.
+ gcc (mingw*) users should ensure that g++ is also installed.
+
+• The libxml2-based configuration reader (which hasn't worked for 2.5 years,
+ and was never the recommended option) has been removed. Expat is now a
+ hard dependency.
+
+Enhancements:
+
+• It should now be safe to call dbus_threads_init_default() from any thread,
+ at any time. Authors of loadable modules and plugins that use libdbus
+ should consider doing so during initialization.
+ (fd.o #54972, Simon McVittie)
+
+• Improve dbus-send documentation and command-line parsing (fd.o #65424,
+ Chengwei Yang)
+
+Unix-specific:
+ · dbus-run-session: experimental new tool to start a temporary D-Bus
+ session, e.g. for regression tests or a text console, replacing
+ certain uses of dbus-launch which weren't really correct
+ (fd.o #39196, Simon)
+
+Other fixes:
+
+• In dbus-daemon, don't crash if a .service file starts with key=value
+ (fd.o #60853, Chengwei Yang)
+
+• Unix-specific:
+ · Fix a crash similar to CVE-2013-2168 the first time we try to use syslog
+ on a platform not defining LOG_PERROR, such as Solaris or QNX.
+ This regressed in 1.7.0. (Simon)
+ · Fix an assertion failure if we try to activate systemd services before
+ systemd connects to the bus (fd.o #50199, Chengwei Yang)
+ · Avoid compiler warnings for ignoring the return from write()
+ (Chengwei Yang)
+
+• Windows-specific:
+ · Under cmake, install runtime libraries (DLLs) into bin/ instead of lib/
+ so that Windows finds them (fd.o #59733, Ralf Habacker)
+
+D-Bus 1.7.2 (2013-04-25)
+==
+
+The “only partially opaque” release.
+
+Configuration changes:
+
+• On non-QNX Unix platforms, the default limit on fds per message in the
+ session bus configuration has reduced from 4096 to 1024. The default
+ limit used on the system bus was already 1024. On QNX, both limits are
+ reduced further, to 128.
+
+Enhancements:
+
+• D-Bus Specification 0.21
+ · Following Unicode Corrigendum #9, the noncharacters U+nFFFE, U+nFFFF,
+ U+FDD0..U+FDEF are allowed in UTF-8 strings again. (fd.o #63072,
+ Simon McVittie)
+
+Fixes:
+
+• Diagnose incorrect use of dbus_connection_get_data() with negative slot
+ (i.e. before allocating the slot) rather than returning junk
+ (fd.o #63127, Dan Williams)
+
+• Fix a cmake build regression since 1.7.0 (fd.o #63682; Ralf Habacker,
+ Simon McVittie)
+
+• Unix-specific:
+ · On Linux, link successfully with glibc 2.17 (fd.o #63166, Simon McVittie)
+  · Under systemd, log to syslog only, not stderr, avoiding duplication
+ (fd.o #61399, #39987; Colin Walters, Dagobert Michelsen)
+ · Under systemd, remove unnecessary dependency on syslog.socket
+ (fd.o #63531, Cristian Rodríguez)
+ · 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)
+ · Reduce the default limit on number of fds per message to 128 under
+ QNX, working around an arbitrary OS limit (fd.o #61176, Matt Fischer)
+
+• Windows-specific:
+ · Do not claim that all bus clients have the dbus-daemon's credentials;
+ pick up local TCPv4 clients' credentials (process ID and security
+ identifier, i.e. user) using GetExtendedTcpTable() (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)
+
+• Merge <servicehelper> from system-local.conf if necessary (fd.o #51560,
+ Krzysztof Konopko)
+
+• 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:
+ · 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)
+==
+
+The "Fix one thing, break another" release.
+
+• Follow up to CVE-2012-3524: The additional hardening
+ work to use __secure_getenv() as a followup to bug #52202
+ broke certain configurations of gnome-keyring. Given
+ the difficulty of making this work without extensive
+ changes to gnome-keyring, use of __secure_getenv() is
+ deferred.
+
+D-Bus 1.6.6 (2012-09-28)
+==
+
+The "Clear the environment in your setuid binaries, please" release.
+
+• CVE-2012-3524: Don't access environment variables (fd.o #52202)
+ Thanks to work and input from Colin Walters, Simon McVittie,
+ Geoffrey Thomas, and others.
+• Unix-specific:
+ · Fix compilation on Solaris (fd.o #53286, Jonathan Perkin)
+ · Work around interdependent headers on OpenBSD by including sys/types.h
+ before each use of sys/socket.h (fd.o #54418, Brad Smith)
+
+D-Bus 1.6.4 (2012-07-18)
+==
+
+• Detect that users are "at the console" correctly when configured with
+ a non-default path such as --enable-console-auth-dir=/run/console
+ (fd.o #51521, Dave Reisner)
+
+• Remove an incorrect assertion from DBusTransport (fd.o #51657,
+ Simon McVittie)
+
+• Make --enable-developer default to "no" (regression in 1.6.2;
+ fd.o #51657, Simon McVittie)
+
+• Windows-specific:
+ · Launch dbus-daemon correctly if its path contains a space
+ (fd.o #49450, Wolfgang Baron)
+
+D-Bus 1.6.2 (2012-06-27)
+==
+
+The "Ice Cabbage" release.
+
+• Change how we create /var/lib/dbus so it works under Automake >= 1.11.4
+ (fd.o #51406, Simon McVittie)
+
+• Don't return from dbus_pending_call_set_notify with a lock held on OOM
+ (fd.o #51032, Simon McVittie)
+
+• Disconnect "developer mode" (assertions, verbose mode etc.) from
+ Automake maintainer mode. D-Bus developers should now configure with
+ --enable-developer. Automake maintainer mode is now on by default;
+ distributions can disable it with --disable-maintainer-mode.
+ (fd.o #34671, Simon McVittie)
+
+• Automatically define DBUS_STATIC_BUILD in static-only Autotools builds,
+ fixing linking when targeting Windows (fd.o #33973; william, Simon McVittie)
+
+• Unix-specific:
+ · Check for libpthread under CMake on Unix (fd.o #47237, Simon McVittie)
+
+D-Bus 1.6.0 (2012-06-05)
+==
+
+The “soul of this machine has improved” release.
+
+This version starts a new stable branch of D-Bus: only bug fixes will
+be accepted into 1.6.x. Other changes will now go to the 1.7.x branch.
+
+Summary of changes since 1.4.x:
+
+• New requirements
+ · PTHREAD_MUTEX_RECURSIVE on Unix
+ · compiler support for 64-bit integers (int64_t or equivalent)
+
+• D-Bus Specification v0.19
+
+• New dbus-daemon features
+ · <allow own_prefix="com.example.Service"/> rules allow the service to
+ own names like com.example.Service.Instance3
+ · optional systemd integration when checking at_console policies
+ · --nopidfile option, mainly for use by systemd
+ · path_namespace and arg0namespace may appear in match rules
+ · eavesdropping is disabled unless the match rule contains eavesdrop=true
+
+• New public API
+ · functions to validate various string types (dbus_validate_path() etc.)
+ · dbus_type_is_valid()
+ · DBusBasicValue, a union of every basic type
+
+• Bug fixes
+ · removed an unsafe reimplementation of recursive mutexes
+ · dbus-daemon no longer busy-loops if it has far too many file descriptors
+ · dbus-daemon.exe --print-address works on Windows
+ · all the other bug fixes from 1.4.20
+
+• Other major implementation changes
+ · on Linux, dbus-daemon uses epoll if supported, for better scalability
+ · dbus_threads_init() ignores its argument and behaves like
+ dbus_threads_init_default() instead
+ · removed the per-connection link cache, improving dbus-daemon performance
+
+• Developer features
+ · optional Valgrind instrumentation (--with-valgrind)
+ · optional Stats interface on the dbus-daemon (--enable-stats)
+ · optionally abort whenever malloc() fails (--enable-embedded-tests
+ and export DBUS_MALLOC_CANNOT_FAIL=1)
+
+Changes since 1.5.12:
+
+• Be more careful about monotonic time vs. real time, fixing DBUS_COOKIE_SHA1
+ spec-compliance (fd.o #48580, David Zeuthen)
+
+• Don't use install(1) within the source/build trees, fixing the build as
+ non-root when using OpenBSD install(1) (fd.o #48217, Antoine Jacoutot)
+
+• Add missing commas in some tcp and nonce-tcp addresses, and remove
+ an unused duplicate copy of the nonce-tcp transport in Windows builds
+ (fd.o #45896, Simon McVittie)
D-Bus 1.5.12 (2012-03-27)
==
diff --git a/README b/README
index fd832ca9..aea83300 100644
--- a/README
+++ b/README
@@ -66,7 +66,9 @@ Configuration
dbus could be build by using autotools or cmake.
When using autotools the configure step is initiated by running ./configure
-with or without additional configuration flags.
+with or without additional configuration flags. dbus requires GNU Make
+(on BSD systems, this is typically called gmake) or a "make" implementation
+with compatible extensions.
When using cmake the configure step is initiated by running the cmake
program with or without additional configuration flags.
diff --git a/README.cmake b/README.cmake
index 5feaf551..c3c6a170 100644
--- a/README.cmake
+++ b/README.cmake
@@ -80,7 +80,7 @@ Configuration flags
When using the cmake build system the dbus-specific configuration flags that can be given
to the cmake program are these (use -D<key>=<value> on command line). The listed values
-are the defaults.
+are the defaults (in a typical build - some are platform-specific).
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
@@ -103,7 +103,7 @@ DBUS_BUILD_TESTS:BOOL=ON
DBUS_DAEMON_NAME:STRING=dbus-daemon
// Disable assertion checking
-DBUS_DISABLE_ASSERTS:BOOL=OFF
+DBUS_DISABLE_ASSERT:BOOL=OFF
// Disable public API sanity checking
DBUS_DISABLE_CHECKS:BOOL=OFF
@@ -129,18 +129,18 @@ DBUS_HAVE_ATOMIC_INT:BOOL=OFF
// install required system libraries
DBUS_INSTALL_SYSTEM_LIBS:BOOL=OFF
-// session bus default address
-DBUS_SESSION_BUS_DEFAULT_ADDRESS:STRING=nonce-tcp:
+// session bus default listening address
+DBUS_SESSION_BUS_LISTEN_ADDRESS:STRING=autolaunch:
-// system bus default address
-DBUS_SYSTEM_BUS_DEFAULT_ADDRESS:STRING=nonce-tcp:
+// session bus fallback address for clients
+DBUS_SESSION_BUS_CONNECT_ADDRESS:STRING=autolaunch:
+
+// system bus default address (only useful on Unix)
+DBUS_SYSTEM_BUS_DEFAULT_ADDRESS:STRING=unix:path=/var/run/dbus/system_bus_socket
// Use atomic integer implementation for 486
DBUS_USE_ATOMIC_INT_486:BOOL=OFF
-// Use expat (== ON) or libxml2 (==OFF)
-DBUS_USE_EXPAT:BOOL=ON
-
win32 only:
// enable win32 debug port for message output
DBUS_USE_OUTPUT_DEBUG_STRING:BOOL=OFF
@@ -149,10 +149,6 @@ gcc only:
// compile with coverage profiling instrumentation
DBUS_GCOV_ENABLED:BOOL=OFF
-linux only:
-// build with dnotify support
-DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX:BOOL=ON
-
solaris only:
// enable console owner file
HAVE_CONSOLE_OWNER_FILE:BOOL=ON
@@ -160,6 +156,18 @@ HAVE_CONSOLE_OWNER_FILE:BOOL=ON
// Directory to check for console ownership
DBUS_CONSOLE_OWNER_FILE:STRING=/dev/console
+// Linux only:
+// enable inotify as dir watch backend
+DBUS_BUS_ENABLE_INOTIFY:BOOL=ON
+
+*BSD only:
+// 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/README.valgrind b/README.valgrind
new file mode 100644
index 00000000..c13f5304
--- /dev/null
+++ b/README.valgrind
@@ -0,0 +1,24 @@
+Running D-Bus clients with Valgrind
+====
+
+When running programs using libdbus in Valgrind, some special care needs to be
+taken so as to avoid incorrect detection of leaks in libdbus. To avoid these
+false positives, do the following:
+
+* Grab a copy of the D-Bus source code
+
+* Run configure with the --enable-developer and --with-valgrind options
+
+* Run make
+
+* Either make sure your code calls dbus_shutdown() (at least while running in
+ Valgrind) or set DBUS_MESSAGE_CACHE=0 in your environment
+
+* Run Valgrind on your program with the /path/to/dbus/source/dbus/.libs in your
+ LD_LIBRARY_PATH
+
+Your Valgrind log should now be free of any (spurious) libdbus-related leaks.
+
+For the curious, the DBUS_MESSAGE_CACHE=0 is required because by
+default, libdbus uses a recyclable pool of message structs. These help
+performance a bit.
diff --git a/README.win b/README.win
index d18f23d0..bd67c188 100644
--- a/README.win
+++ b/README.win
@@ -19,9 +19,7 @@ and mingw-w64|32 are known to work.
Building
--------
DBus can be built on windows using automake or cmake. See the
-file README for more information.
-Special cmake build instructions can be found in cmake/readme-cmake.txt
-
+file INSTALL for more information.
windbus and dbus4win Ports
--------------------------
@@ -33,10 +31,10 @@ updated with windows specific stuff.
Tests
-----
- dbus library check
- bin\dbus-test.exe <build-root>\test\data
+ bin\test-dbus.exe <build-root>\test\data
- bus daemon check
- bin\bus-test.exe <build-root>\test\data
+ bin\test-bus.exe <build-root>\test\data
- check available names
bin\test_names.exe
@@ -88,13 +86,13 @@ FAQ
The OpenWengo dbus-c++ binding has been ported to windows see in WinDBus svn
(http://sf.net/projects/windbus)
- The related test applicationa are running well.
+ The related test applications are running well.
TODO
----
-Oktober 2010:
+October 2010:
- the code wrapped with DBUS_WIN_FIXME should be inspected if it required for windows
diff --git a/autogen.sh b/autogen.sh
index d139fa47..91d4b09d 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -15,8 +15,8 @@ DIE=0
if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
echo "Activating pre-commit hook."
- cp -av .git/hooks/pre-commit.sample .git/hooks/pre-commit
- chmod -c +x .git/hooks/pre-commit
+ cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
+ chmod +x .git/hooks/pre-commit
fi
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
@@ -48,7 +48,7 @@ fi
}
LIBTOOLIZE=`which libtoolize`
-if ! test -f $LIBTOOLIZE; then
+if ! test -f "$LIBTOOLIZE"; then
LIBTOOLIZE=`which glibtoolize`
fi
@@ -101,11 +101,5 @@ else
fi
if $run_configure; then
- $srcdir/configure --enable-maintainer-mode --config-cache "$@"
- echo
- echo "Now type 'make' to compile $PROJECT."
-else
- echo
- echo "Now run 'configure' and 'make' to compile $PROJECT."
+ $srcdir/configure --enable-developer --config-cache "$@"
fi
-
diff --git a/bus/.gitignore b/bus/.gitignore
index 861dc1f5..d856369b 100644
--- a/bus/.gitignore
+++ b/bus/.gitignore
@@ -13,14 +13,14 @@ dbus-daemon-launch-helper-test
*.bbg
*.da
*.gcov
-bus-test
+test-bus
rc.messagebus
messagebus
messagebus-config
session.conf
system.conf
-bus-test-launch-helper
-bus-test-system
+test-bus-launch-helper
+test-bus-system
dbus.service
dbus.socket
org.freedesktop.dbus-session.plist
diff --git a/bus/Makefile.am b/bus/Makefile.am
index 6cbc09a6..f335e30c 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -42,12 +42,7 @@ agentdir=$(LAUNCHD_AGENT_DIR)
agent_DATA=org.freedesktop.dbus-session.plist
endif
-if DBUS_USE_LIBXML
-XML_SOURCES=config-loader-libxml.c
-endif
-if DBUS_USE_EXPAT
XML_SOURCES=config-loader-expat.c
-endif
if DBUS_BUS_ENABLE_KQUEUE
DIR_WATCH_SOURCE=dir-watch-kqueue.c
@@ -55,13 +50,9 @@ else
if DBUS_BUS_ENABLE_INOTIFY
DIR_WATCH_SOURCE=dir-watch-inotify.c
else
-if DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
-DIR_WATCH_SOURCE=dir-watch-dnotify.c
-else
DIR_WATCH_SOURCE=dir-watch-default.c
endif
endif
-endif
BUS_SOURCES= \
activation.c \
@@ -149,15 +140,15 @@ dbus_daemon_launch_helper_test_CPPFLAGS = \
## we build yet another binary so we can do the OOM tests
## DO NOT INSTALL THIS FILE
-bus_test_launch_helper_SOURCES= \
+test_bus_launch_helper_SOURCES= \
test-launch-helper.c \
$(LAUNCH_HELPER_SOURCES)
-bus_test_launch_helper_LDADD= \
+test_bus_launch_helper_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
-bus_test_launch_helper_CPPFLAGS = \
+test_bus_launch_helper_CPPFLAGS = \
$(AM_CPPFLAGS) \
-DACTIVATION_LAUNCHER_TEST \
-DACTIVATION_LAUNCHER_DO_OOM
@@ -173,23 +164,23 @@ endif DBUS_UNIX
## compiled, so we don't put them in TESTS here; we run them in test/
## instead.
-if DBUS_BUILD_TESTS
+if DBUS_ENABLE_EMBEDDED_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS so that we build
## even when not doing "make check"
# run as a test by test/Makefile.am
-noinst_PROGRAMS += bus-test bus-test-system
+noinst_PROGRAMS += test-bus test-bus-system
if DBUS_UNIX
# run as a test by test/Makefile.am
-noinst_PROGRAMS += bus-test-launch-helper
+noinst_PROGRAMS += test-bus-launch-helper
# this is used by the tests but is not,itself, a test
noinst_PROGRAMS += dbus-daemon-launch-helper-test
endif DBUS_UNIX
-endif DBUS_BUILD_TESTS
+endif DBUS_ENABLE_EMBEDDED_TESTS
-bus_test_system_SOURCES= \
+test_bus_system_SOURCES= \
$(XML_SOURCES) \
config-parser-common.c \
config-parser-common.h \
@@ -199,13 +190,13 @@ bus_test_system_SOURCES= \
utils.h \
test-system.c
-bus_test_system_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
+test_bus_system_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
-bus_test_SOURCES= \
+test_bus_SOURCES= \
$(BUS_SOURCES) \
test-main.c
-bus_test_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
+test_bus_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
## mop up the gcov files
clean-local:
diff --git a/bus/activation-helper-bin.c b/bus/activation-helper-bin.c
index a360acc7..f5f16d2c 100644
--- a/bus/activation-helper-bin.c
+++ b/bus/activation-helper-bin.c
@@ -45,6 +45,9 @@ convert_error_to_exit_code (DBusError *error)
return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_INVALID))
+ return BUS_SPAWN_EXIT_CODE_NAME_INVALID;
+
+ if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND))
return BUS_SPAWN_EXIT_CODE_SERVICE_NOT_FOUND;
if (dbus_error_has_name (error, DBUS_ERROR_SPAWN_PERMISSIONS_INVALID))
@@ -65,7 +68,7 @@ convert_error_to_exit_code (DBusError *error)
/* should we assert? */
fprintf(stderr, "%s: %s\n", error->name, error->message);
- return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
+ return BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE;
}
int
diff --git a/bus/activation-helper.c b/bus/activation-helper.c
index ab9d6010..394f3938 100644
--- a/bus/activation-helper.c
+++ b/bus/activation-helper.c
@@ -40,6 +40,7 @@
#include <pwd.h>
#include <grp.h>
+#include <dbus/dbus-misc.h>
#include <dbus/dbus-shell.h>
#include <dbus/dbus-marshal-validate.h>
@@ -140,21 +141,12 @@ out_all:
return desktop_file;
}
-/* Cleares the environment, except for DBUS_VERBOSE and DBUS_STARTER_x */
+/* Clears the environment, except for DBUS_STARTER_x,
+ * which we hardcode to the system bus.
+ */
static dbus_bool_t
clear_environment (DBusError *error)
{
- const char *starter_env = NULL;
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- const char *debug_env = NULL;
-
- /* are we debugging */
- debug_env = _dbus_getenv ("DBUS_VERBOSE");
-#endif
-
- /* we save the starter */
- starter_env = _dbus_getenv ("DBUS_STARTER_ADDRESS");
-
#ifndef ACTIVATION_LAUNCHER_TEST
/* totally clear the environment */
if (!_dbus_clearenv ())
@@ -163,21 +155,12 @@ clear_environment (DBusError *error)
"could not clear environment\n");
return FALSE;
}
-#endif
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- /* restore the debugging environment setting if set */
- if (debug_env)
- _dbus_setenv ("DBUS_VERBOSE", debug_env);
+ /* Ensure the bus is set to system */
+ dbus_setenv ("DBUS_STARTER_ADDRESS", DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
+ dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system");
#endif
- /* restore the starter */
- if (starter_env)
- _dbus_setenv ("DBUS_STARTER_ADDRESS", starter_env);
-
- /* set the type, which must be system if we got this far */
- _dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system");
-
return TRUE;
}
@@ -389,7 +372,7 @@ check_bus_name (const char *bus_name,
_dbus_string_init_const (&str, bus_name);
if (!_dbus_validate_bus_name (&str, 0, _dbus_string_get_length (&str)))
{
- dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND,
+ dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_INVALID,
"bus name '%s' is not a valid bus name\n",
bus_name);
return FALSE;
diff --git a/bus/activation.c b/bus/activation.c
index 3dfba787..fa6c1568 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -80,7 +80,14 @@ typedef struct BusPendingActivationEntry BusPendingActivationEntry;
struct BusPendingActivationEntry
{
+ /* Normally a method call, but if connection is NULL, this is a signal
+ * instead.
+ */
DBusMessage *activation_message;
+ /* NULL if this activation entry is for the dbus-daemon itself,
+ * waiting for systemd to start. In this case, auto_activation is always
+ * TRUE.
+ */
DBusConnection *connection;
dbus_bool_t auto_activation;
@@ -1106,7 +1113,8 @@ bus_activation_service_created (BusActivation *activation,
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- if (dbus_connection_get_is_connected (entry->connection))
+ /* entry->connection is NULL for activating systemd */
+ if (entry->connection && dbus_connection_get_is_connected (entry->connection))
{
/* Only send activation replies to regular activation requests. */
if (!entry->auto_activation)
@@ -1175,7 +1183,7 @@ bus_activation_send_pending_auto_activation_messages (BusActivation *activation
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- if (entry->auto_activation && dbus_connection_get_is_connected (entry->connection))
+ if (entry->auto_activation && (entry->connection == NULL || dbus_connection_get_is_connected (entry->connection)))
{
DBusConnection *addressed_recipient;
@@ -1233,7 +1241,7 @@ try_send_activation_failure (BusPendingActivation *pending_activation,
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- if (dbus_connection_get_is_connected (entry->connection))
+ if (entry->connection && dbus_connection_get_is_connected (entry->connection))
{
if (!bus_transaction_send_error_reply (transaction,
entry->connection,
@@ -1281,6 +1289,10 @@ handle_servicehelper_exit_error (int exit_code,
{
switch (exit_code)
{
+ case BUS_SPAWN_EXIT_CODE_CONFIG_INVALID:
+ dbus_set_error (error, DBUS_ERROR_SPAWN_CONFIG_INVALID,
+ "Invalid configuration (missing or empty <user>?)");
+ break;
case BUS_SPAWN_EXIT_CODE_NO_MEMORY:
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
"Launcher could not run (out of memory)");
@@ -1317,6 +1329,7 @@ handle_servicehelper_exit_error (int exit_code,
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED,
"Launched child was signaled, it probably crashed");
break;
+ case BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE:
default:
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
"Launch helper exited with unknown return code %i", exit_code);
@@ -1759,7 +1772,8 @@ bus_activation_activate_service (BusActivation *activation,
pending_activation_entry->activation_message = activation_message;
dbus_message_ref (activation_message);
pending_activation_entry->connection = connection;
- dbus_connection_ref (connection);
+ if (connection)
+ dbus_connection_ref (connection);
/* Check if the service is being activated */
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name);
@@ -1972,7 +1986,7 @@ bus_activation_activate_service (BusActivation *activation,
service_name,
entry->systemd_service);
/* systemd is not around, let's "activate" it. */
- retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE,
+ retval = bus_activation_activate_service (activation, NULL, activation_transaction, TRUE,
message, "org.freedesktop.systemd1", error);
}
@@ -2090,7 +2104,9 @@ bus_activation_activate_service (BusActivation *activation,
dbus_error_init (&tmp_error);
- if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, argv,
+ if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter,
+ service_name,
+ argv,
envp,
NULL, activation,
&tmp_error))
@@ -2170,7 +2186,7 @@ bus_activation_list_services (BusActivation *activation,
error:
for (j = 0; j < i; j++)
- dbus_free (retval[i]);
+ dbus_free (retval[j]);
dbus_free (retval);
return FALSE;
@@ -2223,7 +2239,7 @@ dbus_activation_systemd_failure (BusActivation *activation,
return TRUE;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
@@ -2530,11 +2546,17 @@ dbus_bool_t
bus_activation_service_reload_test (const DBusString *test_data_dir)
{
DBusString directory;
+ const char *tmp;
if (!_dbus_string_init (&directory))
return FALSE;
- if (!_dbus_string_append (&directory, _dbus_get_tmpdir()))
+ tmp = _dbus_get_tmpdir ();
+
+ if (tmp == NULL)
+ return FALSE;
+
+ if (!_dbus_string_append (&directory, tmp))
return FALSE;
if (!_dbus_string_append (&directory, "/dbus-reload-test-") ||
@@ -2570,4 +2592,4 @@ bus_activation_service_reload_test (const DBusString *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/bus.c b/bus/bus.c
index e80e7080..a514e31d 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -287,7 +287,7 @@ process_config_first_time_only (BusContext *context,
auth_mechanisms = NULL;
pidfile = NULL;
- _dbus_init_system_log ();
+ _dbus_init_system_log (TRUE);
if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION)
context->systemd_activation = TRUE;
@@ -526,6 +526,18 @@ process_config_every_time (BusContext *context,
context->policy = bus_config_parser_steal_policy (parser);
_dbus_assert (context->policy != NULL);
+ /* context->connections is NULL when creating new BusContext */
+ if (context->connections)
+ {
+ _dbus_verbose ("Reload policy rules for completed connections\n");
+ retval = bus_connections_reload_policy (context->connections, error);
+ if (!retval)
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ goto failed;
+ }
+ }
+
/* We have to build the address backward, so that
* <listen> later in the config file have priority
*/
@@ -894,7 +906,7 @@ bus_context_new (const DBusString *config_file,
if (!bus_selinux_full_init ())
{
- bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but AVC initialization failed; check system log\n");
+ bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but D-Bus initialization failed; check system log\n");
}
if (!process_config_postinit (context, parser, error))
diff --git a/bus/config-loader-libxml.c b/bus/config-loader-libxml.c
deleted file mode 100644
index c73a1815..00000000
--- a/bus/config-loader-libxml.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* config-loader-libxml.c libxml2 XML loader
- *
- * Copyright (C) 2003 Red Hat, Inc.
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include <config.h>
-#include "config-parser.h"
-#include <dbus/dbus-internals.h>
-#include <libxml/xmlreader.h>
-#include <libxml/parser.h>
-#include <libxml/globals.h>
-#include <libxml/xmlmemory.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#include <string.h>
-
-/* About the error handling:
- * - setup a "structured" error handler that catches structural
- * errors and some oom errors
- * - assume that a libxml function returning an error code means
- * out-of-memory
- */
-#define _DBUS_MAYBE_SET_OOM(e) (dbus_error_is_set(e) ? (void)0 : _DBUS_SET_OOM(e))
-
-
-static dbus_bool_t
-xml_text_start_element (BusConfigParser *parser,
- xmlTextReader *reader,
- DBusError *error)
-{
- const char *name;
- int n_attributes;
- const char **attribute_names, **attribute_values;
- dbus_bool_t ret;
- int i, status, is_empty;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- ret = FALSE;
- attribute_names = NULL;
- attribute_values = NULL;
-
- name = xmlTextReaderConstName (reader);
- n_attributes = xmlTextReaderAttributeCount (reader);
- is_empty = xmlTextReaderIsEmptyElement (reader);
-
- if (name == NULL || n_attributes < 0 || is_empty == -1)
- {
- _DBUS_MAYBE_SET_OOM (error);
- goto out;
- }
-
- attribute_names = dbus_new0 (const char *, n_attributes + 1);
- attribute_values = dbus_new0 (const char *, n_attributes + 1);
- if (attribute_names == NULL || attribute_values == NULL)
- {
- _DBUS_SET_OOM (error);
- goto out;
- }
- i = 0;
- while ((status = xmlTextReaderMoveToNextAttribute (reader)) == 1)
- {
- _dbus_assert (i < n_attributes);
- attribute_names[i] = xmlTextReaderConstName (reader);
- attribute_values[i] = xmlTextReaderConstValue (reader);
- if (attribute_names[i] == NULL || attribute_values[i] == NULL)
- {
- _DBUS_MAYBE_SET_OOM (error);
- goto out;
- }
- i++;
- }
- if (status == -1)
- {
- _DBUS_MAYBE_SET_OOM (error);
- goto out;
- }
- _dbus_assert (i == n_attributes);
-
- ret = bus_config_parser_start_element (parser, name,
- attribute_names, attribute_values,
- error);
- if (ret && is_empty == 1)
- ret = bus_config_parser_end_element (parser, name, error);
-
- out:
- dbus_free (attribute_names);
- dbus_free (attribute_values);
-
- return ret;
-}
-
-static void xml_shut_up (void *ctx, const char *msg, ...)
-{
- return;
-}
-
-static void
-xml_text_reader_error (void *arg, xmlErrorPtr xml_error)
-{
- DBusError *error = arg;
-
-#if 0
- _dbus_verbose ("XML_ERROR level=%d, domain=%d, code=%d, msg=%s\n",
- xml_error->level, xml_error->domain,
- xml_error->code, xml_error->message);
-#endif
-
- if (!dbus_error_is_set (error))
- {
- if (xml_error->code == XML_ERR_NO_MEMORY)
- _DBUS_SET_OOM (error);
- else if (xml_error->level == XML_ERR_ERROR ||
- xml_error->level == XML_ERR_FATAL)
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Error loading config file: '%s'",
- xml_error->message);
- }
-}
-
-
-BusConfigParser*
-bus_config_load (const DBusString *file,
- dbus_bool_t is_toplevel,
- const BusConfigParser *parent,
- DBusError *error)
-
-{
- xmlTextReader *reader;
- BusConfigParser *parser;
- DBusString dirname, data;
- DBusError tmp_error;
- int ret;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- parser = NULL;
- reader = NULL;
-
- if (!_dbus_string_init (&dirname))
- {
- _DBUS_SET_OOM (error);
- return NULL;
- }
-
- if (!_dbus_string_init (&data))
- {
- _DBUS_SET_OOM (error);
- _dbus_string_free (&dirname);
- return NULL;
- }
-
- if (is_toplevel)
- {
- /* xmlMemSetup only fails if one of the functions is NULL */
- xmlMemSetup (dbus_free,
- dbus_malloc,
- dbus_realloc,
- _dbus_strdup);
- xmlInitParser ();
- xmlSetGenericErrorFunc (NULL, xml_shut_up);
- }
-
- if (!_dbus_string_get_dirname (file, &dirname))
- {
- _DBUS_SET_OOM (error);
- goto failed;
- }
-
- parser = bus_config_parser_new (&dirname, is_toplevel, parent);
- if (parser == NULL)
- {
- _DBUS_SET_OOM (error);
- goto failed;
- }
-
- if (!_dbus_file_get_contents (&data, file, error))
- goto failed;
-
- reader = xmlReaderForMemory (_dbus_string_get_const_data (&data),
- _dbus_string_get_length (&data),
- NULL, NULL, 0);
- if (reader == NULL)
- {
- _DBUS_SET_OOM (error);
- goto failed;
- }
-
- xmlTextReaderSetParserProp (reader, XML_PARSER_SUBST_ENTITIES, 1);
-
- dbus_error_init (&tmp_error);
- xmlTextReaderSetStructuredErrorHandler (reader, xml_text_reader_error, &tmp_error);
-
- while ((ret = xmlTextReaderRead (reader)) == 1)
- {
- int type;
-
- if (dbus_error_is_set (&tmp_error))
- goto reader_out;
-
- type = xmlTextReaderNodeType (reader);
- if (type == -1)
- {
- _DBUS_MAYBE_SET_OOM (&tmp_error);
- goto reader_out;
- }
-
- switch ((xmlReaderTypes) type) {
- case XML_READER_TYPE_ELEMENT:
- xml_text_start_element (parser, reader, &tmp_error);
- break;
-
- case XML_READER_TYPE_TEXT:
- case XML_READER_TYPE_CDATA:
- {
- DBusString content;
- const char *value;
- value = xmlTextReaderConstValue (reader);
- if (value != NULL)
- {
- _dbus_string_init_const (&content, value);
- bus_config_parser_content (parser, &content, &tmp_error);
- }
- else
- _DBUS_MAYBE_SET_OOM (&tmp_error);
- break;
- }
-
- case XML_READER_TYPE_DOCUMENT_TYPE:
- {
- const char *name;
- name = xmlTextReaderConstName (reader);
- if (name != NULL)
- bus_config_parser_check_doctype (parser, name, &tmp_error);
- else
- _DBUS_MAYBE_SET_OOM (&tmp_error);
- break;
- }
-
- case XML_READER_TYPE_END_ELEMENT:
- {
- const char *name;
- name = xmlTextReaderConstName (reader);
- if (name != NULL)
- bus_config_parser_end_element (parser, name, &tmp_error);
- else
- _DBUS_MAYBE_SET_OOM (&tmp_error);
- break;
- }
-
- case XML_READER_TYPE_DOCUMENT:
- case XML_READER_TYPE_DOCUMENT_FRAGMENT:
- case XML_READER_TYPE_PROCESSING_INSTRUCTION:
- case XML_READER_TYPE_COMMENT:
- case XML_READER_TYPE_ENTITY:
- case XML_READER_TYPE_NOTATION:
- case XML_READER_TYPE_WHITESPACE:
- case XML_READER_TYPE_SIGNIFICANT_WHITESPACE:
- case XML_READER_TYPE_END_ENTITY:
- case XML_READER_TYPE_XML_DECLARATION:
- /* nothing to do, just read on */
- break;
-
- case XML_READER_TYPE_NONE:
- case XML_READER_TYPE_ATTRIBUTE:
- case XML_READER_TYPE_ENTITY_REFERENCE:
- _dbus_assert_not_reached ("unexpected nodes in XML");
- }
-
- if (dbus_error_is_set (&tmp_error))
- goto reader_out;
- }
-
- if (ret == -1)
- _DBUS_MAYBE_SET_OOM (&tmp_error);
-
- reader_out:
- xmlFreeTextReader (reader);
- reader = NULL;
- if (dbus_error_is_set (&tmp_error))
- {
- dbus_move_error (&tmp_error, error);
- goto failed;
- }
-
- if (!bus_config_parser_finished (parser, error))
- goto failed;
- _dbus_string_free (&dirname);
- _dbus_string_free (&data);
- if (is_toplevel)
- xmlCleanupParser();
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
- return parser;
-
- failed:
- _DBUS_ASSERT_ERROR_IS_SET (error);
- _dbus_string_free (&dirname);
- _dbus_string_free (&data);
- if (is_toplevel)
- xmlCleanupParser();
- if (parser)
- bus_config_parser_unref (parser);
- _dbus_assert (reader == NULL); /* must go to reader_out first */
- return NULL;
-}
diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c
index 6ef50f8e..64a05c3a 100644
--- a/bus/config-parser-trivial.c
+++ b/bus/config-parser-trivial.c
@@ -330,7 +330,7 @@ bus_config_parser_get_service_dirs (BusConfigParser *parser)
return &parser->service_dirs;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
#include "test.h"
@@ -712,5 +712,5 @@ finish:
return retval;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/config-parser.c b/bus/config-parser.c
index 07e8fbb6..a6a8e1cf 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -30,6 +30,7 @@
#include "selinux.h"
#include <dbus/dbus-list.h>
#include <dbus/dbus-internals.h>
+#include <dbus/dbus-misc.h>
#include <dbus/dbus-sysdeps.h>
#include <string.h>
@@ -317,13 +318,23 @@ merge_included (BusConfigParser *parser,
if (included->keep_umask)
parser->keep_umask = TRUE;
+ if (included->allow_anonymous)
+ parser->allow_anonymous = TRUE;
+
if (included->pidfile != NULL)
{
dbus_free (parser->pidfile);
parser->pidfile = included->pidfile;
included->pidfile = NULL;
}
-
+
+ if (included->servicehelper != NULL)
+ {
+ dbus_free (parser->servicehelper);
+ parser->servicehelper = included->servicehelper;
+ included->servicehelper = NULL;
+ }
+
while ((link = _dbus_list_pop_first_link (&included->listen_on)))
_dbus_list_append_link (&parser->listen_on, link);
@@ -413,9 +424,9 @@ bus_config_parser_new (const DBusString *basedir,
maximum number of file descriptors we can receive. Picking a
high value here thus translates directly to more memory
allocation. */
- parser->limits.max_incoming_unix_fds = 1024*4;
- parser->limits.max_outgoing_unix_fds = 1024*4;
- parser->limits.max_message_unix_fds = 1024;
+ parser->limits.max_incoming_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
+ parser->limits.max_outgoing_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS*4;
+ parser->limits.max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
/* Making this long means the user has to wait longer for an error
* message if something screws up, but making it too short means
@@ -2735,7 +2746,7 @@ bus_config_parser_steal_service_context_table (BusConfigParser *parser)
return table;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
typedef enum
@@ -3410,10 +3421,10 @@ test_default_session_servicedirs (void)
}
#ifdef DBUS_UNIX
- if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
+ if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
- if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
+ if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
#endif
if (!_dbus_get_standard_session_servicedirs (&dirs))
@@ -3543,10 +3554,10 @@ test_default_system_servicedirs (void)
}
#ifdef DBUS_UNIX
- if (!_dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
+ if (!dbus_setenv ("XDG_DATA_HOME", "/testhome/foo/.testlocal/testshare"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_HOME");
- if (!_dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
+ if (!dbus_setenv ("XDG_DATA_DIRS", ":/testusr/testlocal/testshare: :/testusr/testshare:"))
_dbus_assert_not_reached ("couldn't setenv XDG_DATA_DIRS");
#endif
if (!_dbus_get_standard_system_servicedirs (&dirs))
@@ -3629,5 +3640,5 @@ bus_config_parser_test (const DBusString *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/connection.c b/bus/connection.c
index d69758c9..ea2d155a 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -1435,6 +1435,42 @@ fail:
return FALSE;
}
+dbus_bool_t
+bus_connections_reload_policy (BusConnections *connections,
+ DBusError *error)
+{
+ BusConnectionData *d;
+ DBusConnection *connection;
+ DBusList *link;
+
+ _dbus_assert (connections != NULL);
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ for (link = _dbus_list_get_first_link (&(connections->completed));
+ link;
+ link = _dbus_list_get_next_link (&(connections->completed), link))
+ {
+ connection = link->data;
+ d = BUS_CONNECTION_DATA (connection);
+ _dbus_assert (d != NULL);
+ _dbus_assert (d->policy != NULL);
+
+ bus_client_policy_unref (d->policy);
+ d->policy = bus_context_create_client_policy (connections->context,
+ connection,
+ error);
+ if (d->policy == NULL)
+ {
+ _dbus_verbose ("Failed to create security policy for connection %p\n",
+ connection);
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
const char *
bus_connection_get_name (DBusConnection *connection)
{
@@ -1990,12 +2026,6 @@ bus_transaction_get_context (BusTransaction *transaction)
return transaction->context;
}
-BusConnections*
-bus_transaction_get_connections (BusTransaction *transaction)
-{
- return bus_context_get_connections (transaction->context);
-}
-
dbus_bool_t
bus_transaction_send_from_driver (BusTransaction *transaction,
DBusConnection *connection,
@@ -2126,6 +2156,16 @@ bus_transaction_send (BusTransaction *transaction,
}
static void
+transaction_free (BusTransaction *transaction)
+{
+ _dbus_assert (transaction->connections == NULL);
+
+ free_cancel_hooks (transaction);
+
+ dbus_free (transaction);
+}
+
+static void
connection_cancel_transaction (DBusConnection *connection,
BusTransaction *transaction)
{
@@ -2163,14 +2203,10 @@ bus_transaction_cancel_and_free (BusTransaction *transaction)
while ((connection = _dbus_list_pop_first (&transaction->connections)))
connection_cancel_transaction (connection, transaction);
- _dbus_assert (transaction->connections == NULL);
-
_dbus_list_foreach (&transaction->cancel_hooks,
cancel_hook_cancel, NULL);
- free_cancel_hooks (transaction);
-
- dbus_free (transaction);
+ transaction_free (transaction);
}
static void
@@ -2224,11 +2260,7 @@ bus_transaction_execute_and_free (BusTransaction *transaction)
while ((connection = _dbus_list_pop_first (&transaction->connections)))
connection_execute_transaction (connection, transaction);
- _dbus_assert (transaction->connections == NULL);
-
- free_cancel_hooks (transaction);
-
- dbus_free (transaction);
+ transaction_free (transaction);
}
static void
diff --git a/bus/connection.h b/bus/connection.h
index c9360212..9f4f9aea 100644
--- a/bus/connection.h
+++ b/bus/connection.h
@@ -45,6 +45,8 @@ void bus_connections_foreach_active (BusConnections
void *data);
BusContext* bus_connections_get_context (BusConnections *connections);
void bus_connections_increment_stamp (BusConnections *connections);
+dbus_bool_t bus_connections_reload_policy (BusConnections *connections,
+ DBusError *error);
BusContext* bus_connection_get_context (DBusConnection *connection);
BusConnections* bus_connection_get_connections (DBusConnection *connection);
BusRegistry* bus_connection_get_registry (DBusConnection *connection);
@@ -120,7 +122,6 @@ typedef void (* BusTransactionCancelFunction) (void *data);
BusTransaction* bus_transaction_new (BusContext *context);
BusContext* bus_transaction_get_context (BusTransaction *transaction);
-BusConnections* bus_transaction_get_connections (BusTransaction *transaction);
dbus_bool_t bus_transaction_send (BusTransaction *transaction,
DBusConnection *connection,
DBusMessage *message);
diff --git a/bus/dbus.service.in b/bus/dbus.service.in
index 160947c7..1b0bbb29 100644
--- a/bus/dbus.service.in
+++ b/bus/dbus.service.in
@@ -1,7 +1,6 @@
[Unit]
Description=D-Bus System Message Bus
Requires=dbus.socket
-After=syslog.target
[Service]
ExecStart=@EXPANDED_BINDIR@/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
diff --git a/bus/desktop-file.c b/bus/desktop-file.c
index ae441c5e..bfeb72e2 100644
--- a/bus/desktop-file.c
+++ b/bus/desktop-file.c
@@ -688,6 +688,12 @@ bus_desktop_file_load (DBusString *filename,
else if (is_blank_line (&parser) ||
_dbus_string_get_byte (&parser.data, parser.pos) == '#')
parse_comment_or_blank (&parser);
+ else if (parser.current_section < 0)
+ {
+ dbus_set_error(error, DBUS_ERROR_FAILED,
+ "invalid service file: key=value before [Section]");
+ return NULL;
+ }
else
{
if (!parse_key_value (&parser, error))
diff --git a/bus/desktop-file.h b/bus/desktop-file.h
index 58e78e8f..e405625c 100644
--- a/bus/desktop-file.h
+++ b/bus/desktop-file.h
@@ -34,7 +34,6 @@
#define DBUS_SERVICE_NAME "Name"
#define DBUS_SERVICE_EXEC "Exec"
#define DBUS_SERVICE_USER "User"
-#define DBUS_SERVICE_GROUP "Group"
#define DBUS_SERVICE_SYSTEMD_SERVICE "SystemdService"
typedef struct BusDesktopFile BusDesktopFile;
diff --git a/bus/dir-watch-dnotify.c b/bus/dir-watch-dnotify.c
deleted file mode 100644
index b38d7d19..00000000
--- a/bus/dir-watch-dnotify.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* dir-watch-dnotify.c OS specific directory change notification for message bus
- *
- * Copyright (C) 2003 Red Hat, Inc.
- *
- * Licensed under the Academic Free License version 2.1
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#include <config.h>
-
-#define _GNU_SOURCE
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#include <dbus/dbus-internals.h>
-#include "dir-watch.h"
-
-#define MAX_DIRS_TO_WATCH 128
-
-/* use a static array to avoid handling OOM */
-static int fds[MAX_DIRS_TO_WATCH];
-static int num_fds = 0;
-
-void
-bus_watch_directory (const char *dir, BusContext *context)
-{
- int fd;
-
- _dbus_assert (dir != NULL);
-
- if (num_fds >= MAX_DIRS_TO_WATCH )
- {
- _dbus_warn ("Cannot watch config directory '%s'. Already watching %d directories\n", dir, MAX_DIRS_TO_WATCH);
- goto out;
- }
-
- fd = open (dir, O_RDONLY);
- if (fd < 0)
- {
- _dbus_warn ("Cannot open directory '%s'; error '%s'\n", dir, _dbus_strerror (errno));
- goto out;
- }
-
- if (fcntl (fd, F_NOTIFY, DN_CREATE|DN_DELETE|DN_RENAME|DN_MODIFY) == -1)
- {
- _dbus_warn ("Cannot setup D_NOTIFY for '%s' error '%s'\n", dir, _dbus_strerror (errno));
- close (fd);
- goto out;
- }
-
- fds[num_fds++] = fd;
- _dbus_verbose ("Added watch on config directory '%s'\n", dir);
-
- out:
- ;
-}
-
-void
-bus_drop_all_directory_watches (void)
-{
- int i;
-
- _dbus_verbose ("Dropping all watches on config directories\n");
-
- for (i = 0; i < num_fds; i++)
- {
- if (close (fds[i]) != 0)
- {
- _dbus_verbose ("Error closing fd %d for config directory watch\n", fds[i]);
- }
- }
-
- num_fds = 0;
-}
diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c
index 2e9be988..49ebc721 100644
--- a/bus/dir-watch-inotify.c
+++ b/bus/dir-watch-inotify.c
@@ -22,11 +22,15 @@
*
*/
+/* Be careful, this file is not Linux-only: QNX also uses it */
+
#include <config.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
+/* QNX's inotify is broken, and requires stdint.h to be manually included first */
+#include <stdint.h>
#include <sys/inotify.h>
#include <sys/types.h>
#include <signal.h>
@@ -55,32 +59,30 @@ _handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data)
char buffer[INOTIFY_BUF_LEN];
ssize_t ret = 0;
int i = 0;
- pid_t pid;
- dbus_bool_t have_change = FALSE;
ret = read (inotify_fd, buffer, INOTIFY_BUF_LEN);
if (ret < 0)
_dbus_verbose ("Error reading inotify event: '%s'\n", _dbus_strerror(errno));
else if (!ret)
_dbus_verbose ("Error reading inotify event: buffer too small\n");
+ else
+ {
+ _dbus_verbose ("Sending SIGHUP signal on reception of %ld inotify event(s)\n", (long) ret);
+ (void) kill (_dbus_getpid (), SIGHUP);
+ }
+#ifdef DBUS_ENABLE_VERBOSE_MODE
while (i < ret)
{
struct inotify_event *ev;
- pid = _dbus_getpid ();
ev = (struct inotify_event *) &buffer[i];
i += INOTIFY_EVENT_SIZE + ev->len;
-#ifdef DBUS_ENABLE_VERBOSE_MODE
if (ev->len)
_dbus_verbose ("event name: '%s'\n", ev->name);
_dbus_verbose ("inotify event: wd=%d mask=%u cookie=%u len=%u\n", ev->wd, ev->mask, ev->cookie, ev->len);
-#endif
- _dbus_verbose ("Sending SIGHUP signal on reception of a inotify event\n");
- have_change = TRUE;
}
- if (have_change)
- (void) kill (pid, SIGHUP);
+#endif
return TRUE;
}
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c
index ac6290cc..33d5e95d 100644
--- a/bus/dir-watch-kqueue.c
+++ b/bus/dir-watch-kqueue.c
@@ -73,12 +73,12 @@ _handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
{
kq = -1;
if (watch != NULL)
- {
- _dbus_loop_remove_watch (loop, watch);
+ {
+ _dbus_loop_remove_watch (loop, watch);
_dbus_watch_invalidate (watch);
_dbus_watch_unref (watch);
- watch = NULL;
- }
+ watch = NULL;
+ }
pid = getpid ();
_dbus_verbose ("Sending SIGHUP signal since kqueue has been closed\n");
(void) kill (pid, SIGHUP);
@@ -87,11 +87,49 @@ _handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
return TRUE;
}
+static void _shutdown_kqueue (void *data)
+{
+ int i;
+
+ if (kq < 0)
+ return;
+
+ for (i = 0; i < MAX_DIRS_TO_WATCH; i++)
+ {
+ if (fds[i] >= 0)
+ {
+ close (fds[i]);
+ fds[i] = -1;
+ }
+ if (dirs[i] != NULL)
+ {
+ /* dbus_free() is necessary to pass memleak check */
+ dbus_free (dirs[i]);
+ dirs[i] = NULL;
+ }
+ }
+
+ if (loop)
+ {
+ _dbus_loop_remove_watch (loop, watch);
+ _dbus_loop_unref (loop);
+ loop = NULL;
+ }
+
+ if (watch)
+ {
+ _dbus_watch_invalidate (watch);
+ _dbus_watch_unref (watch);
+ watch = NULL;
+ }
+
+ close (kq);
+ kq = -1;
+}
+
static int
_init_kqueue (BusContext *context)
{
- int ret = 0;
-
if (kq < 0)
{
@@ -99,38 +137,61 @@ _init_kqueue (BusContext *context)
if (kq < 0)
{
_dbus_warn ("Cannot create kqueue; error '%s'\n", _dbus_strerror (errno));
- goto out;
- }
-
- loop = bus_context_get_loop (context);
-
- watch = _dbus_watch_new (kq, DBUS_WATCH_READABLE, TRUE,
- _handle_kqueue_watch, NULL, NULL);
-
- if (watch == NULL)
- {
- _dbus_warn ("Unable to create kqueue watch\n");
- close (kq);
- kq = -1;
- goto out;
- }
-
- if (!_dbus_loop_add_watch (loop, watch))
- {
- _dbus_warn ("Unable to add reload watch to main loop");
- _dbus_watch_invalidate (watch);
- _dbus_watch_unref (watch);
- watch = NULL;
- close (kq);
- kq = -1;
- goto out;
- }
+ goto out;
+ }
+
+ loop = bus_context_get_loop (context);
+ _dbus_loop_ref (loop);
+
+ watch = _dbus_watch_new (kq, DBUS_WATCH_READABLE, TRUE,
+ _handle_kqueue_watch, NULL, NULL);
+
+ if (watch == NULL)
+ {
+ _dbus_warn ("Unable to create kqueue watch\n");
+ goto out1;
+ }
+
+ if (!_dbus_loop_add_watch (loop, watch))
+ {
+ _dbus_warn ("Unable to add reload watch to main loop");
+ goto out2;
+ }
+
+ if (!_dbus_register_shutdown_func (_shutdown_kqueue, NULL))
+ {
+ _dbus_warn ("Unable to register shutdown function");
+ goto out3;
+ }
+ }
+
+ return 1;
+
+out3:
+ _dbus_loop_remove_watch (loop, watch);
+
+out2:
+ if (watch)
+ {
+ _dbus_watch_invalidate (watch);
+ _dbus_watch_unref (watch);
+ watch = NULL;
}
- ret = 1;
+out1:
+ if (kq >= 0)
+ {
+ close (kq);
+ kq = -1;
+ }
+ if (loop)
+ {
+ _dbus_loop_unref (loop);
+ loop = NULL;
+ }
out:
- return ret;
+ return 0;
}
void
@@ -139,7 +200,7 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
int new_fds[MAX_DIRS_TO_WATCH];
char *new_dirs[MAX_DIRS_TO_WATCH];
DBusList *link;
- int i, j, f, fd;
+ int i, j, fd;
struct kevent ev;
if (!_init_kqueue (context))
@@ -169,12 +230,12 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0)
{
new_fds[i] = fds[j];
- new_dirs[i] = dirs[j];
- fds[j] = -1;
- dirs[j] = NULL;
- break;
- }
- }
+ new_dirs[i] = dirs[j];
+ fds[j] = -1;
+ dirs[j] = NULL;
+ break;
+ }
+ }
}
/* Any directory we find in "fds" with a nonzero fd must
@@ -185,10 +246,10 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
if (fds[j] != -1)
{
close (fds[j]);
- dbus_free (dirs[j]);
- fds[j] = -1;
- dirs[j] = NULL;
- }
+ dbus_free (dirs[j]);
+ fds[j] = -1;
+ dirs[j] = NULL;
+ }
}
for (i = 0; new_dirs[i]; i++)
@@ -196,9 +257,9 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
if (new_fds[i] == -1)
{
/* FIXME - less lame error handling for failing to add a watch;
- * we may need to sleep.
- */
- fd = open (new_dirs[i], O_RDONLY);
+ * we may need to sleep.
+ */
+ fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC);
if (fd < 0)
{
if (errno != ENOENT)
@@ -223,18 +284,18 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
goto out;
}
- new_fds[i] = fd;
- new_dirs[i] = _dbus_strdup (new_dirs[i]);
- if (!new_dirs[i])
+ new_fds[i] = fd;
+ new_dirs[i] = _dbus_strdup (new_dirs[i]);
+ if (!new_dirs[i])
{
/* FIXME have less lame handling for OOM, we just silently fail to
- * watch. (In reality though, the whole OOM handling in dbus is
- * stupid but we won't go into that in this comment =) )
- */
+ * watch. (In reality though, the whole OOM handling in dbus is
+ * stupid but we won't go into that in this comment =) )
+ */
close (fd);
- new_fds[i] = -1;
- }
- }
+ new_fds[i] = -1;
+ }
+ }
}
num_fds = i;
diff --git a/bus/dispatch.c b/bus/dispatch.c
index 7a96f9dc..7a61953f 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -34,6 +34,7 @@
#include "signals.h"
#include "test.h"
#include <dbus/dbus-internals.h>
+#include <dbus/dbus-misc.h>
#include <string.h>
#ifdef HAVE_UNIX_FD_PASSING
@@ -132,7 +133,7 @@ bus_dispatch_matches (BusTransaction *transaction,
}
/* Now dispatch to others who look interested in this message */
- connections = bus_transaction_get_connections (transaction);
+ connections = bus_context_get_connections (context);
dbus_error_init (&tmp_error);
matchmaker = bus_context_get_matchmaker (context);
@@ -428,7 +429,7 @@ bus_dispatch_remove_connection (DBusConnection *connection)
NULL);
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
@@ -1306,9 +1307,15 @@ check_get_connection_unix_process_id (BusContext *context,
#endif
else
{
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__linux__) || \
+ defined(__OpenBSD__)
warn_unexpected (connection, message, "not this error");
goto out;
+#else
+ _dbus_verbose ("does not support GetConnectionUnixProcessID but perhaps that's OK?\n");
+#endif
}
}
else
@@ -4466,7 +4473,7 @@ setenv_TEST_LAUNCH_HELPER_CONFIG(const DBusString *test_data_dir,
_dbus_verbose ("Setting TEST_LAUNCH_HELPER_CONFIG to '%s'\n",
_dbus_string_get_const_data (&full));
- _dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full));
+ dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", _dbus_string_get_const_data (&full));
_dbus_string_free (&full);
@@ -4907,4 +4914,4 @@ bus_unix_fds_passing_test(const DBusString *test_data_dir)
}
#endif
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/driver.c b/bus/driver.c
index 574e0f3d..e95a79d9 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -32,12 +32,56 @@
#include "signals.h"
#include "stats.h"
#include "utils.h"
+
+#include <dbus/dbus-asv-util.h>
#include <dbus/dbus-string.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-marshal-recursive.h>
#include <string.h>
+static DBusConnection *
+bus_driver_get_conn_helper (DBusConnection *connection,
+ DBusMessage *message,
+ const char *what_we_want,
+ const char **name_p,
+ DBusError *error)
+{
+ const char *name;
+ BusRegistry *registry;
+ BusService *serv;
+ DBusString str;
+ DBusConnection *conn;
+
+ if (!dbus_message_get_args (message, error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID))
+ return NULL;
+
+ _dbus_assert (name != NULL);
+ _dbus_verbose ("asked for %s of connection %s\n", what_we_want, name);
+
+ registry = bus_connection_get_registry (connection);
+ _dbus_string_init_const (&str, name);
+ serv = bus_registry_lookup (registry, &str);
+
+ if (serv == NULL)
+ {
+ dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Could not get %s of name '%s': no such name",
+ what_we_want, name);
+ return NULL;
+ }
+
+ conn = bus_service_get_primary_owners_connection (serv);
+ _dbus_assert (conn != NULL);
+
+ if (name_p != NULL)
+ *name_p = name;
+
+ return conn;
+}
+
static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
DBusMessage *hello_message,
BusTransaction *transaction,
@@ -841,13 +885,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection,
/* The message signature has already been checked for us,
* so let's just assert it's right.
*/
-#ifndef DBUS_DISABLE_ASSERT
- {
- int msg_type = dbus_message_iter_get_arg_type (&iter);
-
- _dbus_assert (msg_type == DBUS_TYPE_ARRAY);
- }
-#endif
+ _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY);
dbus_message_iter_recurse (&iter, &dict_iter);
@@ -1262,40 +1300,21 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
- const char *service;
- DBusString str;
- BusRegistry *registry;
- BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
unsigned long uid;
dbus_uint32_t uid32;
+ const char *service;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (connection);
-
- service = NULL;
reply = NULL;
- if (! dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INVALID))
- goto failed;
-
- _dbus_verbose ("asked for UID of connection %s\n", service);
+ conn = bus_driver_get_conn_helper (connection, message, "UID", &service,
+ error);
- _dbus_string_init_const (&str, service);
- serv = bus_registry_lookup (registry, &str);
- if (serv == NULL)
- {
- dbus_set_error (error,
- DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Could not get UID of name '%s': no such name", service);
- goto failed;
- }
-
- conn = bus_service_get_primary_owners_connection (serv);
+ if (conn == NULL)
+ goto failed;
reply = dbus_message_new_method_return (message);
if (reply == NULL)
@@ -1338,40 +1357,21 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
- const char *service;
- DBusString str;
- BusRegistry *registry;
- BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
unsigned long pid;
dbus_uint32_t pid32;
+ const char *service;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (connection);
-
- service = NULL;
reply = NULL;
- if (! dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INVALID))
- goto failed;
-
- _dbus_verbose ("asked for PID of connection %s\n", service);
+ conn = bus_driver_get_conn_helper (connection, message, "PID", &service,
+ error);
- _dbus_string_init_const (&str, service);
- serv = bus_registry_lookup (registry, &str);
- if (serv == NULL)
- {
- dbus_set_error (error,
- DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Could not get PID of name '%s': no such name", service);
- goto failed;
- }
-
- conn = bus_service_get_primary_owners_connection (serv);
+ if (conn == NULL)
+ goto failed;
reply = dbus_message_new_method_return (message);
if (reply == NULL)
@@ -1414,40 +1414,21 @@ bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
- const char *service;
- DBusString str;
- BusRegistry *registry;
- BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
void *data = NULL;
dbus_uint32_t data_size;
+ const char *service;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (connection);
-
- service = NULL;
reply = NULL;
- if (! dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INVALID))
- goto failed;
-
- _dbus_verbose ("asked for audit session data for connection %s\n", service);
+ conn = bus_driver_get_conn_helper (connection, message,
+ "audit session data", &service, error);
- _dbus_string_init_const (&str, service);
- serv = bus_registry_lookup (registry, &str);
- if (serv == NULL)
- {
- dbus_set_error (error,
- DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Could not get audit session data for name '%s': no such name", service);
- goto failed;
- }
-
- conn = bus_service_get_primary_owners_connection (serv);
+ if (conn == NULL)
+ goto failed;
reply = dbus_message_new_method_return (message);
if (reply == NULL)
@@ -1489,39 +1470,20 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne
DBusMessage *message,
DBusError *error)
{
- const char *service;
- DBusString str;
- BusRegistry *registry;
- BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
BusSELinuxID *context;
+ const char *service;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- registry = bus_connection_get_registry (connection);
-
- service = NULL;
reply = NULL;
- if (! dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &service,
- DBUS_TYPE_INVALID))
- goto failed;
-
- _dbus_verbose ("asked for security context of connection %s\n", service);
+ conn = bus_driver_get_conn_helper (connection, message, "security context",
+ &service, error);
- _dbus_string_init_const (&str, service);
- serv = bus_registry_lookup (registry, &str);
- if (serv == NULL)
- {
- dbus_set_error (error,
- DBUS_ERROR_NAME_HAS_NO_OWNER,
- "Could not get security context of name '%s': no such name", service);
- goto failed;
- }
-
- conn = bus_service_get_primary_owners_connection (serv);
+ if (conn == NULL)
+ goto failed;
reply = dbus_message_new_method_return (message);
if (reply == NULL)
@@ -1557,6 +1519,80 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne
}
static dbus_bool_t
+bus_driver_handle_get_connection_credentials (DBusConnection *connection,
+ BusTransaction *transaction,
+ DBusMessage *message,
+ DBusError *error)
+{
+ DBusConnection *conn;
+ DBusMessage *reply;
+ DBusMessageIter reply_iter;
+ DBusMessageIter array_iter;
+ unsigned long ulong_val;
+ const char *service;
+
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ reply = NULL;
+
+ conn = bus_driver_get_conn_helper (connection, message, "credentials",
+ &service, error);
+
+ if (conn == NULL)
+ goto failed;
+
+ reply = _dbus_asv_new_method_return (message, &reply_iter, &array_iter);
+ if (reply == NULL)
+ goto oom;
+
+ /* we can't represent > 32-bit pids; if your system needs them, please
+ * add ProcessID64 to the spec or something */
+ if (dbus_connection_get_unix_process_id (conn, &ulong_val) &&
+ ulong_val <= _DBUS_UINT32_MAX)
+ {
+ if (!_dbus_asv_add_uint32 (&array_iter, "ProcessID", ulong_val))
+ goto oom;
+ }
+
+ /* we can't represent > 32-bit uids; if your system needs them, please
+ * add UnixUserID64 to the spec or something */
+ if (dbus_connection_get_unix_user (conn, &ulong_val) &&
+ ulong_val <= _DBUS_UINT32_MAX)
+ {
+ if (!_dbus_asv_add_uint32 (&array_iter, "UnixUserID", ulong_val))
+ goto oom;
+ }
+
+ if (!_dbus_asv_close (&reply_iter, &array_iter))
+ goto oom;
+
+ if (! bus_transaction_send_from_driver (transaction, connection, reply))
+ {
+ /* this time we don't want to close the iterator again, so just
+ * get rid of the message */
+ dbus_message_unref (reply);
+ reply = NULL;
+ goto oom;
+ }
+
+ return TRUE;
+
+ oom:
+ BUS_SET_OOM (error);
+
+ failed:
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+
+ if (reply)
+ {
+ _dbus_asv_abandon (&reply_iter, &array_iter);
+ dbus_message_unref (reply);
+ }
+
+ return FALSE;
+}
+
+static dbus_bool_t
bus_driver_handle_reload_config (DBusConnection *connection,
BusTransaction *transaction,
DBusMessage *message,
@@ -1736,6 +1772,8 @@ static const MessageHandler dbus_message_handlers[] = {
"",
DBUS_TYPE_STRING_AS_STRING,
bus_driver_handle_get_id },
+ { "GetConnectionCredentials", "s", "a{sv}",
+ bus_driver_handle_get_connection_credentials },
{ NULL, NULL, NULL, NULL }
};
@@ -1964,13 +2002,8 @@ bus_driver_handle_message (DBusConnection *connection,
_dbus_verbose ("Driver got a method call: %s\n", name);
/* security checks should have kept this from getting here */
-#ifndef DBUS_DISABLE_ASSERT
- {
- const char *sender = dbus_message_get_sender (message);
-
- _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
- }
-#endif
+ _dbus_assert (dbus_message_get_sender (message) != NULL ||
+ strcmp (name, "Hello") == 0);
for (ih = interface_handlers; ih->name != NULL; ih++)
{
diff --git a/bus/expirelist.c b/bus/expirelist.c
index 1a12ea45..9a3886e9 100644
--- a/bus/expirelist.c
+++ b/bus/expirelist.c
@@ -281,7 +281,7 @@ bus_expire_list_contains_item (BusExpireList *list,
return _dbus_list_find_last (&list->items, item) != NULL;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
typedef struct
{
@@ -399,4 +399,4 @@ bus_expire_list_test (const DBusString *test_data_dir)
return result;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/main.c b/bus/main.c
index ca0be3ce..e060baa8 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -61,11 +61,6 @@ signal_handler (int sig)
{
switch (sig)
{
-#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
- case SIGIO:
- /* explicit fall-through */
-#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
-#ifdef SIGHUP
case SIGHUP:
{
DBusString str;
@@ -91,11 +86,13 @@ signal_handler (int sig)
static const char message[] =
"Unable to write to reload pipe - buffer full?\n";
- write (STDERR_FILENO, message, strlen (message));
+ if (write (STDERR_FILENO, message, strlen (message)) != strlen (message))
+ {
+ /* ignore failure to write out a warning */
+ }
}
}
break;
-#endif
case SIGTERM:
{
@@ -113,7 +110,10 @@ signal_handler (int sig)
"Unable to write termination signal to pipe - buffer full?\n"
"Will exit instead.\n";
- write (STDERR_FILENO, message, strlen (message));
+ if (write (STDERR_FILENO, message, strlen (message)) != strlen (message))
+ {
+ /* ignore failure to write out a warning */
+ }
_exit (1);
}
}
@@ -125,7 +125,23 @@ signal_handler (int sig)
static void
usage (void)
{
- fprintf (stderr, DBUS_DAEMON_NAME " [--version] [--session] [--system] [--config-file=FILE] [--print-address[=DESCRIPTOR]] [--print-pid[=DESCRIPTOR]] [--fork] [--nofork] [--introspect] [--address=ADDRESS] [--systemd-activation] [--nopidfile]\n");
+ fprintf (stderr,
+ DBUS_DAEMON_NAME
+ " [--version]"
+ " [--session]"
+ " [--system]"
+ " [--config-file=FILE]"
+ " [--print-address[=DESCRIPTOR]]"
+ " [--print-pid[=DESCRIPTOR]]"
+ " [--introspect]"
+ " [--address=ADDRESS]"
+ " [--nopidfile]"
+ " [--nofork]"
+#ifdef DBUS_UNIX
+ " [--fork]"
+ " [--systemd-activation]"
+#endif
+ "\n");
exit (1);
}
@@ -399,19 +415,21 @@ main (int argc, char **argv)
flags &= ~BUS_CONTEXT_FLAG_FORK_ALWAYS;
flags |= BUS_CONTEXT_FLAG_FORK_NEVER;
}
+#ifdef DBUS_UNIX
else if (strcmp (arg, "--fork") == 0)
{
flags &= ~BUS_CONTEXT_FLAG_FORK_NEVER;
flags |= BUS_CONTEXT_FLAG_FORK_ALWAYS;
}
- else if (strcmp (arg, "--nopidfile") == 0)
- {
- flags &= ~BUS_CONTEXT_FLAG_WRITE_PID_FILE;
- }
else if (strcmp (arg, "--systemd-activation") == 0)
{
flags |= BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION;
}
+#endif
+ else if (strcmp (arg, "--nopidfile") == 0)
+ {
+ flags &= ~BUS_CONTEXT_FLAG_WRITE_PID_FILE;
+ }
else if (strcmp (arg, "--system") == 0)
{
check_two_config_files (&config_file, "system");
@@ -622,12 +640,7 @@ main (int argc, char **argv)
* no point in trying to make the handler portable to non-Unix. */
_dbus_set_signal_handler (SIGTERM, signal_handler);
-#ifdef SIGHUP
_dbus_set_signal_handler (SIGHUP, signal_handler);
-#endif
-#ifdef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
- _dbus_set_signal_handler (SIGIO, signal_handler);
-#endif /* DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX */
#endif /* DBUS_UNIX */
_dbus_verbose ("We are on D-Bus...\n");
diff --git a/bus/policy.c b/bus/policy.c
index 379cea95..082f3853 100644
--- a/bus/policy.c
+++ b/bus/policy.c
@@ -1302,12 +1302,12 @@ bus_client_policy_check_can_own (BusClientPolicy *policy,
return bus_rules_check_can_own (policy->rules, service_name);
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
dbus_bool_t
bus_policy_check_can_own (BusPolicy *policy,
const DBusString *service_name)
{
return bus_rules_check_can_own (policy->default_rules, service_name);
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/policy.h b/bus/policy.h
index 3ff6f482..d1d3e72b 100644
--- a/bus/policy.h
+++ b/bus/policy.h
@@ -161,7 +161,7 @@ dbus_bool_t bus_client_policy_append_rule (BusClientPolicy *policy,
BusPolicyRule *rule);
void bus_client_policy_optimize (BusClientPolicy *policy);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
dbus_bool_t bus_policy_check_can_own (BusPolicy *policy,
const DBusString *service_name);
#endif
diff --git a/bus/selinux.c b/bus/selinux.c
index 36287e9f..99994ca9 100644
--- a/bus/selinux.c
+++ b/bus/selinux.c
@@ -44,8 +44,6 @@
#include <syslog.h>
#include <selinux/selinux.h>
#include <selinux/avc.h>
-#include <selinux/av_permissions.h>
-#include <selinux/flask.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
@@ -314,8 +312,27 @@ bus_selinux_pre_init (void)
#endif
}
+/*
+ * Private Flask definitions; the order of these constants must
+ * exactly match that of the structure array below!
+ */
+/* security dbus class constants */
+#define SECCLASS_DBUS 1
+
+/* dbus's per access vector constants */
+#define DBUS__ACQUIRE_SVC 1
+#define DBUS__SEND_MSG 2
+
+#ifdef HAVE_SELINUX
+static struct security_class_mapping dbus_map[] = {
+ { "dbus", { "acquire_svc", "send_msg", NULL } },
+ { NULL }
+};
+#endif /* HAVE_SELINUX */
+
/**
- * Initialize the user space access vector cache (AVC) for D-Bus and set up
+ * Establish dynamic object class and permission mapping and
+ * initialize the user space access vector cache (AVC) for D-Bus and set up
* logging callbacks.
*/
dbus_bool_t
@@ -334,6 +351,13 @@ bus_selinux_full_init (void)
_dbus_verbose ("SELinux is enabled in this kernel.\n");
+ if (selinux_set_mapping (dbus_map) < 0)
+ {
+ _dbus_warn ("Failed to set up security class mapping (selinux_set_mapping():%s).\n",
+ strerror (errno));
+ return FALSE;
+ }
+
avc_entry_ref_init (&aeref);
if (avc_init ("avc", &mem_cb, &log_cb, &thread_cb, &lock_cb) < 0)
{
@@ -936,8 +960,7 @@ bus_selinux_get_policy_root (void)
void
bus_selinux_id_table_print (DBusHashTable *service_table)
{
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-#ifdef HAVE_SELINUX
+#if defined (DBUS_ENABLE_VERBOSE_MODE) && defined (HAVE_SELINUX)
DBusHashIter iter;
if (!selinux_enabled)
@@ -953,19 +976,18 @@ bus_selinux_id_table_print (DBusHashTable *service_table)
_dbus_verbose ("The context is %s\n", sid->ctx);
_dbus_verbose ("The refcount is %d\n", sid->refcnt);
}
-#endif /* HAVE_SELINUX */
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
+#endif /* DBUS_ENABLE_VERBOSE_MODE && HAVE_SELINUX */
}
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-#ifdef HAVE_SELINUX
/**
* Print out some AVC statistics.
*/
+#ifdef HAVE_SELINUX
static void
bus_avc_print_stats (void)
{
+#ifdef DBUS_ENABLE_VERBOSE_MODE
struct avc_cache_stats cstats;
if (!selinux_enabled)
@@ -983,10 +1005,9 @@ bus_avc_print_stats (void)
_dbus_verbose ("CAV hits: %d\n", cstats.cav_hits);
_dbus_verbose ("CAV probes: %d\n", cstats.cav_probes);
_dbus_verbose ("CAV misses: %d\n", cstats.cav_misses);
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
}
#endif /* HAVE_SELINUX */
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
-
/**
* Destroy the AVC before we terminate.
@@ -1005,12 +1026,7 @@ bus_selinux_shutdown (void)
sidput (bus_sid);
bus_sid = SECSID_WILD;
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-
- if (_dbus_is_verbose())
- bus_avc_print_stats ();
-
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
+ bus_avc_print_stats ();
avc_destroy ();
#ifdef HAVE_LIBAUDIT
@@ -1051,10 +1067,17 @@ _dbus_change_to_daemon_user (const char *user,
if (_dbus_geteuid () == 0)
{
int rc;
+ int have_audit_write;
+ have_audit_write = capng_have_capability (CAPNG_PERMITTED, CAP_AUDIT_WRITE);
capng_clear (CAPNG_SELECT_BOTH);
- capng_update (CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED,
- CAP_AUDIT_WRITE);
+ /* Only attempt to retain CAP_AUDIT_WRITE if we had it when
+ * starting. See:
+ * https://bugs.freedesktop.org/show_bug.cgi?id=49062#c9
+ */
+ if (have_audit_write)
+ capng_update (CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED,
+ CAP_AUDIT_WRITE);
rc = capng_change_id (uid, gid, CAPNG_DROP_SUPP_GRP);
if (rc)
{
diff --git a/bus/services.c b/bus/services.c
index 6f380fac..01a720ed 100644
--- a/bus/services.c
+++ b/bus/services.c
@@ -368,7 +368,7 @@ bus_registry_list_services (BusRegistry *registry,
error:
for (j = 0; j < i; j++)
- dbus_free (retval[i]);
+ dbus_free (retval[j]);
dbus_free (retval);
return FALSE;
diff --git a/bus/session.conf.in b/bus/session.conf.in
index e121ff93..74d9d1fd 100644
--- a/bus/session.conf.in
+++ b/bus/session.conf.in
@@ -12,7 +12,7 @@
the behavior of child processes. -->
<keep_umask/>
- <listen>@DBUS_SESSION_BUS_DEFAULT_ADDRESS@</listen>
+ <listen>@DBUS_SESSION_BUS_LISTEN_ADDRESS@</listen>
<standard_session_servicedirs />
@@ -49,7 +49,7 @@
<limit name="max_outgoing_bytes">1000000000</limit>
<limit name="max_outgoing_unix_fds">250000000</limit>
<limit name="max_message_size">1000000000</limit>
- <limit name="max_message_unix_fds">4096</limit>
+ <limit name="max_message_unix_fds">@DEFAULT_MESSAGE_UNIX_FDS@</limit>
<limit name="service_start_timeout">120000</limit>
<limit name="auth_timeout">240000</limit>
<limit name="max_completed_connections">100000</limit>
diff --git a/bus/signals.c b/bus/signals.c
index 28506d3f..4c500c67 100644
--- a/bus/signals.c
+++ b/bus/signals.c
@@ -64,7 +64,7 @@ bus_match_rule_new (DBusConnection *matches_go_to)
rule->refcount = 1;
rule->matches_go_to = matches_go_to;
-#ifndef DBUS_BUILD_TESTS
+#ifndef DBUS_ENABLE_EMBEDDED_TESTS
_dbus_assert (rule->matches_go_to != NULL);
#endif
@@ -1836,8 +1836,11 @@ match_rule_matches (BusMatchRule *rule,
* namespace, rather than just starting with that string,
* by checking that the matched prefix is followed by a '/'
* or the end of the path.
+ *
+ * Special case: the only valid path of length 1, "/",
+ * matches everything.
*/
- if (path[len] != '\0' && path[len] != '/')
+ if (len > 1 && path[len] != '\0' && path[len] != '/')
return FALSE;
}
@@ -1980,12 +1983,10 @@ get_recipients_from_list (DBusList **rules,
if (!_dbus_list_append (recipients_p, rule->matches_go_to))
return FALSE;
}
-#ifdef DBUS_ENABLE_VERBOSE_MODE
else
{
_dbus_verbose ("Connection already receiving this message, so not adding again\n");
}
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
}
link = _dbus_list_get_next_link (rules, link);
@@ -2056,7 +2057,7 @@ bus_matchmaker_get_recipients (BusMatchmaker *matchmaker,
return TRUE;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "test.h"
#include <stdlib.h>
@@ -2719,6 +2720,7 @@ test_path_matching (void)
static const char*
path_namespace_should_match_message_1[] = {
+ "type='signal',path_namespace='/'",
"type='signal',path_namespace='/foo'",
"type='signal',path_namespace='/foo/TheObjectManager'",
NULL
@@ -2733,6 +2735,7 @@ path_namespace_should_not_match_message_1[] = {
static const char*
path_namespace_should_match_message_2[] = {
+ "type='signal',path_namespace='/'",
"type='signal',path_namespace='/foo/TheObjectManager'",
NULL
};
@@ -2744,6 +2747,7 @@ path_namespace_should_not_match_message_2[] = {
static const char*
path_namespace_should_match_message_3[] = {
+ "type='signal',path_namespace='/'",
NULL
};
@@ -2753,12 +2757,25 @@ path_namespace_should_not_match_message_3[] = {
NULL
};
+static const char*
+path_namespace_should_match_message_4[] = {
+ "type='signal',path_namespace='/'",
+ NULL
+};
+
+static const char*
+path_namespace_should_not_match_message_4[] = {
+ "type='signal',path_namespace='/foo/TheObjectManager'",
+ NULL
+};
+
static void
test_matching_path_namespace (void)
{
DBusMessage *message1;
DBusMessage *message2;
DBusMessage *message3;
+ DBusMessage *message4;
message1 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
_dbus_assert (message1 != NULL);
@@ -2775,6 +2792,11 @@ test_matching_path_namespace (void)
if (!dbus_message_set_path (message3, "/foo/TheObjectManagerOther"))
_dbus_assert_not_reached ("oom");
+ message4 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
+ _dbus_assert (message4 != NULL);
+ if (!dbus_message_set_path (message4, "/"))
+ _dbus_assert_not_reached ("oom");
+
check_matching (message1, 1,
path_namespace_should_match_message_1,
path_namespace_should_not_match_message_1);
@@ -2784,7 +2806,11 @@ test_matching_path_namespace (void)
check_matching (message3, 3,
path_namespace_should_match_message_3,
path_namespace_should_not_match_message_3);
+ check_matching (message4, 4,
+ path_namespace_should_match_message_4,
+ path_namespace_should_not_match_message_4);
+ dbus_message_unref (message4);
dbus_message_unref (message3);
dbus_message_unref (message2);
dbus_message_unref (message1);
@@ -2811,5 +2837,5 @@ bus_signals_test (const DBusString *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/bus/stats.c b/bus/stats.c
index 28fd49ba..2bf86d66 100644
--- a/bus/stats.c
+++ b/bus/stats.c
@@ -1,5 +1,8 @@
/* stats.c - statistics from the bus driver
*
+ * Copyright © 2011-2012 Nokia Corporation
+ * Copyright © 2012-2013 Collabora Ltd.
+ *
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
@@ -21,6 +24,7 @@
#include <config.h>
#include "stats.h"
+#include <dbus/dbus-asv-util.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection-internal.h>
@@ -30,153 +34,6 @@
#ifdef DBUS_ENABLE_STATS
-static DBusMessage *
-new_asv_reply (DBusMessage *message,
- DBusMessageIter *iter,
- DBusMessageIter *arr_iter)
-{
- DBusMessage *reply = dbus_message_new_method_return (message);
-
- if (reply == NULL)
- return NULL;
-
- dbus_message_iter_init_append (reply, iter);
-
- if (!dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{sv}",
- arr_iter))
- {
- dbus_message_unref (reply);
- return NULL;
- }
-
- return reply;
-}
-
-static dbus_bool_t
-open_asv_entry (DBusMessageIter *arr_iter,
- DBusMessageIter *entry_iter,
- const char *key,
- const char *type,
- DBusMessageIter *var_iter)
-{
- if (!dbus_message_iter_open_container (arr_iter, DBUS_TYPE_DICT_ENTRY,
- NULL, entry_iter))
- return FALSE;
-
- if (!dbus_message_iter_append_basic (entry_iter, DBUS_TYPE_STRING, &key))
- {
- dbus_message_iter_abandon_container (arr_iter, entry_iter);
- return FALSE;
- }
-
- if (!dbus_message_iter_open_container (entry_iter, DBUS_TYPE_VARIANT,
- type, var_iter))
- {
- dbus_message_iter_abandon_container (arr_iter, entry_iter);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static dbus_bool_t
-close_asv_entry (DBusMessageIter *arr_iter,
- DBusMessageIter *entry_iter,
- DBusMessageIter *var_iter)
-{
- if (!dbus_message_iter_close_container (entry_iter, var_iter))
- {
- dbus_message_iter_abandon_container (arr_iter, entry_iter);
- return FALSE;
- }
-
- if (!dbus_message_iter_close_container (arr_iter, entry_iter))
- return FALSE;
-
- return TRUE;
-}
-
-static dbus_bool_t
-close_asv_reply (DBusMessageIter *iter,
- DBusMessageIter *arr_iter)
-{
- return dbus_message_iter_close_container (iter, arr_iter);
-}
-
-static void
-abandon_asv_entry (DBusMessageIter *arr_iter,
- DBusMessageIter *entry_iter,
- DBusMessageIter *var_iter)
-{
- dbus_message_iter_abandon_container (entry_iter, var_iter);
- dbus_message_iter_abandon_container (arr_iter, entry_iter);
-}
-
-static void
-abandon_asv_reply (DBusMessageIter *iter,
- DBusMessageIter *arr_iter)
-{
- dbus_message_iter_abandon_container (iter, arr_iter);
-}
-
-static dbus_bool_t
-asv_add_uint32 (DBusMessageIter *iter,
- DBusMessageIter *arr_iter,
- const char *key,
- dbus_uint32_t value)
-{
- DBusMessageIter entry_iter, var_iter;
-
- if (!open_asv_entry (arr_iter, &entry_iter, key, DBUS_TYPE_UINT32_AS_STRING,
- &var_iter))
- goto oom;
-
- if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_UINT32,
- &value))
- {
- abandon_asv_entry (arr_iter, &entry_iter, &var_iter);
- goto oom;
- }
-
- if (!close_asv_entry (arr_iter, &entry_iter, &var_iter))
- goto oom;
-
- return TRUE;
-
-oom:
- abandon_asv_reply (iter, arr_iter);
- return FALSE;
-}
-
-static dbus_bool_t
-asv_add_string (DBusMessageIter *iter,
- DBusMessageIter *arr_iter,
- const char *key,
- const char *value)
-{
- DBusMessageIter entry_iter, var_iter;
-
- if (!open_asv_entry (arr_iter, &entry_iter, key, DBUS_TYPE_STRING_AS_STRING,
- &var_iter))
- goto oom;
-
- if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_STRING,
- &value))
- {
- abandon_asv_entry (arr_iter, &entry_iter, &var_iter);
- goto oom;
- }
-
- if (!close_asv_entry (arr_iter, &entry_iter, &var_iter))
- goto oom;
-
- return TRUE;
-
-oom:
- abandon_asv_reply (iter, arr_iter);
- return FALSE;
-}
-
dbus_bool_t
bus_stats_handle_get_stats (DBusConnection *connection,
BusTransaction *transaction,
@@ -191,49 +48,52 @@ bus_stats_handle_get_stats (DBusConnection *connection,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- connections = bus_transaction_get_connections (transaction);
+ connections = bus_context_get_connections (transaction->context);
- reply = new_asv_reply (message, &iter, &arr_iter);
+ reply = _dbus_asv_new_method_return (message, &iter, &arr_iter);
if (reply == NULL)
goto oom;
/* Globals */
- if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++))
- goto oom;
-
_dbus_list_get_stats (&in_use, &in_free_list, &allocated);
- if (!asv_add_uint32 (&iter, &arr_iter, "ListMemPoolUsedBytes", in_use) ||
- !asv_add_uint32 (&iter, &arr_iter, "ListMemPoolCachedBytes",
- in_free_list) ||
- !asv_add_uint32 (&iter, &arr_iter, "ListMemPoolAllocatedBytes",
- allocated))
- goto oom;
+
+ if (!_dbus_asv_add_uint32 (&arr_iter, "Serial", stats_serial++) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolUsedBytes", in_use) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolCachedBytes", in_free_list) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "ListMemPoolAllocatedBytes", allocated))
+ {
+ _dbus_asv_abandon (&iter, &arr_iter);
+ goto oom;
+ }
/* Connections */
- if (!asv_add_uint32 (&iter, &arr_iter, "ActiveConnections",
+ if (!_dbus_asv_add_uint32 (&arr_iter, "ActiveConnections",
bus_connections_get_n_active (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "IncompleteConnections",
+ !_dbus_asv_add_uint32 (&arr_iter, "IncompleteConnections",
bus_connections_get_n_incomplete (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "MatchRules",
+ !_dbus_asv_add_uint32 (&arr_iter, "MatchRules",
bus_connections_get_total_match_rules (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules",
bus_connections_get_peak_match_rules (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRulesPerConnection",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRulesPerConnection",
bus_connections_get_peak_match_rules_per_conn (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "BusNames",
+ !_dbus_asv_add_uint32 (&arr_iter, "BusNames",
bus_connections_get_total_bus_names (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames",
bus_connections_get_peak_bus_names (connections)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakBusNamesPerConnection",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNamesPerConnection",
bus_connections_get_peak_bus_names_per_conn (connections)))
- goto oom;
+ {
+ _dbus_asv_abandon (&iter, &arr_iter);
+ goto oom;
+ }
/* end */
- if (!close_asv_reply (&iter, &arr_iter))
+ if (!_dbus_asv_close (&iter, &arr_iter))
goto oom;
if (!bus_transaction_send_from_driver (transaction, connection, reply))
@@ -289,25 +149,28 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection,
stats_connection = bus_service_get_primary_owners_connection (service);
_dbus_assert (stats_connection != NULL);
- reply = new_asv_reply (message, &iter, &arr_iter);
+ reply = _dbus_asv_new_method_return (message, &iter, &arr_iter);
if (reply == NULL)
goto oom;
/* Bus daemon per-connection stats */
- if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++) ||
- !asv_add_uint32 (&iter, &arr_iter, "MatchRules",
+ if (!_dbus_asv_add_uint32 (&arr_iter, "Serial", stats_serial++) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "MatchRules",
bus_connection_get_n_match_rules (stats_connection)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules",
bus_connection_get_peak_match_rules (stats_connection)) ||
- !asv_add_uint32 (&iter, &arr_iter, "BusNames",
+ !_dbus_asv_add_uint32 (&arr_iter, "BusNames",
bus_connection_get_n_services_owned (stats_connection)) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames",
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames",
bus_connection_get_peak_bus_names (stats_connection)) ||
- !asv_add_string (&iter, &arr_iter, "UniqueName",
+ !_dbus_asv_add_string (&arr_iter, "UniqueName",
bus_connection_get_name (stats_connection)))
- goto oom;
+ {
+ _dbus_asv_abandon (&iter, &arr_iter);
+ goto oom;
+ }
/* DBusConnection per-connection stats */
@@ -317,21 +180,24 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection,
&out_messages, &out_bytes, &out_fds,
&out_peak_bytes, &out_peak_fds);
- if (!asv_add_uint32 (&iter, &arr_iter, "IncomingMessages", in_messages) ||
- !asv_add_uint32 (&iter, &arr_iter, "IncomingBytes", in_bytes) ||
- !asv_add_uint32 (&iter, &arr_iter, "IncomingFDs", in_fds) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingBytes", in_peak_bytes) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakIncomingFDs", in_peak_fds) ||
- !asv_add_uint32 (&iter, &arr_iter, "OutgoingMessages", out_messages) ||
- !asv_add_uint32 (&iter, &arr_iter, "OutgoingBytes", out_bytes) ||
- !asv_add_uint32 (&iter, &arr_iter, "OutgoingFDs", out_fds) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingBytes", out_peak_bytes) ||
- !asv_add_uint32 (&iter, &arr_iter, "PeakOutgoingFDs", out_peak_fds))
- goto oom;
+ if (!_dbus_asv_add_uint32 (&arr_iter, "IncomingMessages", in_messages) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "IncomingBytes", in_bytes) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "IncomingFDs", in_fds) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakIncomingBytes", in_peak_bytes) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakIncomingFDs", in_peak_fds) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "OutgoingMessages", out_messages) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "OutgoingBytes", out_bytes) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "OutgoingFDs", out_fds) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakOutgoingBytes", out_peak_bytes) ||
+ !_dbus_asv_add_uint32 (&arr_iter, "PeakOutgoingFDs", out_peak_fds))
+ {
+ _dbus_asv_abandon (&iter, &arr_iter);
+ goto oom;
+ }
/* end */
- if (!close_asv_reply (&iter, &arr_iter))
+ if (!_dbus_asv_close (&iter, &arr_iter))
goto oom;
if (!bus_transaction_send_from_driver (transaction, caller_connection,
diff --git a/bus/test-launch-helper.c b/bus/test-launch-helper.c
index ab36b6ec..e9ba412a 100644
--- a/bus/test-launch-helper.c
+++ b/bus/test-launch-helper.c
@@ -28,8 +28,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus-internals.h>
+#include <dbus/dbus-misc.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
die (const char *failure)
{
@@ -56,7 +57,7 @@ test_post_hook (const char *name)
{
check_memleaks (name);
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
#ifdef ACTIVATION_LAUNCHER_DO_OOM
@@ -97,7 +98,7 @@ bus_activation_helper_oom_test (void *data)
int
main (int argc, char **argv)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
const char *dir;
DBusString config_file;
@@ -122,8 +123,8 @@ main (int argc, char **argv)
return 1;
/* use a config file that will actually work... */
- _dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG",
- _dbus_string_get_const_data (&config_file));
+ dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG",
+ _dbus_string_get_const_data (&config_file));
_dbus_string_free (&config_file);
@@ -137,7 +138,7 @@ main (int argc, char **argv)
printf ("%s: Success\n", argv[0]);
return 0;
-#else /* DBUS_BUILD_TESTS */
+#else /* DBUS_ENABLE_EMBEDDED_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test-main.c b/bus/test-main.c
index 0f736c7c..01d22870 100644
--- a/bus/test-main.c
+++ b/bus/test-main.c
@@ -31,7 +31,7 @@
#include <dbus/dbus-message-internal.h>
#include "selinux.h"
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
die (const char *failure)
{
@@ -52,7 +52,7 @@ check_memleaks (const char *name)
die ("memleaks");
}
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
static DBusInitialFDs *initial_fds = NULL;
@@ -84,7 +84,7 @@ test_post_hook (void)
int
main (int argc, char **argv)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
const char *dir;
const char *only;
DBusString test_data_dir;
@@ -181,7 +181,7 @@ main (int argc, char **argv)
return 0;
-#else /* DBUS_BUILD_TESTS */
+#else /* DBUS_ENABLE_EMBEDDED_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test-system.c b/bus/test-system.c
index 56a7d4ea..5f02d0ab 100644
--- a/bus/test-system.c
+++ b/bus/test-system.c
@@ -29,7 +29,7 @@
#include <dbus/dbus-sysdeps.h>
#include <dbus/dbus-internals.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
die (const char *failure)
{
@@ -50,7 +50,7 @@ check_memleaks (const char *name)
die ("memleaks");
}
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
static void
test_pre_hook (void)
@@ -67,7 +67,7 @@ test_post_hook (void)
int
main (int argc, char **argv)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
const char *dir;
DBusString test_data_dir;
@@ -98,7 +98,7 @@ main (int argc, char **argv)
printf ("%s: Success\n", argv[0]);
return 0;
-#else /* DBUS_BUILD_TESTS */
+#else /* DBUS_ENABLE_EMBEDDED_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test.c b/bus/test.c
index 1ca96070..31ef4c8f 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "test.h"
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
diff --git a/bus/test.h b/bus/test.h
index 98a2c6ba..38b74e89 100644
--- a/bus/test.h
+++ b/bus/test.h
@@ -24,7 +24,7 @@
#ifndef BUS_TEST_H
#define BUS_TEST_H
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <dbus/dbus.h>
#include <dbus/dbus-string.h>
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index ba44d575..c8a68345 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1,3 +1,9 @@
+# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
+
+# we do not need to have WIN32 defined
+set(CMAKE_LEGACY_CYGWIN_WIN32 0)
+
project(dbus)
# we need to be up to date
@@ -6,8 +12,6 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
-# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules")
# detect version
include(MacrosAutotools)
@@ -15,6 +19,14 @@ autoversion(../configure.ac dbus)
# used by file version info
set (DBUS_PATCH_VERSION "0")
+# set PACKAGE_... variables
+autopackage(
+ dbus
+ ${DBUS_VERSION_STRING}
+ "http://dbus.freedesktop.org"
+ "https://bugs.freedesktop.org/enter_bug.cgi?product=dbus"
+)
+
include(Macros)
TIMESTAMP(DBUS_BUILD_TIMESTAMP)
@@ -60,12 +72,18 @@ set(EXPANDED_SYSCONFDIR ${DBUS_INSTALL_DIR}/etc)
set(EXPANDED_DATADIR ${DBUS_INSTALL_DIR}/${DBUS_DATADIR})
set(DBUS_MACHINE_UUID_FILE ${DBUS_INSTALL_DIR}/lib/dbus/machine-id)
set(DBUS_BINDIR ${EXPANDED_BINDIR})
-set(DBUS_DAEMONDIR ${EXPANDED_BINDIR})
+set(DBUS_DAEMONDIR ${EXPANDED_BINDIR})
#enable building of shared library
SET(BUILD_SHARED_LIBS ON)
+if(WIN32)
+ set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "bin" LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib")
+else()
+ set(INSTALL_TARGETS_DEFAULT_ARGS RUNTIME DESTINATION "${EXPANDED_LIBDIR}" LIBRARY DESTINATION "${EXPANDED_LIBDIR}" ARCHIVE DESTINATION "${EXPANDED_LIBDIR}")
+endif()
+
if (CYGWIN)
set (WIN32)
endif (CYGWIN)
@@ -79,28 +97,26 @@ if (WIN32)
addExplorerWrapper(${CMAKE_PROJECT_NAME})
endif (WIN32)
-option (DBUS_USE_EXPAT "Use expat (== ON) or libxml2 (==OFF)" ON)
-
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)
-#AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$USE_MAINTAINER_MODE)
-option (DBUS_DISABLE_ASSERTS "Disable assertion checking" OFF)
+option (DBUS_DISABLE_ASSERT "Disable assertion checking" OFF)
option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF)
-option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF)
-
-if (DBUS_USE_EXPAT)
- find_package(LibExpat)
-else ()
- find_package(LibXml2)
-endif ()
+find_package(EXPAT)
find_package(X11)
+find_package(GLib2)
+find_package(GObject)
+if(GLIB2_FOUND AND GOBJECT_FOUND)
+ option (DBUS_WITH_GLIB "build with glib" ON)
+endif()
# analogous to AC_USE_SYSTEM_EXTENSIONS in configure.ac
-add_definitions(-D_POSIX_C_SOURCE=199309L -D_GNU_SOURCE)
+add_definitions(-D_GNU_SOURCE)
# do config checks
INCLUDE(ConfigureChecks.cmake)
@@ -155,12 +171,12 @@ if(WIN32)
endif(MSVC)
endif(WIN32)
-if (UNIX AND NOT DBUS_DISABLE_ASSERTS)
+if (UNIX AND NOT DBUS_DISABLE_ASSERT)
# required for backtrace
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wl,--export-dynamic")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wl,--export-dynamic")
add_definitions(-DDBUS_BUILT_R_DYNAMIC)
-endif (UNIX AND NOT DBUS_DISABLE_ASSERTS)
+endif (UNIX AND NOT DBUS_DISABLE_ASSERT)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
@@ -225,11 +241,12 @@ ENABLE_TESTING()
########### command line options ###############
# TODO: take check from configure.in
-#AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests],[enable unit test code]),enable_tests=$enableval,enable_tests=$USE_MAINTAINER_MODE)
option (DBUS_BUILD_TESTS "enable unit test code" ON)
if(DBUS_BUILD_TESTS)
- add_definitions(-DDBUS_BUILD_TESTS -DDBUS_ENABLE_EMBEDDED_TESTS)
+ set (DBUS_ENABLE_EMBEDDED_TESTS ON)
+ set (DBUS_ENABLE_MODULAR_TESTS ON)
+ add_definitions(-DDBUS_ENABLE_EMBEDDED_TESTS -DDBUS_ENABLE_MODULAR_TESTS)
endif(DBUS_BUILD_TESTS)
option (DBUS_USE_OUTPUT_DEBUG_STRING "enable win32 debug port for message output" OFF)
@@ -242,7 +259,6 @@ if(WIN32)
option (DBUS_SERVICE "enable dbus service installer" OFF)
endif(WIN32)
-#AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no)
option (DBUS_ENABLE_ANSI "enable -ansi -pedantic gcc flags" OFF)
if(DBUS_ENABLE_ANSI)
if(NOT MSVC)
@@ -252,14 +268,11 @@ if(DBUS_ENABLE_ANSI)
endif(NOT MSVC)
endif(DBUS_ENABLE_ANSI)
-#AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
option (DBUS_ENABLE_VERBOSE_MODE "support verbose debug mode" ON)
-#AC_ARG_ENABLE(checks, AS_HELP_STRING([--enable-checks],[include sanity checks on public API]),enable_checks=$enableval,enable_checks=yes)
option (DBUS_DISABLE_CHECKS "Disable public API sanity checking" OFF)
if(NOT MSVC)
- #AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],[compile with coverage profiling instrumentation (gcc only)]),enable_gcov=$enableval,enable_gcov=no)
option (DBUS_GCOV_ENABLED "compile with coverage profiling instrumentation (gcc only)" OFF)
if(DBUS_GCOV_ENABLED)
add_definitions(-fprofile-arcs -ftest-coverage)
@@ -269,21 +282,27 @@ if(NOT MSVC)
endif(DBUS_GCOV_ENABLED)
endif(NOT MSVC)
-#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)
-# -> moved before include(ConfigureChecks.cmake)
-
-#AC_ARG_ENABLE(selinux, AS_HELP_STRING([--enable-selinux],[build with SELinux support]),enable_selinux=$enableval,enable_selinux=auto)
-#selinux missing
-
-#AC_ARG_ENABLE(dnotify, AS_HELP_STRING([--enable-dnotify],[build with dnotify support (linux only)]),enable_dnotify=$enableval,enable_dnotify=auto)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
- option (DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX "build with dnotify support (linux only)" ON) # add a check !
+ option (DBUS_BUS_ENABLE_INOTIFY "build with inotify support (linux only)" ON)
+ if(DBUS_BUS_ENABLE_INOTIFY)
+ check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
+ if(NOT HAVE_SYS_INOTIFY_H)
+ message(FATAL_ERROR "sys/inotify.h not found!")
+ endif(NOT HAVE_SYS_INOTIFY_H)
+ endif(DBUS_BUS_ENABLE_INOTIFY)
+elseif("${CMAKE_SYSTEM_NAME}" MATCHES ".*BSD")
+ option (DBUS_BUS_ENABLE_KQUEUE "build with kqueue support (FreeBSD only)" ON)
+ if(DBUS_BUS_ENABLE_KQUEUE)
+ # cmake check a header by compiling a test program with
+ # the header, sys/event.h needs stdint.h and sys/types.h
+ # to work.
+ check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
+ if(NOT HAVE_SYS_EVENT_H)
+ message(FATAL_ERROR "sys/event.h not found!")
+ endif(NOT HAVE_SYS_EVENT_H)
+ endif(DBUS_BUS_ENABLE_KQUEUE)
endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
-#AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support (FreeBSD only)]),enable_kqueue=$enableval,enable_kqueue=auto)
-#missing
-
-#AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)
STRING(TOUPPER ${CMAKE_SYSTEM_NAME} sysname)
if("${sysname}" MATCHES ".*SOLARIS.*")
option (HAVE_CONSOLE_OWNER_FILE "enable console owner file (solaris only)" ON)
@@ -292,31 +311,14 @@ if("${sysname}" MATCHES ".*SOLARIS.*")
endif(HAVE_CONSOLE_OWNER_FILE)
endif("${sysname}" MATCHES ".*SOLARIS.*")
-#AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use]))
-if(NOT LIBXML2_FOUND AND NOT LIBEXPAT_FOUND)
- message(FATAL "Neither expat nor libxml2 found!")
-endif(NOT LIBXML2_FOUND AND NOT LIBEXPAT_FOUND)
-
-if(DBUS_USE_EXPAT)
- SET(XML_LIB "Expat")
- SET(XML_LIBRARY ${LIBEXPAT_LIBRARIES})
- SET(XML_INCLUDE_DIR ${LIBEXPAT_INCLUDE_DIR})
-else(DBUS_USE_EXPAT)
- SET(XML_LIB "LibXML2")
- SET(XML_LIBRARY ${LIBXML2_LIBRARIES})
- SET(XML_INCLUDE_DIR ${LIBXML2_INCLUDE_DIR})
-endif(DBUS_USE_EXPAT)
-
-
-#AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install]))
-#AC_ARG_WITH(session-socket-dir, AS_HELP_STRING([--with-session-socket-dir=[dirname]],[Where to put sockets for the per-login-session message bus]))
-#AC_ARG_WITH(test-socket-dir, AS_HELP_STRING([--with-test-socket-dir=[dirname]],[Where to put sockets for make check]))
-#AC_ARG_WITH(system-pid-file, AS_HELP_STRING([--with-system-pid-file=[pidfile]],[PID file for systemwide daemon]))
-#AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon]))
-#AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip]))
-#AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner]))
-#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]))
+if(NOT EXPAT_FOUND)
+ message(FATAL_ERROR "expat not found!")
+endif(NOT EXPAT_FOUND)
+
+SET(XML_LIB "Expat")
+SET(XML_LIBRARY ${EXPAT_LIBRARIES})
+SET(XML_INCLUDE_DIR ${EXPAT_INCLUDE_DIR})
+
# all missing or hardcoded for now
# 'hidden' ones
@@ -351,9 +353,8 @@ endif(X11_FOUND)
# test binary names
if (WIN32)
- # Automake calls this EXEEXT, and CMake doesn't have a standard name
- # for it; follow Automake's naming convention so we can share .in files
- set (EXEEXT ".exe")
+ # follow Automake's naming convention so we can share .in files
+ set (EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
endif(WIN32)
if (MSVC_IDE)
@@ -388,7 +389,7 @@ endif (MSVC_IDE)
else (NOT $ENV{TMP} STREQUAL "")
if (WIN32)
#Should never happen, both TMP and TEMP seem always set on Windows
- message(FATAL "Could not determine a usable temporary directory")
+ message(FATAL_ERROR "Could not determine a usable temporary directory")
else(WIN32)
set (DBUS_SESSION_SOCKET_DIR /tmp)
endif(WIN32)
@@ -396,17 +397,6 @@ endif (MSVC_IDE)
endif (NOT $ENV{TEMP} STREQUAL "")
endif (NOT $ENV{TMPDIR} STREQUAL "")
-#AC_ARG_WITH(test-socket-dir, AS_HELP_STRING([--with-test-socket-dir=[dirname]],[Where to put sockets for make check]))
-
-#AC_ARG_WITH(system-pid-file, AS_HELP_STRING([--with-system-pid-file=[pidfile]],[PID file for systemwide daemon]))
-
-#if ! test -z "$with_system_pid_file"; then
-# DBUS_SYSTEM_PID_FILE=$with_system_pid_file
-#elif test x$operating_system = xredhat ; then
-# DBUS_SYSTEM_PID_FILE=${EXPANDED_LOCALSTATEDIR}/run/messagebus.pid
-#else
-# DBUS_SYSTEM_PID_FILE=${EXPANDED_LOCALSTATEDIR}/run/dbus/pid
-#fi
# TODO: fix redhet
if (WIN32)
# bus-test expects a non empty string
@@ -415,32 +405,39 @@ else (WIN32)
set (DBUS_SYSTEM_PID_FILE ${EXPANDED_LOCALSTATEDIR}/run/dbus/pid)
endif (WIN32)
-#AC_ARG_WITH(system-socket, AS_HELP_STRING([--with-system-socket=[filename]],[UNIX domain socket for systemwide daemon]))
-
-#AC_ARG_WITH(console-auth-dir, AS_HELP_STRING([--with-console-auth-dir=[dirname]],[directory to check for console ownerhip]))
-
if (WIN32)
set (DBUS_CONSOLE_AUTH_DIR "")
else (WIN32)
set (DBUS_CONSOLE_AUTH_DIR "/var/run/console/")
endif (WIN32)
-#AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)]))
-
set (DBUS_USER )
+# In Autotools this has a different default on QNX, but there seems little
+# point in replicating that here; if you're on an unusual Unix, use Autotools.
+set (DEFAULT_MESSAGE_UNIX_FDS 1024)
+
+# 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.
+set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path=${EXPANDED_LOCALSTATEDIR}/run/dbus/system_bus_socket" CACHE STRING "system bus default address")
if (WIN32)
- set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "nonce-tcp:" CACHE STRING "system bus default address")
- set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "nonce-tcp:" CACHE STRING "session bus default address")
+ 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")
set (DBUS_SYSTEM_CONFIG_FILE "etc/dbus-1/system.conf")
set (DBUS_SESSION_CONFIG_FILE "etc/dbus-1/session.conf")
# bus-test expects a non empty string
set (DBUS_USER "Administrator")
else (WIN32)
- set (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:tmpdir=" CACHE STRING "system bus default address")
- set (DBUS_SESSION_BUS_DEFAULT_ADDRESS "unix:path=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default address")
+ set (DBUS_SESSION_BUS_LISTEN_ADDRESS "unix:tmpdir=${DBUS_SESSION_SOCKET_DIR}" CACHE STRING "session bus default listening address")
+ set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
set (sysconfdir "")
set (configdir ${sysconfdir}/dbus-1 )
set (DBUS_SYSTEM_CONFIG_FILE ${configdir}/system.conf)
@@ -470,6 +467,7 @@ if (DBUS_BUILD_TESTS)
set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data)
set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} )
set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test)
+ set(TEST_BUS_LAUNCH_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-launch${EXEEXT})
if (UNIX)
set (TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}")
endif (UNIX)
@@ -485,7 +483,9 @@ set(DBUS_INTERNAL_LIBRARIES dbus-internal)
# important note: DBUS_INTERNAL_xxxxx_DEFINITIONS must *not* be set when building dbus-1 library
set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC)
set (DBUS_INTERNAL_LIBRARY_DEFINITIONS "-DDBUS_STATIC_BUILD")
-set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD")
+# For now, the CMake build system doesn't support replacing the internal
+# main loop with dbus-glib
+set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD -DDBUS_COMPILATION -DDBUS_TEST_USE_INTERNAL")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
@@ -524,7 +524,6 @@ message(" install exec_prefix: ${exec_prefix} "
message(" install libdir: ${EXPANDED_LIBDIR} ")
message(" install bindir: ${EXPANDED_BINDIR} ")
message(" install sysconfdir: ${EXPANDED_SYSCONFDIR} ")
-#message(" install localstatedir: ${EXPANDED_LOCALSTATEDIR} ")
message(" install datadir: ${EXPANDED_DATADIR} ")
message(" source code location: ${DBUS_SOURCE_DIR} ")
message(" build dir: ${CMAKE_BINARY_DIR} ")
@@ -543,27 +542,24 @@ message(" Doxygen: ${DOXYGEN} "
message(" Docbook Generator: ${DOCBOOK_GENERATOR_NAME} ")
-#message(" Maintainer mode: ${USE_MAINTAINER_MODE} ")
message(" gcc coverage profiling: ${DBUS_GCOV_ENABLED} ")
message(" Building unit tests: ${DBUS_BUILD_TESTS} ")
+message(" Building with GLib: ${DBUS_WITH_GLIB} ")
message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ")
-message(" Building w/o assertions: ${DBUS_DISABLE_ASSERTS} ")
+message(" Building w/o assertions: ${DBUS_DISABLE_ASSERT} ")
message(" Building w/o checks: ${DBUS_DISABLE_CHECKS} ")
message(" Building bus stats API: ${DBUS_ENABLE_STATS} ")
message(" installing system libs: ${DBUS_INSTALL_SYSTEM_LIBS} ")
-#message(" Building SELinux support: ${have_selinux} ")
-#message(" Building dnotify support: ${have_dnotify} ")
+message(" Building inotify support: ${DBUS_BUS_ENABLE_INOTIFY} ")
+message(" Building kqueue support: ${DBUS_BUS_ENABLE_KQUEUE} ")
message(" Building Doxygen docs: ${DBUS_ENABLE_DOXYGEN_DOCS} ")
message(" Building XML docs: ${DBUS_ENABLE_XML_DOCS} ")
-#message(" Gettext libs (empty OK): ${INTLLIBS} ")
-message(" Using XML parser: ${XML_LIB} ")
message(" Daemon executable name: ${DBUS_DAEMON_NAME}")
if (WIN32)
message(" System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} ")
-message(" Session bus address: ${DBUS_SESSION_BUS_DEFAULT_ADDRESS} ")
+message(" Session bus listens on: ${DBUS_SESSION_BUS_LISTEN_ADDRESS} ")
+message(" Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} ")
else (WIN32)
-#message(" Init scripts style: ${with_init_scripts} ")
-#message(" Abstract socket names: ${have_abstract_sockets} ")
message(" System bus socket: ${DBUS_SYSTEM_SOCKET} ")
message(" System bus address: ${DBUS_SYSTEM_BUS_DEFAULT_ADDRESS} ")
message(" System bus PID file: ${DBUS_SYSTEM_PID_FILE} ")
@@ -582,9 +578,9 @@ if (DBUS_BUILD_TESTS)
message("NOTE: building with unit tests increases the size of the installed library and renders it insecure.")
endif(DBUS_BUILD_TESTS)
-if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERTS)
+if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
message("NOTE: building with unit tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)")
-endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERTS)
+endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
if (DBUS_GCOV_ENABLED)
message("NOTE: building with coverage profiling is definitely for developers only.")
@@ -594,9 +590,9 @@ if (DBUS_ENABLE_VERBOSE_MODE)
message("NOTE: building with verbose mode increases library size, may slightly increase security risk, and decreases performance.")
endif(DBUS_ENABLE_VERBOSE_MODE)
-if(NOT DBUS_DISABLE_ASSERTS)
+if(NOT DBUS_DISABLE_ASSERT)
message("NOTE: building with assertions increases library size and decreases performance.")
-endif(NOT DBUS_DISABLE_ASSERTS)
+endif(NOT DBUS_DISABLE_ASSERT)
if (DBUS_DISABLE_CHECKS)
message("NOTE: building without checks for arguments passed to public API makes it harder to debug apps using D-BUS, but will slightly decrease D-BUS library size and _very_ slightly improve performance.")
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index 33a9cee2..d290b0f2 100644
--- a/cmake/ConfigureChecks.cmake
+++ b/cmake/ConfigureChecks.cmake
@@ -11,7 +11,6 @@ check_include_file(sys/time.h HAVE_SYS_TIME_H)# dbus-sysdeps-win.c
check_include_file(sys/wait.h HAVE_SYS_WAIT_H)# dbus-sysdeps-win.c
check_include_file(time.h HAVE_TIME_H) # dbus-sysdeps-win.c
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)# dbus-sysdeps-win.c
-check_include_file(wspiapi.h HAVE_WSPIAPI_H) # dbus-sysdeps-win.c
check_include_file(unistd.h HAVE_UNISTD_H) # dbus-sysdeps-util-win.c
check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h
check_include_file(sys/syslimits.h HAVE_SYS_SYSLIMITS_H) # dbus-sysdeps-unix.c
@@ -52,25 +51,23 @@ check_type_size("__int64" SIZEOF___INT64)
# DBUS_INT64_TYPE
if(SIZEOF_INT EQUAL 8)
- set (DBUS_HAVE_INT64 1)
set (DBUS_INT64_TYPE "int")
set (DBUS_INT64_CONSTANT "(val)")
set (DBUS_UINT64_CONSTANT "(val##U)")
elseif(SIZEOF_LONG EQUAL 8)
- set (DBUS_HAVE_INT64 1)
set (DBUS_INT64_TYPE "long")
set (DBUS_INT64_CONSTANT "(val##L)")
set (DBUS_UINT64_CONSTANT "(val##UL)")
elseif(SIZEOF_LONG_LONG EQUAL 8)
- set (DBUS_HAVE_INT64 1)
set (DBUS_INT64_TYPE "long long")
set (DBUS_INT64_CONSTANT "(val##LL)")
set (DBUS_UINT64_CONSTANT "(val##ULL)")
elseif(SIZEOF___INT64 EQUAL 8)
- set (DBUS_HAVE_INT64 1)
set (DBUS_INT64_TYPE "__int64")
set (DBUS_INT64_CONSTANT "(val##i64)")
set (DBUS_UINT64_CONSTANT "(val##ui64)")
+else(SIZEOF_INT EQUAL 8)
+ message (FATAL_ERROR "Could not find a 64-bit integer type")
endif(SIZEOF_INT EQUAL 8)
# DBUS_INT32_TYPE
@@ -93,7 +90,7 @@ find_program(DOXYGEN doxygen)
find_program(XMLTO xmlto)
if(MSVC)
- SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN";)
+ SET(DBUS_VA_COPY_FUNC "_DBUS_VA_COPY_ASSIGN")
else(MSVC)
write_file("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/cmake_try_compile.c" "#include <stdarg.h>
#include <stdlib.h>
diff --git a/cmake/Doxyfile.cmake b/cmake/Doxyfile.cmake
deleted file mode 100644
index e00984e7..00000000
--- a/cmake/Doxyfile.cmake
+++ /dev/null
@@ -1,182 +0,0 @@
-# Doxyfile 0.1
-
-#---------------------------------------------------------------------------
-# General configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = D-Bus
-PROJECT_NUMBER = @VERSION@
-OUTPUT_DIRECTORY = api
-OUTPUT_LANGUAGE = English
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = NO
-HIDE_UNDOC_MEMBERS = NO
-HIDE_UNDOC_CLASSES = NO
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ALWAYS_DETAILED_SEC = NO
-FULL_PATH_NAMES = NO
-STRIP_FROM_PATH =
-INTERNAL_DOCS = NO
-STRIP_CODE_COMMENTS = YES
-CASE_SENSE_NAMES = YES
-SHORT_NAMES = NO
-HIDE_SCOPE_NAMES = NO
-VERBATIM_HEADERS = YES
-SHOW_INCLUDE_FILES = YES
-JAVADOC_AUTOBRIEF = YES
-INHERIT_DOCS = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-TAB_SIZE = 8
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = YES
-ALIASES =
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-OPTIMIZE_OUTPUT_FOR_C = YES
-SHOW_USED_FILES = YES
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = YES
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = YES
-WARN_FORMAT =
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = @top_srcdir@/dbus
-FILE_PATTERNS = *.c *.h
-RECURSIVE = YES
-#EXCLUDE = test
-
-# If the value of the INPUT tag contains directories, you can use the
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
-# certain files from those directories.
-
-EXCLUDE_PATTERNS = Makefile.* ChangeLog CHANGES CHANGES.* README \
- README.* *.png AUTHORS DESIGN DESIGN.* *.desktop \
- DESKTOP* COMMENTS HOWTO magic NOTES TODO THANKS
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or
-# directories that contain example code fragments that are included (see
-# the \include command).
-
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS =
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH =
-INPUT_FILTER =
-FILTER_SOURCE_FILES = NO
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-REFERENCED_BY_RELATION = YES
-REFERENCES_RELATION = YES
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = NO
-COLS_IN_ALPHA_INDEX = 5
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT =
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = NO
-GENERATE_CHI = NO
-BINARY_TOC = NO
-TOC_EXPAND = NO
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = NO
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = NO
-LATEX_OUTPUT =
-COMPACT_LATEX = NO
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = NO
-USE_PDFLATEX = NO
-LATEX_BATCHMODE = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT =
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = YES
-MAN_OUTPUT = man
-MAN_EXTENSION = .3dbus
-MAN_LINKS = YES
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = YES
-EXPAND_ONLY_PREDEF = YES
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = "DBUS_BEGIN_DECLS=" \
- "DBUS_END_DECLS=" \
- "DOXYGEN_SHOULD_SKIP_THIS" \
- "DBUS_GNUC_DEPRECATED=" \
- "_DBUS_DEFINE_GLOBAL_LOCK(name)=" \
- "_DBUS_GNUC_PRINTF(from,to)=" \
- "DBUS_EXPORT="
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::addtions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-PERL_PATH =
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = YES
-HAVE_DOT = NO
-CLASS_GRAPH = YES
-COLLABORATION_GRAPH = YES
-TEMPLATE_RELATIONS = YES
-HIDE_UNDOC_RELATIONS = YES
-INCLUDE_GRAPH = YES
-INCLUDED_BY_GRAPH = YES
-GRAPHICAL_HIERARCHY = YES
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_WIDTH = 640
-MAX_DOT_GRAPH_HEIGHT = 1024
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::addtions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = NO
diff --git a/cmake/bus/CMakeLists.txt b/cmake/bus/CMakeLists.txt
index faf9a8e9..f5b41cd8 100644
--- a/cmake/bus/CMakeLists.txt
+++ b/cmake/bus/CMakeLists.txt
@@ -1,5 +1,3 @@
-project(bus)
-
add_definitions(-DDBUS_COMPILATION)
SET(EFENCE "")
@@ -12,7 +10,10 @@ set (config_DATA
# config files for installation
CONFIGURE_FILE( "${BUS_DIR}/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/session.conf" IMMEDIATE @ONLY)
+FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/session.d)
+
CONFIGURE_FILE( "system.conf.cmake" "${CMAKE_CURRENT_BINARY_DIR}/system.conf" IMMEDIATE @ONLY)
+FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/system.d)
# copy services for local daemon start to local service dir data/dbus-1/services
SET (SERVICE_FILES test/data/valid-service-files)
@@ -26,15 +27,15 @@ FOREACH(FILE ${FILES})
configure_file(${FILE} ${TARGET} )
ENDFOREACH(FILE)
-if(DBUS_USE_EXPAT)
- SET (XML_SOURCES ${BUS_DIR}/config-loader-expat.c)
-else(DBUS_USE_EXPAT)
- SET (XML_SOURCES ${BUS_DIR}/config-loader-libxml.c)
-endif (DBUS_USE_EXPAT)
+SET (XML_SOURCES ${BUS_DIR}/config-loader-expat.c)
-# after next cvs update
-#set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-default.c)
-set (DIR_WATCH_SOURCE )
+if (DBUS_BUS_ENABLE_INOTIFY)
+ set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-inotify.c)
+elseif (DBUS_BUS_ENABLE_KQUEUE)
+ set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-kqueue.c)
+else (DBUS_BUS_ENABLE_INOTIFY)
+ set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-default.c)
+endif (DBUS_BUS_ENABLE_INOTIFY)
set (BUS_SOURCES
${BUS_DIR}/activation.c
@@ -43,14 +44,13 @@ set (BUS_SOURCES
${BUS_DIR}/bus.h
${BUS_DIR}/config-parser.c
${BUS_DIR}/config-parser.h
- ${BUS_DIR}/config-parser-common.c
- ${BUS_DIR}/config-parser-common.h
+ ${BUS_DIR}/config-parser-common.c
+ ${BUS_DIR}/config-parser-common.h
# ${BUS_DIR}/config-parser-trivial.c
${BUS_DIR}/connection.c
${BUS_DIR}/connection.h
${BUS_DIR}/desktop-file.c
${BUS_DIR}/desktop-file.h
- ${BUS_DIR}/dir-watch-default.c
${BUS_DIR}/dir-watch.h
${BUS_DIR}/dispatch.c
${BUS_DIR}/dispatch.h
@@ -78,7 +78,7 @@ if(DBUS_ENABLE_STATS)
${BUS_DIR}/stats.c
${BUS_DIR}/stats.h
)
-endif()
+endif(DBUS_ENABLE_STATS)
include_directories(${XML_INCLUDE_DIR})
@@ -105,12 +105,11 @@ if (DBUS_SERVICE)
install_targets(/bin dbus-service )
endif (DBUS_SERVICE)
-if (DBUS_BUILD_TESTS)
- add_executable(bus-test ${BUS_SOURCES} ${BUS_DIR}/test-main.c)
- target_link_libraries(bus-test ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
- set_target_properties(bus-test PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
- add_test(bus-test ${EXECUTABLE_OUTPUT_PATH}/bus-test ${CMAKE_BINARY_DIR}/test/data)
-endif (DBUS_BUILD_TESTS)
+if (DBUS_ENABLE_EMBEDDED_TESTS)
+ set(SOURCES ${BUS_SOURCES} ${BUS_DIR}/test-main.c)
+ add_test_executable(test-bus "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
+ set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
+endif (DBUS_ENABLE_EMBEDDED_TESTS)
if(MSVC)
project_source_group(${GROUP_CODE} bus_test_SOURCES dummy)
@@ -146,11 +145,9 @@ if(NOT WIN32)
set_target_properties(dbus-daemon-launch-helper-test PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST")
target_link_libraries(dbus-daemon-launch-helper-test ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} )
- add_executable(bus-test-launch-helper ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/test-launch-helper.c)
- set_target_properties(bus-test-launch-helper PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST -DACTIVATION_LAUNCHER_DO_OOM")
- target_link_libraries(bus-test-launch-helper ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} )
- add_test(bus-test-launch-helper ${EXECUTABLE_OUTPUT_PATH}/bus-test-launch-helper )
-
+ set (SOURCES ${LAUNCH_HELPER_SOURCES} ${BUS_DIR}/test-launch-helper.c)
+ add_test_executable(test-bus-launch-helper "${SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
+ set_target_properties(test-bus-launch-helper PROPERTIES COMPILE_FLAGS "-DACTIVATION_LAUNCHER_TEST -DACTIVATION_LAUNCHER_DO_OOM")
endif(NOT WIN32)
#### Init scripts fun
diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake
index 6221c190..119ed396 100644
--- a/cmake/config.h.cmake
+++ b/cmake/config.h.cmake
@@ -6,6 +6,12 @@
/* indicate that we are building with cmake */
#define DBUS_CMAKE 1
+@AUTOPACKAGE_CONFIG_H_TEMPLATE@
+
+/*
+ * Variables defined by AC_DEFINE in ../configure.ac
+ * should be placed in this file
+*/
#cmakedefine HAVE_GNUC_VARARGS 1
#cmakedefine DBUS_CONSOLE_AUTH_DIR "@DBUS_CONSOLE_AUTH_DIR@"
@@ -15,35 +21,30 @@
#cmakedefine DBUS_SESSION_CONFIG_FILE "@DBUS_SESSION_CONFIG_FILE@"
#cmakedefine DBUS_DAEMON_NAME "@DBUS_DAEMON_NAME@"
#cmakedefine DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@"
+#cmakedefine DBUS_SESSION_BUS_CONNECT_ADDRESS "@DBUS_SESSION_BUS_CONNECT_ADDRESS@"
#cmakedefine DBUS_MACHINE_UUID_FILE "@DBUS_MACHINE_UUID_FILE@"
-#cmakedefine DBUS_SESSION_BUS_DEFAULT_ADDRESS "@DBUS_SESSION_BUS_DEFAULT_ADDRESS@"
#cmakedefine DBUS_DAEMONDIR "@DBUS_DAEMONDIR@"
-#cmakedefine PACKAGE "@PACKAGE@"
-/* Version number of package */
-#cmakedefine DBUS_MAJOR_VERSION @DBUS_MAJOR_VERSION@
-#cmakedefine DBUS_MINOR_VERSION @DBUS_MINOR_VERSION@
-#cmakedefine DBUS_MICRO_VERSION @DBUS_MICRO_VERSION@
-#cmakedefine DBUS_VERSION ((@DBUS_MAJOR_VERSION@ << 16) | (@DBUS_MINOR_VERSION@ << 8) | (@DBUS_MICRO_VERSION@))
-#cmakedefine DBUS_VERSION_STRING "@DBUS_VERSION_STRING@"
-#cmakedefine DBUS_ENABLE_STATS
-#define VERSION DBUS_VERSION_STRING
+#cmakedefine DBUS_ENABLE_STATS
#define TEST_LISTEN "@TEST_LISTEN@"
// test binaries
#define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@"
#define DBUS_EXEEXT "@EXEEXT@"
-
-/* Full path to test file test/test-exit in builddir */
-#define TEST_BUS_BINARY "@TEST_BUS_BINARY@"
+#cmakedefine TEST_BUS_LAUNCH_BINARY "@TEST_BUS_LAUNCH_BINARY@"
/* Some dbus features */
-#cmakedefine DBUS_BUILD_TESTS 1
#cmakedefine DBUS_ENABLE_ANSI 1
#cmakedefine DBUS_ENABLE_VERBOSE_MODE 1
-#cmakedefine DBUS_DISABLE_ASSERTS 1
+#cmakedefine DBUS_DISABLE_ASSERT 1
+#ifndef DBUS_DISABLE_ASSERT
+# define DBUS_ENABLE_ASSERT 1
+#endif
#cmakedefine DBUS_DISABLE_CHECKS 1
+#ifndef DBUS_DISABLE_CHECKS
+# define DBUS_ENABLE_CHECKS 1
+#endif
/* xmldocs */
/* doxygen */
#cmakedefine DBUS_GCOV_ENABLED 1
@@ -63,7 +64,6 @@
#endif
/* selinux */
-#cmakedefine DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX 1
/* kqueue */
#cmakedefine HAVE_CONSOLE_OWNER_FILE 1
#define DBUS_CONSOLE_OWNER_FILE "@DBUS_CONSOLE_OWNER_FILE@"
@@ -82,6 +82,8 @@
# define DBUS_ENABLE_X11_AUTOLAUNCH 1
#endif
+#define DBUS_DEFAULT_MESSAGE_UNIX_FDS @DEFAULT_MESSAGE_UNIX_FDS@
+
#define _DBUS_VA_COPY_ASSIGN(a1,a2) { a1 = a2; }
#cmakedefine DBUS_VA_COPY_FUNC
@@ -120,9 +122,6 @@
/* Define to 1 if you have ws2tcpip.h */
#cmakedefine HAVE_WS2TCPIP_H
-/* Define to 1 if you have wspiapi.h */
-#cmakedefine HAVE_WSPIAPI_H 1
-
/* Define to 1 if you have unistd.h */
#cmakedefine HAVE_UNISTD_H 1
diff --git a/cmake/cross-compile.sh b/cmake/cross-compile.sh
deleted file mode 100755
index 49e66e50..00000000
--- a/cmake/cross-compile.sh
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/sh
-#
-# cross compile script for cmake
-#
-# initial written by Fridrich Strba
-# refactored to debian/lenny by Ralf Habacker
-#
-# reported to work at least on debian/lenny
-#
-
-if test -f /usr/bin/i686-pc-mingw32-gcc; then
- cross_cc=i686-pc-mingw32
-elif test -f /usr/bin/i586-mingw32msvc-gcc; then
- cross_cc=i586-mingw32msvc
-else
- echo "could not determine mingw cross compiler"
- exit 1
-fi
-
-if test -d ~/$cross_cc; then
- cross_root=~/$cross_cc
-elif test -d /usr/$cross_cc/sys-root/mingw; then
- cross_root=/usr/$cross_cc/sys-root/mingw
-elif test -d /usr/$cross_cc/lib; then
- cross_root=/usr/$cross_cc
-else
- echo "could not determine mingw cross compiler sdk"
- exit 1
-fi
-
-if ! TEMP=`mktemp --tmpdir -d dbus-cross-compile.XXXXXX`; then
- echo "mktemp failed, try with coreutils 6.10 or later?" >&2
- exit 1
-fi
-
-# make cmake happy
-export TEMP
-
-HOST_CC=gcc; export HOST_CC;
-
-if test -d $cross_root/lib/pkgconfig; then
- PKG_CONFIG_PATH="$cross_root/lib/pkgconfig:$cross_root/share/pkgconfig"; export PKG_CONFIG_PATH;
-fi
-
-if test -d "$MINGW32_CLASSPATH" || test -f "$cross_root/share/java/libgcj.jar"; then
- CLASSPATH="$CLASSPATH:${MINGW32_CLASSPATH:-$cross_root/share/java/libgcj.jar:$cross_root/share/java/libgcj-tools.jar}"; export CLASSPATH;
-fi
-
-_PREFIX="/usr/bin/$cross_cc-";
-for i in `ls -1 ${_PREFIX}* | grep -v 'gcc-'`; do
- x=`echo $i|sed "s,${_PREFIX},,"|sed "s,\.awk*,,"|tr "a-z+-" "A-ZX_"`;
- declare -x $x="$i" ; export $x;
-done;
-unset _PREFIX;
-
-CC="${MINGW32_CC:-$cross_cc-gcc}"; export CC;
-CFLAGS="${MINGW32_CFLAGS:--O2 -g -pipe -Wall -fexceptions -fno-omit-frame-pointer -fno-optimize-sibling-calls --param=ssp-buffer-size=4 -mms-bitfields}"; export CFLAGS;
-LDFLAGS="${MINGW32_LDFLAGS:--Wl,--exclude-libs=libintl.a -Wl,--exclude-libs=libiconv.a}"; export LDFLAGS;
-
-if [ -x "/usr/bin/$cross_cc-g++" ]; then
- CXX="${MINGW32_CXX:-$cross_cc-g++}"; export CXX;
- CXXFLAGS="${MINGW32_CXXFLAGS:--O2 -g -pipe -Wall -fexceptions -fno-omit-frame-pointer -fno-optimize-sibling-calls --param=ssp-buffer-size=4 -mms-bitfields}"; export CXXFLAGS;
-else
- CXX=; export CXX;
- ac_cv_prog_CXX=no; export ac_cv_prog_CXX;
- CXXFLAGS=; export CXXFLAGS;
-fi;
-for i in `ls $cross_root/bin/*|grep -- "-config$"` ; do
- x=`basename $i|tr "a-z+-" "A-ZX_"|sed "s,\.,,"`;
- declare -x $x="$i" ; export $x;
-done;
-unset x i ;
-
-if ! test -f "$cross_root/lib/libexpat.dll.a"; then
- (cd $TEMP && wget http://www.winkde.org/pub/kde/ports/win32/repository/win32libs/expat-2.0.1-bin.zip)
- (cd $TEMP && wget http://www.winkde.org/pub/kde/ports/win32/repository/win32libs/expat-2.0.1-lib.zip)
- (cd $cross_root && unzip -x $TMP/expat-2.0.1-bin.zip)
- (cd $cross_root && unzip -x $TMP/expat-2.0.1-lib.zip)
-fi
-
-if test -f "$cross_root/lib/libexpat.dll.a"; then
- xml_library=-DDBUS_USE_EXPAT=On -DLIBEXPAT_INCLUDE_DIR:PATH=$cross_root/include -DLIBEXPAT_LIBRARIES:PATH=$cross_root/lib/libexpat.dll.a
-else
- echo "could not find a cross compile xml libraray"
- exit 1
-fi
-
-cmake \
- -DCMAKE_SYSTEM_NAME="Windows" \
- -DCMAKE_VERBOSE_MAKEFILE=ON \
- -DCMAKE_INSTALL_PREFIX:PATH=$cross_root \
- -DCMAKE_INSTALL_LIBDIR:PATH=$cross_root/lib \
- -DINCLUDE_INSTALL_DIR:PATH=$cross_root/include \
- -DLIB_INSTALL_DIR:PATH=$cross_root/lib \
- -DSYSCONF_INSTALL_DIR:PATH=$cross_root/etc \
- -DSHARE_INSTALL_PREFIX:PATH=$cross_root/share \
- -DBUILD_SHARED_LIBS:BOOL=ON \
- -DCMAKE_C_COMPILER="/usr/bin/$cross_cc-gcc" \
- -DCMAKE_CXX_COMPILER="/usr/bin/$cross_cc-g++" \
- -DCMAKE_FIND_ROOT_PATH="$cross_root" \
- -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
- -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
- -DCMAKE_CXX_COMPILER="/usr/bin/$cross_cc-g++" \
- -DCMAKE_FIND_ROOT_PATH="$cross_root" \
- -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
- -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
- $xml_library \
- -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
- $*
-
diff --git a/cmake/dbus-env.bat.cmake b/cmake/dbus-env.bat.cmake
index 85f70051..d859ce03 100644
--- a/cmake/dbus-env.bat.cmake
+++ b/cmake/dbus-env.bat.cmake
@@ -2,7 +2,7 @@
@echo off
:: session bus address
-set DBUS_SESSION_BUS_ADDRESS=@DBUS_SESSION_BUS_DEFAULT_ADDRESS@
+set DBUS_SESSION_BUS_ADDRESS=@DBUS_SESSION_BUS_CONNECT_ADDRESS@
:: system bus address
-set DBUS_SYSTEM_BUS_DEFAULT_ADDRESS=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@ \ No newline at end of file
+set DBUS_SYSTEM_BUS_DEFAULT_ADDRESS=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt
index 13d6f87a..a5481b78 100644
--- a/cmake/dbus/CMakeLists.txt
+++ b/cmake/dbus/CMakeLists.txt
@@ -1,5 +1,3 @@
-project(dbus-lib)
-
SET(DBUS_DIR ${CMAKE_SOURCE_DIR}/../dbus)
configure_file(${DBUS_DIR}/dbus-arch-deps.h.in ${CMAKE_CURRENT_BINARY_DIR}/dbus-arch-deps.h )
@@ -149,6 +147,7 @@ set (DBUS_SHARED_HEADERS
### should be underscore-prefixed but don't really need
### to be unless they move to DBUS_SHARED_SOURCES later)
set (DBUS_UTIL_SOURCES
+ ${DBUS_DIR}/dbus-asv-util.c
${DBUS_DIR}/dbus-auth-script.c
${DBUS_DIR}/dbus-auth-util.c
${DBUS_DIR}/dbus-credentials-util.c
@@ -165,14 +164,15 @@ set (DBUS_UTIL_SOURCES
${DBUS_DIR}/dbus-sysdeps-util.c
)
-if (DBUS_BUILD_TESTS)
+if (DBUS_ENABLE_EMBEDDED_TESTS)
set (DBUS_UTIL_SOURCES
${DBUS_UTIL_SOURCES}
${DBUS_DIR}/dbus-test.c
)
-endif (DBUS_BUILD_TESTS)
+endif (DBUS_ENABLE_EMBEDDED_TESTS)
set (DBUS_UTIL_HEADERS
+ ${DBUS_DIR}/dbus-asv-util.h
${DBUS_DIR}/dbus-auth-script.h
${DBUS_DIR}/dbus-mainloop.h
${DBUS_DIR}/dbus-message-factory.h
@@ -186,6 +186,7 @@ set (DBUS_UTIL_HEADERS
if (WIN32)
set (DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES}
${DBUS_DIR}/dbus-file-win.c
+ ${DBUS_DIR}/dbus-init-win.cpp
${DBUS_DIR}/dbus-sysdeps-win.c
${DBUS_DIR}/dbus-pipe-win.c
${DBUS_DIR}/dbus-sysdeps-thread-win.c
@@ -264,11 +265,13 @@ if(WIN32)
if(WINCE)
target_link_libraries(dbus-1 ws2)
else(WINCE)
- target_link_libraries(dbus-1 ws2_32 advapi32 netapi32)
+ target_link_libraries(dbus-1 ws2_32 advapi32 netapi32 iphlpapi)
endif(WINCE)
+else(WIN32)
+ target_link_libraries(dbus-1 ${CMAKE_THREAD_LIBS_INIT} rt)
endif(WIN32)
-install_targets(/lib dbus-1 )
+install(TARGETS dbus-1 ${INSTALL_TARGETS_DEFAULT_ARGS})
install_files(/include/dbus FILES ${dbusinclude_HEADERS})
### Internal library, used for the daemon, tools and tests, compiled statically.
@@ -287,17 +290,16 @@ if(WIN32)
if(WINCE)
target_link_libraries(dbus-internal ws2)
else(WINCE)
- target_link_libraries(dbus-internal ws2_32 advapi32 netapi32)
+ target_link_libraries(dbus-internal ws2_32 advapi32 netapi32 iphlpapi)
endif(WINCE)
+else(WIN32)
+ target_link_libraries(dbus-internal ${CMAKE_THREAD_LIBS_INIT} rt)
endif(WIN32)
-if (DBUS_BUILD_TESTS)
- set (TESTS_ENVIRONMENT "DBUS_TEST_DATA=${CMAKE_SOURCE_DIR}/test/data DBUS_TEST_HOMEDIR=${CMAKE_BUILD_DIR}/dbus")
- ADD_EXECUTABLE(dbus-test ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c)
- target_link_libraries(dbus-test ${DBUS_INTERNAL_LIBRARIES})
- add_test(dbus-test ${EXECUTABLE_OUTPUT_PATH}/dbus-test ${CMAKE_SOURCE_DIR}/../test/data)
- set_target_properties(dbus-test PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
-ENDIF (DBUS_BUILD_TESTS)
+if (DBUS_ENABLE_EMBEDDED_TESTS)
+ add_test_executable(test-dbus ${CMAKE_SOURCE_DIR}/../dbus/dbus-test-main.c ${DBUS_INTERNAL_LIBRARIES})
+ set_target_properties(test-dbus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
+ENDIF (DBUS_ENABLE_EMBEDDED_TESTS)
if (UNIX)
# set version info
diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt
index df6b587b..7fdfc219 100644
--- a/cmake/doc/CMakeLists.txt
+++ b/cmake/doc/CMakeLists.txt
@@ -6,9 +6,10 @@ endif(DOXYGEN_EXECUTABLE)
if (DBUS_ENABLE_DOXYGEN_DOCS)
set (top_srcdir ${CMAKE_SOURCE_DIR}/..)
- configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.cmake ${CMAKE_BINARY_DIR}/Doxyfile )
+ configure_file(${CMAKE_SOURCE_DIR}/../Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile )
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif (DBUS_ENABLE_DOXYGEN_DOCS)
@@ -21,54 +22,72 @@ find_program(XMLTO_EXECUTABLE xmlto)
if (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE)
OPTION(DBUS_ENABLE_XML_DOCS "build XML documentation (requires xmlto or meinproc4)" ON)
+ ADD_CUSTOM_TARGET(xmldoc ALL)
endif (MEINPROC4_EXECUTABLE OR XMLTO_EXECUTABLE)
-if (MEINPROC4_EXECUTABLE)
+if (XMLTO_EXECUTABLE)
+ set (DOCBOOK_GENERATOR_NAME "xmlto" PARENT_SCOPE)
+ set(DBUS_XML_DOCS_ENABLED 1)
+ set(MEINPROC4_EXECUTABLE 0)
+ MESSAGE(STATUS "xmlto docbook generator found")
+ set(STYLESHEET_MAN "${DOCBOOKXSL_DIR}/manpages/docbook.xsl")
+ set(STYLESHEET_HTML "${DOCBOOKXSL_DIR}/html/docbook.xsl")
+
+elseif (MEINPROC4_EXECUTABLE)
set(DOCBOOK_GENERATOR_NAME "meinproc4" PARENT_SCOPE)
set(DBUS_XML_DOCS_ENABLED 1)
if(WIN32)
get_filename_component(_a ${MEINPROC4_EXECUTABLE} PATH)
get_filename_component(_meinproc_install_path ${_a} PATH)
+ set(STYLESHEET_HTML "${_meinproc_install_path}/share/apps/ksgmltools2/docbook/xsl/html/docbook.xsl")
else(WIN32)
- set(_meinproc_install_path ${CMAKE_INSTALL_PREFIX})
+ set(STYLESHEET_HTML file:///usr/share/kde4/apps/ksgmltools2/customization/kde-nochunk.xsl)
endif(WIN32)
- set(STYLESHEET "${_meinproc_install_path}/share/apps/ksgmltools2/docbook/xsl/html/docbook.xsl")
-endif (MEINPROC4_EXECUTABLE)
-
-
-if (XMLTO_EXECUTABLE)
- set (DOCBOOK_GENERATOR_NAME "xmlto" PARENT_SCOPE)
- set(DBUS_XML_DOCS_ENABLED 1)
- MESSAGE(STATUS "xmlto docbook generator found")
-endif (XMLTO_EXECUTABLE)
+endif ()
if (DBUS_ENABLE_XML_DOCS)
-macro (DOCBOOK _sources _options)
+macro (DOCBOOK _sources _format)
get_filename_component(_infile ${_sources} ABSOLUTE)
- get_filename_component(_basename ${_infile} NAME_WE)
- set(_outfile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.html)
+ get_filename_component(_name ${_infile} NAME)
+ set(_deps ${CMAKE_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
+
+ if (${_format} STREQUAL "man")
+ string(REPLACE ".xml" "" _outname ${_name})
+ set(STYLESHEET ${STYLESHEET_MAN})
+ else()
+ string(REPLACE ".xml" ".html" _outname ${_name})
+ set(STYLESHEET ${STYLESHEET_HTML})
+ endif ()
+ set(_outfile ${CMAKE_CURRENT_BINARY_DIR}/${_outname})
if (EXISTS ${_sources})
if (MEINPROC4_EXECUTABLE)
- ADD_CUSTOM_TARGET(${_basename}.html ALL
- ${MEINPROC4_EXECUTABLE} --stylesheet ${STYLESHEET} -o ${_outfile} ${_infile}
- DEPENDS ${_infile}
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_outfile}
+ COMMAND ${MEINPROC4_EXECUTABLE} --stylesheet ${STYLESHEET} -o ${_outfile} ${_infile}
+ DEPENDS ${_infile} ${STYLESHEET} ${_deps}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif ()
if (XMLTO_EXECUTABLE)
- ADD_CUSTOM_TARGET(${_basename}.html ALL
- ${XMLTO_EXECUTABLE} -vv ${_options} ${_infile}
- DEPENDS ${_infile}
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${_outfile}
+ COMMAND ${XMLTO_EXECUTABLE} -vv ${_format} ${_infile}
+ DEPENDS ${_infile} ${_deps}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif ()
- install(FILES ${_outfile} DESTINATION share/doc/dbus)
+ if (${_format} STREQUAL "man")
+ install(FILES ${_outfile} DESTINATION share/man/man1)
+ else ()
+ install(FILES ${_outfile} DESTINATION share/doc/dbus)
+ endif ()
else ()
MESSAGE(STATUS "skipping xml doc generating for ${_infile}, file not found")
endif ()
-
+ ADD_CUSTOM_TARGET(${_outname} DEPENDS ${_outfile})
+ ADD_DEPENDENCIES(xmldoc ${_outname})
endmacro (DOCBOOK)
### copy tests to builddir so that generated tests and static tests
@@ -98,11 +117,26 @@ DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-test-plan.xml html-nochunks)
DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-tutorial.xml html-nochunks)
DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-specification.xml html-nochunks)
DOCBOOK(${CMAKE_SOURCE_DIR}/../doc/dbus-faq.xml html-nochunks)
-DOCBOOK(${CMAKE_SOURCE_DIR}/bus/dbus-daemon.xml html-nochunks)
-DOCBOOK(${CMAKE_SOURCE_DIR}/tools/dbus-monitor.xml html-nochunks)
-DOCBOOK(${CMAKE_SOURCE_DIR}/tools/dbus-send.xml html-nochunks)
-DOCBOOK(${CMAKE_SOURCE_DIR}/tools/dbus-launch.xml html-nochunks)
-
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-cleanup-sockets.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml)
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-daemon.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml)
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-launch.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml)
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-monitor.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml)
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-send.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml)
+configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-uuidgen.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml html-nochunks)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml html-nochunks)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml html-nochunks)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml html-nochunks)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml html-nochunks)
+DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml html-nochunks)
+if (UNIX)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-daemon.1.xml man)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-monitor.1.xml man)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-send.1.xml man)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-launch.1.xml man)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml man)
+ DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-cleanup-sockets.1.xml man)
+endif()
#
# handle html index file
#
diff --git a/cmake/modules/COPYING-CMAKE-SCRIPTS b/cmake/modules/COPYING-CMAKE-SCRIPTS
new file mode 100644
index 00000000..53b6b71e
--- /dev/null
+++ b/cmake/modules/COPYING-CMAKE-SCRIPTS
@@ -0,0 +1,22 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/cmake/modules/CPackInstallConfig.cmake b/cmake/modules/CPackInstallConfig.cmake
index f8073a25..74b66898 100644
--- a/cmake/modules/CPackInstallConfig.cmake
+++ b/cmake/modules/CPackInstallConfig.cmake
@@ -1,14 +1,7 @@
if (DBUS_INSTALL_SYSTEM_LIBS)
if (MINGW)
- if (DBUS_USE_EXPAT)
- # expat
- install_files(/bin FILES ${LIBEXPAT_LIBRARIES})
- else (DBUS_USE_EXPAT)
- # xml2
- install_files(/bin FILES ${LIBXML2_LIBRARIES})
- install_files(/bin FILES ${LIBICONV_LIBRARIES})
- endif (DBUS_USE_EXPAT)
+ install_files(/bin FILES ${LIBEXPAT_LIBRARIES})
else (MINGW)
INCLUDE(InstallRequiredSystemLibraries)
endif (MINGW)
diff --git a/cmake/modules/FindGLIB.cmake b/cmake/modules/FindGLIB.cmake
deleted file mode 100644
index 1fdaee95..00000000
--- a/cmake/modules/FindGLIB.cmake
+++ /dev/null
@@ -1,42 +0,0 @@
-# - Try to find the GLIB library
-# Once done this will define
-#
-# GLIB_FOUND - system has GLIB
-# GLIB_INCLUDES - the GLIB include directories
-# GLIB_LIBRARIES - The libraries needed to use GLIB
-
-if (WIN32)
-
-INCLUDE(MacroGetenvWinPath)
-
-MACRO_GETENV_WIN_PATH(_program_FILES_DIR PROGRAMFILES)
-
-FIND_PATH(GLIB_INCLUDE_DIR glib.h
- ${_program_FILES_DIR}/glib/include/glib-2.0
-)
-
-
-# search for GLIB in the default install directory for applications (default of (n)make install)
-FIND_LIBRARY(GLIB_LIBRARY NAMES glib-2.0
- PATHS
- ${_program_FILES_DIR}/glib/lib
-)
-
-if (GLIB_LIBRARY AND GLIB_INCLUDE_DIR)
- set(GLIB_FOUND TRUE)
- set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${GLIB_INCLUDES})
- set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${GLIB_LIBRARIES})
-
-endif (GLIB_LIBRARY AND GLIB_INCLUDE_DIR)
-
-if (GLIB_FOUND)
- if (NOT GLIB_FIND_QUIETLY)
- message(STATUS "Found GLIB: ${GLIB_LIBRARY}")
- endif (NOT GLIB_FIND_QUIETLY)
-else (GLIB_FOUND)
- if (GLIB_FIND_REQUIRED)
- message(FATAL_ERROR "Could NOT find GLIB library")
- endif (GLIB_FIND_REQUIRED)
-endif (GLIB_FOUND)
-
-endif (WIN32)
diff --git a/cmake/modules/FindGLib2.cmake b/cmake/modules/FindGLib2.cmake
new file mode 100644
index 00000000..d72b2a09
--- /dev/null
+++ b/cmake/modules/FindGLib2.cmake
@@ -0,0 +1,60 @@
+# - Try to find the GLIB2 libraries
+# Once done this will define
+#
+# GLIB2_FOUND - system has glib2
+# GLIB2_INCLUDE_DIR - the glib2 include directory
+# GLIB2_LIBRARIES - glib2 library
+
+# Copyright (c) 2008 Laurent Montel, <montel@kde.org>
+# Copyright (c) 2013 Ralf Habacker, <ralf.habacker@freenet.de>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+ # Already in cache, be silent
+ set(GLIB2_FIND_QUIETLY TRUE)
+endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+
+if (NOT WIN32)
+ find_package(PkgConfig)
+ pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0)
+endif()
+
+find_path(GLIB2_MAIN_INCLUDE_DIR
+ NAMES glib.h
+ HINTS ${PC_LibGLIB2_INCLUDEDIR}
+ PATH_SUFFIXES glib-2.0)
+
+find_library(GLIB2_LIBRARY
+ NAMES glib-2.0
+ HINTS ${PC_LibGLIB2_LIBDIR}
+)
+
+find_library(GIO2_LIBRARY
+ NAMES gio-2.0
+ HINTS ${PC_LibGLIB2_LIBDIR}
+)
+
+set(GLIB2_LIBRARIES ${GLIB2_LIBRARY} ${GIO2_LIBRARY})
+
+# search the glibconfig.h include dir under the same root where the library is found
+get_filename_component(glib2LibDir "${GLIB2_LIBRARY}" PATH)
+
+find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h
+ PATH_SUFFIXES glib-2.0/include
+ HINTS ${PC_LibGLIB2_INCLUDEDIR} "${glib2LibDir}" ${CMAKE_SYSTEM_LIBRARY_PATH})
+
+set(GLIB2_INCLUDE_DIR "${GLIB2_MAIN_INCLUDE_DIR}")
+
+# not sure if this include dir is optional or required
+# for now it is optional
+if(GLIB2_INTERNAL_INCLUDE_DIR)
+ set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} "${GLIB2_INTERNAL_INCLUDE_DIR}")
+endif(GLIB2_INTERNAL_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR)
+
+mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES)
diff --git a/cmake/modules/FindGObject.cmake b/cmake/modules/FindGObject.cmake
new file mode 100644
index 00000000..af0c9f73
--- /dev/null
+++ b/cmake/modules/FindGObject.cmake
@@ -0,0 +1,52 @@
+# - Try to find GObject
+# Once done this will define
+#
+# GOBJECT_FOUND - system has GObject
+# GOBJECT_INCLUDE_DIR - the GObject include directory
+# GOBJECT_LIBRARIES - the libraries needed to use GObject
+# GOBJECT_DEFINITIONS - Compiler switches required for using GObject
+
+# Copyright (c) 2011, Raphael Kubo da Costa <kubito@gmail.com>
+# Copyright (c) 2006, Tim Beaulen <tbscope@gmail.com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+FIND_PACKAGE(PkgConfig)
+PKG_CHECK_MODULES(PC_GOBJECT gobject-2.0)
+SET(GOBJECT_DEFINITIONS ${PC_GOBJECT_CFLAGS_OTHER})
+
+FIND_PATH(GOBJECT_INCLUDE_DIR gobject.h
+ HINTS
+ ${PC_GOBJECT_INCLUDEDIR}
+ ${PC_GOBJECT_INCLUDE_DIRS}
+ PATH_SUFFIXES glib-2.0/gobject/
+ )
+
+FIND_LIBRARY(_GObjectLibs NAMES gobject-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GModuleLibs NAMES gmodule-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GThreadLibs NAMES gthread-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+FIND_LIBRARY(_GLibs NAMES glib-2.0
+ HINTS
+ ${PC_GOBJECT_LIBDIR}
+ ${PC_GOBJECT_LIBRARY_DIRS}
+ )
+
+SET( GOBJECT_LIBRARIES ${_GObjectLibs} ${_GModuleLibs} ${_GThreadLibs} ${_GLibs} )
+
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GOBJECT DEFAULT_MSG GOBJECT_LIBRARIES GOBJECT_INCLUDE_DIR)
+
+MARK_AS_ADVANCED(GOBJECT_INCLUDE_DIR _GObjectLibs _GModuleLibs _GThreadLibs _GLibs)
diff --git a/cmake/modules/FindLibExpat.cmake b/cmake/modules/FindLibExpat.cmake
deleted file mode 100644
index a07c8de4..00000000
--- a/cmake/modules/FindLibExpat.cmake
+++ /dev/null
@@ -1,61 +0,0 @@
-# - Try to find LIBEXPAT
-# Once done this will define
-#
-# LIBEXPAT_FOUND - system has LIBEXPAT
-# LIBEXPAT_INCLUDE_DIR - the LIBEXPAT include directory
-# LIBEXPAT_LIBRARIES - the libraries needed to use LIBEXPAT
-# LIBEXPAT_DEFINITIONS - Compiler switches required for using LIBEXPAT
-
-if (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
-
- # in cache already
- SET(LIBEXPAT_FOUND TRUE)
-
-else (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
-
- IF (WIN32)
- file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _progFiles)
- find_FILE(LIBEXPAT_DIR expat Source/lib/expat.h
- PATHS
- "${_progFiles}"
- )
- if (LIBEXPAT_DIR)
- set (_LIBEXPATIncDir ${LIBEXPAT_DIR}/Source/lib)
- set (_LIBEXPATLinkDir ${LIBEXPAT_DIR}/libs)
- endif (LIBEXPAT_DIR)
- ELSE (WIN32)
- # use pkg-config to get the directories and then use these values
- # in the FIND_PATH() and FIND_LIBRARY() calls
- INCLUDE(UsePkgConfig)
- PKGCONFIG(LIBEXPAT-2.0 _LIBEXPATIncDir _LIBEXPATLinkDir _LIBEXPATLinkFlags _LiIconvCflags)
- SET(LIBEXPAT_DEFINITIONS ${_LIBEXPATCflags})
- ENDIF (WIN32)
-
- FIND_PATH(LIBEXPAT_INCLUDE_DIR expat.h
- PATHS
- ${_LIBEXPATIncDir}
- PATH_SUFFIXES LIBEXPAT
- )
-
- FIND_LIBRARY(LIBEXPAT_LIBRARIES NAMES expat libexpat
- PATHS
- ${_LIBEXPATLinkDir}
- )
-
- if (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
- set(LIBEXPAT_FOUND TRUE)
- endif (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
-
- if (LIBEXPAT_FOUND)
- if (NOT LIBEXPAT_FIND_QUIETLY)
- message(STATUS "Found libexpat: ${LIBEXPAT_LIBRARIES}")
- endif (NOT LIBEXPAT_FIND_QUIETLY)
- else (LIBEXPAT_FOUND)
- if (LIBEXPAT_FIND_REQUIRED)
- message(SEND_ERROR "Could NOT find libexpat")
- endif (LIBEXPAT_FIND_REQUIRED)
- endif (LIBEXPAT_FOUND)
-
- MARK_AS_ADVANCED(LIBEXPAT_INCLUDE_DIR LIBEXPAT_LIBRARIES)
-
-endif (LIBEXPAT_INCLUDE_DIR AND LIBEXPAT_LIBRARIES)
diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake
index b6371568..545f2e58 100644
--- a/cmake/modules/Macros.cmake
+++ b/cmake/modules/Macros.cmake
@@ -1,15 +1,36 @@
-
MACRO(TIMESTAMP RESULT)
- IF(WIN32)
+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE DATE)
string(REGEX REPLACE "(..)[/.](..)[/.](....).*" "\\3\\2\\1" DATE ${DATE})
EXECUTE_PROCESS(COMMAND "cmd" " /C time /T" OUTPUT_VARIABLE TIME)
string(REGEX REPLACE "(..):(..)" "\\1\\2" TIME ${TIME})
set (${RESULT} "${DATE}${TIME}")
- ELSEIF(UNIX)
+ else ()
EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT})
- ELSE()
- MESSAGE(SEND_ERROR "date not implemented")
- SET(${RESULT} 000000000000)
- ENDIF()
+ endif ()
ENDMACRO()
+
+macro(add_test_executable _target _source)
+ add_executable(${_target} ${_source})
+ target_link_libraries(${_target} ${ARGN})
+ if (CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ # run tests with binfmt_misc
+ set(PREFIX "z:")
+ set(_env "DBUS_TEST_DAEMON=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}")
+ add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}>)
+ else()
+ set(PREFIX)
+ set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}")
+ add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}>)
+ endif()
+ list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=")
+ list(APPEND _env "DBUS_FATAL_WARNINGS=1")
+ list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data")
+ list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus")
+ set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}")
+endmacro(add_test_executable)
+
+macro(add_helper_executable _target _source)
+ add_executable(${_target} ${_source})
+ target_link_libraries(${_target} ${ARGN})
+endmacro(add_helper_executable)
diff --git a/cmake/modules/MacrosAutotools.cmake b/cmake/modules/MacrosAutotools.cmake
index ff30eaf9..68e8ae51 100644
--- a/cmake/modules/MacrosAutotools.cmake
+++ b/cmake/modules/MacrosAutotools.cmake
@@ -23,6 +23,66 @@ macro(autoversion config prefix)
endmacro()
#
+# Defines package related variables (PACKAGE_..., PACKAGE and VERSION)
+# as done by autotools.
+#
+# Additional it defines a cmake variable named PACKAGE_CONFIG_H_TEMPLATE
+# which could be placed in config.h templates to have those variables
+# defined at code level like shown below:
+#
+# config.h.template
+# ...
+# @AUTOPACKAGE_CONFIG_H_TEMPLATE@
+# ...
+#
+macro(autopackage name version url support_url)
+ # Define to the full name of this package.
+ set(PACKAGE_NAME ${name})
+
+ # Define to the version of this package.
+ set(PACKAGE_VERSION ${version})
+
+ # Define to the home page for this package.
+ set(PACKAGE_URL ${url})
+
+ # Define to the address where bug reports for this package should be sent.
+ set(PACKAGE_BUGREPORT ${support_url})
+
+ # Define to the full name and version of this package.
+ set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+
+ # Define to the one symbol short name of this package.
+ set(PACKAGE_TARNAME ${PACKAGE_NAME})
+
+ set(PACKAGE ${name})
+ set(VERSION ${DBUS_VERSION_STRING})
+
+ set(AUTOPACKAGE_CONFIG_H_TEMPLATE "/* generated by cmake macro autopackage */\n
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT \"@PACKAGE_BUGREPORT@\"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME \"@PACKAGE_NAME@\"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING \"@PACKAGE_STRING@\"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME \"@PACKAGE_TARNAME@\"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL \"@PACKAGE_URL@\"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION \"@PACKAGE_VERSION@\"
+
+/* defined by autotools package */
+#define PACKAGE \"@PACKAGE@\"
+#define VERSION \"@VERSION@\"
+")
+endmacro(autopackage)
+
+#
# parses config.h template and create cmake equivalent
# not implemented yet
#
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index 8657e4c7..9195eae7 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -1,7 +1,8 @@
-project(test)
add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
+set(DBUS_SESSION_BUS_LISTEN_ADDRESS ${TEST_LISTEN})
+
add_library(dbus-testutils STATIC
${CMAKE_SOURCE_DIR}/../test/test-utils.h
${CMAKE_SOURCE_DIR}/../test/test-utils.c
@@ -26,11 +27,11 @@ set (test-shell-service_SOURCES
${CMAKE_SOURCE_DIR}/../test/test-shell-service.c
)
-set (shell-test_SOURCES
+set (test-shell_SOURCES
${CMAKE_SOURCE_DIR}/../test/shell-test.c
)
-set (spawn-test_SOURCES
+set (test-spawn_SOURCES
${CMAKE_SOURCE_DIR}/../test/spawn-test.c
)
@@ -46,30 +47,40 @@ set (test-sleep-forever_SOURCES
${CMAKE_SOURCE_DIR}/../test/test-sleep-forever.c
)
-add_executable(test-service ${test-service_SOURCES})
-target_link_libraries(test-service dbus-testutils)
-
-add_executable(test-names ${test-names_SOURCES})
-target_link_libraries(test-names dbus-testutils)
-
-add_executable(shell-test ${shell-test_SOURCES})
-target_link_libraries(shell-test ${DBUS_INTERNAL_LIBRARIES})
-ADD_TEST(shell-test ${EXECUTABLE_OUTPUT_PATH}/shell-test${EXEEXT})
-
-add_executable(test-shell-service ${test-shell-service_SOURCES})
-target_link_libraries(test-shell-service dbus-testutils)
-
-add_executable(spawn-test ${spawn-test_SOURCES})
-target_link_libraries(spawn-test ${DBUS_INTERNAL_LIBRARIES})
-
-add_executable(test-exit ${test-exit_SOURCES})
-target_link_libraries(test-exit ${DBUS_INTERNAL_LIBRARIES})
-
-add_executable(test-segfault ${test-segfault_SOURCES})
-target_link_libraries(test-segfault ${DBUS_INTERNAL_LIBRARIES})
-
-add_executable(test-sleep-forever ${test-sleep-forever_SOURCES})
-target_link_libraries(test-sleep-forever ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-service ${test-service_SOURCES} dbus-testutils)
+add_helper_executable(test-names ${test-names_SOURCES} dbus-testutils)
+add_test_executable(test-shell ${test-shell_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_test_executable(test-printf ${CMAKE_SOURCE_DIR}/../test/internals/printf.c dbus-testutils)
+add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
+add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-segfault ${test-segfault_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-sleep-forever ${test-sleep-forever_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
+
+if(DBUS_WITH_GLIB)
+ message(STATUS "with glib test apps")
+ add_definitions(
+ ${GLIB2_DEFINITIONS}
+ ${GOBJECT_DEFINITIONS}
+ )
+ include_directories(
+ ${GLIB2_INCLUDE_DIR}
+ ${GOBJECT_INCLUDE_DIR}
+ ${CMAKE_SOURCE_DIR}/../test
+ )
+ set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
+
+ add_test_executable(test-corrupt ${CMAKE_SOURCE_DIR}/../test/corrupt.c ${TEST_LIBRARIES})
+ add_test_executable(test-dbus-daemon ${CMAKE_SOURCE_DIR}/../test/dbus-daemon.c ${TEST_LIBRARIES})
+ add_test_executable(test-dbus-daemon-eavesdrop ${CMAKE_SOURCE_DIR}/../test/dbus-daemon-eavesdrop.c ${TEST_LIBRARIES})
+ add_test_executable(test-loopback ${CMAKE_SOURCE_DIR}/../test/loopback.c ${TEST_LIBRARIES})
+ add_test_executable(test-marshal ${CMAKE_SOURCE_DIR}/../test/marshal.c ${TEST_LIBRARIES})
+ add_test_executable(test-refs ${CMAKE_SOURCE_DIR}/../test/internals/refs.c ${TEST_LIBRARIES})
+ add_test_executable(test-relay ${CMAKE_SOURCE_DIR}/../test/relay.c ${TEST_LIBRARIES})
+ add_test_executable(test-syntax ${CMAKE_SOURCE_DIR}/../test/syntax.c ${TEST_LIBRARIES})
+ add_test_executable(test-syslog ${CMAKE_SOURCE_DIR}/../test/internals/syslog.c ${TEST_LIBRARIES})
+ add_helper_executable(manual-authz ${CMAKE_SOURCE_DIR}/../test/manual-authz.c ${TEST_LIBRARIES})
+endif()
### keep these in creation order, i.e. uppermost dirs first
set (TESTDIRS
@@ -81,6 +92,7 @@ set (TESTDIRS
test/data/sha-1
test/data/valid-config-files
test/data/valid-config-files/basic.d
+ test/data/valid-config-files/session.d
test/data/valid-config-files/system.d
test/data/valid-config-files-system
test/data/valid-introspection-files
@@ -139,17 +151,18 @@ ENDFOREACH(FILE_TYPE)
MESSAGE(STATUS "Copying generated bus config files to test directory")
set (OUTDIR ${CMAKE_BINARY_DIR}/test/data/valid-config-files)
-FILE(GLOB FILES "${CMAKE_BINARY_DIR}/bus/*.conf" )
+FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../bus/*.conf.in" )
FILE(MAKE_DIRECTORY ${OUTDIR})
FOREACH(FILE ${FILES})
GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME)
+ STRING(REGEX REPLACE "\\.in$" "" FILENAME ${FILENAME})
SET (TARGET ${OUTDIR}/${FILENAME})
- configure_file(${FILE} ${TARGET} COPYONLY)
+ configure_file(${FILE} ${TARGET} @ONLY)
IF (CONFIG_VERBOSE)
MESSAGE("FROM: ${FILE}\nTO: ${TARGET}\n")
ENDIF (CONFIG_VERBOSE)
ENDFOREACH(FILE)
-# todo: for installation the TEST_..._BINARY variables must reflect the
-# installation dir or has to be defined relative
-#
+add_custom_target(check
+ COMMAND ctest -R ^test-.*
+)
diff --git a/cmake/test/name-test/CMakeLists.txt b/cmake/test/name-test/CMakeLists.txt
index 80b9908b..befb28f9 100644
--- a/cmake/test/name-test/CMakeLists.txt
+++ b/cmake/test/name-test/CMakeLists.txt
@@ -1,39 +1,15 @@
-if (DBUS_BUILD_TESTS)
+if (DBUS_ENABLE_EMBEDDED_TESTS)
set (NAMEtest-DIR ../../../test/name-test)
-add_definitions(-DDBUS_COMPILATION)
-
-add_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c)
-target_link_libraries(test-pending-call-dispatch ${DBUS_INTERNAL_LIBRARIES})
-ADD_TEST(test-pending-call-dispatch ${EXECUTABLE_OUTPUT_PATH}/test-pending-call-dispatch)
-
-add_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c)
-target_link_libraries(test-pending-call-timeout ${DBUS_INTERNAL_LIBRARIES})
-ADD_TEST(test-pending-call-timeout ${EXECUTABLE_OUTPUT_PATH}/test-pending-call-timeout)
-
-add_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c)
-target_link_libraries(test-thread-init ${DBUS_INTERNAL_LIBRARIES})
-ADD_TEST(test-thread-init ${EXECUTABLE_OUTPUT_PATH}/test-thread-init)
-
-add_executable(test-ids ${NAMEtest-DIR}/test-ids.c)
-target_link_libraries(test-ids ${DBUS_INTERNAL_LIBRARIES})
-ADD_TEST(test-ids ${EXECUTABLE_OUTPUT_PATH}/test-ids)
-
-add_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c)
-target_link_libraries(test-shutdown dbus-testutils)
-ADD_TEST(test-shutdown ${EXECUTABLE_OUTPUT_PATH}/test-shutdown)
-
-add_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c)
-target_link_libraries(test-privserver dbus-testutils)
-ADD_TEST(test-privserver ${EXECUTABLE_OUTPUT_PATH}/test-privserver)
-
-add_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c)
-target_link_libraries(test-privserver-client dbus-testutils)
-ADD_TEST(test-privserver-client ${EXECUTABLE_OUTPUT_PATH}/test-privserver-client)
-
-add_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c)
-target_link_libraries(test-autolaunch dbus-testutils)
-ADD_TEST(test-autolaunch ${EXECUTABLE_OUTPUT_PATH}/test-autolaunch)
-
-endif (DBUS_BUILD_TESTS)
+add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
+
+add_helper_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-pending-call-timeout ${NAMEtest-DIR}/test-pending-call-timeout.c ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-thread-init ${NAMEtest-DIR}/test-threads-init.c ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-ids ${NAMEtest-DIR}/test-ids.c ${DBUS_INTERNAL_LIBRARIES})
+add_helper_executable(test-shutdown ${NAMEtest-DIR}/test-shutdown.c dbus-testutils)
+add_helper_executable(test-privserver ${NAMEtest-DIR}/test-privserver.c dbus-testutils)
+add_helper_executable(test-privserver-client ${NAMEtest-DIR}/test-privserver-client.c dbus-testutils)
+add_helper_executable(test-autolaunch ${NAMEtest-DIR}/test-autolaunch.c dbus-testutils)
+endif (DBUS_ENABLE_EMBEDDED_TESTS)
diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt
index 101c7e60..ddbd5bcf 100644
--- a/cmake/tools/CMakeLists.txt
+++ b/cmake/tools/CMakeLists.txt
@@ -1,5 +1,3 @@
-project(tools)
-
set (dbus_send_SOURCES
../../tools/dbus-print-message.c
../../tools/dbus-print-message.h
diff --git a/configure.ac b/configure.ac
index 59b23d27..ed77046a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,8 +2,8 @@ dnl -*- mode: m4 -*-
AC_PREREQ([2.63])
m4_define([dbus_major_version], [1])
-m4_define([dbus_minor_version], [5])
-m4_define([dbus_micro_version], [13])
+m4_define([dbus_minor_version], [8])
+m4_define([dbus_micro_version], [0])
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])
@@ -19,8 +19,9 @@ GETTEXT_PACKAGE=dbus-1
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext domain])
- ## must come before we use the $USE_MAINTAINER_MODE variable later
-AM_MAINTAINER_MODE
+# By default, rebuild autotools files on demand; only use ./missing if the
+# user says --disable-maintainer-mode (some distributions like to do this)
+AM_MAINTAINER_MODE([enable])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
@@ -32,16 +33,16 @@ AC_DEFINE_UNQUOTED(DBUS_DAEMON_NAME,"dbus-daemon",[Name of executable])
#
## 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=0
+LT_REVISION=3
## 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)
@@ -123,24 +124,38 @@ AM_CONDITIONAL(DBUS_WINCE, test "$dbus_wince" = yes)
AM_CONDITIONAL(DBUS_UNIX, test "$dbus_unix" = yes)
AM_CONDITIONAL(DBUS_CYGWIN, test "$dbus_cygwin" = yes)
+# this must come first: other options use this to set their defaults
+AC_ARG_ENABLE([developer],
+ [AS_HELP_STRING([--enable-developer],
+ [set defaults to be appropriate for a D-Bus developer instead of a distribution/end-user])],
+ [],
+ [enable_developer=no])
+
+DBUS_STATIC_BUILD_CPPFLAGS=
+if test "x$enable_shared" = xno; then
+ # On Windows, linking against the static library requires special effort
+ # to turn off DLL import/export processing. We normally link some things
+ # against the dynamic library, but if we're not building that, we'll
+ # have to link everything statically.
+ DBUS_STATIC_BUILD_CPPFLAGS=-DDBUS_STATIC_BUILD
+fi
+AC_SUBST([DBUS_STATIC_BUILD_CPPFLAGS])
+
AC_ARG_ENABLE(ansi, AS_HELP_STRING([--enable-ansi],[enable -ansi -pedantic gcc flags]),enable_ansi=$enableval,enable_ansi=no)
-AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$USE_MAINTAINER_MODE)
-AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$USE_MAINTAINER_MODE)
+AC_ARG_ENABLE(verbose-mode, AS_HELP_STRING([--enable-verbose-mode],[support verbose debug mode]),enable_verbose_mode=$enableval,enable_verbose_mode=$enable_developer)
+AC_ARG_ENABLE(asserts, AS_HELP_STRING([--enable-asserts],[include assertion checks]),enable_asserts=$enableval,enable_asserts=$enable_developer)
AC_ARG_ENABLE(checks, AS_HELP_STRING([--enable-checks],[include sanity checks on public API]),enable_checks=$enableval,enable_checks=yes)
AC_ARG_ENABLE(xml-docs, AS_HELP_STRING([--enable-xml-docs],[build XML documentation (requires xmlto)]),enable_xml_docs=$enableval,enable_xml_docs=auto)
AC_ARG_ENABLE(doxygen-docs, AS_HELP_STRING([--enable-doxygen-docs],[build DOXYGEN documentation (requires Doxygen)]),enable_doxygen_docs=$enableval,enable_doxygen_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(libaudit,AS_HELP_STRING([--enable-libaudit],[build audit daemon support for SELinux]),enable_libaudit=$enableval,enable_libaudit=auto)
-AC_ARG_ENABLE(dnotify, AS_HELP_STRING([--enable-dnotify],[build with dnotify support (linux only)]),enable_dnotify=$enableval,enable_dnotify=auto)
AC_ARG_ENABLE(inotify, AS_HELP_STRING([--enable-inotify],[build with inotify support (linux only)]),enable_inotify=$enableval,enable_inotify=auto)
AC_ARG_ENABLE(kqueue, AS_HELP_STRING([--enable-kqueue],[build with kqueue support]),enable_kqueue=$enableval,enable_kqueue=auto)
AC_ARG_ENABLE(console-owner-file, AS_HELP_STRING([--enable-console-owner-file],[enable console owner file]),enable_console_owner_file=$enableval,enable_console_owner_file=auto)
-AC_ARG_ENABLE(userdb-cache, AS_HELP_STRING([--enable-userdb-cache],[build with userdb-cache support]),enable_userdb_cache=$enableval,enable_userdb_cache=yes)
AC_ARG_ENABLE(launchd, AS_HELP_STRING([--enable-launchd],[build with launchd auto-launch support]),enable_launchd=$enableval,enable_launchd=auto)
AC_ARG_ENABLE(systemd, AS_HELP_STRING([--enable-systemd],[build with systemd at_console support]),enable_systemd=$enableval,enable_systemd=auto)
-AC_ARG_WITH(xml, AS_HELP_STRING([--with-xml=[libxml/expat]],[XML library to use (libxml may be named libxml2 on some systems)]))
AC_ARG_WITH(init-scripts, AS_HELP_STRING([--with-init-scripts=[redhat]],[Style of init scripts to install]))
AC_ARG_WITH(session-socket-dir, AS_HELP_STRING([--with-session-socket-dir=[dirname]],[Where to put sockets for the per-login-session message bus]))
AC_ARG_WITH(test-socket-dir, AS_HELP_STRING([--with-test-socket-dir=[dirname]],[Where to put sockets for make check]))
@@ -151,12 +166,11 @@ AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filen
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],
[enable unit test code in the library and binaries]),
- [], [enable_embedded_tests=$USE_MAINTAINER_MODE])
+ [], [enable_embedded_tests=$enable_developer])
AC_ARG_ENABLE([modular-tests],
AS_HELP_STRING([--enable-modular-tests],
[enable modular regression tests (requires GLib)]),
@@ -177,16 +191,12 @@ AC_ARG_ENABLE([tests],
[])
# DBUS_ENABLE_EMBEDDED_TESTS controls unit tests built in to .c files
-# and also some stuff in the test/ subdir. DBUS_BUILD_TESTS was an older
-# name for this.
-AM_CONDITIONAL([DBUS_BUILD_TESTS], [test "x$enable_embedded_tests" = xyes])
+# and also some stuff in the test/ subdir.
AM_CONDITIONAL([DBUS_ENABLE_EMBEDDED_TESTS],
[test "x$enable_embedded_tests" = xyes])
if test "x$enable_embedded_tests" = xyes; then
AC_DEFINE([DBUS_ENABLE_EMBEDDED_TESTS], [1],
[Define to build test code into the library and binaries])
- AC_DEFINE([DBUS_BUILD_TESTS], [1],
- [Define to build test code into the library and binaries])
fi
# DBUS_ENABLE_MODULAR_TESTS controls tests that work based on public API.
@@ -194,9 +204,13 @@ fi
# 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_32], [Prevent post-2.32 APIs])
+
with_glib=yes
-if test "x$enable_modular_tests" != xno; then
+AS_IF([test "x$enable_modular_tests" != xno],
+ [
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24, gio-2.0 >= 2.24],
[],
[if test "x$enable_modular_tests" = xyes; then
@@ -205,16 +219,25 @@ if test "x$enable_modular_tests" != xno; then
else # assumed to be "auto"
with_glib=no
fi])
- # If dbus-gmain.[ch] returned to libdbus then we wouldn't need this
- PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1],
+ ],
+ [with_glib=no])
+
+# Not required, because we can use internal APIs (but that makes the
+# "installable tests" less useful as integration tests)
+AC_ARG_WITH([dbus_glib],
+ [AS_HELP_STRING([--with-dbus-glib], [Use dbus-glib for regression tests])],
+ [],
+ [with_dbus_glib=auto])
+AS_IF([test "x$with_dbus_glib" != xno],
+ [PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1],
[],
- [if test "x$enable_modular_tests" = xyes; then
- AC_MSG_NOTICE([Full test coverage (--enable-modular-tests=yes or --enable-tests=yes) requires dbus-glib])
- AC_MSG_ERROR([$DBUS_GLIB_ERRORS])
- else # assumed to be "auto"
- with_glib=no
- fi])
-fi
+ [AS_IF([test "x$with_dbus_glib" = xyes],
+ dnl specifically requested, but not found
+ [AC_MSG_ERROR([$DBUS_GLIB_ERRORS])],
+ dnl else: assumed to be "auto"
+ [with_dbus_glib=no])])])
+AM_CONDITIONAL([DBUS_WITH_DBUS_GLIB], [test "x$with_dbus_glib" != xno])
+
if test "x$enable_modular_tests" != xno; then
AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1],
[Define to build independent test binaries])
@@ -259,6 +282,11 @@ if test x$enable_asserts = xno; then
AC_DEFINE(DBUS_DISABLE_ASSERT,1,[Disable assertion checking])
DISABLE_UNUSED_WARNINGS="unused-label"
R_DYNAMIC_LDFLAG=""
+ if test x$enable_embedded_tests = xyes; then
+ DISABLE_UNUSED_WARNINGS="$DISABLE_UNUSED_WARNINGS \
+ unused-but-set-variable unused-variable \
+ unused-function"
+ fi
else
# -rdynamic is needed for glibc's backtrace_symbols to work.
# No clue how much overhead this adds, but it's useful
@@ -278,9 +306,14 @@ if test x$enable_checks = xno; then
DISABLE_UNUSED_WARNINGS="unused-label"
fi
-if test x$enable_userdb_cache = xyes; then
- AC_DEFINE(DBUS_ENABLE_USERDB_CACHE,1,[Build with caching of user data])
-fi
+AH_BOTTOM([
+/* explicitly define these macros to get less confusing conditions */
+#ifndef DBUS_DISABLE_ASSERT
+# define DBUS_ENABLE_ASSERT 1
+#endif
+#ifndef DBUS_DISABLE_CHECKS
+# define DBUS_ENABLE_CHECKS 1
+#endif])
if test x$enable_compiler_coverage = xyes; then
## so that config.h changes when you toggle gcov support
@@ -322,12 +355,6 @@ AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long long)
AC_CHECK_SIZEOF(__int64)
-AC_ARG_WITH([64-bit],
- [AS_HELP_STRING([--without-64-bit],
- [If you have to use this option, please report it as a bug])],
- [],
- [with_64_bit=yes])
-
### See what our 64 bit type is called
AC_MSG_CHECKING([64-bit integer type])
@@ -366,33 +393,17 @@ $ac_cv_sizeof___int64)
esac
AS_IF(
- [test "x$with_64_bit" = xno],
- [
- DBUS_INT64_TYPE="no_int64_type_detected"
- DBUS_HAVE_INT64=0
- DBUS_INT64_CONSTANT=
- DBUS_UINT64_CONSTANT=
- AC_MSG_RESULT([disabled via --without-64-bit])
- ],
- dnl else if
[test -z "$dbusint64"],
[AC_MSG_RESULT([not found])
AC_MSG_ERROR([Could not find a 64-bit integer type.
Please report a bug here with details of your platform and compiler:
- http://bugs.freedesktop.org/enter_bug.cgi?product=DBus&component=core
-
-To compile D-Bus with all 64-bit integer types removed (not recommended), use
-the option "--without-64-bit".
-
-This option is likely to be removed in future, unless you report that your
-platform needs it.])
+ http://bugs.freedesktop.org/enter_bug.cgi?product=DBus&component=core])
],
dnl else
[
DBUS_INT64_TYPE="$dbusint64"
- DBUS_HAVE_INT64=1
DBUS_INT64_CONSTANT="$dbusint64_constant"
DBUS_UINT64_CONSTANT="$dbusuint64_constant"
if test x"$dbusint64_printf_modifier" != x; then
@@ -404,7 +415,6 @@ platform needs it.])
AC_SUBST(DBUS_INT64_TYPE)
AC_SUBST(DBUS_INT64_CONSTANT)
AC_SUBST(DBUS_UINT64_CONSTANT)
-AC_SUBST(DBUS_HAVE_INT64)
### see what 32-bit int is called
AC_MSG_CHECKING([32-bit integer type])
@@ -578,7 +588,7 @@ AC_DEFINE_UNQUOTED([DBUS_USE_SYNC], [$have_sync], [Use the gcc __sync extension]
AC_SEARCH_LIBS(socket,[socket network])
AC_CHECK_FUNC(gethostbyname,,[AC_CHECK_LIB(nsl,gethostbyname)])
-AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull)
+AC_CHECK_FUNCS(vsnprintf vasprintf nanosleep usleep setenv clearenv unsetenv socketpair getgrouplist fpathconf setrlimit poll setlocale localeconv strtoll strtoull issetugid getresuid)
AC_CHECK_HEADERS([syslog.h])
if test "x$ac_cv_header_syslog_h" = "xyes"; then
@@ -666,7 +676,7 @@ AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(ws2tcpip.h)
-AC_CHECK_HEADERS(wspiapi.h)
+AC_CHECK_HEADERS(alloca.h)
# Add -D_POSIX_PTHREAD_SEMANTICS if on Solaris
#
@@ -748,7 +758,8 @@ dnl needed on darwin for NAME_MAX
AC_CHECK_HEADERS(sys/syslimits.h)
dnl Make it easy to check if we have MSG_NOSIGNAL without actually having to include sys/socket.h
-AC_CHECK_DECLS([MSG_NOSIGNAL], [], [], [[ #include <sys/socket.h> ]])
+AC_CHECK_DECLS([MSG_NOSIGNAL], [], [], [[ #include <sys/types.h>
+#include <sys/socket.h> ]])
dnl check for flavours of varargs macros (test from GLib)
AC_MSG_CHECKING(for ISO C99 varargs macros in C)
@@ -883,66 +894,66 @@ fi
# unix:path=/foo or unix:abstract=/foo
AC_SUBST(DBUS_PATH_OR_ABSTRACT)
-PKG_PROG_PKG_CONFIG
-
#### Sort out XML library
-# see what we have
AC_CHECK_LIB(expat, XML_ParserCreate_MM,
- [ AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false) ],
- have_expat=false)
-
-# see what we want to use
-dbus_use_libxml=false
-dbus_use_expat=false
-if test x$with_xml = xexpat; then
- if ! $have_expat ; then
- AC_MSG_ERROR([Explicitly requested expat but expat not found])
- fi
- dbus_use_expat=true
-elif test x$with_xml = xlibxml; then
- PKG_CHECK_MODULES(LIBXML, libxml-2.0 >= 2.6.0, have_libxml=true, have_libxml=false)
- if ! $have_libxml ; then
- AC_MSG_ERROR([Explicitly requested libxml but libxml not found])
- fi
- dbus_use_libxml=true
-else
- ### expat is the default because libxml can't currently survive
- ### our brutal OOM-handling unit test setup.
- ### http://bugzilla.gnome.org/show_bug.cgi?id=109368
- if test x$have_expat = xfalse; then
- AC_MSG_ERROR([Could not find expat.h, check config.log for failed attempts])
- fi
- ### By default, only use Expat since it's tested and known to work. If you're a
- ### general-purpose OS vendor, please don't enable libxml. For embedded use
- ### if your OS is built around libxml, that's another case.
- dbus_use_expat=true
-fi
-
-AM_CONDITIONAL(DBUS_USE_EXPAT, $dbus_use_expat)
-AM_CONDITIONAL(DBUS_USE_LIBXML, $dbus_use_libxml)
+ [ AC_CHECK_HEADERS(expat.h, [],
+ [AC_MSG_ERROR([Could not find expat.h, check config.log for failed attempts])]) ],
+ [ AC_MSG_ERROR([Explicitly requested expat but expat not found]) ])
-if $dbus_use_expat; then
- XML_LIBS=-lexpat
- XML_CFLAGS=
-fi
-if $dbus_use_libxml; then
- XML_LIBS=$LIBXML_LIBS
- XML_CFLAGS=$LIBXML_CFLAGS
-fi
+XML_LIBS=-lexpat
+XML_CFLAGS=
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;
@@ -951,15 +962,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])
@@ -1025,24 +1038,6 @@ fi
AM_CONDITIONAL(DBUS_BUS_ENABLE_INOTIFY, test x$have_inotify = xyes)
-# dnotify checks
-if test x$enable_dnotify = xno ; then
- have_dnotify=no;
-else
- if test x$have_inotify = xno -a x$host_os = xlinux-gnu -o x$host_os = xlinux; then
- have_dnotify=yes;
- else
- have_dnotify=no;
- fi
-fi
-
-dnl check if dnotify backend is enabled
-if test x$have_dnotify = xyes; then
- AC_DEFINE(DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX,1,[Use dnotify on Linux])
-fi
-
-AM_CONDITIONAL(DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX, test x$have_dnotify = xyes)
-
# For simplicity, we require the userland API for epoll_create1 at
# compile-time (glibc 2.9), but we'll run on kernels that turn out
# not to have it at runtime.
@@ -1146,7 +1141,7 @@ if test x$enable_systemd = xno ; then
have_systemd=no;
else
PKG_CHECK_MODULES(SYSTEMD,
- [libsystemd-login >= 32, libsystemd-daemon >= 32],
+ [libsystemd-login >= 32, libsystemd-daemon >= 32, libsystemd-journal >= 32],
have_systemd=yes,
have_systemd=no)
fi
@@ -1202,6 +1197,7 @@ AC_SUBST([ADT_LIBS])
# Check for SCM_RIGHTS
AC_MSG_CHECKING([for SCM_RIGHTS])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
static int x = SCM_RIGHTS;
@@ -1215,7 +1211,7 @@ if test x$dbus_win = xyes ; then
if test x$dbus_wince = xyes ; then
NETWORK_libs="-lws2"
else
- NETWORK_libs="-lws2_32"
+ NETWORK_libs="-lws2_32 -liphlpapi"
fi
fi
@@ -1227,11 +1223,26 @@ AC_ARG_WITH([valgrind],
[],
[with_valgrind=no])
+AS_IF([test "x$with_valgrind" = xauto],
+ [PKG_CHECK_EXISTS([valgrind >= 3.6],
+ [with_valgrind=yes], [with_valgrind=no])])
+
if test x$with_valgrind != xno; then
PKG_CHECK_MODULES([VALGRIND], [valgrind >= 3.6])
AC_DEFINE([WITH_VALGRIND], [1], [Define to add Valgrind instrumentation])
fi
+# Determine maximum number of Unix fds which may be passed
+AS_CASE([$host_os],
+ [*qnx*],
+ [DEFAULT_MESSAGE_UNIX_FDS=256],
+ [*],
+ [DEFAULT_MESSAGE_UNIX_FDS=1024])
+AC_DEFINE_UNQUOTED([DBUS_DEFAULT_MESSAGE_UNIX_FDS],
+ [$DEFAULT_MESSAGE_UNIX_FDS],
+ [Default for dbus_connection_get_max_message_unix_fds()])
+AC_SUBST([DEFAULT_MESSAGE_UNIX_FDS])
+
#### Set up final flags
LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs"
AC_SUBST([LIBDBUS_LIBS])
@@ -1298,9 +1309,9 @@ cc_supports_flag() {
TP_COMPILER_WARNINGS([WARNING_CFLAGS],
dnl Use -Werror by default if:
dnl - we're not on Windows (too many warnings), and
- dnl - we're in maintainer mode (a D-Bus developer, not a distro or end-user)
+ dnl - we're in developer mode (a D-Bus developer, not a distro or end-user)
dnl Override with --enable-Werror or --disable-Werror
- [test x$dbus_win != xyes -a x$dbus_cygwin != xyes -a x$USE_MAINTAINER_MODE = xyes],
+ [test x$dbus_win != xyes -a x$dbus_cygwin != xyes -a x$enable_developer = xyes],
dnl Enable these warnings if possible:
[all \
@@ -1361,6 +1372,8 @@ case $host_os in
solaris*)
# Solaris' C library apparently needs these runes to be threadsafe...
CFLAGS="$CFLAGS -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT"
+ # ... this opt-in to get sockaddr_in6 and sockaddr_storage...
+ CFLAGS="$CFLAGS -D__EXTENSIONS__"
# ... and this opt-in to get file descriptor passing support
CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500"
;;
@@ -1427,13 +1440,8 @@ fi
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
@@ -1489,7 +1497,7 @@ AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service
if test "x$with_systemdsystemunitdir" != xno; then
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
fi
-AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
+AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$have_systemd" != "xno" -a -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
##### Set up location for system bus socket
if ! test -z "$with_system_socket"; then
@@ -1501,8 +1509,17 @@ 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])
-## 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])
@@ -1598,9 +1615,8 @@ AC_DEFINE_UNQUOTED([DBUS_TEST_EXEC], ["$DBUS_TEST_EXEC"],
AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"],
[Extension for executables, typically empty or .exe])
-AC_DEFINE_UNQUOTED(TEST_BUS_BINARY, ["$DBUS_PWD/bus/dbus-daemon$EXEEXT"],
- [Full path to the daemon in the builddir])
-AC_SUBST(TEST_BUS_BINARY)
+AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"],
+ [Full path to the dbus-launch in the builddir])
## Export the non-setuid external helper
TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT"
@@ -1646,14 +1662,64 @@ fi
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
- DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
+ # 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_DEFAULT_ADDRESS)
+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
+ # 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_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)
@@ -1695,11 +1761,18 @@ tools/Makefile
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-run-session.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
test/data/valid-config-files/debug-allow-all-sha1.conf
+test/data/valid-config-files/incoming-limit.conf
test/data/valid-config-files-system/debug-allow-all-pass.conf
test/data/valid-config-files-system/debug-allow-all-fail.conf
test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service
@@ -1740,36 +1813,34 @@ 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 "
- Maintainer mode: ${USE_MAINTAINER_MODE}
+ Rebuilding generated files: ${USE_MAINTAINER_MODE}
gcc coverage profiling: ${enable_compiler_coverage}
Building embedded tests: ${enable_embedded_tests}
Building modular tests: ${enable_modular_tests}
- with GLib: ${with_glib}
+ - with dbus-glib: ${with_dbus_glib}
Building verbose mode: ${enable_verbose_mode}
Building assertions: ${enable_asserts}
Building checks: ${enable_checks}
Building bus stats API: ${enable_stats}
Building SELinux support: ${have_selinux}
Building inotify support: ${have_inotify}
- Building dnotify support: ${have_dnotify}
Building kqueue support: ${have_kqueue}
Building systemd support: ${have_systemd}
- Building X11 code: ${enable_x11}
+ Building X11 code: ${have_x11}
Building Doxygen docs: ${enable_doxygen_docs}
Building XML docs: ${enable_xml_docs}
- Building cache support: ${enable_userdb_cache}
Building launchd support: ${have_launchd}
- Using XML parser: ${with_xml}
Init scripts style: ${with_init_scripts}
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}
- 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}
@@ -1800,20 +1871,3 @@ fi
if test x$enable_checks = xno; then
echo "NOTE: building without checks for arguments passed to public API makes it harder to debug apps using D-Bus, but will slightly decrease D-Bus library size and _very_ slightly improve performance."
fi
-if test x$dbus_use_libxml = xtrue; then
- echo
- echo "WARNING: You have chosen to use libxml as your xml parser however this code path is not maintained by the D-Bus developers and if it breaks you get to keep the pieces. If you have selected this option in err please reconfigure with expat (e.g. --with-xml=expat)."
-fi
-
-if test "x$DBUS_HAVE_INT64" = x0; then
- AC_MSG_WARN([You have disabled 64-bit integers via --without-64-bit.
-
- This removes parts of the standard D-Bus API and ABI (the 't' and 'x'
- typecodes, the dbus_int64_t and dbus_uint64_t types, etc.) and should only be
- used if your compiler lacks support for 64-bit integers. Please report a bug
- with details of your platform and compiler.
-
- This option is likely to be removed in future, unless the D-Bus developers
- receive reports that it is still needed.
- ])
-fi
diff --git a/dbus-1-uninstalled.pc.in b/dbus-1-uninstalled.pc.in
index f0072325..038c83e2 100644
--- a/dbus-1-uninstalled.pc.in
+++ b/dbus-1-uninstalled.pc.in
@@ -14,4 +14,4 @@ Description: Free desktop message bus (uninstalled copy)
Version: @VERSION@
Libs: ${abs_top_builddir}/dbus/libdbus-1.la
Libs.private: @LIBDBUS_LIBS@
-Cflags: -I${abs_top_srcdir}
+Cflags: -I${abs_top_srcdir} @DBUS_STATIC_BUILD_CPPFLAGS@
diff --git a/dbus-1.pc.in b/dbus-1.pc.in
index 7201e07f..25f8bcee 100644
--- a/dbus-1.pc.in
+++ b/dbus-1.pc.in
@@ -14,4 +14,4 @@ Description: Free desktop message bus
Version: @VERSION@
Libs: -L${libdir} -ldbus-1
Libs.private: @LIBDBUS_LIBS@
-Cflags: -I${includedir}/dbus-1.0 -I${libdir}/dbus-1.0/include
+Cflags: -I${includedir}/dbus-1.0 -I${libdir}/dbus-1.0/include @DBUS_STATIC_BUILD_CPPFLAGS@
diff --git a/dbus/.gitignore b/dbus/.gitignore
index 34eace4d..fd91ccee 100644
--- a/dbus/.gitignore
+++ b/dbus/.gitignore
@@ -4,7 +4,7 @@ Makefile
Makefile.in
*.lo
*.la
-dbus-test
+test-dbus
*.bb
*.bbg
*.gcov
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index bb5cccaf..b2481073 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -12,6 +12,10 @@ AM_CPPFLAGS = \
-DDBUS_SESSION_CONFIG_FILE=\""$(configdir)/session.conf"\" \
$(NULL)
+# On Linux with glibc 2.17, sd-daemon.c support for POSIX message queues
+# results in an otherwise unnecessary dependency on librt. Disable it.
+AM_CPPFLAGS += -DSD_DAEMON_DISABLE_MQ
+
# if assertions are enabled, improve backtraces
AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
@@ -35,7 +39,7 @@ dbus_res_ldflag = -Wl,$(dbus_res)
no_undefined = -no-undefined
export_symbols =
-libdbus_1_la_DEPENDENCIES = $(dbus_res)
+EXTRA_libdbus_1_la_DEPENDENCIES = $(dbus_res)
intllibs =
else
@@ -233,6 +237,8 @@ DBUS_SHARED_SOURCES= \
### should be underscore-prefixed but don't really need
### to be unless they move to DBUS_SHARED_SOURCES later)
DBUS_UTIL_SOURCES= \
+ dbus-asv-util.c \
+ dbus-asv-util.h \
dbus-auth-script.c \
dbus-auth-script.h \
dbus-auth-util.c \
@@ -291,22 +297,33 @@ libdbus_internal_la_CPPFLAGS = \
$(NULL)
libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) $(SYSTEMD_LIBS)
+if DBUS_WIN
+# This must be a separate convenience library, otherwise libtool notices
+# that libdbus-1 might contain C++, links it with g++ and links in libstdc++,
+# even on Unix where in fact it doesn't contain any C++. For Windows, where
+# this code is used, we don't actually need libstdc++.
+noinst_LTLIBRARIES += libdbus-init-win.la
+libdbus_init_win_la_SOURCES = dbus-init-win.cpp
+libdbus_1_la_LIBADD += libdbus-init-win.la
+libdbus_internal_la_LIBADD += libdbus-init-win.la
+endif
+
noinst_PROGRAMS =
-if DBUS_BUILD_TESTS
+if DBUS_ENABLE_EMBEDDED_TESTS
# We can't actually run this til we've reached test/
-noinst_PROGRAMS += dbus-test
+noinst_PROGRAMS += test-dbus
endif
-dbus_test_SOURCES= \
+test_dbus_SOURCES= \
dbus-test-main.c
-dbus_test_LDADD = libdbus-internal.la
+test_dbus_LDADD = libdbus-internal.la
## mop up the gcov files
clean-local:
/bin/rm *.bb *.bbg *.da *.gcov .libs/*.da .libs/*.bbg || true
update-systemd:
- curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c
- curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h > sd-daemon.h
+ curl http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c > $(srcdir)/sd-daemon.c
+ curl http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h > $(srcdir)/sd-daemon.h
diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c
index 90484dc1..c4cfbbe5 100644
--- a/dbus/dbus-address.c
+++ b/dbus/dbus-address.c
@@ -104,15 +104,15 @@ dbus_bool_t
_dbus_address_append_escaped (DBusString *escaped,
const DBusString *unescaped)
{
- const char *p;
- const char *end;
+ const unsigned char *p;
+ const unsigned char *end;
dbus_bool_t ret;
int orig_len;
ret = FALSE;
orig_len = _dbus_string_get_length (escaped);
- p = _dbus_string_get_const_data (unescaped);
+ p = (const unsigned char *) _dbus_string_get_const_data (unescaped);
end = p + _dbus_string_get_length (unescaped);
while (p != end)
{
@@ -648,7 +648,7 @@ dbus_address_unescape_value (const char *value,
/** @} */ /* End of public API */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -678,7 +678,9 @@ static const EscapeTest escape_tests[] = {
{ "Z", "Z" },
{ "a", "a" },
{ "i", "i" },
- { "z", "z" }
+ { "z", "z" },
+ /* Bug: https://bugs.freedesktop.org/show_bug.cgi?id=53499 */
+ { "%c3%b6", "\xc3\xb6" }
};
static const char* invalid_escaped_values[] = {
diff --git a/dbus/dbus-arch-deps.h.in b/dbus/dbus-arch-deps.h.in
index 45952cfb..dfc3589e 100644
--- a/dbus/dbus-arch-deps.h.in
+++ b/dbus/dbus-arch-deps.h.in
@@ -31,7 +31,7 @@
DBUS_BEGIN_DECLS
-#if @DBUS_HAVE_INT64@
+/* D-Bus no longer supports platforms with no 64-bit integer type. */
#define DBUS_HAVE_INT64 1
_DBUS_GNUC_EXTENSION typedef @DBUS_INT64_TYPE@ dbus_int64_t;
_DBUS_GNUC_EXTENSION typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t;
@@ -39,12 +39,6 @@ _DBUS_GNUC_EXTENSION typedef unsigned @DBUS_INT64_TYPE@ dbus_uint64_t;
#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_INT64_CONSTANT@)
#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION @DBUS_UINT64_CONSTANT@)
-#else
-#undef DBUS_HAVE_INT64
-#undef DBUS_INT64_CONSTANT
-#undef DBUS_UINT64_CONSTANT
-#endif
-
typedef @DBUS_INT32_TYPE@ dbus_int32_t;
typedef unsigned @DBUS_INT32_TYPE@ dbus_uint32_t;
diff --git a/dbus/dbus-asv-util.c b/dbus/dbus-asv-util.c
new file mode 100644
index 00000000..583e41fa
--- /dev/null
+++ b/dbus/dbus-asv-util.c
@@ -0,0 +1,260 @@
+/* dbus-asv-util.c - utility functions for a{sv}
+ *
+ * Copyright © 2011-2012 Nokia Corporation
+ * Copyright © 2012-2013 Collabora Ltd.
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <config.h>
+
+#include <dbus/dbus.h>
+
+#include "dbus/dbus-asv-util.h"
+
+/**
+ * Convenience function to create a method-call reply whose type is a{sv}
+ * (map from string to variant).
+ *
+ * Append values with 0 or more sequences of _dbus_asv_open_entry(),
+ * appending a value to var_iter, and _dbus_asv_close_entry(),
+ * then close the a{sv} with _dbus_asv_close() or _dbus_asv_abandon().
+ *
+ * This must be paired with a call to _dbus_asv_close() or _dbus_asv_abandon().
+ *
+ * @param message a method call message
+ * @param iter an iterator which will be initialized to append to the message
+ * @param arr_iter an iterator which will be initialized to append to the array
+ * @returns a new message, or #NULL if not enough memory
+ */
+DBusMessage *
+_dbus_asv_new_method_return (DBusMessage *message,
+ DBusMessageIter *iter,
+ DBusMessageIter *arr_iter)
+{
+ DBusMessage *reply = dbus_message_new_method_return (message);
+
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append (reply, iter);
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, "{sv}",
+ arr_iter))
+ {
+ dbus_message_unref (reply);
+ return NULL;
+ }
+
+ return reply;
+}
+
+/*
+ * Open a new entry in an a{sv} (map from string to variant).
+ *
+ * This must be paired with a call to either _dbus_asv_close_entry()
+ * or _dbus_asv_abandon_entry().
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param entry_iter will be initialized to append to the dict-entry
+ * @param key a UTF-8 key for the map
+ * @param type the type of the variant value, e.g. DBUS_TYPE_STRING_AS_STRING
+ * @param var_iter will be initialized to append (i.e. write) to the variant
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+static dbus_bool_t
+_dbus_asv_open_entry (DBusMessageIter *arr_iter,
+ DBusMessageIter *entry_iter,
+ const char *key,
+ const char *type,
+ DBusMessageIter *var_iter)
+{
+ if (!dbus_message_iter_open_container (arr_iter, DBUS_TYPE_DICT_ENTRY,
+ NULL, entry_iter))
+ return FALSE;
+
+ if (!dbus_message_iter_append_basic (entry_iter, DBUS_TYPE_STRING, &key))
+ {
+ dbus_message_iter_abandon_container (arr_iter, entry_iter);
+ return FALSE;
+ }
+
+ if (!dbus_message_iter_open_container (entry_iter, DBUS_TYPE_VARIANT,
+ type, var_iter))
+ {
+ dbus_message_iter_abandon_container (arr_iter, entry_iter);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ * Closes an a{sv} entry after successfully appending the value.
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param entry_iter the iterator appending to the dict-entry, will be closed
+ * @param var_iter the iterator appending to the variant, will be closed
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+static dbus_bool_t
+_dbus_asv_close_entry (DBusMessageIter *arr_iter,
+ DBusMessageIter *entry_iter,
+ DBusMessageIter *var_iter)
+{
+ if (!dbus_message_iter_close_container (entry_iter, var_iter))
+ {
+ dbus_message_iter_abandon_container (arr_iter, entry_iter);
+ return FALSE;
+ }
+
+ if (!dbus_message_iter_close_container (arr_iter, entry_iter))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * Closes an a{sv} after successfully appending all values.
+ *
+ * If this function fails, you must abandon iter and whatever
+ * larger data structure (message, etc.) the a{sv} was embedded in.
+ *
+ * @param iter the iterator which is appending to the message or other data structure containing the a{sv}
+ * @param arr_iter the iterator appending to the array, will be closed
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+dbus_bool_t
+_dbus_asv_close (DBusMessageIter *iter,
+ DBusMessageIter *arr_iter)
+{
+ return dbus_message_iter_close_container (iter, arr_iter);
+}
+
+/*
+ * Closes an a{sv} entry after unsuccessfully appending a value.
+ * You must also abandon the a{sv} itself (for instance with
+ * _dbus_asv_abandon()), and abandon whatever larger data structure
+ * the a{sv} was embedded in.
+ *
+ * @param iter the iterator which is appending to the message or other data structure containing the a{sv}
+ * @param arr_iter the iterator appending to the array, will be closed
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+static void
+_dbus_asv_abandon_entry (DBusMessageIter *arr_iter,
+ DBusMessageIter *entry_iter,
+ DBusMessageIter *var_iter)
+{
+ dbus_message_iter_abandon_container (entry_iter, var_iter);
+ dbus_message_iter_abandon_container (arr_iter, entry_iter);
+}
+
+/**
+ * Closes an a{sv} after unsuccessfully appending a value.
+ *
+ * You must also abandon whatever larger data structure (message, etc.)
+ * the a{sv} was embedded in.
+ *
+ * @param iter the iterator which is appending to the message or other data structure containing the a{sv}
+ * @param arr_iter the iterator appending to the array, will be closed
+ */
+void
+_dbus_asv_abandon (DBusMessageIter *iter,
+ DBusMessageIter *arr_iter)
+{
+ dbus_message_iter_abandon_container (iter, arr_iter);
+}
+
+/**
+ * Create a new entry in an a{sv} (map from string to variant)
+ * with a 32-bit unsigned integer value.
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param key a UTF-8 key for the map
+ * @param value the value
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+dbus_bool_t
+_dbus_asv_add_uint32 (DBusMessageIter *arr_iter,
+ const char *key,
+ dbus_uint32_t value)
+{
+ DBusMessageIter entry_iter, var_iter;
+
+ if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key,
+ DBUS_TYPE_UINT32_AS_STRING, &var_iter))
+ return FALSE;
+
+ if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_UINT32,
+ &value))
+ {
+ _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
+ return FALSE;
+ }
+
+ if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
+ * Create a new entry in an a{sv} (map from string to variant)
+ * with a UTF-8 string value.
+ *
+ * If this function fails, the a{sv} must be abandoned, for instance
+ * with _dbus_asv_abandon().
+ *
+ * @param arr_iter the iterator which is appending to the array
+ * @param key a UTF-8 key for the map
+ * @param value the value
+ * @returns #TRUE on success, or #FALSE if not enough memory
+ */
+dbus_bool_t
+_dbus_asv_add_string (DBusMessageIter *arr_iter,
+ const char *key,
+ const char *value)
+{
+ DBusMessageIter entry_iter, var_iter;
+
+ if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key,
+ DBUS_TYPE_STRING_AS_STRING, &var_iter))
+ return FALSE;
+
+ if (!dbus_message_iter_append_basic (&var_iter, DBUS_TYPE_STRING,
+ &value))
+ {
+ _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
+ return FALSE;
+ }
+
+ if (!_dbus_asv_close_entry (arr_iter, &entry_iter, &var_iter))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/dbus/dbus-asv-util.h b/dbus/dbus-asv-util.h
new file mode 100644
index 00000000..0337260a
--- /dev/null
+++ b/dbus/dbus-asv-util.h
@@ -0,0 +1,46 @@
+/* dbus-asv-util.h - utility functions for a{sv}
+ *
+ * Copyright © 2011-2012 Nokia Corporation
+ * Copyright © 2012-2013 Collabora Ltd.
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef DBUS_ASV_UTIL_H
+#define DBUS_ASV_UTIL_H
+
+#include <dbus/dbus-internals.h>
+
+DBUS_BEGIN_DECLS
+
+DBusMessage *_dbus_asv_new_method_return (DBusMessage *message,
+ DBusMessageIter *iter,
+ DBusMessageIter *arr_iter);
+dbus_bool_t _dbus_asv_close (DBusMessageIter *iter,
+ DBusMessageIter *arr_iter);
+void _dbus_asv_abandon (DBusMessageIter *iter,
+ DBusMessageIter *arr_iter);
+
+dbus_bool_t _dbus_asv_add_uint32 (DBusMessageIter *arr_iter,
+ const char *key,
+ dbus_uint32_t value);
+dbus_bool_t _dbus_asv_add_string (DBusMessageIter *arr_iter,
+ const char *key,
+ const char *value);
+
+#endif
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index 6285e3ba..164743b0 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -22,7 +22,7 @@
*/
#include <config.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-auth-script.h"
#include "dbus-auth.h"
@@ -223,7 +223,7 @@ auth_set_unix_credentials(DBusAuth *auth,
if (uid != DBUS_UID_UNSET)
_dbus_credentials_add_unix_uid (credentials, uid);
if (pid != DBUS_PID_UNSET)
- _dbus_credentials_add_unix_pid (credentials, pid);
+ _dbus_credentials_add_pid (credentials, pid);
_dbus_auth_set_credentials (auth, credentials);
@@ -584,11 +584,11 @@ _dbus_auth_script_run (const DBusString *filename)
{
_dbus_warn ("not enough memory to call bytes_received, or can't add bytes to auth object already in end state\n");
_dbus_string_free (&to_send);
- _dbus_auth_return_buffer (auth, buffer, 0);
+ _dbus_auth_return_buffer (auth, buffer);
goto out;
}
- _dbus_auth_return_buffer (auth, buffer, _dbus_string_get_length (&to_send));
+ _dbus_auth_return_buffer (auth, buffer);
}
_dbus_string_free (&to_send);
@@ -800,4 +800,4 @@ _dbus_auth_script_run (const DBusString *filename)
}
/** @} */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-auth-util.c b/dbus/dbus-auth-util.c
index 776e8e27..e88d6696 100644
--- a/dbus/dbus-auth-util.c
+++ b/dbus/dbus-auth-util.c
@@ -33,7 +33,7 @@
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include "dbus-auth-script.h"
#include <stdio.h>
@@ -167,4 +167,4 @@ _dbus_auth_test (const char *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index d2c37a7a..6a07665f 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -2238,8 +2238,8 @@ process_command (DBusAuth *auth)
/**
* Creates a new auth conversation object for the server side.
- * See doc/dbus-sasl-profile.txt for full details on what
- * this object does.
+ * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
+ * for full details on what this object does.
*
* @returns the new object or #NULL if no memory
*/
@@ -2284,8 +2284,8 @@ _dbus_auth_server_new (const DBusString *guid)
/**
* Creates a new auth conversation object for the client side.
- * See doc/dbus-sasl-profile.txt for full details on what
- * this object does.
+ * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
+ * for full details on what this object does.
*
* @returns the new object or #NULL if no memory
*/
@@ -2533,12 +2533,10 @@ _dbus_auth_get_buffer (DBusAuth *auth,
*
* @param auth the auth conversation
* @param buffer the buffer being returned
- * @param bytes_read number of new bytes added
*/
void
_dbus_auth_return_buffer (DBusAuth *auth,
- DBusString *buffer,
- int bytes_read)
+ DBusString *buffer)
{
_dbus_assert (buffer == &auth->incoming);
_dbus_assert (auth->buffer_outstanding);
diff --git a/dbus/dbus-auth.h b/dbus/dbus-auth.h
index ae3f3647..ba1975f7 100644
--- a/dbus/dbus-auth.h
+++ b/dbus/dbus-auth.h
@@ -55,8 +55,7 @@ void _dbus_auth_bytes_sent (DBusAuth *auth,
void _dbus_auth_get_buffer (DBusAuth *auth,
DBusString **buffer);
void _dbus_auth_return_buffer (DBusAuth *auth,
- DBusString *buffer,
- int bytes_read);
+ DBusString *buffer);
void _dbus_auth_get_unused_bytes (DBusAuth *auth,
const DBusString **str);
void _dbus_auth_delete_unused_bytes (DBusAuth *auth);
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index fadc3a8b..0fd48311 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -28,6 +28,7 @@
#include "dbus-internals.h"
#include "dbus-message.h"
#include "dbus-marshal-validate.h"
+#include "dbus-misc.h"
#include "dbus-threads-internal.h"
#include "dbus-connection-internal.h"
#include "dbus-string.h"
@@ -95,19 +96,6 @@ static DBusBusType activation_bus_type = DBUS_BUS_STARTER;
static dbus_bool_t initialized = FALSE;
-/**
- * Lock for globals in this file
- */
-_DBUS_DEFINE_GLOBAL_LOCK (bus);
-
-/**
- * Global lock covering all BusData on any connection. The bet is
- * that some lock contention is better than more memory
- * for a per-connection lock, but it's tough to imagine it mattering
- * either way.
- */
-_DBUS_DEFINE_GLOBAL_LOCK (bus_datas);
-
static void
addresses_shutdown_func (void *data)
{
@@ -192,12 +180,12 @@ init_session_address (void)
if (!retval)
return FALSE;
- /* The DBUS_SESSION_BUS_DEFAULT_ADDRESS should have really been named
- * DBUS_SESSION_BUS_FALLBACK_ADDRESS.
- */
+ /* We have a hard-coded (but compile-time-configurable) fallback address for
+ * the session bus. */
if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
bus_connection_addresses[DBUS_BUS_SESSION] =
- _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
+ _dbus_strdup (DBUS_SESSION_BUS_CONNECT_ADDRESS);
+
if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
return FALSE;
@@ -306,12 +294,6 @@ init_connections_unlocked (void)
* the above code will work right
*/
- if (!_dbus_setenv ("DBUS_ACTIVATION_ADDRESS", NULL))
- return FALSE;
-
- if (!_dbus_setenv ("DBUS_ACTIVATION_BUS_TYPE", NULL))
- return FALSE;
-
if (!_dbus_register_shutdown_func (addresses_shutdown_func,
NULL))
return FALSE;
@@ -330,7 +312,11 @@ bus_data_free (void *data)
if (bd->is_well_known)
{
int i;
- _DBUS_LOCK (bus);
+
+ if (!_DBUS_LOCK (bus))
+ _dbus_assert_not_reached ("global locks should have been initialized "
+ "when we attached bus data");
+
/* We may be stored in more than one slot */
/* This should now be impossible - these slots are supposed to
* be cleared on disconnect, so should not need to be cleared on
@@ -401,8 +387,13 @@ void
_dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection)
{
int i;
-
- _DBUS_LOCK (bus);
+
+ if (!_DBUS_LOCK (bus))
+ {
+ /* If it was in bus_connections, we would have initialized global locks
+ * when we added it. So, it can't be. */
+ return;
+ }
/* We are expecting to have the connection saved in only one of these
* slots, but someone could in a pathological case set system and session
@@ -436,7 +427,12 @@ internal_bus_get (DBusBusType type,
connection = NULL;
- _DBUS_LOCK (bus);
+ if (!_DBUS_LOCK (bus))
+ {
+ _DBUS_SET_OOM (error);
+ /* do not "goto out", that would try to unlock */
+ return NULL;
+ }
if (!init_connections_unlocked ())
{
@@ -506,8 +502,10 @@ internal_bus_get (DBusBusType type,
*/
dbus_connection_set_exit_on_disconnect (connection,
TRUE);
-
- _DBUS_LOCK (bus_datas);
+
+ if (!_DBUS_LOCK (bus_datas))
+ _dbus_assert_not_reached ("global locks were initialized already");
+
bd = ensure_bus_data (connection);
_dbus_assert (bd != NULL); /* it should have been created on
register, so OOM not possible */
@@ -554,7 +552,7 @@ out:
*
* @param type bus type
* @param error address where an error can be returned.
- * @returns a #DBusConnection with new ref
+ * @returns a #DBusConnection with new ref or #NULL on error
*/
DBusConnection *
dbus_bus_get (DBusBusType type,
@@ -660,7 +658,12 @@ dbus_bus_register (DBusConnection *connection,
message = NULL;
reply = NULL;
- _DBUS_LOCK (bus_datas);
+ if (!_DBUS_LOCK (bus_datas))
+ {
+ _DBUS_SET_OOM (error);
+ /* do not "goto out", that would try to unlock */
+ return FALSE;
+ }
bd = ensure_bus_data (connection);
if (bd == NULL)
@@ -769,8 +772,12 @@ dbus_bus_set_unique_name (DBusConnection *connection,
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (unique_name != NULL, FALSE);
- _DBUS_LOCK (bus_datas);
-
+ if (!_DBUS_LOCK (bus_datas))
+ {
+ /* do not "goto out", that would try to unlock */
+ return FALSE;
+ }
+
bd = ensure_bus_data (connection);
if (bd == NULL)
goto out;
@@ -812,8 +819,13 @@ dbus_bus_get_unique_name (DBusConnection *connection)
_dbus_return_val_if_fail (connection != NULL, NULL);
- _DBUS_LOCK (bus_datas);
-
+ if (!_DBUS_LOCK (bus_datas))
+ {
+ /* We'd have initialized locks when we gave it its unique name, if it
+ * had one. Don't "goto out", that would try to unlock. */
+ return NULL;
+ }
+
bd = ensure_bus_data (connection);
if (bd == NULL)
goto out;
diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h
index 3d37f188..2842f2f4 100644
--- a/dbus/dbus-connection-internal.h
+++ b/dbus/dbus-connection-internal.h
@@ -115,7 +115,7 @@ void _dbus_connection_get_stats (DBusConnection *connection,
dbus_uint32_t *out_peak_fds);
-/* if DBUS_BUILD_TESTS */
+/* if DBUS_ENABLE_EMBEDDED_TESTS */
const char* _dbus_connection_get_address (DBusConnection *connection);
/* This _dbus_bus_* stuff doesn't really belong here, but dbus-bus-internal.h seems
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c
index ee33b6cc..f0b6871e 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -203,26 +203,19 @@
* @{
*/
-#ifdef DBUS_ENABLE_VERBOSE_MODE
static void
_dbus_connection_trace_ref (DBusConnection *connection,
int old_refcount,
int new_refcount,
const char *why)
{
+#ifdef DBUS_ENABLE_VERBOSE_MODE
static int enabled = -1;
_dbus_trace_ref ("DBusConnection", connection, old_refcount, new_refcount,
why, "DBUS_CONNECTION_TRACE", &enabled);
-}
-#else
-#define _dbus_connection_trace_ref(c,o,n,w) \
- do \
- {\
- (void) (o); \
- (void) (n); \
- } while (0)
#endif
+}
/**
* Internal struct representing a message filter function
@@ -336,8 +329,8 @@ struct DBusConnection
#ifndef DBUS_DISABLE_CHECKS
unsigned int have_connection_lock : 1; /**< Used to check locking */
#endif
-
-#ifndef DBUS_DISABLE_CHECKS
+
+#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
int generation; /**< _dbus_current_generation that should correspond to this connection */
#endif
};
@@ -446,7 +439,7 @@ _dbus_connection_wakeup_mainloop (DBusConnection *connection)
(*connection->wakeup_main_function) (connection->wakeup_main_data);
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Gets the locks so we can examine them
*
@@ -490,9 +483,9 @@ _dbus_connection_queue_received_message_link (DBusConnection *connection,
DBusPendingCall *pending;
dbus_uint32_t reply_serial;
DBusMessage *message;
-
- _dbus_assert (_dbus_transport_get_is_authenticated (connection->transport));
-
+
+ _dbus_assert (_dbus_transport_peek_is_authenticated (connection->transport));
+
_dbus_list_append_link (&connection->incoming_messages,
link);
message = link->data;
@@ -1354,7 +1347,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
connection->disconnected_message_arrived = FALSE;
connection->disconnected_message_processed = FALSE;
-#ifndef DBUS_DISABLE_CHECKS
+#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
connection->generation = _dbus_current_generation;
#endif
@@ -1531,7 +1524,7 @@ _dbus_connection_handle_watch (DBusWatch *watch,
return retval;
}
-_DBUS_DEFINE_GLOBAL_LOCK (shared_connections);
+/* Protected by _DBUS_LOCK (shared_connections) */
static DBusHashTable *shared_connections = NULL;
static DBusList *shared_connections_no_guid = NULL;
@@ -1555,9 +1548,14 @@ static void
shared_connections_shutdown (void *data)
{
int n_entries;
-
- _DBUS_LOCK (shared_connections);
-
+
+ if (!_DBUS_LOCK (shared_connections))
+ {
+ /* We'd have initialized locks before adding anything, so there
+ * can't be anything there. */
+ return;
+ }
+
/* This is a little bit unpleasant... better ideas? */
while ((n_entries = _dbus_hash_table_get_n_entries (shared_connections)) > 0)
{
@@ -1571,7 +1569,8 @@ shared_connections_shutdown (void *data)
_DBUS_UNLOCK (shared_connections);
close_connection_on_shutdown (connection);
- _DBUS_LOCK (shared_connections);
+ if (!_DBUS_LOCK (shared_connections))
+ _dbus_assert_not_reached ("global locks were already initialized");
/* The connection should now be dead and not in our hash ... */
_dbus_assert (_dbus_hash_table_get_n_entries (shared_connections) < n_entries);
@@ -1590,7 +1589,8 @@ shared_connections_shutdown (void *data)
{
_DBUS_UNLOCK (shared_connections);
close_connection_on_shutdown (connection);
- _DBUS_LOCK (shared_connections);
+ if (!_DBUS_LOCK (shared_connections))
+ _dbus_assert_not_reached ("global locks were already initialized");
connection = _dbus_list_pop_first (&shared_connections_no_guid);
}
}
@@ -1607,8 +1607,13 @@ connection_lookup_shared (DBusAddressEntry *entry,
_dbus_verbose ("checking for existing connection\n");
*result = NULL;
-
- _DBUS_LOCK (shared_connections);
+
+ if (!_DBUS_LOCK (shared_connections))
+ {
+ /* If it was shared, we'd have initialized global locks when we put
+ * it in shared_connections. */
+ return FALSE;
+ }
if (shared_connections == NULL)
{
@@ -1706,7 +1711,8 @@ connection_record_shared_unlocked (DBusConnection *connection,
if (guid == NULL)
{
- _DBUS_LOCK (shared_connections);
+ if (!_DBUS_LOCK (shared_connections))
+ return FALSE;
if (!_dbus_list_prepend (&shared_connections_no_guid, connection))
{
@@ -1733,8 +1739,14 @@ connection_record_shared_unlocked (DBusConnection *connection,
dbus_free (guid_key);
return FALSE;
}
-
- _DBUS_LOCK (shared_connections);
+
+ if (!_DBUS_LOCK (shared_connections))
+ {
+ dbus_free (guid_in_connection);
+ dbus_free (guid_key);
+ return FALSE;
+ }
+
_dbus_assert (shared_connections != NULL);
if (!_dbus_hash_table_insert_string (shared_connections,
@@ -1765,9 +1777,14 @@ connection_forget_shared_unlocked (DBusConnection *connection)
if (!connection->shareable)
return;
-
- _DBUS_LOCK (shared_connections);
-
+
+ if (!_DBUS_LOCK (shared_connections))
+ {
+ /* If it was shared, we'd have initialized global locks when we put
+ * it in the table; so it can't be there. */
+ return;
+ }
+
if (connection->server_guid != NULL)
{
_dbus_verbose ("dropping connection to %s out of the shared table\n",
@@ -2150,7 +2167,7 @@ _dbus_connection_close_if_only_one_ref (DBusConnection *connection)
* relatively long time for memory, if they were only willing to block
* briefly then we retry for memory at a rapid rate.
*
- * @timeout_milliseconds the timeout requested for blocking
+ * @param timeout_milliseconds the timeout requested for blocking
*/
static void
_dbus_memory_pause_based_on_timeout (int timeout_milliseconds)
@@ -2683,6 +2700,7 @@ _dbus_connection_last_unref (DBusConnection *connection)
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL);
dbus_connection_set_unix_user_function (connection, NULL, NULL, NULL);
+ dbus_connection_set_windows_user_function (connection, NULL, NULL, NULL);
_dbus_watch_list_free (connection->watches);
connection->watches = NULL;
@@ -2952,9 +2970,9 @@ dbus_connection_get_is_authenticated (DBusConnection *connection)
dbus_bool_t res;
_dbus_return_val_if_fail (connection != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- res = _dbus_transport_get_is_authenticated (connection->transport);
+ res = _dbus_transport_try_to_authenticate (connection->transport);
CONNECTION_UNLOCK (connection);
return res;
@@ -3938,7 +3956,7 @@ _dbus_connection_pop_message_link_unlocked (DBusConnection *connection)
link = _dbus_list_pop_first_link (&connection->incoming_messages);
connection->n_incoming -= 1;
- _dbus_verbose ("Message %p (%s %s %s %s '%s') removed from incoming queue %p, %d incoming\n",
+ _dbus_verbose ("Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n",
link->data,
dbus_message_type_to_string (dbus_message_get_type (link->data)),
dbus_message_get_path (link->data) ?
@@ -3951,6 +3969,7 @@ _dbus_connection_pop_message_link_unlocked (DBusConnection *connection)
dbus_message_get_member (link->data) :
"no member",
dbus_message_get_signature (link->data),
+ dbus_message_get_serial (link->data),
connection, connection->n_incoming);
_dbus_message_trace_ref (link->data, -1, -1,
@@ -5148,10 +5167,10 @@ dbus_connection_get_unix_user (DBusConnection *connection,
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (uid != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_get_is_authenticated (connection->transport))
+ if (!_dbus_transport_try_to_authenticate (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_unix_user (connection->transport,
@@ -5184,10 +5203,10 @@ dbus_connection_get_unix_process_id (DBusConnection *connection,
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (pid != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_get_is_authenticated (connection->transport))
+ if (!_dbus_transport_try_to_authenticate (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_unix_process_id (connection->transport,
@@ -5205,7 +5224,8 @@ dbus_connection_get_unix_process_id (DBusConnection *connection,
* connection.
*
* @param connection the connection
- * @param data return location for audit data
+ * @param data return location for audit data
+ * @param data_size return location for length of audit data
* @returns #TRUE if audit data is filled in with a valid ucred pointer
*/
dbus_bool_t
@@ -5218,10 +5238,10 @@ dbus_connection_get_adt_audit_session_data (DBusConnection *connection,
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (data != NULL, FALSE);
_dbus_return_val_if_fail (data_size != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_get_is_authenticated (connection->transport))
+ if (!_dbus_transport_try_to_authenticate (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_adt_audit_session_data (connection->transport,
@@ -5314,10 +5334,10 @@ dbus_connection_get_windows_user (DBusConnection *connection,
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (windows_sid_p != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_get_is_authenticated (connection->transport))
+ if (!_dbus_transport_try_to_authenticate (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_windows_user (connection->transport,
@@ -5435,7 +5455,7 @@ dbus_connection_set_route_peer_messages (DBusConnection *connection,
_dbus_return_if_fail (connection != NULL);
CONNECTION_LOCK (connection);
- connection->route_peer_messages = TRUE;
+ connection->route_peer_messages = value;
CONNECTION_UNLOCK (connection);
}
@@ -5852,8 +5872,8 @@ dbus_connection_list_registered (DBusConnection *connection,
return retval;
}
-static DBusDataSlotAllocator slot_allocator;
-_DBUS_DEFINE_GLOBAL_LOCK (connection_slots);
+static DBusDataSlotAllocator slot_allocator =
+ _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (connection_slots));
/**
* Allocates an integer ID to be used for storing application-specific
@@ -5873,7 +5893,6 @@ dbus_bool_t
dbus_connection_allocate_data_slot (dbus_int32_t *slot_p)
{
return _dbus_data_slot_allocator_alloc (&slot_allocator,
- &_DBUS_LOCK_NAME (connection_slots),
slot_p);
}
@@ -5974,7 +5993,8 @@ dbus_connection_get_data (DBusConnection *connection,
void *res;
_dbus_return_val_if_fail (connection != NULL, NULL);
-
+ _dbus_return_val_if_fail (slot >= 0, NULL);
+
SLOTS_LOCK (connection);
res = _dbus_data_slot_list_get (&slot_allocator,
@@ -6043,7 +6063,7 @@ dbus_connection_get_max_message_size (DBusConnection *connection)
* result in disconnecting the connection.
*
* @param connection a #DBusConnection
- * @param size maximum message unix fds the connection can receive
+ * @param n maximum message unix fds the connection can receive
*/
void
dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
@@ -6141,7 +6161,7 @@ dbus_connection_get_max_received_size (DBusConnection *connection)
* The semantics are analogous to those of dbus_connection_set_max_received_size().
*
* @param connection the connection
- * @param size the maximum size in bytes of all outstanding messages
+ * @param n the maximum size in bytes of all outstanding messages
*/
void
dbus_connection_set_max_received_unix_fds (DBusConnection *connection,
@@ -6258,7 +6278,7 @@ dbus_connection_get_outgoing_unix_fds (DBusConnection *connection)
return res;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Returns the address of the transport object of this connection
*
diff --git a/dbus/dbus-credentials-util.c b/dbus/dbus-credentials-util.c
index 02771966..d2d164f7 100644
--- a/dbus/dbus-credentials-util.c
+++ b/dbus/dbus-credentials-util.c
@@ -33,14 +33,14 @@
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
#include <string.h>
static DBusCredentials*
make_credentials(dbus_uid_t unix_uid,
- dbus_pid_t unix_pid,
+ dbus_pid_t pid,
const char *windows_sid)
{
DBusCredentials *credentials;
@@ -56,9 +56,9 @@ make_credentials(dbus_uid_t unix_uid,
}
}
- if (unix_pid != DBUS_PID_UNSET)
+ if (pid != DBUS_PID_UNSET)
{
- if (!_dbus_credentials_add_unix_pid (credentials, unix_pid))
+ if (!_dbus_credentials_add_pid (credentials, pid))
{
_dbus_credentials_unref (credentials);
return NULL;
@@ -102,7 +102,7 @@ _dbus_credentials_test (const char *test_data_dir)
_dbus_assert (_dbus_credentials_include (creds, DBUS_CREDENTIAL_WINDOWS_SID));
_dbus_assert (_dbus_credentials_get_unix_uid (creds) == 12);
- _dbus_assert (_dbus_credentials_get_unix_pid (creds) == 511);
+ _dbus_assert (_dbus_credentials_get_pid (creds) == 511);
_dbus_assert (strcmp (_dbus_credentials_get_windows_sid (creds), SAMPLE_SID) == 0);
_dbus_assert (!_dbus_credentials_are_empty (creds));
@@ -118,7 +118,7 @@ _dbus_credentials_test (const char *test_data_dir)
_dbus_assert (_dbus_credentials_include (creds2, DBUS_CREDENTIAL_WINDOWS_SID));
_dbus_assert (_dbus_credentials_get_unix_uid (creds2) == 12);
- _dbus_assert (_dbus_credentials_get_unix_pid (creds2) == 511);
+ _dbus_assert (_dbus_credentials_get_pid (creds2) == 511);
_dbus_assert (strcmp (_dbus_credentials_get_windows_sid (creds2), SAMPLE_SID) == 0);
_dbus_assert (_dbus_credentials_are_superset (creds, creds2));
@@ -192,7 +192,7 @@ _dbus_credentials_test (const char *test_data_dir)
_dbus_assert (!_dbus_credentials_include (creds, DBUS_CREDENTIAL_WINDOWS_SID));
_dbus_assert (_dbus_credentials_get_unix_uid (creds) == DBUS_UID_UNSET);
- _dbus_assert (_dbus_credentials_get_unix_pid (creds) == DBUS_PID_UNSET);
+ _dbus_assert (_dbus_credentials_get_pid (creds) == DBUS_PID_UNSET);
_dbus_assert (_dbus_credentials_get_windows_sid (creds) == NULL);
_dbus_assert (_dbus_credentials_are_empty (creds));
@@ -203,4 +203,4 @@ _dbus_credentials_test (const char *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-credentials.c b/dbus/dbus-credentials.c
index ff69f3b0..7325125c 100644
--- a/dbus/dbus-credentials.c
+++ b/dbus/dbus-credentials.c
@@ -48,7 +48,7 @@
struct DBusCredentials {
int refcount;
dbus_uid_t unix_uid;
- dbus_pid_t unix_pid;
+ dbus_pid_t pid;
char *windows_sid;
void *adt_audit_data;
dbus_int32_t adt_audit_data_size;
@@ -77,7 +77,7 @@ _dbus_credentials_new (void)
creds->refcount = 1;
creds->unix_uid = DBUS_UID_UNSET;
- creds->unix_pid = DBUS_PID_UNSET;
+ creds->pid = DBUS_PID_UNSET;
creds->windows_sid = NULL;
creds->adt_audit_data = NULL;
creds->adt_audit_data_size = 0;
@@ -146,10 +146,10 @@ _dbus_credentials_unref (DBusCredentials *credentials)
* @returns #FALSE if no memory
*/
dbus_bool_t
-_dbus_credentials_add_unix_pid (DBusCredentials *credentials,
- dbus_pid_t pid)
+_dbus_credentials_add_pid (DBusCredentials *credentials,
+ dbus_pid_t pid)
{
- credentials->unix_pid = pid;
+ credentials->pid = pid;
return TRUE;
}
@@ -231,7 +231,7 @@ _dbus_credentials_include (DBusCredentials *credentials,
switch (type)
{
case DBUS_CREDENTIAL_UNIX_PROCESS_ID:
- return credentials->unix_pid != DBUS_PID_UNSET;
+ return credentials->pid != DBUS_PID_UNSET;
case DBUS_CREDENTIAL_UNIX_USER_ID:
return credentials->unix_uid != DBUS_UID_UNSET;
case DBUS_CREDENTIAL_WINDOWS_SID:
@@ -252,9 +252,9 @@ _dbus_credentials_include (DBusCredentials *credentials,
* @returns UNIX process ID
*/
dbus_pid_t
-_dbus_credentials_get_unix_pid (DBusCredentials *credentials)
+_dbus_credentials_get_pid (DBusCredentials *credentials)
{
- return credentials->unix_pid;
+ return credentials->pid;
}
/**
@@ -322,8 +322,8 @@ _dbus_credentials_are_superset (DBusCredentials *credentials,
DBusCredentials *possible_subset)
{
return
- (possible_subset->unix_pid == DBUS_PID_UNSET ||
- possible_subset->unix_pid == credentials->unix_pid) &&
+ (possible_subset->pid == DBUS_PID_UNSET ||
+ possible_subset->pid == credentials->pid) &&
(possible_subset->unix_uid == DBUS_UID_UNSET ||
possible_subset->unix_uid == credentials->unix_uid) &&
(possible_subset->windows_sid == NULL ||
@@ -345,7 +345,7 @@ dbus_bool_t
_dbus_credentials_are_empty (DBusCredentials *credentials)
{
return
- credentials->unix_pid == DBUS_PID_UNSET &&
+ credentials->pid == DBUS_PID_UNSET &&
credentials->unix_uid == DBUS_UID_UNSET &&
credentials->windows_sid == NULL &&
credentials->adt_audit_data == NULL;
@@ -410,9 +410,9 @@ _dbus_credentials_add_credential (DBusCredentials *credentials,
DBusCredentials *other_credentials)
{
if (which == DBUS_CREDENTIAL_UNIX_PROCESS_ID &&
- other_credentials->unix_pid != DBUS_PID_UNSET)
+ other_credentials->pid != DBUS_PID_UNSET)
{
- if (!_dbus_credentials_add_unix_pid (credentials, other_credentials->unix_pid))
+ if (!_dbus_credentials_add_pid (credentials, other_credentials->pid))
return FALSE;
}
else if (which == DBUS_CREDENTIAL_UNIX_USER_ID &&
@@ -445,7 +445,7 @@ _dbus_credentials_add_credential (DBusCredentials *credentials,
void
_dbus_credentials_clear (DBusCredentials *credentials)
{
- credentials->unix_pid = DBUS_PID_UNSET;
+ credentials->pid = DBUS_PID_UNSET;
credentials->unix_uid = DBUS_UID_UNSET;
dbus_free (credentials->windows_sid);
credentials->windows_sid = NULL;
@@ -523,9 +523,9 @@ _dbus_credentials_to_string_append (DBusCredentials *credentials,
goto oom;
join = TRUE;
}
- if (credentials->unix_pid != DBUS_PID_UNSET)
+ if (credentials->pid != DBUS_PID_UNSET)
{
- if (!_dbus_string_append_printf (string, "%spid=" DBUS_PID_FORMAT, join ? " " : "", credentials->unix_pid))
+ if (!_dbus_string_append_printf (string, "%spid=" DBUS_PID_FORMAT, join ? " " : "", credentials->pid))
goto oom;
join = TRUE;
}
diff --git a/dbus/dbus-credentials.h b/dbus/dbus-credentials.h
index ef6124fd..abcc4bb3 100644
--- a/dbus/dbus-credentials.h
+++ b/dbus/dbus-credentials.h
@@ -41,7 +41,7 @@ DBusCredentials* _dbus_credentials_new_from_current_process (void);
DBusCredentials* _dbus_credentials_new (void);
void _dbus_credentials_ref (DBusCredentials *credentials);
void _dbus_credentials_unref (DBusCredentials *credentials);
-dbus_bool_t _dbus_credentials_add_unix_pid (DBusCredentials *credentials,
+dbus_bool_t _dbus_credentials_add_pid (DBusCredentials *credentials,
dbus_pid_t pid);
dbus_bool_t _dbus_credentials_add_unix_uid (DBusCredentials *credentials,
dbus_uid_t uid);
@@ -52,7 +52,7 @@ dbus_bool_t _dbus_credentials_add_adt_audit_data (DBusCredentials
dbus_int32_t size);
dbus_bool_t _dbus_credentials_include (DBusCredentials *credentials,
DBusCredentialType type);
-dbus_pid_t _dbus_credentials_get_unix_pid (DBusCredentials *credentials);
+dbus_pid_t _dbus_credentials_get_pid (DBusCredentials *credentials);
dbus_uid_t _dbus_credentials_get_unix_uid (DBusCredentials *credentials);
const char* _dbus_credentials_get_windows_sid (DBusCredentials *credentials);
void * _dbus_credentials_get_adt_audit_data (DBusCredentials *credentials);
diff --git a/dbus/dbus-dataslot.c b/dbus/dbus-dataslot.c
index 0369612e..e37c9dd5 100644
--- a/dbus/dbus-dataslot.c
+++ b/dbus/dbus-dataslot.c
@@ -43,13 +43,14 @@
* @param allocator the allocator to initialize
*/
dbus_bool_t
-_dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator)
+_dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator,
+ DBusGlobalLock lock)
{
allocator->allocated_slots = NULL;
allocator->n_allocated_slots = 0;
allocator->n_used_slots = 0;
- allocator->lock_loc = NULL;
-
+ allocator->lock = lock;
+
return TRUE;
}
@@ -61,29 +62,17 @@ _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator)
* is allocated and stored at *slot_id_p.
*
* @param allocator the allocator
- * @param mutex_loc the location lock for this allocator
* @param slot_id_p address to fill with the slot ID
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator,
- DBusRMutex **mutex_loc,
dbus_int32_t *slot_id_p)
{
dbus_int32_t slot;
- _dbus_rmutex_lock (*mutex_loc);
-
- if (allocator->n_allocated_slots == 0)
- {
- _dbus_assert (allocator->lock_loc == NULL);
- allocator->lock_loc = mutex_loc;
- }
- else if (allocator->lock_loc != mutex_loc)
- {
- _dbus_warn_check_failed ("D-Bus threads were initialized after first using the D-Bus library. If your application does not directly initialize threads or use D-Bus, keep in mind that some library or plugin may have used D-Bus or initialized threads behind your back. You can often fix this problem by calling dbus_init_threads() or dbus_g_threads_init() early in your main() method, before D-Bus is used.\n");
- _dbus_assert_not_reached ("exiting");
- }
+ if (!_dbus_lock (allocator->lock))
+ return FALSE;
if (*slot_id_p >= 0)
{
@@ -146,7 +135,7 @@ _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator,
slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
out:
- _dbus_rmutex_unlock (*(allocator->lock_loc));
+ _dbus_unlock (allocator->lock);
return slot >= 0;
}
@@ -165,8 +154,10 @@ void
_dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
dbus_int32_t *slot_id_p)
{
- _dbus_rmutex_lock (*(allocator->lock_loc));
-
+ if (!_dbus_lock (allocator->lock))
+ _dbus_assert_not_reached ("we should have initialized global locks "
+ "before we allocated this slot");
+
_dbus_assert (*slot_id_p < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[*slot_id_p].slot_id == *slot_id_p);
_dbus_assert (allocator->allocated_slots[*slot_id_p].refcount > 0);
@@ -175,7 +166,7 @@ _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
if (allocator->allocated_slots[*slot_id_p].refcount > 0)
{
- _dbus_rmutex_unlock (*(allocator->lock_loc));
+ _dbus_unlock (allocator->lock);
return;
}
@@ -190,19 +181,12 @@ _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
if (allocator->n_used_slots == 0)
{
- DBusRMutex **mutex_loc = allocator->lock_loc;
-
dbus_free (allocator->allocated_slots);
allocator->allocated_slots = NULL;
allocator->n_allocated_slots = 0;
- allocator->lock_loc = NULL;
-
- _dbus_rmutex_unlock (*mutex_loc);
- }
- else
- {
- _dbus_rmutex_unlock (*(allocator->lock_loc));
}
+
+ _dbus_unlock (allocator->lock);
}
/**
@@ -247,10 +231,13 @@ _dbus_data_slot_list_set (DBusDataSlotAllocator *allocator,
* be e.g. realloc()ing allocated_slots. We avoid doing this if asserts
* are disabled, since then the asserts are empty.
*/
- _dbus_rmutex_lock (*(allocator->lock_loc));
+ if (!_dbus_lock (allocator->lock))
+ _dbus_assert_not_reached ("we should have initialized global locks "
+ "before we allocated this slot");
+
_dbus_assert (slot < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
- _dbus_rmutex_unlock (*(allocator->lock_loc));
+ _dbus_unlock (allocator->lock);
#endif
if (slot >= list->n_slots)
@@ -304,11 +291,14 @@ _dbus_data_slot_list_get (DBusDataSlotAllocator *allocator,
* be e.g. realloc()ing allocated_slots. We avoid doing this if asserts
* are disabled, since then the asserts are empty.
*/
- _dbus_rmutex_lock (*(allocator->lock_loc));
+ if (!_dbus_lock (allocator->lock))
+ _dbus_assert_not_reached ("we should have initialized global locks "
+ "before we allocated this slot");
+
_dbus_assert (slot >= 0);
_dbus_assert (slot < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
- _dbus_rmutex_unlock (*(allocator->lock_loc));
+ _dbus_unlock (allocator->lock);
#endif
if (slot >= list->n_slots)
@@ -358,7 +348,7 @@ _dbus_data_slot_list_free (DBusDataSlotList *list)
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -384,17 +374,12 @@ _dbus_data_slot_test (void)
int i;
DBusFreeFunction old_free_func;
void *old_data;
- DBusRMutex *mutex;
-
- if (!_dbus_data_slot_allocator_init (&allocator))
+
+ if (!_dbus_data_slot_allocator_init (&allocator, _DBUS_LOCK_server_slots))
_dbus_assert_not_reached ("no memory for allocator");
_dbus_data_slot_list_init (&list);
- _dbus_rmutex_new_at_location (&mutex);
- if (mutex == NULL)
- _dbus_assert_not_reached ("failed to alloc mutex");
-
#define N_SLOTS 100
i = 0;
@@ -405,8 +390,8 @@ _dbus_data_slot_test (void)
* here.
*/
dbus_int32_t tmp = -1;
-
- _dbus_data_slot_allocator_alloc (&allocator, &mutex, &tmp);
+
+ _dbus_data_slot_allocator_alloc (&allocator, &tmp);
if (tmp != i)
_dbus_assert_not_reached ("did not allocate slots in numeric order\n");
@@ -471,9 +456,7 @@ _dbus_data_slot_test (void)
++i;
}
- _dbus_rmutex_free_at_location (&mutex);
-
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-dataslot.h b/dbus/dbus-dataslot.h
index 3d9d5edd..1e04fcbc 100644
--- a/dbus/dbus-dataslot.h
+++ b/dbus/dbus-dataslot.h
@@ -57,9 +57,11 @@ struct DBusDataSlotAllocator
DBusAllocatedSlot *allocated_slots; /**< Allocated slots */
int n_allocated_slots; /**< number of slots malloc'd */
int n_used_slots; /**< number of slots used */
- DBusRMutex **lock_loc; /**< location of thread lock */
+ DBusGlobalLock lock; /**< index of thread lock */
};
+#define _DBUS_DATA_SLOT_ALLOCATOR_INIT(x) { NULL, 0, 0, x }
+
/**
* Data structure that stores the actual user data set at a given
* slot.
@@ -70,9 +72,9 @@ struct DBusDataSlotList
int n_slots; /**< Slots we have storage for in data_slots */
};
-dbus_bool_t _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator);
+dbus_bool_t _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator,
+ DBusGlobalLock lock);
dbus_bool_t _dbus_data_slot_allocator_alloc (DBusDataSlotAllocator *allocator,
- DBusRMutex **mutex_loc,
int *slot_id_p);
void _dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
int *slot_id_p);
diff --git a/dbus/dbus-errors.c b/dbus/dbus-errors.c
index db3305b9..a0571a50 100644
--- a/dbus/dbus-errors.c
+++ b/dbus/dbus-errors.c
@@ -235,7 +235,7 @@ dbus_error_free (DBusError *error)
* must ensure the name and message are global data that won't be
* freed. You probably want dbus_set_error() instead, in most cases.
*
- * @param error the error.or #NULL
+ * @param error the error or #NULL
* @param name the error name (not copied!!!)
* @param message the error message (not copied!!!)
*/
@@ -379,7 +379,6 @@ dbus_set_error (DBusError *error,
message_from_error (name)))
{
_dbus_string_free (&str);
- va_end (args);
goto nomem;
}
}
diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c
index c4c6f935..c80835aa 100644
--- a/dbus/dbus-hash.c
+++ b/dbus/dbus-hash.c
@@ -1401,7 +1401,7 @@ _dbus_hash_table_get_n_entries (DBusHashTable *table)
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1828,4 +1828,4 @@ _dbus_hash_test (void)
return ret;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-init-win.cpp b/dbus/dbus-init-win.cpp
new file mode 100644
index 00000000..687f248c
--- /dev/null
+++ b/dbus/dbus-init-win.cpp
@@ -0,0 +1,52 @@
+/*
+ * dbus-init-win.cpp - once-per-process initialization
+ *
+ * Copyright © 2013 Intel Corporation
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <config.h>
+
+extern "C"
+{
+#include "dbus-sysdeps-win.h"
+}
+
+class DBusInternalInit
+ {
+ public:
+ DBusInternalInit ()
+ {
+ _dbus_threads_windows_init_global ();
+ }
+
+ void must_not_be_omitted ()
+ {
+ }
+ };
+
+static DBusInternalInit init;
+
+extern "C" void
+_dbus_threads_windows_ensure_ctor_linked ()
+{
+ /* Do nothing significant, just ensure that the global initializer gets
+ * linked in. */
+ init.must_not_be_omitted ();
+}
diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c
index 0e5d807e..e2482597 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -163,26 +163,11 @@
*/
/**
- * @def _DBUS_DEFINE_GLOBAL_LOCK
- *
- * Defines a global lock variable with the given name.
- * The lock must be added to the list to initialize
- * in dbus_threads_init().
- */
-
-/**
- * @def _DBUS_DECLARE_GLOBAL_LOCK
- *
- * Expands to declaration of a global lock defined
- * with _DBUS_DEFINE_GLOBAL_LOCK.
- * The lock must be added to the list to initialize
- * in dbus_threads_init().
- */
-
-/**
* @def _DBUS_LOCK
*
- * Locks a global lock
+ * Locks a global lock, initializing it first if necessary.
+ *
+ * @returns #FALSE if not enough memory
*/
/**
@@ -347,25 +332,22 @@ _dbus_verbose_init (void)
*/
static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
{
- static int prefix = -1;
+ int prefix = 0;
+ char *p = (char *)file + strlen(file);
+ int i = 0;
- if (prefix == -1)
+ for (;p >= file;p--)
{
- char *p = (char *)file + strlen(file);
- int i = 0;
- prefix = 0;
- for (;p >= file;p--)
+ if (DBUS_IS_DIR_SEPARATOR(*p))
{
- if (DBUS_IS_DIR_SEPARATOR(*p))
+ if (++i >= level)
{
- if (++i >= level)
- {
- prefix = p-file+1;
- break;
- }
- }
- }
+ prefix = p-file+1;
+ break;
+ }
+ }
}
+
return (char *)file+prefix;
}
@@ -847,7 +829,7 @@ _dbus_read_uuid_file (const DBusString *filename,
}
}
-_DBUS_DEFINE_GLOBAL_LOCK (machine_uuid);
+/* Protected by _DBUS_LOCK (machine_uuid) */
static int machine_uuid_initialized_generation = 0;
static DBusGUID machine_uuid;
@@ -866,7 +848,9 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
{
dbus_bool_t ok;
- _DBUS_LOCK (machine_uuid);
+ if (!_DBUS_LOCK (machine_uuid))
+ return FALSE;
+
if (machine_uuid_initialized_generation != _dbus_current_generation)
{
DBusError error = DBUS_ERROR_INIT;
@@ -874,7 +858,7 @@ _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE,
&error))
{
-#ifndef DBUS_BUILD_TESTS
+#ifndef DBUS_ENABLE_EMBEDDED_TESTS
/* For the test suite, we may not be installed so just continue silently
* here. But in a production build, we want to be nice and loud about
* this.
@@ -953,7 +937,7 @@ _dbus_real_assert_not_reached (const char *explanation,
}
#endif /* DBUS_DISABLE_ASSERT */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static dbus_bool_t
run_failing_each_malloc (int n_mallocs,
const char *description,
@@ -1048,6 +1032,6 @@ _dbus_test_oom_handling (const char *description,
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
/** @} */
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index 8036a2ba..c5a3c9b8 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -35,10 +35,6 @@
DBUS_BEGIN_DECLS
-#ifndef DBUS_SESSION_BUS_DEFAULT_ADDRESS
-#define DBUS_SESSION_BUS_DEFAULT_ADDRESS "autolaunch:"
-#endif
-
void _dbus_warn (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
@@ -234,10 +230,8 @@ char** _dbus_dup_string_array (const char **array);
#define _DBUS_INT_MIN _DBUS_INT32_MIN
#define _DBUS_INT_MAX _DBUS_INT32_MAX
#define _DBUS_UINT_MAX _DBUS_UINT32_MAX
-#ifdef DBUS_HAVE_INT64
#define _DBUS_INT64_MAX DBUS_INT64_CONSTANT (0x7fffffffffffffff)
#define _DBUS_UINT64_MAX DBUS_UINT64_CONSTANT (0xffffffffffffffff)
-#endif
#define _DBUS_ONE_KILOBYTE 1024
#define _DBUS_ONE_MEGABYTE 1024 * _DBUS_ONE_KILOBYTE
#define _DBUS_ONE_HOUR_IN_MILLISECONDS (1000 * 60 * 60)
@@ -270,7 +264,7 @@ void _dbus_verbose_bytes_of_string (const DBusString *str,
extern const char *_dbus_no_memory_message;
#define _DBUS_SET_OOM(error) dbus_set_error_const ((error), DBUS_ERROR_NO_MEMORY, _dbus_no_memory_message)
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* Memory debugging */
void _dbus_set_fail_alloc_counter (int until_next_fail);
int _dbus_get_fail_alloc_counter (void);
@@ -294,45 +288,46 @@ dbus_bool_t _dbus_test_oom_handling (const char *description,
#define _dbus_decrement_fail_alloc_counter() (FALSE)
#define _dbus_disable_mem_pools() (FALSE)
#define _dbus_get_malloc_blocks_outstanding (0)
-#endif /* !DBUS_BUILD_TESTS */
+#endif /* !DBUS_ENABLE_EMBEDDED_TESTS */
typedef void (* DBusShutdownFunction) (void *data);
-dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
- void *data);
+dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
+ void *data);
+dbus_bool_t _dbus_register_shutdown_func_unlocked (DBusShutdownFunction function,
+ void *data);
extern int _dbus_current_generation;
-/* Thread initializers */
-#define _DBUS_LOCK_NAME(name) _dbus_lock_##name
-#define _DBUS_DECLARE_GLOBAL_LOCK(name) extern DBusRMutex *_dbus_lock_##name
-#define _DBUS_DEFINE_GLOBAL_LOCK(name) DBusRMutex *_dbus_lock_##name
-#define _DBUS_LOCK(name) _dbus_rmutex_lock (_dbus_lock_##name)
-#define _DBUS_UNLOCK(name) _dbus_rmutex_unlock (_dbus_lock_##name)
-
-/* 1-5 */
-_DBUS_DECLARE_GLOBAL_LOCK (list);
-_DBUS_DECLARE_GLOBAL_LOCK (connection_slots);
-_DBUS_DECLARE_GLOBAL_LOCK (pending_call_slots);
-_DBUS_DECLARE_GLOBAL_LOCK (server_slots);
-_DBUS_DECLARE_GLOBAL_LOCK (message_slots);
-/* 5-10 */
-_DBUS_DECLARE_GLOBAL_LOCK (bus);
-_DBUS_DECLARE_GLOBAL_LOCK (bus_datas);
-_DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
-_DBUS_DECLARE_GLOBAL_LOCK (system_users);
-_DBUS_DECLARE_GLOBAL_LOCK (message_cache);
-/* 10-14 */
-_DBUS_DECLARE_GLOBAL_LOCK (shared_connections);
-_DBUS_DECLARE_GLOBAL_LOCK (win_fds);
-_DBUS_DECLARE_GLOBAL_LOCK (sid_atom_cache);
-_DBUS_DECLARE_GLOBAL_LOCK (machine_uuid);
-
-#if !DBUS_USE_SYNC
-_DBUS_DECLARE_GLOBAL_LOCK (atomic);
-#define _DBUS_N_GLOBAL_LOCKS (15)
-#else
-#define _DBUS_N_GLOBAL_LOCKS (14)
-#endif
+/* The weird case convention is to avoid having to change all the callers,
+ * which would be quite a mega-patch. */
+typedef enum
+{
+ /* index 0-4 */
+ _DBUS_LOCK_list,
+ _DBUS_LOCK_connection_slots,
+ _DBUS_LOCK_pending_call_slots,
+ _DBUS_LOCK_server_slots,
+ _DBUS_LOCK_message_slots,
+ /* index 5-9 */
+ _DBUS_LOCK_bus,
+ _DBUS_LOCK_bus_datas,
+ _DBUS_LOCK_shutdown_funcs,
+ _DBUS_LOCK_system_users,
+ _DBUS_LOCK_message_cache,
+ /* index 10-12 */
+ _DBUS_LOCK_shared_connections,
+ _DBUS_LOCK_machine_uuid,
+ _DBUS_LOCK_sysdeps,
+
+ _DBUS_N_GLOBAL_LOCKS
+} DBusGlobalLock;
+
+dbus_bool_t _dbus_lock (DBusGlobalLock lock) _DBUS_GNUC_WARN_UNUSED_RESULT;
+void _dbus_unlock (DBusGlobalLock lock);
+
+#define _DBUS_LOCK_NAME(name) _DBUS_LOCK_##name
+#define _DBUS_LOCK(name) _dbus_lock (_DBUS_LOCK_##name)
+#define _DBUS_UNLOCK(name) _dbus_unlock (_DBUS_LOCK_##name)
dbus_bool_t _dbus_threads_init_debug (void);
diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c
index 23b9df5a..f0c64de3 100644
--- a/dbus/dbus-keyring.c
+++ b/dbus/dbus-keyring.c
@@ -80,7 +80,7 @@
* Maximum number of keys in the keyring before
* we just ignore the rest
*/
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#define MAX_KEYS_IN_FILE 10
#else
#define MAX_KEYS_IN_FILE 256
@@ -697,10 +697,10 @@ _dbus_keyring_unref (DBusKeyring *keyring)
/**
* Creates a new keyring that lives in the ~/.dbus-keyrings directory
- * of the given user credentials. If the credentials are #NULL or
- * empty, uses those of the current process.
+ * of the user represented by @p credentials. If the @p credentials are
+ * #NULL or empty, uses those of the current process.
*
- * @param username username to get keyring for, or #NULL
+ * @param credentials a set of credentials representing a user or #NULL
* @param context which keyring to get
* @param error return location for errors
* @returns the keyring or #NULL on error
@@ -717,6 +717,13 @@ _dbus_keyring_new_for_credentials (DBusCredentials *credentials,
DBusCredentials *our_credentials;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+ if (_dbus_check_setuid ())
+ {
+ dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Unable to create DBus keyring when setuid");
+ return NULL;
+ }
keyring = NULL;
error_set = FALSE;
@@ -1016,7 +1023,7 @@ _dbus_keyring_get_hex_key (DBusKeyring *keyring,
/** @} */ /* end of exposed API */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1149,5 +1156,5 @@ _dbus_keyring_test (void)
return FALSE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-list.c b/dbus/dbus-list.c
index 7e11cc8d..c4c1856f 100644
--- a/dbus/dbus-list.c
+++ b/dbus/dbus-list.c
@@ -35,8 +35,8 @@
* Types and functions related to DBusList.
*/
+/* Protected by _DBUS_LOCK (list) */
static DBusMemPool *list_pool;
-_DBUS_DEFINE_GLOBAL_LOCK (list);
/**
* @defgroup DBusListInternals Linked list implementation details
@@ -56,7 +56,8 @@ alloc_link (void *data)
{
DBusList *link;
- _DBUS_LOCK (list);
+ if (!_DBUS_LOCK (list))
+ return FALSE;
if (list_pool == NULL)
{
@@ -93,7 +94,10 @@ alloc_link (void *data)
static void
free_link (DBusList *link)
{
- _DBUS_LOCK (list);
+ if (!_DBUS_LOCK (list))
+ _dbus_assert_not_reached ("we should have initialized global locks "
+ "before we allocated a linked-list link");
+
if (_dbus_mem_pool_dealloc (list_pool, link))
{
_dbus_mem_pool_free (list_pool);
@@ -152,7 +156,14 @@ _dbus_list_get_stats (dbus_uint32_t *in_use_p,
dbus_uint32_t *in_free_list_p,
dbus_uint32_t *allocated_p)
{
- _DBUS_LOCK (list);
+ if (!_DBUS_LOCK (list))
+ {
+ *in_use_p = 0;
+ *in_free_list_p = 0;
+ *allocated_p = 0;
+ return;
+ }
+
_dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
_DBUS_UNLOCK (list);
}
@@ -777,7 +788,7 @@ _dbus_list_length_is_one (DBusList **list)
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h
index dcd3eebd..cae4100e 100644
--- a/dbus/dbus-macros.h
+++ b/dbus/dbus-macros.h
@@ -88,13 +88,21 @@
#define DBUS_ALLOC_SIZE2(x,y)
#endif
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define _DBUS_GNUC_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+#define _DBUS_GNUC_WARN_UNUSED_RESULT
+#endif
+
/** @def _DBUS_GNUC_PRINTF
* used to tell gcc about printf format strings
*/
/** @def _DBUS_GNUC_NORETURN
* used to tell gcc about functions that never return, such as _dbus_abort()
*/
-
+/** @def _DBUS_GNUC_WARN_UNUSED_RESULT
+ * used to tell gcc about functions whose result must be used
+ */
/* Normally docs are in .c files, but there isn't a .c file for this. */
/**
diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c
index cef676a3..7ff9dc2c 100644
--- a/dbus/dbus-mainloop.c
+++ b/dbus/dbus-mainloop.c
@@ -34,27 +34,6 @@
#define MAINLOOP_SPEW 0
-#if MAINLOOP_SPEW
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-static const char*
-watch_flags_to_string (int flags)
-{
- const char *watch_type;
-
- if ((flags & DBUS_WATCH_READABLE) &&
- (flags & DBUS_WATCH_WRITABLE))
- watch_type = "readwrite";
- else if (flags & DBUS_WATCH_READABLE)
- watch_type = "read";
- else if (flags & DBUS_WATCH_WRITABLE)
- watch_type = "write";
- else
- watch_type = "not read or write";
- return watch_type;
-}
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
-#endif /* MAINLOOP_SPEW */
-
struct DBusLoop
{
int refcount;
@@ -675,7 +654,7 @@ _dbus_loop_iterate (DBusLoop *loop,
timeout = MIN (timeout, _dbus_get_oom_wait ());
#if MAINLOOP_SPEW
- _dbus_verbose (" polling on %d descriptors timeout %ld\n", n_fds, timeout);
+ _dbus_verbose (" polling on %d descriptors timeout %ld\n", _DBUS_N_ELEMENTS (ready_fds), timeout);
#endif
n_ready = _dbus_socket_set_poll (loop->socket_set, ready_fds,
@@ -922,7 +901,7 @@ _dbus_loop_quit (DBusLoop *loop)
int
_dbus_get_oom_wait (void)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* make tests go fast */
return 0;
#else
diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c
index 88b19f36..eafc2a9a 100644
--- a/dbus/dbus-marshal-basic.c
+++ b/dbus/dbus-marshal-basic.c
@@ -58,12 +58,10 @@ _DBUS_ASSERT_ALIGNMENT (dbus_bool_t, <=, 4);
_DBUS_STATIC_ASSERT (sizeof (double) == 8);
_DBUS_ASSERT_ALIGNMENT (double, <=, 8);
-#ifdef DBUS_HAVE_INT64
_DBUS_STATIC_ASSERT (sizeof (dbus_int64_t) == 8);
_DBUS_ASSERT_ALIGNMENT (dbus_int64_t, <=, 8);
_DBUS_STATIC_ASSERT (sizeof (dbus_uint64_t) == 8);
_DBUS_ASSERT_ALIGNMENT (dbus_uint64_t, <=, 8);
-#endif
_DBUS_STATIC_ASSERT (sizeof (DBusBasicValue) >= 8);
/* The alignment of a DBusBasicValue might conceivably be > 8 because of the
@@ -120,15 +118,10 @@ pack_8_octets (DBusBasicValue value,
{
_dbus_assert (_DBUS_ALIGN_ADDRESS (data, 8) == data);
-#ifdef DBUS_HAVE_INT64
if ((byte_order) == DBUS_LITTLE_ENDIAN)
*((dbus_uint64_t*)(data)) = DBUS_UINT64_TO_LE (value.u64);
else
*((dbus_uint64_t*)(data)) = DBUS_UINT64_TO_BE (value.u64);
-#else
- *(DBus8ByteStruct*)data = value.eight;
- swap_8_octets ((DBusBasicValue*)data, byte_order);
-#endif
}
/**
@@ -146,65 +139,16 @@ _dbus_pack_uint32 (dbus_uint32_t value,
pack_4_octets (value, byte_order, data);
}
-#ifndef DBUS_HAVE_INT64
-/* from ORBit */
-static void
-swap_bytes (unsigned char *data,
- unsigned int len)
-{
- unsigned char *p1 = data;
- unsigned char *p2 = data + len - 1;
-
- while (p1 < p2)
- {
- unsigned char tmp = *p1;
- *p1 = *p2;
- *p2 = tmp;
-
- --p2;
- ++p1;
- }
-}
-#endif /* !DBUS_HAVE_INT64 */
-
static void
swap_8_octets (DBusBasicValue *value,
int byte_order)
{
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
{
-#ifdef DBUS_HAVE_INT64
value->u64 = DBUS_UINT64_SWAP_LE_BE (value->u64);
-#else
- swap_bytes (&value->bytes, 8);
-#endif
}
}
-#if 0
-static DBusBasicValue
-unpack_8_octets (int byte_order,
- const unsigned char *data)
-{
- DBusBasicValue r;
-
- _dbus_assert (_DBUS_ALIGN_ADDRESS (data, 8) == data);
- _dbus_assert (sizeof (r) == 8);
-
-#ifdef DBUS_HAVE_INT64
- if (byte_order == DBUS_LITTLE_ENDIAN)
- r.u64 = DBUS_UINT64_FROM_LE (*(dbus_uint64_t*)data);
- else
- r.u64 = DBUS_UINT64_FROM_BE (*(dbus_uint64_t*)data);
-#else
- r.eight = *(DBus8ByteStruct*)data;
- swap_8_octets (&r, byte_order);
-#endif
-
- return r;
-}
-#endif
-
#ifndef _dbus_unpack_uint16
/**
* Unpacks a 16 bit unsigned integer from a data pointer
@@ -601,15 +545,10 @@ _dbus_marshal_read_basic (const DBusString *str,
{
volatile dbus_uint64_t *vp = value;
pos = _DBUS_ALIGN_VALUE (pos, 8);
-#ifdef DBUS_HAVE_INT64
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
*vp = DBUS_UINT64_SWAP_LE_BE (*(dbus_uint64_t*)(str_data + pos));
else
*vp = *(dbus_uint64_t*)(str_data + pos);
-#else
- *vp = *(DBus8ByteStruct*) (str_data + pos);
- swap_8_octets (vp, byte_order);
-#endif
pos += 8;
}
break;
@@ -965,11 +904,7 @@ _dbus_swap_array (unsigned char *data,
{
while (d != end)
{
-#ifdef DBUS_HAVE_INT64
*((dbus_uint64_t*)d) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)d));
-#else
- swap_8_bytes ((DBusBasicValue*) d);
-#endif
d += 8;
}
}
@@ -1501,7 +1436,7 @@ _dbus_first_type_in_signature_c_str (const char *str,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1674,12 +1609,10 @@ _dbus_marshal_test (void)
unsigned char array1[5] = { 3, 4, 0, 1, 9 };
dbus_int16_t array2[3] = { 124, 457, 780 };
dbus_int32_t array4[3] = { 123, 456, 789 };
-#ifdef DBUS_HAVE_INT64
dbus_int64_t array8[3] = { DBUS_INT64_CONSTANT (0x123ffffffff),
DBUS_INT64_CONSTANT (0x456ffffffff),
DBUS_INT64_CONSTANT (0x789ffffffff) };
dbus_int64_t *v_ARRAY_INT64;
-#endif
unsigned char *v_ARRAY_BYTE;
dbus_int16_t *v_ARRAY_INT16;
dbus_uint16_t *v_ARRAY_UINT16;
@@ -1735,7 +1668,6 @@ _dbus_marshal_test (void)
MARSHAL_TEST (UINT32, DBUS_BIG_ENDIAN, 0x12345678);
MARSHAL_TEST (UINT32, DBUS_LITTLE_ENDIAN, 0x12345678);
-#ifdef DBUS_HAVE_INT64
/* Marshal signed integers */
MARSHAL_TEST (INT64, DBUS_BIG_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7));
MARSHAL_TEST (INT64, DBUS_LITTLE_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7));
@@ -1743,7 +1675,6 @@ _dbus_marshal_test (void)
/* Marshal unsigned integers */
MARSHAL_TEST (UINT64, DBUS_BIG_ENDIAN, DBUS_UINT64_CONSTANT (0x123456789abc7));
MARSHAL_TEST (UINT64, DBUS_LITTLE_ENDIAN, DBUS_UINT64_CONSTANT (0x123456789abc7));
-#endif /* DBUS_HAVE_INT64 */
/* Marshal byte */
MARSHAL_TEST (BYTE, DBUS_BIG_ENDIAN, 5);
@@ -1785,10 +1716,8 @@ _dbus_marshal_test (void)
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_BIG_ENDIAN, array1);
MARSHAL_TEST_FIXED_ARRAY (BYTE, DBUS_LITTLE_ENDIAN, array1);
-#ifdef DBUS_HAVE_INT64
MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_BIG_ENDIAN, array8);
MARSHAL_TEST_FIXED_ARRAY (INT64, DBUS_LITTLE_ENDIAN, array8);
-#endif
#if 0
@@ -1796,7 +1725,6 @@ _dbus_marshal_test (void)
* FIXME restore the set/pack tests
*/
-#ifdef DBUS_HAVE_INT64
/* set/pack 64-bit integers */
_dbus_string_set_length (&str, 8);
@@ -1867,7 +1795,6 @@ _dbus_marshal_test (void)
_dbus_assert (DBUS_UINT64_CONSTANT (0x123456789abc7) ==
_dbus_unpack_uint64 (DBUS_BIG_ENDIAN,
_dbus_string_get_const_data (&str)));
-#endif /* DBUS_HAVE_INT64 */
/* set/pack 32-bit integers */
_dbus_string_set_length (&str, 4);
@@ -1992,4 +1919,4 @@ _dbus_marshal_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h
index 034fdaba..9df67cb8 100644
--- a/dbus/dbus-marshal-basic.h
+++ b/dbus/dbus-marshal-basic.h
@@ -57,8 +57,6 @@
#endif /* HAVE_BYTESWAP_H */
-#ifdef DBUS_HAVE_INT64
-
#ifdef HAVE_BYTESWAP_H
#define DBUS_UINT64_SWAP_LE_BE_CONSTANT(val) bswap_64(val)
#else /* HAVE_BYTESWAP_H */
@@ -80,7 +78,6 @@
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0x00ff000000000000)) >> 40) | \
(((dbus_uint64_t) (val) & \
(dbus_uint64_t) DBUS_UINT64_CONSTANT (0xff00000000000000)) >> 56)))
-#endif /* DBUS_HAVE_INT64 */
#endif /* HAVE_BYTESWAP_H */
@@ -90,10 +87,8 @@
#define DBUS_UINT32_SWAP_LE_BE(val) (DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
#define DBUS_INT32_SWAP_LE_BE(val) ((dbus_int32_t)DBUS_UINT32_SWAP_LE_BE_CONSTANT (val))
-#ifdef DBUS_HAVE_INT64
-# define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
-# define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
-#endif /* DBUS_HAVE_INT64 */
+#define DBUS_UINT64_SWAP_LE_BE(val) (DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
+#define DBUS_INT64_SWAP_LE_BE(val) ((dbus_int64_t)DBUS_UINT64_SWAP_LE_BE_CONSTANT (val))
#ifdef WORDS_BIGENDIAN
@@ -105,12 +100,10 @@
# define DBUS_UINT32_TO_BE(val) ((dbus_uint32_t) (val))
# define DBUS_INT32_TO_LE(val) (DBUS_INT32_SWAP_LE_BE (val))
# define DBUS_UINT32_TO_LE(val) (DBUS_UINT32_SWAP_LE_BE (val))
-# ifdef DBUS_HAVE_INT64
-# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
-# define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
-# define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
-# define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
-# endif /* DBUS_HAVE_INT64 */
+# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) (val))
+# define DBUS_UINT64_TO_BE(val) ((dbus_uint64_t) (val))
+# define DBUS_INT64_TO_LE(val) (DBUS_INT64_SWAP_LE_BE (val))
+# define DBUS_UINT64_TO_LE(val) (DBUS_UINT64_SWAP_LE_BE (val))
#else /* WORDS_BIGENDIAN */
@@ -122,12 +115,10 @@
# define DBUS_UINT32_TO_LE(val) ((dbus_uint32_t) (val))
# define DBUS_INT32_TO_BE(val) ((dbus_int32_t) DBUS_UINT32_SWAP_LE_BE (val))
# define DBUS_UINT32_TO_BE(val) (DBUS_UINT32_SWAP_LE_BE (val))
-# ifdef DBUS_HAVE_INT64
-# define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
-# define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
-# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
-# define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
-# endif /* DBUS_HAVE_INT64 */
+# define DBUS_INT64_TO_LE(val) ((dbus_int64_t) (val))
+# define DBUS_UINT64_TO_LE(val) ((dbus_uint64_t) (val))
+# define DBUS_INT64_TO_BE(val) ((dbus_int64_t) DBUS_UINT64_SWAP_LE_BE (val))
+# define DBUS_UINT64_TO_BE(val) (DBUS_UINT64_SWAP_LE_BE (val))
#endif
/* The transformation is symmetric, so the FROM just maps to the TO. */
@@ -139,12 +130,10 @@
#define DBUS_UINT32_FROM_LE(val) (DBUS_UINT32_TO_LE (val))
#define DBUS_INT32_FROM_BE(val) (DBUS_INT32_TO_BE (val))
#define DBUS_UINT32_FROM_BE(val) (DBUS_UINT32_TO_BE (val))
-#ifdef DBUS_HAVE_INT64
-# define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
-# define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
-# define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
-# define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
-#endif /* DBUS_HAVE_INT64 */
+#define DBUS_INT64_FROM_LE(val) (DBUS_INT64_TO_LE (val))
+#define DBUS_UINT64_FROM_LE(val) (DBUS_UINT64_TO_LE (val))
+#define DBUS_INT64_FROM_BE(val) (DBUS_INT64_TO_BE (val))
+#define DBUS_UINT64_FROM_BE(val) (DBUS_UINT64_TO_BE (val))
#ifdef DBUS_DISABLE_ASSERT
#define _dbus_unpack_uint16(byte_order, data) \
diff --git a/dbus/dbus-marshal-byteswap-util.c b/dbus/dbus-marshal-byteswap-util.c
index edb74cad..57874859 100644
--- a/dbus/dbus-marshal-byteswap-util.c
+++ b/dbus/dbus-marshal-byteswap-util.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-marshal-byteswap.h"
#include "dbus-test.h"
#include <stdio.h>
@@ -102,4 +102,4 @@ _dbus_marshal_byteswap_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c
index 22d7e22b..e6711be6 100644
--- a/dbus/dbus-marshal-byteswap.c
+++ b/dbus/dbus-marshal-byteswap.c
@@ -73,11 +73,7 @@ byteswap_body_helper (DBusTypeReader *reader,
case DBUS_TYPE_DOUBLE:
{
p = _DBUS_ALIGN_ADDRESS (p, 8);
-#ifdef DBUS_HAVE_INT64
*((dbus_uint64_t*)p) = DBUS_UINT64_SWAP_LE_BE (*((dbus_uint64_t*)p));
-#else
- _dbus_swap_array (p, 1, 8);
-#endif
p += 8;
}
break;
diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c
index 88887a82..48151c62 100644
--- a/dbus/dbus-marshal-header.c
+++ b/dbus/dbus-marshal-header.c
@@ -276,6 +276,7 @@ _dbus_header_cache_known_nonexistent (DBusHeader *header,
* Writes a struct of { byte, variant } with the given basic type.
*
* @param writer the writer (should be ready to write a struct)
+ * @param field the header field
* @param type the type of the value
* @param value the value as for _dbus_marshal_set_basic()
* @returns #FALSE if no memory
@@ -336,6 +337,7 @@ write_basic_field (DBusTypeWriter *writer,
* Sets a struct of { byte, variant } with the given basic type.
*
* @param reader the reader (should be iterating over the array pointing at the field to set)
+ * @param field the header field
* @param type the type of the value
* @param value the value as for _dbus_marshal_set_basic()
* @param realign_root where to realign from
@@ -452,7 +454,6 @@ _dbus_header_reinit (DBusHeader *header)
* to make the header valid, you have to call _dbus_header_create().
*
* @param header header to initialize
- * @param byte_order byte order of the header
* @returns #FALSE if not enough memory
*/
dbus_bool_t
@@ -514,6 +515,7 @@ _dbus_header_copy (const DBusHeader *header,
* sense, and passing them in will trigger an assertion failure.
*
* @param header the header
+ * @param byte_order byte order of the header
* @param message_type the message type
* @param destination destination field or #NULL
* @param path path field or #NULL
diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c
index 95124140..0e2b4201 100644
--- a/dbus/dbus-marshal-recursive-util.c
+++ b/dbus/dbus-marshal-recursive-util.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-marshal-recursive.h"
#include "dbus-marshal-basic.h"
@@ -34,13 +34,7 @@
static void
basic_value_zero (DBusBasicValue *value)
{
-
-#ifdef DBUS_HAVE_INT64
value->u64 = 0;
-#else
- value->eight.first32 = 0;
- value->eight.second32 = 0;
-#endif
}
static dbus_bool_t
@@ -56,12 +50,7 @@ basic_value_equal (int type,
}
else
{
-#ifdef DBUS_HAVE_INT64
return lhs->u64 == rhs->u64;
-#else
- return lhs->eight.first32 == rhs->eight.first32 &&
- lhs->eight.second32 == rhs->eight.second32;
-#endif
}
}
@@ -1785,10 +1774,13 @@ make_and_run_test_nodes (void)
start_next_test ("All values in one big toplevel %d iteration\n", 1);
{
TestTypeNode *nodes[N_VALUES];
+ TestTypeNode *node;
i = 0;
- while ((nodes[i] = value_generator (&i)))
- ;
+ while ((node = value_generator (&i)))
+ {
+ nodes[i - 1] = node;
+ }
run_test_nodes (nodes, N_VALUES);
@@ -2337,7 +2329,6 @@ int32_read_multi (TestTypeNode *node,
return TRUE;
}
-#ifdef DBUS_HAVE_INT64
static dbus_int64_t
int64_from_seed (int seed)
{
@@ -2351,7 +2342,6 @@ int64_from_seed (int seed)
return v;
}
-#endif
static dbus_bool_t
int64_write_value (TestTypeNode *node,
@@ -2359,7 +2349,6 @@ int64_write_value (TestTypeNode *node,
DBusTypeWriter *writer,
int seed)
{
-#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2368,9 +2357,6 @@ int64_write_value (TestTypeNode *node,
return _dbus_type_writer_write_basic (writer,
node->klass->typecode,
&v);
-#else
- return TRUE;
-#endif
}
static dbus_bool_t
@@ -2378,7 +2364,6 @@ int64_read_value (TestTypeNode *node,
DBusTypeReader *reader,
int seed)
{
-#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2390,9 +2375,6 @@ int64_read_value (TestTypeNode *node,
_dbus_assert (v == int64_from_seed (seed));
return TRUE;
-#else
- return TRUE;
-#endif
}
static dbus_bool_t
@@ -2401,7 +2383,6 @@ int64_set_value (TestTypeNode *node,
DBusTypeReader *realign_root,
int seed)
{
-#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2410,9 +2391,6 @@ int64_set_value (TestTypeNode *node,
return _dbus_type_reader_set_basic (reader,
&v,
realign_root);
-#else
- return TRUE;
-#endif
}
#define MAX_SAMPLE_STRING_LEN 10
@@ -3574,4 +3552,4 @@ container_destroy (TestTypeNode *node)
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-marshal-validate-util.c b/dbus/dbus-marshal-validate-util.c
index 81135bcf..d52cb6d8 100644
--- a/dbus/dbus-marshal-validate-util.c
+++ b/dbus/dbus-marshal-validate-util.c
@@ -22,7 +22,7 @@
*/
#include <config.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -585,4 +585,4 @@ _dbus_marshal_validate_test (void)
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c
index a033b540..22e80727 100644
--- a/dbus/dbus-memory.c
+++ b/dbus/dbus-memory.c
@@ -26,6 +26,7 @@
#include "dbus-internals.h"
#include "dbus-sysdeps.h"
#include "dbus-list.h"
+#include "dbus-threads.h"
#include <stdlib.h>
/**
@@ -96,7 +97,7 @@
* @{
*/
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static dbus_bool_t debug_initialized = FALSE;
static int fail_nth = -1;
static size_t fail_size = 0;
@@ -239,7 +240,7 @@ _dbus_get_fail_alloc_failures (void)
return n_failures_per_failure;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Called when about to alloc some memory; if
* it returns #TRUE, then the allocation should
@@ -293,7 +294,7 @@ _dbus_decrement_fail_alloc_counter (void)
return FALSE;
}
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
/**
* Get the number of outstanding malloc()'d blocks.
@@ -459,7 +460,7 @@ set_guards (void *real_block,
void*
dbus_malloc (size_t bytes)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -471,7 +472,7 @@ dbus_malloc (size_t bytes)
if (bytes == 0) /* some system mallocs handle this, some don't */
return NULL;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -498,7 +499,7 @@ dbus_malloc (size_t bytes)
void *mem;
mem = malloc (bytes);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (mem)
{
_dbus_atomic_inc (&n_blocks_outstanding);
@@ -529,7 +530,7 @@ dbus_malloc (size_t bytes)
void*
dbus_malloc0 (size_t bytes)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -542,7 +543,7 @@ dbus_malloc0 (size_t bytes)
if (bytes == 0)
return NULL;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -570,7 +571,7 @@ dbus_malloc0 (size_t bytes)
void *mem;
mem = calloc (bytes, 1);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (mem)
{
_dbus_atomic_inc (&n_blocks_outstanding);
@@ -600,7 +601,7 @@ void*
dbus_realloc (void *memory,
size_t bytes)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -616,7 +617,7 @@ dbus_realloc (void *memory,
dbus_free (memory);
return NULL;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -676,7 +677,7 @@ dbus_realloc (void *memory,
void *mem;
mem = realloc (memory, bytes);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (mem == NULL && malloc_cannot_fail)
{
_dbus_warn ("out of memory: malloc (%ld)\n", (long) bytes);
@@ -699,7 +700,7 @@ dbus_realloc (void *memory,
void
dbus_free (void *memory)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (guards)
{
check_guards (memory, TRUE);
@@ -723,7 +724,7 @@ dbus_free (void *memory)
if (memory) /* we guarantee it's safe to free (NULL) */
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifdef DBUS_DISABLE_ASSERT
_dbus_atomic_dec (&n_blocks_outstanding);
#else
@@ -794,7 +795,7 @@ struct ShutdownClosure
void *data; /**< Data for function */
};
-_DBUS_DEFINE_GLOBAL_LOCK (shutdown_funcs);
+/* Protected by _DBUS_LOCK (shutdown_funcs) */
static ShutdownClosure *registered_globals = NULL;
/**
@@ -809,6 +810,20 @@ dbus_bool_t
_dbus_register_shutdown_func (DBusShutdownFunction func,
void *data)
{
+ dbus_bool_t ok;
+
+ if (!_DBUS_LOCK (shutdown_funcs))
+ return FALSE;
+
+ ok = _dbus_register_shutdown_func_unlocked (func, data);
+ _DBUS_UNLOCK (shutdown_funcs);
+ return ok;
+}
+
+dbus_bool_t
+_dbus_register_shutdown_func_unlocked (DBusShutdownFunction func,
+ void *data)
+{
ShutdownClosure *c;
c = dbus_new (ShutdownClosure, 1);
@@ -819,13 +834,9 @@ _dbus_register_shutdown_func (DBusShutdownFunction func,
c->func = func;
c->data = data;
- _DBUS_LOCK (shutdown_funcs);
-
c->next = registered_globals;
registered_globals = c;
- _DBUS_UNLOCK (shutdown_funcs);
-
return TRUE;
}
@@ -845,7 +856,7 @@ _dbus_register_shutdown_func (DBusShutdownFunction func,
* can be useful to free these internal data structures.
*
* dbus_shutdown() does NOT free memory that was returned
- * to the application. It only returns libdbus-internal
+ * to the application. It only frees libdbus-internal
* data structures.
*
* You MUST free all memory and release all reference counts
@@ -890,12 +901,18 @@ dbus_shutdown (void)
dbus_free (c);
}
+ /* We wrap this in the thread-initialization lock because
+ * dbus_threads_init() uses the current generation to tell whether
+ * we're initialized, so we need to make sure that un-initializing
+ * propagates into all threads. */
+ _dbus_threads_lock_platform_specific ();
_dbus_current_generation += 1;
+ _dbus_threads_unlock_platform_specific ();
}
/** @} */ /** End of public API docs block */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
/**
diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c
index 33aabf9c..52466151 100644
--- a/dbus/dbus-mempool.c
+++ b/dbus/dbus-mempool.c
@@ -173,7 +173,7 @@ _dbus_mem_pool_new (int element_size,
_dbus_assert ((pool->block_size %
pool->element_size) == 0);
- VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements)
+ VALGRIND_CREATE_MEMPOOL (pool, 0, zero_elements);
return pool;
}
@@ -188,7 +188,7 @@ _dbus_mem_pool_free (DBusMemPool *pool)
{
DBusMemBlock *block;
- VALGRIND_DESTROY_MEMPOOL (pool)
+ VALGRIND_DESTROY_MEMPOOL (pool);
block = pool->blocks;
while (block != NULL)
@@ -213,7 +213,7 @@ _dbus_mem_pool_free (DBusMemPool *pool)
void*
_dbus_mem_pool_alloc (DBusMemPool *pool)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (_dbus_disable_mem_pools ())
{
DBusMemBlock *block;
@@ -241,7 +241,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
pool->allocated_elements += 1;
VALGRIND_MEMPOOL_ALLOC (pool, (void *) &block->elements[0],
- pool->element_size)
+ pool->element_size);
return (void*) &block->elements[0];
}
else
@@ -261,7 +261,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
pool->free_elements = pool->free_elements->next;
- VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size)
+ VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size);
if (pool->zero_elements)
memset (element, '\0', pool->element_size);
@@ -280,7 +280,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
/* Need a new block */
DBusMemBlock *block;
int alloc_size;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
int saved_counter;
#endif
@@ -294,7 +294,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
alloc_size = sizeof (DBusMemBlock) - ELEMENT_PADDING + pool->block_size;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* We save/restore the counter, so that memory pools won't
* cause a given function to have different number of
* allocations on different invocations. i.e. when testing
@@ -310,7 +310,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
else
block = dbus_malloc (alloc_size);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
_dbus_set_fail_alloc_counter (saved_counter);
_dbus_assert (saved_counter == _dbus_get_fail_alloc_counter ());
#endif
@@ -329,7 +329,7 @@ _dbus_mem_pool_alloc (DBusMemPool *pool)
pool->allocated_elements += 1;
- VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size)
+ VALGRIND_MEMPOOL_ALLOC (pool, element, pool->element_size);
return element;
}
}
@@ -347,9 +347,9 @@ dbus_bool_t
_dbus_mem_pool_dealloc (DBusMemPool *pool,
void *element)
{
- VALGRIND_MEMPOOL_FREE (pool, element)
+ VALGRIND_MEMPOOL_FREE (pool, element);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (_dbus_disable_mem_pools ())
{
DBusMemBlock *block;
@@ -393,7 +393,7 @@ _dbus_mem_pool_dealloc (DBusMemPool *pool,
freed = element;
/* used for internal mempool administration */
- VALGRIND_MAKE_MEM_UNDEFINED (freed, sizeof (freed));
+ VALGRIND_MAKE_MEM_UNDEFINED (freed, sizeof (*freed));
freed->next = pool->free_elements;
pool->free_elements = freed;
@@ -449,7 +449,7 @@ _dbus_mem_pool_get_stats (DBusMemPool *pool,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
#include <time.h>
@@ -459,8 +459,10 @@ time_for_size (int size)
{
int i;
int j;
+#ifdef DBUS_ENABLE_VERBOSE_MODE
clock_t start;
clock_t end;
+#endif
#define FREE_ARRAY_SIZE 512
#define N_ITERATIONS FREE_ARRAY_SIZE * 512
void *to_free[FREE_ARRAY_SIZE];
@@ -470,8 +472,10 @@ time_for_size (int size)
_dbus_verbose (" malloc\n");
+#ifdef DBUS_ENABLE_VERBOSE_MODE
start = clock ();
-
+#endif
+
i = 0;
j = 0;
while (i < N_ITERATIONS)
@@ -496,6 +500,7 @@ time_for_size (int size)
++i;
}
+#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -506,6 +511,7 @@ time_for_size (int size)
_dbus_verbose (" mempools\n");
start = clock ();
+#endif
pool = _dbus_mem_pool_new (size, FALSE);
@@ -535,6 +541,7 @@ time_for_size (int size)
_dbus_mem_pool_free (pool);
+#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -543,6 +550,7 @@ time_for_size (int size)
_dbus_verbose (" zeroed malloc\n");
start = clock ();
+#endif
i = 0;
j = 0;
@@ -568,6 +576,7 @@ time_for_size (int size)
++i;
}
+#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -576,6 +585,7 @@ time_for_size (int size)
_dbus_verbose (" zeroed mempools\n");
start = clock ();
+#endif
pool = _dbus_mem_pool_new (size, TRUE);
@@ -605,10 +615,12 @@ time_for_size (int size)
_dbus_mem_pool_free (pool);
+#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
N_ITERATIONS, (end - start) / (double) CLOCKS_PER_SEC);
+#endif
}
/**
@@ -632,4 +644,4 @@ _dbus_mem_pool_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-message-factory.c b/dbus/dbus-message-factory.c
index efa4e029..b742e4c1 100644
--- a/dbus/dbus-message-factory.c
+++ b/dbus/dbus-message-factory.c
@@ -24,7 +24,7 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-message-factory.h"
#include "dbus-message-private.h"
#include "dbus-signature.h"
@@ -1302,4 +1302,4 @@ _dbus_message_data_iter_get_and_next (DBusMessageDataIter *iter,
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-message-factory.h b/dbus/dbus-message-factory.h
index b0747504..fd7a4764 100644
--- a/dbus/dbus-message-factory.h
+++ b/dbus/dbus-message-factory.h
@@ -24,7 +24,7 @@
#ifndef DBUS_MESSAGE_FACTORY_H
#define DBUS_MESSAGE_FACTORY_H
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <dbus/dbus-string.h>
#include <dbus/dbus-marshal-basic.h>
@@ -56,6 +56,6 @@ dbus_bool_t _dbus_message_data_iter_get_and_next (DBusMessageDataIter *iter,
DBUS_END_DECLS
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
#endif /* DBUS_MESSAGE_FACTORY_H */
diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h
index c1948732..5d6594e3 100644
--- a/dbus/dbus-message-internal.h
+++ b/dbus/dbus-message-internal.h
@@ -70,8 +70,7 @@ void _dbus_message_loader_unref (DBusMessageLoader
void _dbus_message_loader_get_buffer (DBusMessageLoader *loader,
DBusString **buffer);
void _dbus_message_loader_return_buffer (DBusMessageLoader *loader,
- DBusString *buffer,
- int bytes_read);
+ DBusString *buffer);
dbus_bool_t _dbus_message_loader_get_unix_fds (DBusMessageLoader *loader,
int **fds,
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c
index f7859520..f615af83 100644
--- a/dbus/dbus-message-util.c
+++ b/dbus/dbus-message-util.c
@@ -45,7 +45,7 @@
* @{
*/
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Reads arguments from a message iterator given a variable argument
* list. Only arguments of basic type and arrays of fixed-length
@@ -76,11 +76,11 @@ dbus_message_iter_get_args (DBusMessageIter *iter,
return retval;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include "dbus-message-factory.h"
#include <stdio.h>
@@ -493,7 +493,7 @@ dbus_internal_do_not_use_try_message_data (const DBusString *data,
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_byte (buffer,
_dbus_string_get_byte (data, i));
- _dbus_message_loader_return_buffer (loader, buffer, 1);
+ _dbus_message_loader_return_buffer (loader, buffer);
}
if (!check_loader_results (loader, expected_validity))
@@ -512,7 +512,7 @@ dbus_internal_do_not_use_try_message_data (const DBusString *data,
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_copy (data, 0, buffer,
_dbus_string_get_length (buffer));
- _dbus_message_loader_return_buffer (loader, buffer, 1);
+ _dbus_message_loader_return_buffer (loader, buffer);
}
if (!check_loader_results (loader, expected_validity))
@@ -536,7 +536,7 @@ dbus_internal_do_not_use_try_message_data (const DBusString *data,
if ((i+1) < len)
_dbus_string_append_byte (buffer,
_dbus_string_get_byte (data, i+1));
- _dbus_message_loader_return_buffer (loader, buffer, 1);
+ _dbus_message_loader_return_buffer (loader, buffer);
}
if (!check_loader_results (loader, expected_validity))
@@ -754,10 +754,8 @@ message_iter_test (DBusMessage *message)
dbus_uint16_t v_UINT16;
dbus_int32_t v_INT32;
dbus_uint32_t v_UINT32;
-#ifdef DBUS_HAVE_INT64
dbus_int64_t v_INT64;
dbus_uint64_t v_UINT64;
-#endif
unsigned char v_BYTE;
dbus_bool_t v_BOOLEAN;
@@ -830,14 +828,12 @@ verify_test_message (DBusMessage *message)
int our_uint32_array_len;
dbus_int32_t *our_int32_array = (void*)0xdeadbeef;
int our_int32_array_len;
-#ifdef DBUS_HAVE_INT64
dbus_int64_t our_int64;
dbus_uint64_t our_uint64;
dbus_int64_t *our_uint64_array = (void*)0xdeadbeef;
int our_uint64_array_len;
const dbus_int64_t *our_int64_array = (void*)0xdeadbeef;
int our_int64_array_len;
-#endif
const double *our_double_array = (void*)0xdeadbeef;
int our_double_array_len;
const unsigned char *our_byte_array = (void*)0xdeadbeef;
@@ -854,10 +850,8 @@ verify_test_message (DBusMessage *message)
DBUS_TYPE_UINT16, &our_uint16,
DBUS_TYPE_INT32, &our_int,
DBUS_TYPE_UINT32, &our_uint,
-#ifdef DBUS_HAVE_INT64
DBUS_TYPE_INT64, &our_int64,
DBUS_TYPE_UINT64, &our_uint64,
-#endif
DBUS_TYPE_STRING, &our_str,
DBUS_TYPE_DOUBLE, &our_double,
DBUS_TYPE_BOOLEAN, &our_bool,
@@ -867,12 +861,10 @@ verify_test_message (DBusMessage *message)
&our_uint32_array, &our_uint32_array_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_INT32,
&our_int32_array, &our_int32_array_len,
-#ifdef DBUS_HAVE_INT64
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64,
&our_uint64_array, &our_uint64_array_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_INT64,
&our_int64_array, &our_int64_array_len,
-#endif
DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE,
&our_double_array, &our_double_array_len,
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
@@ -900,12 +892,10 @@ verify_test_message (DBusMessage *message)
if (our_uint != 0x12300042)
_dbus_assert_not_reached ("uints differ!");
-#ifdef DBUS_HAVE_INT64
if (our_int64 != DBUS_INT64_CONSTANT (-0x123456789abcd))
_dbus_assert_not_reached ("64-bit integers differ!");
if (our_uint64 != DBUS_UINT64_CONSTANT (0x123456789abcd))
_dbus_assert_not_reached ("64-bit unsigned integers differ!");
-#endif
v_DOUBLE = 3.14159;
if (! _DBUS_DOUBLES_BITWISE_EQUAL (our_double, v_DOUBLE))
@@ -937,7 +927,6 @@ verify_test_message (DBusMessage *message)
our_int32_array[3] != -0x45678123)
_dbus_assert_not_reached ("int array differs");
-#ifdef DBUS_HAVE_INT64
if (our_uint64_array_len != 4 ||
our_uint64_array[0] != 0x12345678 ||
our_uint64_array[1] != 0x23456781 ||
@@ -951,7 +940,6 @@ verify_test_message (DBusMessage *message)
our_int64_array[2] != 0x34567812 ||
our_int64_array[3] != -0x45678123)
_dbus_assert_not_reached ("int64 array differs");
-#endif /* DBUS_HAVE_INT64 */
if (our_double_array_len != 3)
_dbus_assert_not_reached ("double array had wrong length");
@@ -1003,6 +991,161 @@ verify_test_message (DBusMessage *message)
_dbus_assert_not_reached ("Didn't reach end of arguments");
}
+static void
+verify_test_message_args_ignored (DBusMessage *message)
+{
+ DBusMessageIter iter;
+ DBusError error = DBUS_ERROR_INIT;
+ dbus_uint32_t our_uint;
+ DBusInitialFDs *initial_fds;
+
+ initial_fds = _dbus_check_fdleaks_enter ();
+
+ /* parse with empty signature: "" */
+ dbus_message_iter_init (message, &iter);
+ if (!dbus_message_iter_get_args (&iter, &error,
+ DBUS_TYPE_INVALID))
+ {
+ _dbus_warn ("error: %s - %s\n", error.name,
+ (error.message != NULL) ? error.message : "no message");
+ }
+ else
+ {
+ _dbus_assert (!dbus_error_is_set (&error));
+ _dbus_verbose ("arguments ignored.\n");
+ }
+
+ /* parse with shorter signature: "u" */
+ dbus_message_iter_init (message, &iter);
+ if (!dbus_message_iter_get_args (&iter, &error,
+ DBUS_TYPE_UINT32, &our_uint,
+ DBUS_TYPE_INVALID))
+ {
+ _dbus_warn ("error: %s - %s\n", error.name,
+ (error.message != NULL) ? error.message : "no message");
+ }
+ else
+ {
+ _dbus_assert (!dbus_error_is_set (&error));
+ _dbus_verbose ("arguments ignored.\n");
+ }
+
+ _dbus_check_fdleaks_leave (initial_fds);
+}
+
+static void
+verify_test_message_memleak (DBusMessage *message)
+{
+ DBusMessageIter iter;
+ DBusError error = DBUS_ERROR_INIT;
+ dbus_uint32_t our_uint1;
+ dbus_uint32_t our_uint2;
+ dbus_uint32_t our_uint3;
+ char **our_string_array1;
+ int our_string_array_len1;
+ char **our_string_array2;
+ int our_string_array_len2;
+ int our_unix_fd1;
+ int our_unix_fd2;
+ DBusInitialFDs *initial_fds;
+
+ initial_fds = _dbus_check_fdleaks_enter ();
+
+ /* parse with wrong signature: "uashuu" */
+ dbus_error_free (&error);
+ dbus_message_iter_init (message, &iter);
+ if (!dbus_message_iter_get_args (&iter, &error,
+ DBUS_TYPE_UINT32, &our_uint1,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array1, &our_string_array_len1,
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &our_unix_fd1,
+#endif
+ DBUS_TYPE_UINT32, &our_uint2,
+ DBUS_TYPE_UINT32, &our_uint3,
+ DBUS_TYPE_INVALID))
+ {
+ _dbus_verbose ("expected error: %s - %s\n", error.name,
+ (error.message != NULL) ? error.message : "no message");
+ /* ensure array of string and unix fd not leaked */
+ _dbus_assert (our_string_array1 == NULL);
+#ifdef HAVE_UNIX_FD_PASSING
+ _dbus_assert (our_unix_fd1 == -1);
+#endif
+ }
+ else
+ {
+ _dbus_warn ("error: parse with wrong signature: 'uashuu'.\n");
+ }
+
+ /* parse with wrong signature: "uashuashu" */
+ dbus_message_iter_init (message, &iter);
+ dbus_error_free (&error);
+ if (!dbus_message_iter_get_args (&iter, &error,
+ DBUS_TYPE_UINT32, &our_uint1,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array1, &our_string_array_len1,
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &our_unix_fd1,
+#endif
+ DBUS_TYPE_UINT32, &our_uint2,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array2, &our_string_array_len2,
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &our_unix_fd2,
+#endif
+ DBUS_TYPE_UINT32, &our_uint3,
+ DBUS_TYPE_INVALID))
+ {
+ _dbus_verbose ("expected error: %s - %s\n", error.name,
+ (error.message != NULL) ? error.message : "no message");
+ /* ensure array of string and unix fd not leaked */
+ _dbus_assert (our_string_array1 == NULL);
+ _dbus_assert (our_string_array2 == NULL);
+#ifdef HAVE_UNIX_FD_PASSING
+ _dbus_assert (our_unix_fd1 == -1);
+ _dbus_assert (our_unix_fd2 == -1);
+#endif
+ }
+ else
+ {
+ _dbus_warn ("error: parse with wrong signature: 'uashuashu'.\n");
+ }
+
+ /* parse with correct signature: "uashuash" */
+ dbus_message_iter_init (message, &iter);
+ dbus_error_free (&error);
+ if (!dbus_message_iter_get_args (&iter, &error,
+ DBUS_TYPE_UINT32, &our_uint1,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array1, &our_string_array_len1,
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &our_unix_fd1,
+#endif
+ DBUS_TYPE_UINT32, &our_uint2,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+ &our_string_array2, &our_string_array_len2,
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &our_unix_fd2,
+#endif
+ DBUS_TYPE_INVALID))
+ {
+ _dbus_warn ("error: %s - %s\n", error.name,
+ (error.message != NULL) ? error.message : "no message");
+ _dbus_assert_not_reached ("Could not get arguments");
+ }
+ else
+ {
+ dbus_free_string_array (our_string_array1);
+ dbus_free_string_array (our_string_array2);
+#ifdef HAVE_UNIX_FD_PASSING
+ _dbus_close (our_unix_fd1, &error);
+ _dbus_close (our_unix_fd2, &error);
+#endif
+ }
+ _dbus_check_fdleaks_leave (initial_fds);
+}
+
/**
* @ingroup DBusMessageInternals
* Unit test for DBusMessage.
@@ -1025,16 +1168,16 @@ _dbus_message_test (const char *test_data_dir)
{ 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array;
const dbus_int32_t *v_ARRAY_INT32 = our_int32_array;
-#ifdef DBUS_HAVE_INT64
const dbus_uint64_t our_uint64_array[] =
{ 0x12345678, 0x23456781, 0x34567812, 0x45678123 };
const dbus_int64_t our_int64_array[] =
{ 0x12345678, -0x23456781, 0x34567812, -0x45678123 };
const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array;
const dbus_int64_t *v_ARRAY_INT64 = our_int64_array;
-#endif
const char *our_string_array[] = { "Foo", "bar", "", "woo woo woo woo" };
+ const char *our_string_array1[] = { "foo", "Bar", "", "Woo woo Woo woo" };
const char **v_ARRAY_STRING = our_string_array;
+ const char **v1_ARRAY_STRING = our_string_array1;
const double our_double_array[] = { 0.1234, 9876.54321, -300.0 };
const double *v_ARRAY_DOUBLE = our_double_array;
const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 };
@@ -1049,16 +1192,16 @@ _dbus_message_test (const char *test_data_dir)
dbus_uint16_t v_UINT16;
dbus_int32_t v_INT32;
dbus_uint32_t v_UINT32;
-#ifdef DBUS_HAVE_INT64
+ dbus_uint32_t v1_UINT32;
dbus_int64_t v_INT64;
dbus_uint64_t v_UINT64;
-#endif
unsigned char v_BYTE;
unsigned char v2_BYTE;
dbus_bool_t v_BOOLEAN;
DBusMessageIter iter, array_iter, struct_iter;
#ifdef HAVE_UNIX_FD_PASSING
int v_UNIX_FD;
+ int v1_UNIX_FD;
#endif
char **decomposed;
DBusInitialFDs *initial_fds;
@@ -1201,10 +1344,8 @@ _dbus_message_test (const char *test_data_dir)
v_UINT16 = 0x123;
v_INT32 = -0x12345678;
v_UINT32 = 0x12300042;
-#ifdef DBUS_HAVE_INT64
v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd);
v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd);
-#endif
v_STRING = "Test string";
v_DOUBLE = 3.14159;
v_BOOLEAN = TRUE;
@@ -1212,6 +1353,7 @@ _dbus_message_test (const char *test_data_dir)
v2_BYTE = 24;
#ifdef HAVE_UNIX_FD_PASSING
v_UNIX_FD = 1;
+ v1_UNIX_FD = 2;
#endif
dbus_message_append_args (message,
@@ -1219,10 +1361,8 @@ _dbus_message_test (const char *test_data_dir)
DBUS_TYPE_UINT16, &v_UINT16,
DBUS_TYPE_INT32, &v_INT32,
DBUS_TYPE_UINT32, &v_UINT32,
-#ifdef DBUS_HAVE_INT64
DBUS_TYPE_INT64, &v_INT64,
DBUS_TYPE_UINT64, &v_UINT64,
-#endif
DBUS_TYPE_STRING, &v_STRING,
DBUS_TYPE_DOUBLE, &v_DOUBLE,
DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
@@ -1232,12 +1372,10 @@ _dbus_message_test (const char *test_data_dir)
_DBUS_N_ELEMENTS (our_uint32_array),
DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY_INT32,
_DBUS_N_ELEMENTS (our_int32_array),
-#ifdef DBUS_HAVE_INT64
DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &v_ARRAY_UINT64,
_DBUS_N_ELEMENTS (our_uint64_array),
DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &v_ARRAY_INT64,
_DBUS_N_ELEMENTS (our_int64_array),
-#endif
DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &v_ARRAY_DOUBLE,
_DBUS_N_ELEMENTS (our_double_array),
DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &v_ARRAY_BYTE,
@@ -1254,10 +1392,8 @@ _dbus_message_test (const char *test_data_dir)
sig[i++] = DBUS_TYPE_UINT16;
sig[i++] = DBUS_TYPE_INT32;
sig[i++] = DBUS_TYPE_UINT32;
-#ifdef DBUS_HAVE_INT64
sig[i++] = DBUS_TYPE_INT64;
sig[i++] = DBUS_TYPE_UINT64;
-#endif
sig[i++] = DBUS_TYPE_STRING;
sig[i++] = DBUS_TYPE_DOUBLE;
sig[i++] = DBUS_TYPE_BOOLEAN;
@@ -1267,12 +1403,10 @@ _dbus_message_test (const char *test_data_dir)
sig[i++] = DBUS_TYPE_UINT32;
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_INT32;
-#ifdef DBUS_HAVE_INT64
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_UINT64;
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_INT64;
-#endif
sig[i++] = DBUS_TYPE_ARRAY;
sig[i++] = DBUS_TYPE_DOUBLE;
sig[i++] = DBUS_TYPE_ARRAY;
@@ -1353,7 +1487,7 @@ _dbus_message_test (const char *test_data_dir)
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_byte (buffer, data[i]);
- _dbus_message_loader_return_buffer (loader, buffer, 1);
+ _dbus_message_loader_return_buffer (loader, buffer);
}
/* Write the body data one byte at a time */
@@ -1364,7 +1498,7 @@ _dbus_message_test (const char *test_data_dir)
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_byte (buffer, data[i]);
- _dbus_message_loader_return_buffer (loader, buffer, 1);
+ _dbus_message_loader_return_buffer (loader, buffer);
}
#ifdef HAVE_UNIX_FD_PASSING
@@ -1489,6 +1623,51 @@ _dbus_message_test (const char *test_data_dir)
dbus_message_unref (message);
+ /* Check we should not leak array of string or unix fd, fd.o#21259 */
+ message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
+ "/org/freedesktop/TestPath",
+ "Foo.TestInterface",
+ "Method");
+
+ /* signature "uashuash" */
+ dbus_message_append_args (message,
+ DBUS_TYPE_UINT32, &v_UINT32,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING,
+ _DBUS_N_ELEMENTS (our_string_array),
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &v_UNIX_FD,
+#endif
+ DBUS_TYPE_UINT32, &v1_UINT32,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v1_ARRAY_STRING,
+ _DBUS_N_ELEMENTS (our_string_array1),
+#ifdef HAVE_UNIX_FD_PASSING
+ DBUS_TYPE_UNIX_FD, &v1_UNIX_FD,
+#endif
+
+ DBUS_TYPE_INVALID);
+
+ i = 0;
+ sig[i++] = DBUS_TYPE_UINT32;
+ sig[i++] = DBUS_TYPE_ARRAY;
+ sig[i++] = DBUS_TYPE_STRING;
+#ifdef HAVE_UNIX_FD_PASSING
+ sig[i++] = DBUS_TYPE_UNIX_FD;
+#endif
+ sig[i++] = DBUS_TYPE_UINT32;
+ sig[i++] = DBUS_TYPE_ARRAY;
+ sig[i++] = DBUS_TYPE_STRING;
+#ifdef HAVE_UNIX_FD_PASSING
+ sig[i++] = DBUS_TYPE_UNIX_FD;
+#endif
+ sig[i++] = DBUS_TYPE_INVALID;
+
+ _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig));
+
+ verify_test_message_args_ignored (message);
+ verify_test_message_memleak (message);
+
+ dbus_message_unref (message);
+
/* Load all the sample messages from the message factory */
{
DBusMessageDataIter diter;
@@ -1542,4 +1721,4 @@ _dbus_message_test (const char *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index f48977ca..2c30482c 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -56,7 +56,7 @@ static void dbus_message_finalize (DBusMessage *message);
* @{
*/
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static dbus_bool_t
_dbus_enable_message_cache (void)
{
@@ -462,7 +462,7 @@ set_or_delete_string_field (DBusMessage *message,
/** Avoid caching too many messages */
#define MAX_MESSAGE_CACHE_SIZE 5
-_DBUS_DEFINE_GLOBAL_LOCK (message_cache);
+/* Protected by _DBUS_LOCK (message_cache) */
static DBusMessage *message_cache[MAX_MESSAGE_CACHE_SIZE];
static int message_cache_count = 0;
static dbus_bool_t message_cache_shutdown_registered = FALSE;
@@ -472,7 +472,9 @@ dbus_message_cache_shutdown (void *data)
{
int i;
- _DBUS_LOCK (message_cache);
+ if (!_DBUS_LOCK (message_cache))
+ _dbus_assert_not_reached ("we would have initialized global locks "
+ "before registering a shutdown function");
i = 0;
while (i < MAX_MESSAGE_CACHE_SIZE)
@@ -504,7 +506,12 @@ dbus_message_get_cached (void)
message = NULL;
- _DBUS_LOCK (message_cache);
+ if (!_DBUS_LOCK (message_cache))
+ {
+ /* we'd have initialized global locks before caching anything,
+ * so there can't be anything in the cache */
+ return NULL;
+ }
_dbus_assert (message_cache_count >= 0);
@@ -616,7 +623,13 @@ dbus_message_cache_or_finalize (DBusMessage *message)
was_cached = FALSE;
- _DBUS_LOCK (message_cache);
+ if (!_DBUS_LOCK (message_cache))
+ {
+ /* The only way to get a non-null message goes through
+ * dbus_message_get_cached() which takes the lock. */
+ _dbus_assert_not_reached ("we would have initialized global locks "
+ "the first time we constructed a message");
+ }
if (!message_cache_shutdown_registered)
{
@@ -672,7 +685,7 @@ dbus_message_cache_or_finalize (DBusMessage *message)
dbus_message_finalize (message);
}
-#ifndef DBUS_DISABLE_CHECKS
+#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
static dbus_bool_t
_dbus_message_iter_check (DBusMessageRealIter *iter)
{
@@ -720,15 +733,13 @@ _dbus_message_iter_check (DBusMessageRealIter *iter)
return TRUE;
}
-#endif /* DBUS_DISABLE_CHECKS */
+#endif /* DBUS_ENABLE_CHECKS || DBUS_ENABLE_ASSERT */
/**
* Implementation of the varargs arg-getting functions.
* dbus_message_get_args() is the place to go for complete
* documentation.
*
- * @todo This may leak memory and file descriptors if parsing fails. See #21259
- *
* @see dbus_message_get_args
* @param iter the message iter
* @param error error to be filled in
@@ -743,8 +754,9 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
va_list var_args)
{
DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
- int spec_type, msg_type, i;
+ int spec_type, msg_type, i, j;
dbus_bool_t retval;
+ va_list copy_args;
_dbus_assert (_dbus_message_iter_check (real));
@@ -753,12 +765,17 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
spec_type = first_arg_type;
i = 0;
+ /* copy var_args first, then we can do another iteration over it to
+ * free memory and close unix fds if parse failed at some point.
+ */
+ DBUS_VA_COPY (copy_args, var_args);
+
while (spec_type != DBUS_TYPE_INVALID)
{
msg_type = dbus_message_iter_get_arg_type (iter);
if (msg_type != spec_type)
- {
+ {
dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
"Argument %d is specified to be of type \"%s\", but "
"is actually of type \"%s\"\n", i,
@@ -766,7 +783,7 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
_dbus_type_to_string (msg_type));
goto out;
- }
+ }
if (spec_type == DBUS_TYPE_UNIX_FD)
{
@@ -879,30 +896,30 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
/* Now go through and dup each string */
_dbus_type_reader_recurse (&real->u.reader, &array);
- i = 0;
- while (i < n_elements)
+ j = 0;
+ while (j < n_elements)
{
const char *s;
_dbus_type_reader_read_basic (&array,
(void *) &s);
- str_array[i] = _dbus_strdup (s);
- if (str_array[i] == NULL)
+ str_array[j] = _dbus_strdup (s);
+ if (str_array[j] == NULL)
{
dbus_free_string_array (str_array);
_DBUS_SET_OOM (error);
goto out;
}
- ++i;
+ ++j;
if (!_dbus_type_reader_next (&array))
- _dbus_assert (i == n_elements);
+ _dbus_assert (j == n_elements);
}
_dbus_assert (_dbus_type_reader_get_current_type (&array) == DBUS_TYPE_INVALID);
- _dbus_assert (i == n_elements);
- _dbus_assert (str_array[i] == NULL);
+ _dbus_assert (j == n_elements);
+ _dbus_assert (str_array[j] == NULL);
*str_array_p = str_array;
*n_elements_p = n_elements;
@@ -925,6 +942,9 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
}
#endif
+ /* how many arguments already handled */
+ i++;
+
spec_type = va_arg (var_args, int);
if (!_dbus_type_reader_next (&real->u.reader) && spec_type != DBUS_TYPE_INVALID)
{
@@ -932,14 +952,71 @@ _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
"Message has only %d arguments, but more were expected", i);
goto out;
}
-
- i++;
}
retval = TRUE;
out:
+ /* there may memory or unix fd leak in the above iteration if parse failed.
+ * so we have another iteration over copy_args to free memory and close
+ * unix fds.
+ */
+ if (!retval)
+ {
+ spec_type = first_arg_type;
+ j = 0;
+ while (j < i)
+ {
+ if (spec_type == DBUS_TYPE_UNIX_FD)
+ {
+#ifdef HAVE_UNIX_FD_PASSING
+ int *pfd;
+
+ pfd = va_arg (copy_args, int *);
+ _dbus_assert(pfd);
+ if (*pfd >= 0)
+ {
+ _dbus_close (*pfd, NULL);
+ *pfd = -1;
+ }
+#endif
+ }
+ else if (dbus_type_is_basic (spec_type))
+ {
+ /* move the index forward */
+ va_arg (copy_args, DBusBasicValue *);
+ }
+ else if (spec_type == DBUS_TYPE_ARRAY)
+ {
+ int spec_element_type;
+
+ spec_element_type = va_arg (copy_args, int);
+ if (dbus_type_is_fixed (spec_element_type))
+ {
+ /* move the index forward */
+ va_arg (copy_args, const DBusBasicValue **);
+ va_arg (copy_args, int *);
+ }
+ else if (_DBUS_TYPE_IS_STRINGLIKE (spec_element_type))
+ {
+ char ***str_array_p;
+
+ str_array_p = va_arg (copy_args, char ***);
+ /* move the index forward */
+ va_arg (copy_args, int *);
+ _dbus_assert (str_array_p != NULL);
+ dbus_free_string_array (*str_array_p);
+ *str_array_p = NULL;
+ }
+ }
+
+ spec_type = va_arg (copy_args, int);
+ j++;
+ }
+ }
+
+ va_end (copy_args);
return retval;
}
@@ -1202,7 +1279,7 @@ dbus_message_new (int message_type)
*
* @param destination name that the message should be sent to or #NULL
* @param path object path the message should be sent to
- * @param interface interface to invoke method on, or #NULL
+ * @param iface interface to invoke method on, or #NULL
* @param method method to invoke
*
* @returns a new DBusMessage, free with dbus_message_unref()
@@ -1210,7 +1287,7 @@ dbus_message_new (int message_type)
DBusMessage*
dbus_message_new_method_call (const char *destination,
const char *path,
- const char *interface,
+ const char *iface,
const char *method)
{
DBusMessage *message;
@@ -1220,8 +1297,8 @@ dbus_message_new_method_call (const char *destination,
_dbus_return_val_if_fail (destination == NULL ||
_dbus_check_is_valid_bus_name (destination), NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_path (path), NULL);
- _dbus_return_val_if_fail (interface == NULL ||
- _dbus_check_is_valid_interface (interface), NULL);
+ _dbus_return_val_if_fail (iface == NULL ||
+ _dbus_check_is_valid_interface (iface), NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_member (method), NULL);
message = dbus_message_new_empty_header ();
@@ -1231,7 +1308,7 @@ dbus_message_new_method_call (const char *destination,
if (!_dbus_header_create (&message->header,
DBUS_COMPILER_BYTE_ORDER,
DBUS_MESSAGE_TYPE_METHOD_CALL,
- destination, path, interface, method, NULL))
+ destination, path, iface, method, NULL))
{
dbus_message_unref (message);
return NULL;
@@ -1294,22 +1371,22 @@ dbus_message_new_method_return (DBusMessage *method_call)
* specification defines the syntax of these fields).
*
* @param path the path to the object emitting the signal
- * @param interface the interface the signal is emitted from
+ * @param iface the interface the signal is emitted from
* @param name name of the signal
* @returns a new DBusMessage, free with dbus_message_unref()
*/
DBusMessage*
dbus_message_new_signal (const char *path,
- const char *interface,
+ const char *iface,
const char *name)
{
DBusMessage *message;
_dbus_return_val_if_fail (path != NULL, NULL);
- _dbus_return_val_if_fail (interface != NULL, NULL);
+ _dbus_return_val_if_fail (iface != NULL, NULL);
_dbus_return_val_if_fail (name != NULL, NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_path (path), NULL);
- _dbus_return_val_if_fail (_dbus_check_is_valid_interface (interface), NULL);
+ _dbus_return_val_if_fail (_dbus_check_is_valid_interface (iface), NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_member (name), NULL);
message = dbus_message_new_empty_header ();
@@ -1319,7 +1396,7 @@ dbus_message_new_signal (const char *path,
if (!_dbus_header_create (&message->header,
DBUS_COMPILER_BYTE_ORDER,
DBUS_MESSAGE_TYPE_SIGNAL,
- NULL, path, interface, name, NULL))
+ NULL, path, iface, name, NULL))
{
dbus_message_unref (message);
return NULL;
@@ -3069,23 +3146,23 @@ dbus_message_get_path_decomposed (DBusMessage *message,
* in the D-Bus specification.
*
* @param message the message
- * @param interface the interface or #NULL to unset
+ * @param iface the interface or #NULL to unset
* @returns #FALSE if not enough memory
*/
dbus_bool_t
dbus_message_set_interface (DBusMessage *message,
- const char *interface)
+ const char *iface)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (!message->locked, FALSE);
- _dbus_return_val_if_fail (interface == NULL ||
- _dbus_check_is_valid_interface (interface),
+ _dbus_return_val_if_fail (iface == NULL ||
+ _dbus_check_is_valid_interface (iface),
FALSE);
return set_or_delete_string_field (message,
DBUS_HEADER_FIELD_INTERFACE,
DBUS_TYPE_STRING,
- interface);
+ iface);
}
/**
@@ -3120,28 +3197,28 @@ dbus_message_get_interface (DBusMessage *message)
* Checks if the message has an interface
*
* @param message the message
- * @param interface the interface name
+ * @param iface the interface name
* @returns #TRUE if the interface field in the header matches
*/
dbus_bool_t
dbus_message_has_interface (DBusMessage *message,
- const char *interface)
+ const char *iface)
{
const char *msg_interface;
msg_interface = dbus_message_get_interface (message);
if (msg_interface == NULL)
{
- if (interface == NULL)
+ if (iface == NULL)
return TRUE;
else
return FALSE;
}
- if (interface == NULL)
+ if (iface == NULL)
return FALSE;
- if (strcmp (msg_interface, interface) == 0)
+ if (strcmp (msg_interface, iface) == 0)
return TRUE;
return FALSE;
@@ -3474,13 +3551,13 @@ dbus_message_get_signature (DBusMessage *message)
static dbus_bool_t
_dbus_message_has_type_interface_member (DBusMessage *message,
int type,
- const char *interface,
+ const char *iface,
const char *member)
{
const char *n;
_dbus_assert (message != NULL);
- _dbus_assert (interface != NULL);
+ _dbus_assert (iface != NULL);
_dbus_assert (member != NULL);
if (dbus_message_get_type (message) != type)
@@ -3496,7 +3573,7 @@ _dbus_message_has_type_interface_member (DBusMessage *message,
{
n = dbus_message_get_interface (message);
- if (n == NULL || strcmp (n, interface) == 0)
+ if (n == NULL || strcmp (n, iface) == 0)
return TRUE;
}
@@ -3512,18 +3589,18 @@ _dbus_message_has_type_interface_member (DBusMessage *message,
* protocol allows method callers to leave out the interface name.
*
* @param message the message
- * @param interface the name to check (must not be #NULL)
+ * @param iface the name to check (must not be #NULL)
* @param method the name to check (must not be #NULL)
*
* @returns #TRUE if the message is the specified method call
*/
dbus_bool_t
dbus_message_is_method_call (DBusMessage *message,
- const char *interface,
+ const char *iface,
const char *method)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
- _dbus_return_val_if_fail (interface != NULL, FALSE);
+ _dbus_return_val_if_fail (iface != NULL, FALSE);
_dbus_return_val_if_fail (method != NULL, FALSE);
/* don't check that interface/method are valid since it would be
* expensive, and not catch many common errors
@@ -3531,7 +3608,7 @@ dbus_message_is_method_call (DBusMessage *message,
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_METHOD_CALL,
- interface, method);
+ iface, method);
}
/**
@@ -3540,18 +3617,18 @@ dbus_message_is_method_call (DBusMessage *message,
* has a different interface or member field, returns #FALSE.
*
* @param message the message
- * @param interface the name to check (must not be #NULL)
+ * @param iface the name to check (must not be #NULL)
* @param signal_name the name to check (must not be #NULL)
*
* @returns #TRUE if the message is the specified signal
*/
dbus_bool_t
dbus_message_is_signal (DBusMessage *message,
- const char *interface,
+ const char *iface,
const char *signal_name)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
- _dbus_return_val_if_fail (interface != NULL, FALSE);
+ _dbus_return_val_if_fail (iface != NULL, FALSE);
_dbus_return_val_if_fail (signal_name != NULL, FALSE);
/* don't check that interface/name are valid since it would be
* expensive, and not catch many common errors
@@ -3559,7 +3636,7 @@ dbus_message_is_signal (DBusMessage *message,
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_SIGNAL,
- interface, signal_name);
+ iface, signal_name);
}
/**
@@ -3799,7 +3876,7 @@ _dbus_message_loader_new (void)
SCM_RIGHTS works we need to preallocate an fd array of the maximum
number of unix fds we want to receive in advance. A
try-and-reallocate loop is not possible. */
- loader->max_message_unix_fds = 1024;
+ loader->max_message_unix_fds = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
if (!_dbus_string_init (&loader->data))
{
@@ -3896,12 +3973,10 @@ _dbus_message_loader_get_buffer (DBusMessageLoader *loader,
*
* @param loader the loader.
* @param buffer the buffer.
- * @param bytes_read number of bytes that were read into the buffer.
*/
void
_dbus_message_loader_return_buffer (DBusMessageLoader *loader,
- DBusString *buffer,
- int bytes_read)
+ DBusString *buffer)
{
_dbus_assert (loader->buffer_outstanding);
_dbus_assert (buffer == &loader->data);
@@ -3965,7 +4040,7 @@ _dbus_message_loader_get_unix_fds(DBusMessageLoader *loader,
*
* @param loader the message loader.
* @param fds the array fds were read into
- * @param max_n_fds how many fds were read
+ * @param n_fds how many fds were read
*/
void
@@ -4393,7 +4468,7 @@ _dbus_message_loader_get_max_message_size (DBusMessageLoader *loader)
* Sets the maximum unix fds per message we allow.
*
* @param loader the loader
- * @param size the max number of unix fds in a message
+ * @param n the max number of unix fds in a message
*/
void
_dbus_message_loader_set_max_message_unix_fds (DBusMessageLoader *loader,
@@ -4420,8 +4495,8 @@ _dbus_message_loader_get_max_message_unix_fds (DBusMessageLoader *loader)
return loader->max_message_unix_fds;
}
-static DBusDataSlotAllocator slot_allocator;
-_DBUS_DEFINE_GLOBAL_LOCK (message_slots);
+static DBusDataSlotAllocator slot_allocator =
+ _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (message_slots));
/**
* Allocates an integer ID to be used for storing application-specific
@@ -4441,7 +4516,6 @@ dbus_bool_t
dbus_message_allocate_data_slot (dbus_int32_t *slot_p)
{
return _dbus_data_slot_allocator_alloc (&slot_allocator,
- &_DBUS_LOCK_NAME (message_slots),
slot_p);
}
@@ -4737,7 +4811,7 @@ dbus_message_demarshal (const char *str,
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_len (buffer, str, len);
- _dbus_message_loader_return_buffer (loader, buffer, len);
+ _dbus_message_loader_return_buffer (loader, buffer);
if (!_dbus_message_loader_queue_messages (loader))
goto fail_oom;
@@ -4772,9 +4846,8 @@ dbus_message_demarshal (const char *str,
* Generally, this function is only useful for encapsulating D-Bus messages in
* a different protocol.
*
- * @param str data to be marshalled
- * @param len the length of str
- * @param error the location to save errors to
+ * @param buf data to be marshalled
+ * @param len the length of @p buf
* @returns -1 if there was no valid data to be demarshalled, 0 if there wasn't enough data to determine how much should be demarshalled. Otherwise returns the number of bytes to be demarshalled
*
*/
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index 55388ac1..01b7344e 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -71,13 +71,13 @@ DBusMessage* dbus_message_new (int message_type);
DBUS_EXPORT
DBusMessage* dbus_message_new_method_call (const char *bus_name,
const char *path,
- const char *interface,
+ const char *iface,
const char *method);
DBUS_EXPORT
DBusMessage* dbus_message_new_method_return (DBusMessage *method_call);
DBUS_EXPORT
DBusMessage* dbus_message_new_signal (const char *path,
- const char *interface,
+ const char *iface,
const char *name);
DBUS_EXPORT
DBusMessage* dbus_message_new_error (DBusMessage *reply_to,
@@ -108,12 +108,12 @@ dbus_bool_t dbus_message_has_path (DBusMessage *message,
const char *object_path);
DBUS_EXPORT
dbus_bool_t dbus_message_set_interface (DBusMessage *message,
- const char *interface);
+ const char *iface);
DBUS_EXPORT
const char* dbus_message_get_interface (DBusMessage *message);
DBUS_EXPORT
dbus_bool_t dbus_message_has_interface (DBusMessage *message,
- const char *interface);
+ const char *iface);
DBUS_EXPORT
dbus_bool_t dbus_message_set_member (DBusMessage *message,
const char *member);
@@ -149,11 +149,11 @@ DBUS_EXPORT
dbus_bool_t dbus_message_get_no_reply (DBusMessage *message);
DBUS_EXPORT
dbus_bool_t dbus_message_is_method_call (DBusMessage *message,
- const char *interface,
+ const char *iface,
const char *method);
DBUS_EXPORT
dbus_bool_t dbus_message_is_signal (DBusMessage *message,
- const char *interface,
+ const char *iface,
const char *signal_name);
DBUS_EXPORT
dbus_bool_t dbus_message_is_error (DBusMessage *message,
diff --git a/dbus/dbus-misc.c b/dbus/dbus-misc.c
index b1610133..6ca30f24 100644
--- a/dbus/dbus-misc.c
+++ b/dbus/dbus-misc.c
@@ -173,7 +173,7 @@ dbus_get_version (int *major_version_p,
/** @} */ /* End of public API */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
diff --git a/dbus/dbus-misc.h b/dbus/dbus-misc.h
index 3504bcaa..6e72d9ed 100644
--- a/dbus/dbus-misc.h
+++ b/dbus/dbus-misc.h
@@ -44,6 +44,10 @@ void dbus_get_version (int *major_version_p,
int *minor_version_p,
int *micro_version_p);
+DBUS_EXPORT
+dbus_bool_t dbus_setenv (const char *variable,
+ const char *value);
+
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-nonce.c b/dbus/dbus-nonce.c
index e74c2dd5..37f30f00 100644
--- a/dbus/dbus-nonce.c
+++ b/dbus/dbus-nonce.c
@@ -113,7 +113,15 @@ _dbus_read_nonce (const DBusString *fname, DBusString *nonce, DBusError* error)
fp = fopen (_dbus_string_get_const_data (fname), "rb");
if (!fp)
- return FALSE;
+ {
+ dbus_set_error (error,
+ _dbus_error_from_system_errno (),
+ "Failed to open %s for read: %s",
+ _dbus_string_get_const_data (fname),
+ _dbus_strerror_from_errno ());
+ return FALSE;
+ }
+
nread = fread (buffer, 1, sizeof buffer - 1, fp);
fclose (fp);
if (!nread)
@@ -240,6 +248,7 @@ do_noncefile_create (DBusNonceFile *noncefile,
dbus_bool_t use_subdir)
{
DBusString randomStr;
+ const char *tmp;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -257,8 +266,11 @@ do_noncefile_create (DBusNonceFile *noncefile,
goto on_error;
}
+ tmp = _dbus_get_tmpdir ();
+
if (!_dbus_string_init (&noncefile->dir)
- || !_dbus_string_append (&noncefile->dir, _dbus_get_tmpdir()))
+ || tmp == NULL
+ || !_dbus_string_append (&noncefile->dir, tmp))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto on_error;
diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c
index 172c9d95..d256018e 100644
--- a/dbus/dbus-object-tree.c
+++ b/dbus/dbus-object-tree.c
@@ -434,6 +434,185 @@ _dbus_object_tree_register (DBusObjectTree *tree,
}
/**
+ * Attempts to unregister the given subtree. If the subtree is registered,
+ * stores its unregister function and user data for later use and returns
+ * #TRUE. If subtree is not registered, simply returns #FALSE. Does not free
+ * subtree or remove it from the object tree.
+ *
+ * @param subtree the subtree to unregister
+ * @param unregister_function_out stores subtree's unregister_function
+ * @param user_data_out stores subtree's user_data
+ * @return #FALSE if the subtree was not registered, #TRUE on success
+ */
+static dbus_bool_t
+unregister_subtree (DBusObjectSubtree *subtree,
+ DBusObjectPathUnregisterFunction *unregister_function_out,
+ void **user_data_out)
+{
+ _dbus_assert (subtree != NULL);
+ _dbus_assert (unregister_function_out != NULL);
+ _dbus_assert (user_data_out != NULL);
+
+ /* Confirm subtree is registered */
+ if (subtree->message_function != NULL)
+ {
+ subtree->message_function = NULL;
+
+ *unregister_function_out = subtree->unregister_function;
+ *user_data_out = subtree->user_data;
+
+ subtree->unregister_function = NULL;
+ subtree->user_data = NULL;
+
+ return TRUE;
+ }
+ else
+ {
+ /* Assert that this unregistered subtree is either the root node or has
+ children, otherwise we have a dangling path which should never
+ happen */
+ _dbus_assert (subtree->parent == NULL || subtree->n_subtrees > 0);
+
+ /* The subtree is not registered */
+ return FALSE;
+ }
+}
+
+/**
+ * Attempts to remove a child subtree from its parent. If removal is
+ * successful, also frees the child. Returns #TRUE on success, #FALSE
+ * otherwise. A #FALSE return value tells unregister_and_free_path_recurse to
+ * stop attempting to remove ancestors, i.e., that no ancestors of the
+ * specified child are eligible for removal.
+ *
+ * @param parent parent from which to remove child
+ * @param child_index parent->subtrees index of child to remove
+ * @return #TRUE if removal and free succeed, #FALSE otherwise
+ */
+static dbus_bool_t
+attempt_child_removal (DBusObjectSubtree *parent,
+ int child_index)
+{
+ /* Candidate for removal */
+ DBusObjectSubtree* candidate;
+
+ _dbus_assert (parent != NULL);
+ _dbus_assert (child_index >= 0 && child_index < parent->n_subtrees);
+
+ candidate = parent->subtrees[child_index];
+ _dbus_assert (candidate != NULL);
+
+ if (candidate->n_subtrees == 0 && candidate->message_function == NULL)
+ {
+ /* The candidate node is childless and is not a registered
+ path, so... */
+
+ /* ... remove it from its parent... */
+ /* Assumes a 0-byte memmove is OK */
+ memmove (&parent->subtrees[child_index],
+ &parent->subtrees[child_index + 1],
+ (parent->n_subtrees - child_index - 1)
+ * sizeof (parent->subtrees[0]));
+ parent->n_subtrees -= 1;
+
+ /* ... and free it */
+ candidate->parent = NULL;
+ _dbus_object_subtree_unref (candidate);
+
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * Searches the object tree for a registered subtree node at the given path.
+ * If a registered node is found, it is removed from the tree and freed, and
+ * TRUE is returned. If a registered subtree node is not found at the given
+ * path, the tree is not modified and FALSE is returned.
+ *
+ * The found node's unregister_function and user_data are returned in the
+ * corresponding _out arguments. The caller should define these variables and
+ * pass their addresses as arguments.
+ *
+ * Likewise, the caller should define and set to TRUE a boolean variable, then
+ * pass its address as the continue_removal_attempts argument.
+ *
+ * Once a matching registered node is found, removed and freed, the recursive
+ * return path is traversed. Along the way, eligible ancestor nodes are
+ * removed and freed. An ancestor node is eligible for removal if and only if
+ * 1) it has no children, i.e., it has become childless and 2) it is not itself
+ * a registered handler.
+ *
+ * For example, suppose /A/B and /A/C are registered paths, and that these are
+ * the only paths in the tree. If B is removed and freed, C is still reachable
+ * through A, so A cannot be removed and freed. If C is subsequently removed
+ * and freed, then A becomes a childless node and it becomes eligible for
+ * removal, and will be removed and freed.
+ *
+ * Similarly, suppose /A is a registered path, and /A/B is also a registered
+ * path, and that these are the only paths in the tree. If B is removed and
+ * freed, then even though A has become childless, it can't be freed because it
+ * refers to a path that is still registered.
+ *
+ * @param subtree subtree from which to start the search, root for initial call
+ * @param path path to subtree (same as _dbus_object_tree_unregister_and_unlock)
+ * @param continue_removal_attempts pointer to a bool, #TRUE for initial call
+ * @param unregister_function_out returns the found node's unregister_function
+ * @param user_data_out returns the found node's user_data
+ * @returns #TRUE if a registered node was found at path, #FALSE otherwise
+ */
+static dbus_bool_t
+unregister_and_free_path_recurse
+(DBusObjectSubtree *subtree,
+ const char **path,
+ dbus_bool_t *continue_removal_attempts,
+ DBusObjectPathUnregisterFunction *unregister_function_out,
+ void **user_data_out)
+{
+ int i, j;
+
+ _dbus_assert (continue_removal_attempts != NULL);
+ _dbus_assert (*continue_removal_attempts);
+ _dbus_assert (unregister_function_out != NULL);
+ _dbus_assert (user_data_out != NULL);
+
+ if (path[0] == NULL)
+ return unregister_subtree (subtree, unregister_function_out, user_data_out);
+
+ i = 0;
+ j = subtree->n_subtrees;
+ while (i < j)
+ {
+ int k, v;
+
+ k = (i + j) / 2;
+ v = strcmp (path[0], subtree->subtrees[k]->name);
+
+ if (v == 0)
+ {
+ dbus_bool_t freed;
+ freed = unregister_and_free_path_recurse (subtree->subtrees[k],
+ &path[1],
+ continue_removal_attempts,
+ unregister_function_out,
+ user_data_out);
+ if (freed && *continue_removal_attempts)
+ *continue_removal_attempts = attempt_child_removal (subtree, k);
+ return freed;
+ }
+ else if (v < 0)
+ {
+ j = k;
+ }
+ else
+ {
+ i = k + 1;
+ }
+ }
+ return FALSE;
+}
+
+/**
* Unregisters an object subtree that was registered with the
* same path.
*
@@ -444,66 +623,42 @@ void
_dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
const char **path)
{
- int i;
- DBusObjectSubtree *subtree;
+ dbus_bool_t found_subtree;
+ dbus_bool_t continue_removal_attempts;
DBusObjectPathUnregisterFunction unregister_function;
void *user_data;
DBusConnection *connection;
+ _dbus_assert (tree != NULL);
_dbus_assert (path != NULL);
+ continue_removal_attempts = TRUE;
unregister_function = NULL;
user_data = NULL;
- subtree = find_subtree (tree, path, &i);
+ found_subtree = unregister_and_free_path_recurse (tree->root,
+ path,
+ &continue_removal_attempts,
+ &unregister_function,
+ &user_data);
#ifndef DBUS_DISABLE_CHECKS
- if (subtree == NULL)
+ if (found_subtree == FALSE)
{
_dbus_warn ("Attempted to unregister path (path[0] = %s path[1] = %s) which isn't registered\n",
path[0] ? path[0] : "null",
- path[1] ? path[1] : "null");
+ (path[0] && path[1]) ? path[1] : "null");
goto unlock;
}
#else
- _dbus_assert (subtree != NULL);
+ _dbus_assert (found_subtree == TRUE);
#endif
- _dbus_assert (subtree->parent == NULL ||
- (i >= 0 && subtree->parent->subtrees[i] == subtree));
-
- subtree->message_function = NULL;
-
- unregister_function = subtree->unregister_function;
- user_data = subtree->user_data;
-
- subtree->unregister_function = NULL;
- subtree->user_data = NULL;
-
- /* If we have no subtrees of our own, remove from
- * our parent (FIXME could also be more aggressive
- * and remove our parent if it becomes empty)
- */
- if (subtree->parent && subtree->n_subtrees == 0)
- {
- /* assumes a 0-byte memmove is OK */
- memmove (&subtree->parent->subtrees[i],
- &subtree->parent->subtrees[i+1],
- (subtree->parent->n_subtrees - i - 1) *
- sizeof (subtree->parent->subtrees[0]));
- subtree->parent->n_subtrees -= 1;
-
- subtree->parent = NULL;
-
- _dbus_object_subtree_unref (subtree);
- }
- subtree = NULL;
-
unlock:
connection = tree->connection;
/* Unlock and call application code */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (connection)
#endif
{
@@ -515,7 +670,7 @@ unlock:
if (unregister_function)
(* unregister_function) (connection, user_data);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (connection)
#endif
dbus_connection_unref (connection);
@@ -638,7 +793,7 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
DBUS_INTERFACE_INTROSPECTABLE,
"Introspect"))
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -653,7 +808,7 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
if (!_dbus_string_init (&xml))
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -698,7 +853,7 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &v_STRING))
goto out;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -711,7 +866,7 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
result = DBUS_HANDLER_RESULT_HANDLED;
out:
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -741,6 +896,7 @@ handle_default_introspect_and_unlock (DBusObjectTree *tree,
*
* @param tree the global object tree
* @param message the message to dispatch
+ * @param found_object return location for the object
* @returns whether message was handled successfully
*/
DBusHandlerResult
@@ -762,7 +918,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
path = NULL;
if (!dbus_message_get_path_decomposed (message, &path))
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -777,7 +933,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
if (path == NULL)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -846,7 +1002,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
_dbus_verbose (" (invoking a handler)\n");
#endif
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -863,7 +1019,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
message,
user_data);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
_dbus_connection_lock (tree->connection);
@@ -886,7 +1042,7 @@ _dbus_object_tree_dispatch_and_unlock (DBusObjectTree *tree,
}
else
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -1057,7 +1213,7 @@ _dbus_object_tree_list_registered_and_unlock (DBusObjectTree *tree,
parent_path,
child_entries);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (tree->connection)
#endif
{
@@ -1214,7 +1370,7 @@ flatten_path (const char **path)
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -1507,6 +1663,17 @@ run_decompose_tests (void)
return TRUE;
}
+static DBusObjectSubtree*
+find_subtree_registered_or_unregistered (DBusObjectTree *tree,
+ const char **path)
+{
+#if VERBOSE_FIND
+ _dbus_verbose ("Looking for exact subtree, registered or unregistered\n");
+#endif
+
+ return find_subtree_recurse (tree->root, path, FALSE, NULL, NULL);
+}
+
static dbus_bool_t
object_tree_test_iteration (void *data)
{
@@ -1519,6 +1686,13 @@ object_tree_test_iteration (void *data)
const char *path6[] = { "blah", "boof", NULL };
const char *path7[] = { "blah", "boof", "this", "is", "really", "long", NULL };
const char *path8[] = { "childless", NULL };
+ const char *path9[] = { "blah", "a", NULL };
+ const char *path10[] = { "blah", "b", NULL };
+ const char *path11[] = { "blah", "c", NULL };
+ const char *path12[] = { "blah", "a", "d", NULL };
+ const char *path13[] = { "blah", "b", "d", NULL };
+ const char *path14[] = { "blah", "c", "d", NULL };
+ DBusObjectPathVTable test_vtable = { NULL, test_message_function, NULL };
DBusObjectTree *tree;
TreeTestData tree_test_data[9];
int i;
@@ -1889,6 +2063,200 @@ object_tree_test_iteration (void *data)
++i;
}
+ /* Test removal of newly-childless unregistered nodes */
+ if (!do_register (tree, path2, TRUE, 2, tree_test_data))
+ goto out;
+
+ _dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ /* Test that unregistered parents cannot be freed out from under their
+ children */
+ if (!do_register (tree, path2, TRUE, 2, tree_test_data))
+ goto out;
+
+ _dbus_assert (!find_subtree (tree, path1, NULL));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+#if 0
+ /* This triggers the "Attempted to unregister path ..." warning message */
+ _dbus_object_tree_unregister_and_unlock (tree, path1);
+#endif
+ _dbus_assert (find_subtree (tree, path2, NULL));
+ _dbus_assert (!find_subtree (tree, path1, NULL));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_assert (!find_subtree (tree, path2, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ /* Test that registered parents cannot be freed out from under their
+ children, and that if they are unregistered before their children, they
+ are still freed when their children are unregistered */
+ if (!do_register (tree, path1, TRUE, 1, tree_test_data))
+ goto out;
+ if (!do_register (tree, path2, TRUE, 2, tree_test_data))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path1, NULL));
+ _dbus_assert (find_subtree (tree, path2, NULL));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path1);
+ _dbus_assert (!find_subtree (tree, path1, NULL));
+ _dbus_assert (find_subtree (tree, path2, NULL));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_assert (!find_subtree (tree, path1, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (!find_subtree (tree, path2, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ /* Test with NULL unregister_function and user_data */
+ if (!_dbus_object_tree_register (tree, TRUE, path2,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (_dbus_object_tree_get_user_data_unlocked (tree, path2) == NULL);
+ _dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_assert (!find_subtree (tree, path2, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ /* Test freeing a long path */
+ if (!do_register (tree, path3, TRUE, 3, tree_test_data))
+ goto out;
+
+ _dbus_object_tree_unregister_and_unlock (tree, path3);
+ _dbus_assert (!find_subtree (tree, path3, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path0));
+
+ /* Test freeing multiple children from the same path */
+ if (!do_register (tree, path3, TRUE, 3, tree_test_data))
+ goto out;
+ if (!do_register (tree, path4, TRUE, 4, tree_test_data))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path3, NULL));
+ _dbus_assert (find_subtree (tree, path4, NULL));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path3);
+ _dbus_assert (!find_subtree (tree, path3, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
+ _dbus_assert (find_subtree (tree, path4, NULL));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path4));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path1));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path4);
+ _dbus_assert (!find_subtree (tree, path4, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path4));
+ _dbus_assert (!find_subtree (tree, path3, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path3));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path2));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path1));
+
+ /* Test subtree removal */
+ if (!_dbus_object_tree_register (tree, TRUE, path12,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path12, NULL));
+
+ if (!_dbus_object_tree_register (tree, TRUE, path13,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path13, NULL));
+
+ if (!_dbus_object_tree_register (tree, TRUE, path14,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path14, NULL));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path12);
+
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path12));
+ _dbus_assert (find_subtree (tree, path13, NULL));
+ _dbus_assert (find_subtree (tree, path14, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path9));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
+
+ if (!_dbus_object_tree_register (tree, TRUE, path12,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path12, NULL));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path13);
+
+ _dbus_assert (find_subtree (tree, path12, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path13));
+ _dbus_assert (find_subtree (tree, path14, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path10));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
+
+ if (!_dbus_object_tree_register (tree, TRUE, path13,
+ &test_vtable,
+ NULL,
+ NULL))
+ goto out;
+
+ _dbus_assert (find_subtree (tree, path13, NULL));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path14);
+
+ _dbus_assert (find_subtree (tree, path12, NULL));
+ _dbus_assert (find_subtree (tree, path13, NULL));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path14));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path11));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path12);
+
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path12));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path9));
+ _dbus_assert (find_subtree_registered_or_unregistered (tree, path5));
+
+ _dbus_object_tree_unregister_and_unlock (tree, path13);
+
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path13));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path10));
+ _dbus_assert (!find_subtree_registered_or_unregistered (tree, path5));
+
+#if 0
+ /* Test attempting to unregister non-existent paths. These trigger
+ "Attempted to unregister path ..." warning messages */
+ _dbus_object_tree_unregister_and_unlock (tree, path0);
+ _dbus_object_tree_unregister_and_unlock (tree, path1);
+ _dbus_object_tree_unregister_and_unlock (tree, path2);
+ _dbus_object_tree_unregister_and_unlock (tree, path3);
+ _dbus_object_tree_unregister_and_unlock (tree, path4);
+#endif
+
/* Register it all again, and test dispatch */
if (!do_register (tree, path0, TRUE, 0, tree_test_data))
@@ -1962,4 +2330,4 @@ _dbus_object_tree_test (void)
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c
index 8a9d2f49..be534105 100644
--- a/dbus/dbus-pending-call.c
+++ b/dbus/dbus-pending-call.c
@@ -79,26 +79,19 @@ struct DBusPendingCall
unsigned int timeout_added : 1; /**< Have added the timeout */
};
-#ifdef DBUS_ENABLE_VERBOSE_MODE
static void
_dbus_pending_call_trace_ref (DBusPendingCall *pending_call,
int old_refcount,
int new_refcount,
const char *why)
{
+#ifdef DBUS_ENABLE_VERBOSE_MODE
static int enabled = -1;
_dbus_trace_ref ("DBusPendingCall", pending_call, old_refcount,
new_refcount, why, "DBUS_PENDING_CALL_TRACE", &enabled);
-}
-#else
-#define _dbus_pending_call_trace_ref(p, o, n, w) \
- do \
- {\
- (void) (o); \
- (void) (n); \
- } while (0)
#endif
+}
static dbus_int32_t notify_user_data_slot = -1;
@@ -489,8 +482,8 @@ _dbus_pending_call_get_completed_unlocked (DBusPendingCall *pending)
return pending->completed;
}
-static DBusDataSlotAllocator slot_allocator;
-_DBUS_DEFINE_GLOBAL_LOCK (pending_call_slots);
+static DBusDataSlotAllocator slot_allocator =
+ _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (pending_call_slots));
/**
* Stores a pointer on a #DBusPendingCall, along
@@ -631,6 +624,8 @@ dbus_pending_call_set_notify (DBusPendingCall *pending,
void *user_data,
DBusFreeFunction free_user_data)
{
+ dbus_bool_t ret = FALSE;
+
_dbus_return_val_if_fail (pending != NULL, FALSE);
CONNECTION_LOCK (pending->connection);
@@ -638,13 +633,15 @@ dbus_pending_call_set_notify (DBusPendingCall *pending,
/* could invoke application code! */
if (!_dbus_pending_call_set_data_unlocked (pending, notify_user_data_slot,
user_data, free_user_data))
- return FALSE;
+ goto out;
pending->function = function;
+ ret = TRUE;
+out:
CONNECTION_UNLOCK (pending->connection);
- return TRUE;
+ return ret;
}
/**
@@ -764,7 +761,6 @@ dbus_pending_call_allocate_data_slot (dbus_int32_t *slot_p)
_dbus_return_val_if_fail (slot_p != NULL, FALSE);
return _dbus_data_slot_allocator_alloc (&slot_allocator,
- &_DBUS_LOCK_NAME (pending_call_slots),
slot_p);
}
diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c
index 419db5c5..8f5ff5fb 100644
--- a/dbus/dbus-server-debug-pipe.c
+++ b/dbus/dbus-server-debug-pipe.c
@@ -31,7 +31,7 @@
#include "dbus-string.h"
#include "dbus-protocol.h"
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* @defgroup DBusServerDebugPipe DBusServerDebugPipe
@@ -427,5 +427,5 @@ _dbus_transport_open_debug_pipe (DBusAddressEntry *entry,
/** @} */
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-server-launchd.c b/dbus/dbus-server-launchd.c
index db4673c5..9832875e 100644
--- a/dbus/dbus-server-launchd.c
+++ b/dbus/dbus-server-launchd.c
@@ -40,6 +40,7 @@
#include <launch.h>
#include <errno.h>
+#include "dbus-misc.h"
#include "dbus-server-socket.h"
/* put other private launchd functions here */
@@ -176,7 +177,7 @@ _dbus_server_new_for_launchd (const char *launchd_env_var, DBusError * error)
else
{
display = launch_data_get_string(environment_param);
- _dbus_setenv ("DISPLAY", display);
+ dbus_setenv ("DISPLAY", display);
}
}
}
diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c
index ae4b602e..060a919e 100644
--- a/dbus/dbus-server-socket.c
+++ b/dbus/dbus-server-socket.c
@@ -101,7 +101,7 @@ handle_new_client_fd_and_unlock (DBusServer *server,
return TRUE;
}
- transport = _dbus_transport_new_for_socket (client_fd, &server->guid_hex, FALSE);
+ transport = _dbus_transport_new_for_socket (client_fd, &server->guid_hex, NULL);
if (transport == NULL)
{
_dbus_close_socket (client_fd, NULL);
@@ -478,7 +478,10 @@ _dbus_server_new_for_tcp_socket (const char *host,
if (server == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- goto failed_4;
+ if (noncefile != NULL)
+ goto failed_4;
+ else
+ goto failed_2;
}
_dbus_string_free (&port_str);
diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
index 130f66ec..d9952404 100644
--- a/dbus/dbus-server-unix.c
+++ b/dbus/dbus-server-unix.c
@@ -149,7 +149,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
}
else if (strcmp (method, "systemd") == 0)
{
- int n, *fds;
+ int i, n, *fds;
DBusString address;
n = _dbus_listen_systemd_sockets (&fds, error);
@@ -159,27 +159,39 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
}
- _dbus_string_init_const (&address, "systemd:");
+ if (!_dbus_string_init (&address))
+ goto systemd_oom;
- *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
- if (*server_p == NULL)
+ for (i = 0; i < n; i++)
{
- int i;
-
- for (i = 0; i < n; i++)
+ if (i > 0)
{
- _dbus_close_socket (fds[i], NULL);
+ if (!_dbus_string_append (&address, ";"))
+ goto systemd_oom;
}
- dbus_free (fds);
-
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
+ if (!_dbus_append_address_from_socket (fds[i], &address, error))
+ goto systemd_err;
}
+ *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
+ if (*server_p == NULL)
+ goto systemd_oom;
+
dbus_free (fds);
return DBUS_SERVER_LISTEN_OK;
- }
+ systemd_oom:
+ _DBUS_SET_OOM (error);
+ systemd_err:
+ for (i = 0; i < n; i++)
+ {
+ _dbus_close_socket (fds[i], NULL);
+ }
+ dbus_free (fds);
+ _dbus_string_free (&address);
+
+ return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
+ }
#ifdef DBUS_ENABLE_LAUNCHD
else if (strcmp (method, "launchd") == 0)
{
diff --git a/dbus/dbus-server-win.c b/dbus/dbus-server-win.c
index bf1c896c..bb6da483 100644
--- a/dbus/dbus-server-win.c
+++ b/dbus/dbus-server-win.c
@@ -57,33 +57,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
method = dbus_address_entry_get_method (entry);
- if (strcmp (method, "nonce-tcp") == 0)
- {
- const char *host;
- const char *port;
- const char *bind;
- const char *family;
-
- host = dbus_address_entry_get_value (entry, "host");
- bind = dbus_address_entry_get_value (entry, "bind");
- port = dbus_address_entry_get_value (entry, "port");
- family = dbus_address_entry_get_value (entry, "family");
-
- *server_p = _dbus_server_new_for_tcp_socket (host, bind, port,
- family, error, TRUE);
-
- if (*server_p)
- {
- _DBUS_ASSERT_ERROR_IS_CLEAR(error);
- return DBUS_SERVER_LISTEN_OK;
- }
- else
- {
- _DBUS_ASSERT_ERROR_IS_SET(error);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
- }
- else if (strcmp (method, "autolaunch") == 0)
+ if (strcmp (method, "autolaunch") == 0)
{
const char *host = "localhost";
const char *bind = "localhost";
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index b62c2b40..19d8590c 100644
--- a/dbus/dbus-server.c
+++ b/dbus/dbus-server.c
@@ -26,7 +26,7 @@
#include "dbus-server-unix.h"
#include "dbus-server-socket.h"
#include "dbus-string.h"
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-server-debug-pipe.h"
#endif
#include "dbus-address.h"
@@ -529,7 +529,7 @@ static const struct {
} listen_funcs[] = {
{ _dbus_server_listen_socket }
, { _dbus_server_listen_platform_specific }
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
, { _dbus_server_listen_debug_pipe }
#endif
};
@@ -699,13 +699,11 @@ dbus_server_ref (DBusServer *server)
_dbus_return_val_if_fail (server != NULL, NULL);
- /* can't get the refcount without a side-effect */
old_refcount = _dbus_atomic_inc (&server->refcount);
#ifndef DBUS_DISABLE_CHECKS
if (_DBUS_UNLIKELY (old_refcount <= 0))
{
- /* undo side-effect first */
_dbus_atomic_dec (&server->refcount);
_dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
_DBUS_FUNCTION_NAME, "old_refcount > 0",
@@ -736,13 +734,18 @@ dbus_server_unref (DBusServer *server)
_dbus_return_if_fail (server != NULL);
- /* can't get the refcount without a side-effect */
old_refcount = _dbus_atomic_dec (&server->refcount);
#ifndef DBUS_DISABLE_CHECKS
if (_DBUS_UNLIKELY (old_refcount <= 0))
{
- /* undo side-effect first */
+ /* undo side-effect first
+ * please do not try to simplify the code here by using
+ * _dbus_atomic_get(), why we don't use it is
+ * because it issues another atomic operation even though
+ * DBUS_DISABLE_CHECKS defined.
+ * Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68303
+ */
_dbus_atomic_inc (&server->refcount);
_dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
_DBUS_FUNCTION_NAME, "old_refcount > 0",
@@ -777,16 +780,7 @@ dbus_server_disconnect (DBusServer *server)
{
_dbus_return_if_fail (server != NULL);
-#ifdef DBUS_DISABLE_CHECKS
- _dbus_atomic_inc (&server->refcount);
-#else
- {
- dbus_int32_t old_refcount = _dbus_atomic_inc (&server->refcount);
-
- _dbus_return_if_fail (old_refcount > 0);
- }
-#endif
-
+ dbus_server_ref (server);
SERVER_LOCK (server);
_dbus_assert (server->vtable->disconnect != NULL);
@@ -1071,9 +1065,8 @@ dbus_server_set_auth_mechanisms (DBusServer *server,
return TRUE;
}
-
-static DBusDataSlotAllocator slot_allocator;
-_DBUS_DEFINE_GLOBAL_LOCK (server_slots);
+static DBusDataSlotAllocator slot_allocator =
+ _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (server_slots));
/**
* Allocates an integer ID to be used for storing application-specific
@@ -1093,7 +1086,6 @@ dbus_bool_t
dbus_server_allocate_data_slot (dbus_int32_t *slot_p)
{
return _dbus_data_slot_allocator_alloc (&slot_allocator,
- (DBusRMutex **)&_DBUS_LOCK_NAME (server_slots),
slot_p);
}
@@ -1190,7 +1182,7 @@ dbus_server_get_data (DBusServer *server,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <string.h>
@@ -1246,4 +1238,4 @@ _dbus_server_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c
index d1827522..febfba20 100644
--- a/dbus/dbus-sha.c
+++ b/dbus/dbus-sha.c
@@ -511,7 +511,7 @@ _dbus_sha_compute (const DBusString *data,
/** @} */ /* end of exported functions */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -966,4 +966,4 @@ _dbus_sha_test (const char *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-shell.c b/dbus/dbus-shell.c
index 111d39df..2384961c 100644
--- a/dbus/dbus-shell.c
+++ b/dbus/dbus-shell.c
@@ -150,7 +150,7 @@ unquote_string_inplace (char* str, char** end)
* through literally instead of being expanded). This function is
* guaranteed to succeed if applied to the result of
* _dbus_shell_quote(). If it fails, it returns %NULL.
- * The @quoted_string need not actually contain quoted or
+ * The @p quoted_string need not actually contain quoted or
* escaped text; _dbus_shell_unquote() simply goes through the string and
* unquotes/unescapes anything that the shell would. Both single and
* double quotes are handled, as are escapes including escaped
@@ -163,7 +163,7 @@ unquote_string_inplace (char* str, char** end)
* be escaped with backslash. Otherwise double quotes preserve things
* literally.
*
- * @quoted_string: shell-quoted string
+ * @param quoted_string shell-quoted string
**/
char*
_dbus_shell_unquote (const char *quoted_string)
@@ -544,10 +544,10 @@ tokenize_command_line (const char *command_line, DBusError *error)
* does contain such expansions, they are passed through
* literally. Free the returned vector with dbus_free_string_array().
*
- * @command_line: command line to parse
- * @argcp: return location for number of args
- * @argvp: return location for array of args
- * @error: error information
+ * @param command_line command line to parse
+ * @param argcp return location for number of args
+ * @param argvp return location for array of args
+ * @param error error information
**/
dbus_bool_t
_dbus_shell_parse_argv (const char *command_line,
diff --git a/dbus/dbus-signature.c b/dbus/dbus-signature.c
index c130de5b..8a4701c9 100644
--- a/dbus/dbus-signature.c
+++ b/dbus/dbus-signature.c
@@ -410,7 +410,7 @@ dbus_type_is_valid (int typecode)
/** @} */ /* end of DBusSignature group */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* @ingroup DBusSignatureInternals
diff --git a/dbus/dbus-socket-set-poll.c b/dbus/dbus-socket-set-poll.c
index 65a1fd23..e322a3b4 100644
--- a/dbus/dbus-socket-set-poll.c
+++ b/dbus/dbus-socket-set-poll.c
@@ -44,7 +44,7 @@ typedef struct {
#define MINIMUM_SIZE 8
/* If we're in the regression tests, force reallocation to happen sooner */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#define DEFAULT_SIZE_HINT 1
#else
#define DEFAULT_SIZE_HINT MINIMUM_SIZE
diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c
index 3dae4f38..7da7a431 100644
--- a/dbus/dbus-spawn-win.c
+++ b/dbus/dbus-spawn-win.c
@@ -63,12 +63,12 @@ struct DBusBabysitter
int refcount;
HANDLE start_sync_event;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
HANDLE end_sync_event;
#endif
- char *executable;
+ char *log_name;
DBusSpawnChildSetupFunc child_setup;
void *user_data;
@@ -109,7 +109,7 @@ _dbus_babysitter_new (void)
return NULL;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
sitter->end_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL);
if (sitter->end_sync_event == NULL)
{
@@ -250,7 +250,7 @@ _dbus_babysitter_unref (DBusBabysitter *sitter)
sitter->start_sync_event = NULL;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (sitter->end_sync_event != NULL)
{
CloseHandle (sitter->end_sync_event);
@@ -258,7 +258,7 @@ _dbus_babysitter_unref (DBusBabysitter *sitter)
}
#endif
- dbus_free (sitter->executable);
+ dbus_free (sitter->log_name);
dbus_free (sitter);
}
@@ -337,7 +337,7 @@ _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter,
char *emsg = _dbus_win_error_string (sitter->spawn_errno);
dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
"Failed to execute program %s: %s",
- sitter->executable, emsg);
+ sitter->log_name, emsg);
_dbus_win_free_error_string (emsg);
}
else if (sitter->have_child_status)
@@ -345,14 +345,14 @@ _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter,
PING();
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
"Process %s exited with status %d",
- sitter->executable, sitter->child_status);
+ sitter->log_name, sitter->child_status);
}
else
{
PING();
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited, status unknown",
- sitter->executable);
+ sitter->log_name);
}
PING();
}
@@ -593,10 +593,10 @@ babysitter (void *parameter)
(*sitter->child_setup) (sitter->user_data);
}
- _dbus_verbose ("babysitter: spawning %s\n", sitter->executable);
+ _dbus_verbose ("babysitter: spawning %s\n", sitter->log_name);
PING();
- sitter->child_handle = spawn_program (sitter->executable,
+ sitter->child_handle = spawn_program (sitter->log_name,
sitter->argv, sitter->envp);
PING();
@@ -628,7 +628,7 @@ babysitter (void *parameter)
sitter->child_handle = NULL;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
SetEvent (sitter->end_sync_event);
#endif
@@ -642,6 +642,7 @@ babysitter (void *parameter)
dbus_bool_t
_dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
+ const char *log_name,
char **argv,
char **envp,
DBusSpawnChildSetupFunc child_setup,
@@ -653,6 +654,7 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
DWORD sitter_thread_id;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ _dbus_assert (argv[0] != NULL);
*sitter_p = NULL;
@@ -667,8 +669,17 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
sitter->child_setup = child_setup;
sitter->user_data = user_data;
- sitter->executable = _dbus_strdup (argv[0]);
- if (sitter->executable == NULL)
+ sitter->log_name = _dbus_strdup (log_name);
+ if (sitter->log_name == NULL && log_name != NULL)
+ {
+ _DBUS_SET_OOM (error);
+ goto out0;
+ }
+
+ if (sitter->log_name == NULL)
+ sitter->log_name = _dbus_strdup (argv[0]);
+
+ if (sitter->log_name == NULL)
{
_DBUS_SET_OOM (error);
goto out0;
@@ -753,7 +764,7 @@ _dbus_babysitter_set_result_function (DBusBabysitter *sitter,
sitter->finished_data = user_data;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static char *
get_test_exec (const char *exe,
@@ -804,7 +815,7 @@ check_spawn_nonexistent (void *data)
/*** Test launching nonexistent binary */
argv[0] = "/this/does/not/exist/32542sdgafgafdg";
- if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv, NULL,
NULL, NULL,
&error))
{
@@ -857,7 +868,7 @@ check_spawn_segfault (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv, NULL,
NULL, NULL,
&error))
{
@@ -912,7 +923,7 @@ check_spawn_exit (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv, NULL,
NULL, NULL,
&error))
{
@@ -967,7 +978,7 @@ check_spawn_and_kill (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv, NULL,
NULL, NULL,
&error))
{
diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c
index ef00801c..b95cad6e 100644
--- a/dbus/dbus-spawn.c
+++ b/dbus/dbus-spawn.c
@@ -38,6 +38,12 @@
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
+#ifdef HAVE_SYSTEMD
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
+#include <systemd/sd-journal.h>
+#endif
extern char **environ;
@@ -174,6 +180,48 @@ read_pid (int fd,
* and the grandchild. The grandchild is our spawned process. The intermediate
* child is a babysitter process; it keeps track of when the grandchild
* exits/crashes, and reaps the grandchild.
+ *
+ * We automatically reap the babysitter process, killing it if necessary,
+ * when the DBusBabysitter's refcount goes to zero.
+ *
+ * Processes:
+ *
+ * main process
+ * | fork() A
+ * \- babysitter
+ * | fork () B
+ * \- grandchild --> exec --> spawned process
+ *
+ * IPC:
+ * child_err_report_pipe
+ * /-----------<---------<--------------\
+ * | ^
+ * v |
+ * main process babysitter grandchild
+ * ^ ^
+ * v v
+ * \-------<->-------/
+ * babysitter_pipe
+ *
+ * child_err_report_pipe is genuinely a pipe.
+ * The READ_END (also called error_pipe_from_child) is used in the main
+ * process. The WRITE_END (also called child_err_report_fd) is used in
+ * the grandchild process.
+ *
+ * On failure, the grandchild process sends CHILD_EXEC_FAILED + errno.
+ * On success, the pipe just closes (because it's close-on-exec) without
+ * sending any bytes.
+ *
+ * babysitter_pipe is mis-named: it's really a bidirectional socketpair.
+ * The [0] end (also called socket_to_babysitter) is used in the main
+ * process, the [1] end (also called parent_pipe) is used in the babysitter.
+ *
+ * If the fork() labelled B in the diagram above fails, the babysitter sends
+ * CHILD_FORK_FAILED + errno.
+ * On success, the babysitter sends CHILD_PID + the grandchild's pid.
+ * On SIGCHLD, the babysitter sends CHILD_EXITED + the exit status.
+ * The main process doesn't explicitly send anything, but when it exits,
+ * the babysitter gets POLLHUP or POLLERR.
*/
/* Messages from children to parents */
@@ -192,7 +240,8 @@ struct DBusBabysitter
{
int refcount; /**< Reference count */
- char *executable; /**< executable name to use in error messages */
+ char *log_name; /**< the name under which to log messages about this
+ process being spawned */
int socket_to_babysitter; /**< Connection to the babysitter process */
int error_pipe_from_child; /**< Connection to the process that does the exec() */
@@ -308,15 +357,18 @@ _dbus_babysitter_unref (DBusBabysitter *sitter)
if (ret == 0)
kill (sitter->sitter_pid, SIGKILL);
- again:
if (ret == 0)
- ret = waitpid (sitter->sitter_pid, &status, 0);
+ {
+ do
+ {
+ ret = waitpid (sitter->sitter_pid, &status, 0);
+ }
+ while (_DBUS_UNLIKELY (ret < 0 && errno == EINTR));
+ }
if (ret < 0)
{
- if (errno == EINTR)
- goto again;
- else if (errno == ECHILD)
+ if (errno == ECHILD)
_dbus_warn ("Babysitter process not available to be reaped; should not happen\n");
else
_dbus_warn ("Unexpected error %d in waitpid() for babysitter: %s\n",
@@ -343,7 +395,7 @@ _dbus_babysitter_unref (DBusBabysitter *sitter)
if (sitter->watches)
_dbus_watch_list_free (sitter->watches);
- dbus_free (sitter->executable);
+ dbus_free (sitter->log_name);
dbus_free (sitter);
}
@@ -698,34 +750,34 @@ _dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter,
{
dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
"Failed to execute program %s: %s",
- sitter->executable, _dbus_strerror (sitter->errnum));
+ sitter->log_name, _dbus_strerror (sitter->errnum));
}
else if (sitter->have_fork_errnum)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
"Failed to fork a new process %s: %s",
- sitter->executable, _dbus_strerror (sitter->errnum));
+ sitter->log_name, _dbus_strerror (sitter->errnum));
}
else if (sitter->have_child_status)
{
if (WIFEXITED (sitter->status))
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
"Process %s exited with status %d",
- sitter->executable, WEXITSTATUS (sitter->status));
+ sitter->log_name, WEXITSTATUS (sitter->status));
else if (WIFSIGNALED (sitter->status))
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED,
"Process %s received signal %d",
- sitter->executable, WTERMSIG (sitter->status));
+ sitter->log_name, WTERMSIG (sitter->status));
else
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited abnormally",
- sitter->executable);
+ sitter->log_name);
}
else
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited, reason unknown",
- sitter->executable);
+ sitter->log_name);
}
}
@@ -807,9 +859,14 @@ handle_watch (DBusWatch *watch,
#define WRITE_END 1
-/* Avoids a danger in threaded situations (calling close()
- * on a file descriptor twice, and another thread has
- * re-opened it since the first close)
+/* Avoids a danger in re-entrant situations (calling close()
+ * on a file descriptor twice, and another module has
+ * re-opened it since the first close).
+ *
+ * This previously claimed to be relevant for threaded situations, but by
+ * trivial inspection, it is not thread-safe. It doesn't actually
+ * matter, since this module is only used in the -util variant of the
+ * library, which is only used in single-threaded situations.
*/
static int
close_and_invalidate (int *fd)
@@ -936,7 +993,7 @@ do_exec (int child_err_report_fd,
DBusSpawnChildSetupFunc child_setup,
void *user_data)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
int i, max_open;
#endif
@@ -947,7 +1004,7 @@ do_exec (int child_err_report_fd,
if (child_setup)
(* child_setup) (user_data);
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
max_open = sysconf (_SC_OPEN_MAX);
for (i = 3; i < max_open; i++)
@@ -1115,8 +1172,7 @@ babysit (pid_t grandchild_pid,
}
/**
- * Spawns a new process. The executable name and argv[0]
- * are the same, both are provided in argv[0]. The child_setup
+ * Spawns a new process. The child_setup
* function is passed the given user_data and is run in the child
* just before calling exec().
*
@@ -1126,8 +1182,9 @@ babysit (pid_t grandchild_pid,
* If sitter_p is #NULL, no babysitter is kept.
*
* @param sitter_p return location for babysitter or #NULL
+ * @param log_name the name under which to log messages about this process being spawned
* @param argv the executable and arguments
- * @param env the environment (not used on unix yet)
+ * @param env the environment, or #NULL to copy the parent's
* @param child_setup function to call in child pre-exec()
* @param user_data user data for setup function
* @param error error object to be filled in if function fails
@@ -1135,6 +1192,7 @@ babysit (pid_t grandchild_pid,
*/
dbus_bool_t
_dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
+ const char *log_name,
char **argv,
char **env,
DBusSpawnChildSetupFunc child_setup,
@@ -1145,8 +1203,13 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
int child_err_report_pipe[2] = { -1, -1 };
int babysitter_pipe[2] = { -1, -1 };
pid_t pid;
+#ifdef HAVE_SYSTEMD
+ int fd_out = -1;
+ int fd_err = -1;
+#endif
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ _dbus_assert (argv[0] != NULL);
if (sitter_p != NULL)
*sitter_p = NULL;
@@ -1160,8 +1223,17 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
return FALSE;
}
- sitter->executable = _dbus_strdup (argv[0]);
- if (sitter->executable == NULL)
+ sitter->log_name = _dbus_strdup (log_name);
+ if (sitter->log_name == NULL && log_name != NULL)
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto cleanup_and_fail;
+ }
+
+ if (sitter->log_name == NULL)
+ sitter->log_name = _dbus_strdup (argv[0]);
+
+ if (sitter->log_name == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto cleanup_and_fail;
@@ -1221,7 +1293,16 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
}
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
+
+#ifdef HAVE_SYSTEMD
+ /* This may fail, but it's not critical.
+ * In particular, if we were compiled with journald support but are now
+ * running on a non-systemd system, this is going to fail, so we
+ * have to cope gracefully. */
+ fd_out = sd_journal_stream_fd (sitter->log_name, LOG_INFO, FALSE);
+ fd_err = sd_journal_stream_fd (sitter->log_name, LOG_WARNING, FALSE);
+#endif
+
pid = fork ();
if (pid < 0)
@@ -1256,7 +1337,21 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
_dbus_assert_not_reached ("Got to code after write_err_and_exit()");
}
else if (grandchild_pid == 0)
- {
+ {
+ /* Go back to ignoring SIGPIPE, since it's evil
+ */
+ signal (SIGPIPE, SIG_IGN);
+
+ close_and_invalidate (&babysitter_pipe[1]);
+#ifdef HAVE_SYSTEMD
+ /* log to systemd journal if possible */
+ if (fd_out >= 0)
+ dup2 (fd_out, STDOUT_FILENO);
+ if (fd_err >= 0)
+ dup2 (fd_err, STDERR_FILENO);
+ close_and_invalidate (&fd_out);
+ close_and_invalidate (&fd_err);
+#endif
do_exec (child_err_report_pipe[WRITE_END],
argv,
env,
@@ -1265,6 +1360,11 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
}
else
{
+ close_and_invalidate (&child_err_report_pipe[WRITE_END]);
+#ifdef HAVE_SYSTEMD
+ close_and_invalidate (&fd_out);
+ close_and_invalidate (&fd_err);
+#endif
babysit (grandchild_pid, babysitter_pipe[1]);
_dbus_assert_not_reached ("Got to code after babysit()");
}
@@ -1274,6 +1374,10 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
/* Close the uncared-about ends of the pipes */
close_and_invalidate (&child_err_report_pipe[WRITE_END]);
close_and_invalidate (&babysitter_pipe[1]);
+#ifdef HAVE_SYSTEMD
+ close_and_invalidate (&fd_out);
+ close_and_invalidate (&fd_err);
+#endif
sitter->socket_to_babysitter = babysitter_pipe[0];
babysitter_pipe[0] = -1;
@@ -1303,6 +1407,10 @@ _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
close_and_invalidate (&child_err_report_pipe[WRITE_END]);
close_and_invalidate (&babysitter_pipe[0]);
close_and_invalidate (&babysitter_pipe[1]);
+#ifdef HAVE_SYSTEMD
+ close_and_invalidate (&fd_out);
+ close_and_invalidate (&fd_err);
+#endif
if (sitter != NULL)
_dbus_babysitter_unref (sitter);
@@ -1321,7 +1429,7 @@ _dbus_babysitter_set_result_function (DBusBabysitter *sitter,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static char *
get_test_exec (const char *exe,
@@ -1364,7 +1472,7 @@ check_spawn_nonexistent (void *data)
/*** Test launching nonexistent binary */
argv[0] = "/this/does/not/exist/32542sdgafgafdg";
- if (_dbus_spawn_async_with_babysitter (&sitter, argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv,
NULL, NULL, NULL,
&error))
{
@@ -1413,7 +1521,7 @@ check_spawn_segfault (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv,
NULL, NULL, NULL,
&error))
{
@@ -1464,7 +1572,7 @@ check_spawn_exit (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv,
NULL, NULL, NULL,
&error))
{
@@ -1515,7 +1623,7 @@ check_spawn_and_kill (void *data)
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv,
NULL, NULL, NULL,
&error))
{
diff --git a/dbus/dbus-spawn.h b/dbus/dbus-spawn.h
index a8814fb9..e6baae97 100644
--- a/dbus/dbus-spawn.h
+++ b/dbus/dbus-spawn.h
@@ -39,6 +39,7 @@ typedef void (* DBusBabysitterFinishedFunc) (DBusBabysitter *sitter,
void *user_data);
dbus_bool_t _dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
+ const char *log_name,
char **argv,
char **env,
DBusSpawnChildSetupFunc child_setup,
diff --git a/dbus/dbus-string-util.c b/dbus/dbus-string-util.c
index 922580da..3babc053 100644
--- a/dbus/dbus-string-util.c
+++ b/dbus/dbus-string-util.c
@@ -115,7 +115,7 @@ _dbus_string_find_byte_backward (const DBusString *str,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -935,4 +935,4 @@ _dbus_string_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index f2726eee..006e4560 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -246,6 +246,14 @@ _dbus_string_free (DBusString *str)
if (real->constant)
return;
+
+ /* so it's safe if @p str returned by a failed
+ * _dbus_string_init call
+ * Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65959
+ */
+ if (real->str == NULL)
+ return;
+
dbus_free (real->str - real->align_offset);
real->invalid = TRUE;
@@ -277,9 +285,9 @@ compact (DBusRealString *real,
return TRUE;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/* Not using this feature at the moment,
- * so marked DBUS_BUILD_TESTS-only
+ * so marked DBUS_ENABLE_EMBEDDED_TESTS-only
*/
/**
* Locks a string such that any attempts to change the string will
@@ -303,7 +311,7 @@ _dbus_string_lock (DBusString *str)
#define MAX_WASTE 48
compact (real, MAX_WASTE);
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
static dbus_bool_t
reallocate_for_length (DBusRealString *real,
@@ -327,14 +335,11 @@ reallocate_for_length (DBusRealString *real,
* disable asserts to profile, you don't get this destroyer
* of profiles.
*/
-#ifdef DBUS_DISABLE_ASSERT
-#else
-#ifdef DBUS_BUILD_TESTS
+#if defined (DBUS_ENABLE_EMBEDDED_TESTS) && !defined (DBUS_DISABLE_ASSERT)
new_allocated = 0; /* ensure a realloc every time so that we go
* through all malloc failure codepaths
*/
-#endif /* DBUS_BUILD_TESTS */
-#endif /* !DBUS_DISABLE_ASSERT */
+#endif
/* But be sure we always alloc at least space for the new length */
new_allocated = MAX (new_allocated,
@@ -949,29 +954,9 @@ _dbus_string_append (DBusString *str,
#define ASSIGN_4_OCTETS(p, octets) \
*((dbus_uint32_t*)(p)) = *((dbus_uint32_t*)(octets));
-#ifdef DBUS_HAVE_INT64
/** assign 8 bytes from one string to another */
#define ASSIGN_8_OCTETS(p, octets) \
*((dbus_uint64_t*)(p)) = *((dbus_uint64_t*)(octets));
-#else
-/** assign 8 bytes from one string to another */
-#define ASSIGN_8_OCTETS(p, octets) \
-do { \
- unsigned char *b; \
- \
- b = p; \
- \
- *b++ = octets[0]; \
- *b++ = octets[1]; \
- *b++ = octets[2]; \
- *b++ = octets[3]; \
- *b++ = octets[4]; \
- *b++ = octets[5]; \
- *b++ = octets[6]; \
- *b++ = octets[7]; \
- _dbus_assert (b == p + 8); \
-} while (0)
-#endif /* DBUS_HAVE_INT64 */
/**
* Inserts 2 bytes aligned on a 2 byte boundary
@@ -985,7 +970,7 @@ do { \
dbus_bool_t
_dbus_string_insert_2_aligned (DBusString *str,
int insert_at,
- const unsigned char octets[4])
+ const unsigned char octets[2])
{
DBUS_STRING_PREAMBLE (str);
@@ -1593,19 +1578,11 @@ _dbus_string_split_on_byte (DBusString *source,
*
* The second check covers surrogate pairs (category Cs).
*
- * The last two checks cover "Noncharacter": defined as:
- * "A code point that is permanently reserved for
- * internal use, and that should never be interchanged. In
- * Unicode 3.1, these consist of the values U+nFFFE and U+nFFFF
- * (where n is from 0 to 10_16) and the values U+FDD0..U+FDEF."
- *
* @param Char the character
*/
#define UNICODE_VALID(Char) \
((Char) < 0x110000 && \
- (((Char) & 0xFFFFF800) != 0xD800) && \
- ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
- ((Char) & 0xFFFE) != 0xFFFE)
+ (((Char) & 0xFFFFF800) != 0xD800))
/**
* Finds the given substring in the string,
@@ -1920,7 +1897,7 @@ _dbus_string_skip_white_reverse (const DBusString *str,
* @todo owen correctly notes that this is a stupid function (it was
* written purely for test code,
* e.g. dbus-message-builder.c). Probably should be enforced as test
- * code only with ifdef DBUS_BUILD_TESTS
+ * code only with ifdef DBUS_ENABLE_EMBEDDED_TESTS
*
* @param source the source string
* @param dest the destination string (contents are replaced)
@@ -1964,7 +1941,7 @@ _dbus_string_pop_line (DBusString *source,
return TRUE;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Deletes up to and including the first blank space
* in the string.
@@ -1983,7 +1960,7 @@ _dbus_string_delete_first_word (DBusString *str)
}
#endif
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Deletes any leading blanks in the string
*
@@ -2244,7 +2221,7 @@ _dbus_string_starts_with_c_str (const DBusString *a,
*/
dbus_bool_t
_dbus_string_append_byte_as_hex (DBusString *str,
- int byte)
+ unsigned char byte)
{
const char hexdigits[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
diff --git a/dbus/dbus-string.h b/dbus/dbus-string.h
index ec52400a..2ebdf56f 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -263,7 +263,7 @@ void _dbus_string_delete_first_word (DBusString *str);
void _dbus_string_delete_leading_blanks (DBusString *str);
void _dbus_string_chop_white (DBusString *str);
dbus_bool_t _dbus_string_append_byte_as_hex (DBusString *str,
- int byte);
+ unsigned char byte);
dbus_bool_t _dbus_string_hex_encode (const DBusString *source,
int start,
DBusString *dest,
diff --git a/dbus/dbus-syntax.c b/dbus/dbus-syntax.c
index 47922875..7ef659cb 100644
--- a/dbus/dbus-syntax.c
+++ b/dbus/dbus-syntax.c
@@ -93,7 +93,7 @@ dbus_validate_path (const char *path,
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param path a potentially invalid interface name, which must not be #NULL
+ * @param name a potentially invalid interface name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -140,7 +140,7 @@ dbus_validate_interface (const char *name,
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param path a potentially invalid member name, which must not be #NULL
+ * @param name a potentially invalid member name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -187,7 +187,7 @@ dbus_validate_member (const char *name,
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param path a potentially invalid error name, which must not be #NULL
+ * @param name a potentially invalid error name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -234,7 +234,7 @@ dbus_validate_error_name (const char *name,
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param path a potentially invalid bus name, which must not be #NULL
+ * @param name a potentially invalid bus name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
diff --git a/dbus/dbus-sysdeps-pthread.c b/dbus/dbus-sysdeps-pthread.c
index c9ec9e5b..1300ec35 100644
--- a/dbus/dbus-sysdeps-pthread.c
+++ b/dbus/dbus-sysdeps-pthread.c
@@ -36,12 +36,14 @@
#include <config.h>
+#ifdef HAVE_MONOTONIC_CLOCK
/* Whether we have a "monotonic" clock; i.e. a clock not affected by
* changes in system time.
* This is initialized once in check_monotonic_clock below.
* https://bugs.freedesktop.org/show_bug.cgi?id=18121
*/
static dbus_bool_t have_monotonic_clock = 0;
+#endif
struct DBusRMutex {
pthread_mutex_t lock; /**< the lock */
@@ -275,6 +277,26 @@ check_monotonic_clock (void)
dbus_bool_t
_dbus_threads_init_platform_specific (void)
{
+ /* These have static variables, and we need to handle both the case
+ * where dbus_threads_init() has been called and when it hasn't;
+ * so initialize them before any threads are allowed to enter.
+ */
check_monotonic_clock ();
- return dbus_threads_init (NULL);
+ (void) _dbus_check_setuid ();
+
+ return TRUE;
+}
+
+static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+void
+_dbus_threads_lock_platform_specific (void)
+{
+ pthread_mutex_lock (&init_mutex);
+}
+
+void
+_dbus_threads_unlock_platform_specific (void)
+{
+ pthread_mutex_unlock (&init_mutex);
}
diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c
index e30e7b87..0887a549 100644
--- a/dbus/dbus-sysdeps-thread-win.c
+++ b/dbus/dbus-sysdeps-thread-win.c
@@ -30,6 +30,21 @@
#include <windows.h>
+static dbus_bool_t global_init_done = FALSE;
+static CRITICAL_SECTION init_lock;
+
+/* Called from C++ code in dbus-init-win.cpp. */
+void
+_dbus_threads_windows_init_global (void)
+{
+ /* this ensures that the object that acts as our global constructor
+ * actually gets linked in when we're linked statically */
+ _dbus_threads_windows_ensure_ctor_linked ();
+
+ InitializeCriticalSection (&init_lock);
+ global_init_done = TRUE;
+}
+
struct DBusCondVar {
DBusList *list; /**< list thread-local-stored events waiting on the cond variable */
CRITICAL_SECTION lock; /**< lock protecting the list */
@@ -269,6 +284,19 @@ _dbus_threads_init_platform_specific (void)
return FALSE;
}
- return dbus_threads_init (NULL);
+ return TRUE;
+}
+
+void
+_dbus_threads_lock_platform_specific (void)
+{
+ _dbus_assert (global_init_done);
+ EnterCriticalSection (&init_lock);
}
+void
+_dbus_threads_unlock_platform_specific (void)
+{
+ _dbus_assert (global_init_done);
+ LeaveCriticalSection (&init_lock);
+}
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index cef8bd31..ae42f56e 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -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>
@@ -71,6 +72,9 @@
#ifdef HAVE_GETPEERUCRED
#include <ucred.h>
#endif
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#endif
#ifdef HAVE_ADT
#include <bsm/adt.h>
@@ -78,6 +82,10 @@
#include "sd-daemon.h"
+#if !DBUS_USE_SYNC
+#include <pthread.h>
+#endif
+
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -136,7 +144,7 @@ _dbus_open_socket (int *fd_p,
cloexec_done = *fd_p >= 0;
/* Check if kernel seems to be too old to know SOCK_CLOEXEC */
- if (*fd_p < 0 && errno == EINVAL)
+ if (*fd_p < 0 && (errno == EINVAL || errno == EPROTOTYPE))
#endif
{
*fd_p = socket (domain, type, protocol);
@@ -733,7 +741,7 @@ _dbus_write_two (int fd,
}
#else /* HAVE_WRITEV */
{
- int ret1;
+ int ret1, ret2;
ret1 = _dbus_write (fd, buffer1, start1, len1);
if (ret1 == len1 && buffer2 != NULL)
@@ -884,16 +892,24 @@ _dbus_connect_exec (const char *path,
{
int fds[2];
pid_t pid;
+ int retval;
+ dbus_bool_t cloexec_done = 0;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("connecting to process %s\n", path);
- if (socketpair (AF_UNIX, SOCK_STREAM
#ifdef SOCK_CLOEXEC
- |SOCK_CLOEXEC
+ retval = socketpair (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
+ cloexec_done = (retval >= 0);
+
+ if (retval < 0 && (errno == EINVAL || errno == EPROTOTYPE))
#endif
- , 0, fds) < 0)
+ {
+ retval = socketpair (AF_UNIX, SOCK_STREAM, 0, fds);
+ }
+
+ if (retval < 0)
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
@@ -902,8 +918,11 @@ _dbus_connect_exec (const char *path,
return -1;
}
- _dbus_fd_set_close_on_exec (fds[0]);
- _dbus_fd_set_close_on_exec (fds[1]);
+ if (!cloexec_done)
+ {
+ _dbus_fd_set_close_on_exec (fds[0]);
+ _dbus_fd_set_close_on_exec (fds[1]);
+ }
pid = fork ();
if (pid < 0)
@@ -956,39 +975,6 @@ _dbus_connect_exec (const char *path,
}
/**
- * Enables or disables the reception of credentials on the given socket during
- * the next message transmission. This is only effective if the #LOCAL_CREDS
- * system feature exists, in which case the other side of the connection does
- * not have to do anything special to send the credentials.
- *
- * @param fd socket on which to change the #LOCAL_CREDS flag.
- * @param on whether to enable or disable the #LOCAL_CREDS flag.
- */
-static dbus_bool_t
-_dbus_set_local_creds (int fd, dbus_bool_t on)
-{
- dbus_bool_t retval = TRUE;
-
-#if defined(HAVE_CMSGCRED)
- /* NOOP just to make sure only one codepath is used
- * and to prefer CMSGCRED
- */
-#elif defined(LOCAL_CREDS)
- int val = on ? 1 : 0;
- if (setsockopt (fd, 0, LOCAL_CREDS, &val, sizeof (val)) < 0)
- {
- _dbus_verbose ("Unable to set LOCAL_CREDS socket option on fd %d\n", fd);
- retval = FALSE;
- }
- else
- _dbus_verbose ("LOCAL_CREDS %s for further messages on fd %d\n",
- on ? "enabled" : "disabled", fd);
-#endif
-
- return retval;
-}
-
-/**
* Creates a socket and binds it to the given path,
* then listens on the socket. The socket is
* set to be nonblocking.
@@ -1013,7 +999,6 @@ _dbus_listen_unix_socket (const char *path,
int listen_fd;
struct sockaddr_un addr;
size_t path_len;
- unsigned int reuseaddr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1088,13 +1073,6 @@ _dbus_listen_unix_socket (const char *path,
strncpy (addr.sun_path, path, path_len);
}
- reuseaddr = 1;
- if (setsockopt (listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr))==-1)
- {
- _dbus_warn ("Failed to set socket option\"%s\": %s",
- path, _dbus_strerror (errno));
- }
-
if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -1113,15 +1091,6 @@ _dbus_listen_unix_socket (const char *path,
return -1;
}
- if (!_dbus_set_local_creds (listen_fd, TRUE))
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to enable LOCAL_CREDS on socket \"%s\": %s",
- path, _dbus_strerror (errno));
- close (listen_fd);
- return -1;
- }
-
if (!_dbus_set_fd_nonblocking (listen_fd, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
@@ -1145,7 +1114,7 @@ _dbus_listen_unix_socket (const char *path,
*
* This will set FD_CLOEXEC for the sockets returned.
*
- * @oaram fds the file descriptors
+ * @param fds the file descriptors
* @param error return location for errors
* @returns the number of file descriptors
*/
@@ -1207,14 +1176,6 @@ _dbus_listen_systemd_sockets (int **fds,
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++)
{
- if (!_dbus_set_local_creds (fd, TRUE))
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to enable LOCAL_CREDS on systemd socket: %s",
- _dbus_strerror (errno));
- goto fail;
- }
-
if (!_dbus_set_fd_nonblocking (fd, error))
{
_DBUS_ASSERT_ERROR_IS_SET (error);
@@ -1603,13 +1564,19 @@ write_credentials_byte (int server_fd,
|MSG_NOSIGNAL
#endif
);
-#else
- bytes_written = send (server_fd, buf, 1, 0
-#if HAVE_DECL_MSG_NOSIGNAL
- |MSG_NOSIGNAL
+
+ /* If we HAVE_CMSGCRED, the OS still might not let us sendmsg()
+ * with a SOL_SOCKET/SCM_CREDS message - for instance, FreeBSD
+ * only allows that on AF_UNIX. Try just doing a send() instead. */
+ if (bytes_written < 0 && errno == EINVAL)
#endif
- );
+ {
+ bytes_written = send (server_fd, buf, 1, 0
+#if HAVE_DECL_MSG_NOSIGNAL
+ |MSG_NOSIGNAL
#endif
+ );
+ }
if (bytes_written < 0 && errno == EINTR)
goto again;
@@ -1673,12 +1640,6 @@ _dbus_read_credentials_socket (int client_fd,
struct cmsghdr hdr;
char cred[CMSG_SPACE (sizeof (struct cmsgcred))];
} cmsg;
-
-#elif defined(LOCAL_CREDS)
- struct {
- struct cmsghdr hdr;
- struct sockcred cred;
- } cmsg;
#endif
uid_read = DBUS_UID_UNSET;
@@ -1696,12 +1657,6 @@ _dbus_read_credentials_socket (int client_fd,
_dbus_credentials_clear (credentials);
- /* Systems supporting LOCAL_CREDS are configured to have this feature
- * enabled (if it does not conflict with HAVE_CMSGCRED) prior accepting
- * the connection. Therefore, the received message must carry the
- * credentials information without doing anything special.
- */
-
iov.iov_base = &buf;
iov.iov_len = 1;
@@ -1709,7 +1664,7 @@ _dbus_read_credentials_socket (int client_fd,
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
-#if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS)
+#if defined(HAVE_CMSGCRED)
_DBUS_ZERO(cmsg);
msg.msg_control = (caddr_t) &cmsg;
msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred));
@@ -1749,20 +1704,18 @@ _dbus_read_credentials_socket (int client_fd,
return FALSE;
}
-#if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS)
- if (cmsg.hdr.cmsg_len < CMSG_LEN (sizeof (struct cmsgcred))
- || cmsg.hdr.cmsg_type != SCM_CREDS)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Message from recvmsg() was not SCM_CREDS");
- return FALSE;
- }
-#endif
-
_dbus_verbose ("read credentials byte\n");
{
#ifdef SO_PEERCRED
+ /* Supported by at least Linux and OpenBSD, with minor differences.
+ *
+ * This mechanism passes the process ID through and does not require
+ * the peer's cooperation, so we prefer it over all others. Notably,
+ * Linux also supports SCM_CREDENTIALS, which is similar to FreeBSD
+ * SCM_CREDS; it's implemented in GIO, but we don't use it in dbus at all,
+ * because this is much less fragile.
+ */
#ifdef __OpenBSD__
struct sockpeercred cr;
#else
@@ -1782,29 +1735,36 @@ _dbus_read_credentials_socket (int client_fd,
cr_len, (int) sizeof (cr), _dbus_strerror (errno));
}
#elif defined(HAVE_CMSGCRED)
+ /* We only check for HAVE_CMSGCRED, but we're really assuming that the
+ * presence of that struct implies SCM_CREDS. Supported by at least
+ * FreeBSD and DragonflyBSD.
+ *
+ * This mechanism requires the peer to help us (it has to send us a
+ * SCM_CREDS message) but it does pass the process ID through,
+ * which makes it better than getpeereid().
+ */
struct cmsgcred *cred;
+ struct cmsghdr *cmsgp;
- cred = (struct cmsgcred *) CMSG_DATA (&cmsg.hdr);
- pid_read = cred->cmcred_pid;
- uid_read = cred->cmcred_euid;
-#elif defined(LOCAL_CREDS)
- pid_read = DBUS_PID_UNSET;
- uid_read = cmsg.cred.sc_uid;
- /* Since we have already got the credentials from this socket, we can
- * disable its LOCAL_CREDS flag if it was ever set. */
- _dbus_set_local_creds (client_fd, FALSE);
-#elif defined(HAVE_GETPEEREID)
- uid_t euid;
- gid_t egid;
- if (getpeereid (client_fd, &euid, &egid) == 0)
+ for (cmsgp = CMSG_FIRSTHDR (&msg);
+ cmsgp != NULL;
+ cmsgp = CMSG_NXTHDR (&msg, cmsgp))
{
- uid_read = euid;
- }
- else
- {
- _dbus_verbose ("Failed to getpeereid() credentials: %s\n", _dbus_strerror (errno));
+ if (cmsgp->cmsg_type == SCM_CREDS &&
+ cmsgp->cmsg_level == SOL_SOCKET &&
+ cmsgp->cmsg_len >= CMSG_LEN (sizeof (struct cmsgcred)))
+ {
+ cred = (struct cmsgcred *) CMSG_DATA (cmsgp);
+ pid_read = cred->cmcred_pid;
+ uid_read = cred->cmcred_euid;
+ break;
+ }
}
+
#elif defined(HAVE_GETPEERUCRED)
+ /* Supported in at least Solaris >= 10. It should probably be higher
+ * up this list, because it carries the pid and we use this code path
+ * for audit data. */
ucred_t * ucred = NULL;
if (getpeerucred (client_fd, &ucred) == 0)
{
@@ -1848,7 +1808,54 @@ _dbus_read_credentials_socket (int client_fd,
}
if (ucred != NULL)
ucred_free (ucred);
-#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEEREID && !HAVE_GETPEERUCRED */
+
+ /* ----------------------------------------------------------------
+ * When adding new mechanisms, please add them above this point
+ * if they support passing the process ID through, or below if not.
+ * ---------------------------------------------------------------- */
+
+#elif defined(HAVE_GETPEEREID)
+ /* getpeereid() originates from D.J. Bernstein and is fairly
+ * widely-supported. According to a web search, it might be present in
+ * any/all of:
+ *
+ * - AIX?
+ * - Blackberry?
+ * - Cygwin
+ * - FreeBSD 4.6+ (but we prefer SCM_CREDS: it carries the pid)
+ * - Mac OS X
+ * - Minix 3.1.8+
+ * - MirBSD?
+ * - NetBSD 5.0+ (but LOCAL_PEEREID would be better: it carries the pid)
+ * - OpenBSD 3.0+ (but we prefer SO_PEERCRED: it carries the pid)
+ * - QNX?
+ */
+ uid_t euid;
+ gid_t egid;
+ if (getpeereid (client_fd, &euid, &egid) == 0)
+ {
+ uid_read = euid;
+ }
+ else
+ {
+ _dbus_verbose ("Failed to getpeereid() credentials: %s\n", _dbus_strerror (errno));
+ }
+#else /* no supported mechanism */
+
+#warning Socket credentials not supported on this Unix OS
+#warning Please tell https://bugs.freedesktop.org/enter_bug.cgi?product=DBus
+
+ /* Please add other operating systems known to support at least one of
+ * the mechanisms above to this list, keeping alphabetical order.
+ * Everything not in this list is best-effort.
+ */
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
+ defined(__linux__) || \
+ defined(__OpenBSD__) || \
+ defined(__NetBSD__)
+# error Credentials passing not working on this OS is a regression!
+#endif
+
_dbus_verbose ("Socket credentials not supported on this OS\n");
#endif
}
@@ -1862,7 +1869,7 @@ _dbus_read_credentials_socket (int client_fd,
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;
@@ -1934,11 +1941,15 @@ _dbus_accept (int listen_fd)
retry:
#ifdef HAVE_ACCEPT4
- /* We assume that if accept4 is available SOCK_CLOEXEC is too */
+ /*
+ * At compile-time, we assume that if accept4() is available in
+ * libc headers, SOCK_CLOEXEC is too. At runtime, it is still
+ * not necessarily true that either is supported by the running kernel.
+ */
client_fd = accept4 (listen_fd, &addr, &addrlen, SOCK_CLOEXEC);
cloexec_done = client_fd >= 0;
- if (client_fd < 0 && errno == ENOSYS)
+ if (client_fd < 0 && (errno == ENOSYS || errno == EINVAL))
#endif
{
client_fd = accept (listen_fd, &addr, &addrlen);
@@ -1988,6 +1999,16 @@ _dbus_check_dir_is_private_to_user (DBusString *dir, DBusError *error)
return FALSE;
}
+ if (sb.st_uid != geteuid ())
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "%s directory is owned by user %lu, not %lu",
+ directory,
+ (unsigned long) sb.st_uid,
+ (unsigned long) geteuid ());
+ return FALSE;
+ }
+
if ((S_IROTH & sb.st_mode) || (S_IWOTH & sb.st_mode) ||
(S_IRGRP & sb.st_mode) || (S_IWGRP & sb.st_mode))
{
@@ -2317,7 +2338,7 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
_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;
@@ -2424,7 +2445,12 @@ _dbus_parse_uid (const DBusString *uid_str,
}
#if !DBUS_USE_SYNC
-_DBUS_DEFINE_GLOBAL_LOCK (atomic);
+/* To be thread-safe by default on platforms that don't necessarily have
+ * atomic operations (notably Debian armel, which is armv4t), we must
+ * use a mutex that can be initialized statically, like this.
+ * GLib >= 2.32 uses a similar system.
+ */
+static pthread_mutex_t atomic_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
/**
@@ -2440,10 +2466,12 @@ _dbus_atomic_inc (DBusAtomic *atomic)
return __sync_add_and_fetch(&atomic->value, 1)-1;
#else
dbus_int32_t res;
- _DBUS_LOCK (atomic);
+
+ pthread_mutex_lock (&atomic_mutex);
res = atomic->value;
atomic->value += 1;
- _DBUS_UNLOCK (atomic);
+ pthread_mutex_unlock (&atomic_mutex);
+
return res;
#endif
}
@@ -2462,10 +2490,11 @@ _dbus_atomic_dec (DBusAtomic *atomic)
#else
dbus_int32_t res;
- _DBUS_LOCK (atomic);
+ pthread_mutex_lock (&atomic_mutex);
res = atomic->value;
atomic->value -= 1;
- _DBUS_UNLOCK (atomic);
+ pthread_mutex_unlock (&atomic_mutex);
+
return res;
#endif
}
@@ -2486,9 +2515,10 @@ _dbus_atomic_get (DBusAtomic *atomic)
#else
dbus_int32_t res;
- _DBUS_LOCK (atomic);
+ pthread_mutex_lock (&atomic_mutex);
res = atomic->value;
- _DBUS_UNLOCK (atomic);
+ pthread_mutex_unlock (&atomic_mutex);
+
return res;
#endif
}
@@ -2912,6 +2942,7 @@ _dbus_close (int fd,
* (i.e. avoids stdin/stdout/stderr). Sets O_CLOEXEC.
*
* @param fd the file descriptor to duplicate
+ * @param error address of error location.
* @returns duplicated file descriptor
* */
int
@@ -3052,7 +3083,7 @@ _dbus_full_duplex_pipe (int *fd1,
retval = socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
cloexec_done = retval >= 0;
- if (retval < 0 && errno == EINVAL)
+ if (retval < 0 && (errno == EINVAL || errno == EPROTOTYPE))
#endif
{
retval = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
@@ -3118,8 +3149,11 @@ _dbus_printf_string_upper_bound (const char *format,
char static_buf[1024];
int bufsize = sizeof (static_buf);
int len;
+ va_list args_copy;
- len = vsnprintf (static_buf, bufsize, format, args);
+ DBUS_VA_COPY (args_copy, args);
+ len = vsnprintf (static_buf, bufsize, format, args_copy);
+ va_end (args_copy);
/* If vsnprintf() returned non-negative, then either the string fits in
* static_buf, or this OS has the POSIX and C99 behaviour where vsnprintf
@@ -3135,8 +3169,12 @@ _dbus_printf_string_upper_bound (const char *format,
* or the real length could be coincidentally the same. Which is it?
* If vsnprintf returns the truncated length, we'll go to the slow
* path. */
- if (vsnprintf (static_buf, 1, format, args) == 1)
+ DBUS_VA_COPY (args_copy, args);
+
+ if (vsnprintf (static_buf, 1, format, args_copy) == 1)
len = -1;
+
+ va_end (args_copy);
}
/* If vsnprintf() returned negative, we have to do more work.
@@ -3152,7 +3190,10 @@ _dbus_printf_string_upper_bound (const char *format,
if (buf == NULL)
return -1;
- len = vsnprintf (buf, bufsize, format, args);
+ DBUS_VA_COPY (args_copy, args);
+ len = vsnprintf (buf, bufsize, format, args_copy);
+ va_end (args_copy);
+
dbus_free (buf);
/* If the reported length is exactly the buffer size, round up to the
@@ -3169,13 +3210,17 @@ _dbus_printf_string_upper_bound (const char *format,
* Gets the temporary files directory by inspecting the environment variables
* TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned
*
- * @returns location of temp directory
+ * @returns location of temp directory, or #NULL if no memory for locking
*/
const char*
_dbus_get_tmpdir(void)
{
+ /* Protected by _DBUS_LOCK_sysdeps */
static const char* tmpdir = NULL;
+ if (!_DBUS_LOCK (sysdeps))
+ return NULL;
+
if (tmpdir == NULL)
{
/* TMPDIR is what glibc uses, then
@@ -3198,11 +3243,14 @@ _dbus_get_tmpdir(void)
tmpdir = "/tmp";
}
+ _DBUS_UNLOCK (sysdeps);
+
_dbus_assert(tmpdir != NULL);
return tmpdir;
}
+#if defined(DBUS_ENABLE_X11_AUTOLAUNCH) || defined(DBUS_ENABLE_LAUNCHD)
/**
* Execute a subprocess, returning up to 1024 bytes of output
* into @p result.
@@ -3299,15 +3347,12 @@ _read_subprocess_line_argv (const char *progpath,
/* 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 ();
@@ -3407,6 +3452,7 @@ _read_subprocess_line_argv (const char *progpath,
return retval;
}
+#endif
/**
* Returns the address of a new session bus.
@@ -3415,6 +3461,7 @@ _read_subprocess_line_argv (const char *progpath,
* address. If a failure happens, returns #FALSE and
* sets an error in @p error.
*
+ * @param scope scope of autolaunch (Windows only)
* @param address a DBusString where the address can be stored
* @param error a DBusError to store the error in case of failure
* @returns #TRUE on success, #FALSE if an error happened
@@ -3429,11 +3476,18 @@ _dbus_get_autolaunch_address (const char *scope,
* but that's done elsewhere, and if it worked, this function wouldn't
* be called.) */
const char *display;
- static char *argv[6];
+ char *argv[6];
int i;
DBusString uuid;
dbus_bool_t retval;
+ if (_dbus_check_setuid ())
+ {
+ dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Unable to autolaunch when setuid");
+ return FALSE;
+ }
+
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
retval = FALSE;
@@ -3462,7 +3516,12 @@ _dbus_get_autolaunch_address (const char *scope,
}
i = 0;
- argv[i] = "dbus-launch";
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+ if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL)
+ argv[i] = TEST_BUS_LAUNCH_BINARY;
+ else
+#endif
+ argv[i] = DBUS_BINDIR "/dbus-launch";
++i;
argv[i] = "--autolaunch";
++i;
@@ -3477,7 +3536,7 @@ _dbus_get_autolaunch_address (const char *scope,
_dbus_assert (i == _DBUS_N_ELEMENTS (argv));
- retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch",
+ retval = _read_subprocess_line_argv (argv[0],
TRUE,
argv, address, error);
@@ -3531,11 +3590,9 @@ _dbus_read_local_machine_uuid (DBusGUID *machine_id,
return _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
}
-#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
-#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
-
/**
* quries launchd for a specific env var which holds the socket path.
+ * @param socket_path append the socket path to this DBusString
* @param launchd_env_var the env var to look up
* @param error a DBusError to store the error in case of failure
* @return the value of the env var
@@ -3551,6 +3608,13 @@ _dbus_lookup_launchd_socket (DBusString *socket_path,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ if (_dbus_check_setuid ())
+ {
+ dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Unable to find launchd socket when setuid");
+ return FALSE;
+ }
+
i = 0;
argv[i] = "launchctl";
++i;
@@ -3591,6 +3655,13 @@ _dbus_lookup_session_address_launchd (DBusString *address, DBusError *error)
dbus_bool_t valid_socket;
DBusString socket_path;
+ if (_dbus_check_setuid ())
+ {
+ dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Unable to find launchd socket when setuid");
+ return FALSE;
+ }
+
if (!_dbus_string_init (&socket_path))
{
_DBUS_SET_OOM (error);
@@ -3670,167 +3741,6 @@ _dbus_lookup_session_address (dbus_bool_t *supported,
}
/**
- * Returns the standard directories for a session bus to look for service
- * activation files
- *
- * On UNIX this should be the standard xdg freedesktop.org data directories:
- *
- * XDG_DATA_HOME=${XDG_DATA_HOME-$HOME/.local/share}
- * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
- *
- * and
- *
- * DBUS_DATADIR
- *
- * @param dirs the directory list we are returning
- * @returns #FALSE on OOM
- */
-
-dbus_bool_t
-_dbus_get_standard_session_servicedirs (DBusList **dirs)
-{
- const char *xdg_data_home;
- const char *xdg_data_dirs;
- DBusString servicedir_path;
-
- if (!_dbus_string_init (&servicedir_path))
- return FALSE;
-
- xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
- xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
-
- if (xdg_data_home != NULL)
- {
- if (!_dbus_string_append (&servicedir_path, xdg_data_home))
- goto oom;
- }
- else
- {
- const DBusString *homedir;
- DBusString local_share;
-
- if (!_dbus_homedir_from_current_process (&homedir))
- goto oom;
-
- if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
- goto oom;
-
- _dbus_string_init_const (&local_share, "/.local/share");
- if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
- goto oom;
- }
-
- if (!_dbus_string_append (&servicedir_path, ":"))
- goto oom;
-
- if (xdg_data_dirs != NULL)
- {
- if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
- goto oom;
-
- if (!_dbus_string_append (&servicedir_path, ":"))
- goto oom;
- }
- else
- {
- if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
- goto oom;
- }
-
- /*
- * add configured datadir to defaults
- * this may be the same as an xdg dir
- * however the config parser should take
- * care of duplicates
- */
- if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
- goto oom;
-
- if (!_dbus_split_paths_and_append (&servicedir_path,
- DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
- dirs))
- goto oom;
-
- _dbus_string_free (&servicedir_path);
- return TRUE;
-
- oom:
- _dbus_string_free (&servicedir_path);
- return FALSE;
-}
-
-
-/**
- * Returns the standard directories for a system bus to look for service
- * activation files
- *
- * On UNIX this should be the standard xdg freedesktop.org data directories:
- *
- * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
- *
- * and
- *
- * DBUS_DATADIR
- *
- * On Windows there is no system bus and this function can return nothing.
- *
- * @param dirs the directory list we are returning
- * @returns #FALSE on OOM
- */
-
-dbus_bool_t
-_dbus_get_standard_system_servicedirs (DBusList **dirs)
-{
- /*
- * DBUS_DATADIR may be the same as one of the standard directories. However,
- * the config parser should take care of the duplicates.
- *
- * Also, append /lib as counterpart of /usr/share on the root
- * directory (the root directory does not know /share), in order to
- * facilitate early boot system bus activation where /usr might not
- * be available.
- */
- static const char standard_search_path[] =
- "/usr/local/share:"
- "/usr/share:"
- DBUS_DATADIR ":"
- "/lib";
- DBusString servicedir_path;
-
- _dbus_string_init_const (&servicedir_path, standard_search_path);
-
- return _dbus_split_paths_and_append (&servicedir_path,
- DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
- dirs);
-}
-
-/**
- * Append the absolute path of the system.conf file
- * (there is no system bus on Windows so this can just
- * return FALSE and print a warning or something)
- *
- * @param str the string to append to
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_append_system_config_file (DBusString *str)
-{
- return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
-}
-
-/**
- * Append the absolute path of the session.conf file.
- *
- * @param str the string to append to
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_append_session_config_file (DBusString *str)
-{
- return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
-}
-
-/**
* Called when the bus daemon is signaled to reload its configuration; any
* caches should be nuked. Of course any caches that need explicit reload
* are probably broken, but c'est la vie.
@@ -3876,7 +3786,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
if (!_dbus_homedir_from_uid (uid, &homedir))
goto failed;
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
{
const char *override;
@@ -3892,6 +3802,8 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
}
else
{
+ /* Not strictly thread-safe, but if we fail at thread-safety here,
+ * the worst that will happen is some extra warnings. */
static dbus_bool_t already_warned = FALSE;
if (!already_warned)
{
@@ -4007,20 +3919,6 @@ _dbus_socket_can_pass_unix_fd(int fd) {
#endif
}
-
-/*
- * replaces the term DBUS_PREFIX in configure_time_path by the
- * current dbus installation directory. On unix this function is a noop
- *
- * @param configure_time_path
- * @return real path
- */
-const char *
-_dbus_replace_install_prefix (const char *configure_time_path)
-{
- return configure_time_path;
-}
-
/**
* Closes all file descriptors except the first three (i.e. stdin,
* stdout, stderr).
@@ -4086,4 +3984,133 @@ _dbus_close_all (void)
close (i);
}
+/**
+ * **NOTE**: If you modify this function, please also consider making
+ * the corresponding change in GLib. See
+ * glib/gutils.c:g_check_setuid().
+ *
+ * Returns TRUE if the current process was executed as setuid (or an
+ * equivalent __libc_enable_secure is available). See:
+ * http://osdir.com/ml/linux.lfs.hardened/2007-04/msg00032.html
+ */
+dbus_bool_t
+_dbus_check_setuid (void)
+{
+ /* TODO: get __libc_enable_secure exported from glibc.
+ * See http://www.openwall.com/lists/owl-dev/2012/08/14/1
+ */
+#if 0 && defined(HAVE_LIBC_ENABLE_SECURE)
+ {
+ /* See glibc/include/unistd.h */
+ extern int __libc_enable_secure;
+ return __libc_enable_secure;
+ }
+#elif defined(HAVE_ISSETUGID)
+ /* BSD: http://www.freebsd.org/cgi/man.cgi?query=issetugid&sektion=2 */
+ return issetugid ();
+#else
+ uid_t ruid, euid, suid; /* Real, effective and saved user ID's */
+ gid_t rgid, egid, sgid; /* Real, effective and saved group ID's */
+
+ /* We call into this function from _dbus_threads_init_platform_specific()
+ * to make sure these are initialized before we start threading. */
+ static dbus_bool_t check_setuid_initialised;
+ static dbus_bool_t is_setuid;
+
+ if (_DBUS_UNLIKELY (!check_setuid_initialised))
+ {
+#ifdef HAVE_GETRESUID
+ if (getresuid (&ruid, &euid, &suid) != 0 ||
+ getresgid (&rgid, &egid, &sgid) != 0)
+#endif /* HAVE_GETRESUID */
+ {
+ suid = ruid = getuid ();
+ sgid = rgid = getgid ();
+ euid = geteuid ();
+ egid = getegid ();
+ }
+
+ check_setuid_initialised = TRUE;
+ is_setuid = (ruid != euid || ruid != suid ||
+ rgid != egid || rgid != sgid);
+
+ }
+ return is_setuid;
+#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);
+ DBusString path_str;
+
+ if (getsockname (fd, &socket.sa, &size))
+ goto err;
+
+ switch (socket.sa.sa_family)
+ {
+ case AF_UNIX:
+ if (socket.un.sun_path[0]=='\0')
+ {
+ _dbus_string_init_const (&path_str, &(socket.un.sun_path[1]));
+ if (_dbus_string_append (address, "unix:abstract=") &&
+ _dbus_address_append_escaped (address, &path_str))
+ return TRUE;
+ }
+ else
+ {
+ _dbus_string_init_const (&path_str, socket.un.sun_path);
+ if (_dbus_string_append (address, "unix:path=") &&
+ _dbus_address_append_escaped (address, &path_str))
+ 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:
+ _dbus_string_init_const (&path_str, hostip);
+ if (inet_ntop (AF_INET6, &socket.ipv6.sin6_addr, hostip, sizeof (hostip)))
+ if (_dbus_string_append_printf (address, "tcp:family=ipv6,port=%u,host=",
+ ntohs (socket.ipv6.sin6_port)) &&
+ _dbus_address_append_escaped (address, &path_str))
+ 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 */
diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h
index 9b708967..a265b335 100644
--- a/dbus/dbus-sysdeps-unix.h
+++ b/dbus/dbus-sysdeps-unix.h
@@ -138,6 +138,10 @@ dbus_bool_t _dbus_parse_uid (const DBusString *uid_str,
void _dbus_close_all (void);
+dbus_bool_t _dbus_append_address_from_socket (int fd,
+ DBusString *address,
+ DBusError *error);
+
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
index ef86d738..0d8a66c7 100644
--- a/dbus/dbus-sysdeps-util-unix.c
+++ b/dbus/dbus-sysdeps-util-unix.c
@@ -49,12 +49,17 @@
#include <sys/socket.h>
#include <dirent.h>
#include <sys/un.h>
+
+#ifdef HAVE_SYSLOG_H
#include <syslog.h>
+#endif
#ifdef HAVE_SYS_SYSLIMITS_H
#include <sys/syslimits.h>
#endif
+#include "sd-daemon.h"
+
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -123,6 +128,7 @@ _dbus_become_daemon (const DBusString *pidfile,
dup2 (dev_null_fd, 2);
else
_dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
+ close (dev_null_fd);
}
if (!keep_umask)
@@ -375,13 +381,13 @@ _dbus_change_to_daemon_user (const char *user,
/**
* Attempt to ensure that the current process can open
- * at least @limit file descriptors.
+ * at least @p limit file descriptors.
*
- * If @limit is lower than the current, it will not be
+ * If @p limit is lower than the current, it will not be
* lowered. No error is returned if the request can
* not be satisfied.
*
- * @limit Number of file descriptors
+ * @param limit number of file descriptors
*/
void
_dbus_request_file_descriptor_limit (unsigned int limit)
@@ -422,12 +428,19 @@ _dbus_request_file_descriptor_limit (unsigned int limit)
}
void
-_dbus_init_system_log (void)
+_dbus_init_system_log (dbus_bool_t is_daemon)
{
-#ifdef HAVE_DECL_LOG_PERROR
- openlog ("dbus", LOG_PID | LOG_PERROR, LOG_DAEMON);
-#else
- openlog ("dbus", LOG_PID, LOG_DAEMON);
+#ifdef HAVE_SYSLOG_H
+ int logopts = LOG_PID;
+
+#if HAVE_DECL_LOG_PERROR
+#ifdef HAVE_SYSTEMD
+ if (!is_daemon || sd_booted () <= 0)
+#endif
+ logopts |= LOG_PERROR;
+#endif
+
+ openlog ("dbus", logopts, LOG_DAEMON);
#endif
}
@@ -436,8 +449,6 @@ _dbus_init_system_log (void)
*
* @param severity a severity value
* @param msg a printf-style format string
- * @param args arguments for the format string
- *
*/
void
_dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
@@ -464,6 +475,8 @@ _dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
void
_dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
{
+ va_list tmp;
+#ifdef HAVE_SYSLOG_H
int flags;
switch (severity)
{
@@ -480,11 +493,14 @@ _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args
return;
}
-#ifndef HAVE_DECL_LOG_PERROR
+ DBUS_VA_COPY (tmp, args);
+ vsyslog (flags, msg, tmp);
+ va_end (tmp);
+#endif
+
+#if !defined(HAVE_SYSLOG_H) || !HAVE_DECL_LOG_PERROR
{
/* vsyslog() won't write to stderr, so we'd better do it */
- va_list tmp;
-
DBUS_VA_COPY (tmp, args);
fprintf (stderr, "dbus[" DBUS_PID_FORMAT "]: ", _dbus_getpid ());
vfprintf (stderr, msg, tmp);
@@ -493,8 +509,6 @@ _dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args
}
#endif
- vsyslog (flags, msg, args);
-
if (severity == DBUS_SYSTEM_LOG_FATAL)
exit (1);
}
@@ -540,7 +554,7 @@ _dbus_user_at_console (const char *username,
DBusError *error)
{
- DBusString f;
+ DBusString u, f;
dbus_bool_t result;
result = FALSE;
@@ -556,8 +570,9 @@ _dbus_user_at_console (const char *username,
goto out;
}
+ _dbus_string_init_const (&u, username);
- if (!_dbus_string_append (&f, username))
+ if (!_dbus_concat_dir_and_file (&f, &u))
{
_DBUS_SET_OOM (error);
goto out;
@@ -1142,6 +1157,7 @@ _dbus_command_for_pid (unsigned long pid,
"Failed to read from \"%s\": %s",
_dbus_string_get_const_data (&path),
_dbus_strerror (errno));
+ _dbus_close (fd, NULL);
goto fail;
}
@@ -1163,3 +1179,180 @@ fail:
_dbus_string_free (&path);
return FALSE;
}
+
+/*
+ * replaces the term DBUS_PREFIX in configure_time_path by the
+ * current dbus installation directory. On unix this function is a noop
+ *
+ * @param configure_time_path
+ * @return real path
+ */
+const char *
+_dbus_replace_install_prefix (const char *configure_time_path)
+{
+ return configure_time_path;
+}
+
+#define DBUS_UNIX_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
+#define DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
+
+/**
+ * Returns the standard directories for a session bus to look for service
+ * activation files
+ *
+ * On UNIX this should be the standard xdg freedesktop.org data directories:
+ *
+ * XDG_DATA_HOME=${XDG_DATA_HOME-$HOME/.local/share}
+ * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
+ *
+ * and
+ *
+ * DBUS_DATADIR
+ *
+ * @param dirs the directory list we are returning
+ * @returns #FALSE on OOM
+ */
+
+dbus_bool_t
+_dbus_get_standard_session_servicedirs (DBusList **dirs)
+{
+ const char *xdg_data_home;
+ const char *xdg_data_dirs;
+ DBusString servicedir_path;
+
+ if (!_dbus_string_init (&servicedir_path))
+ return FALSE;
+
+ xdg_data_home = _dbus_getenv ("XDG_DATA_HOME");
+ xdg_data_dirs = _dbus_getenv ("XDG_DATA_DIRS");
+
+ if (xdg_data_home != NULL)
+ {
+ if (!_dbus_string_append (&servicedir_path, xdg_data_home))
+ goto oom;
+ }
+ else
+ {
+ const DBusString *homedir;
+ DBusString local_share;
+
+ if (!_dbus_homedir_from_current_process (&homedir))
+ goto oom;
+
+ if (!_dbus_string_append (&servicedir_path, _dbus_string_get_const_data (homedir)))
+ goto oom;
+
+ _dbus_string_init_const (&local_share, "/.local/share");
+ if (!_dbus_concat_dir_and_file (&servicedir_path, &local_share))
+ goto oom;
+ }
+
+ if (!_dbus_string_append (&servicedir_path, ":"))
+ goto oom;
+
+ if (xdg_data_dirs != NULL)
+ {
+ if (!_dbus_string_append (&servicedir_path, xdg_data_dirs))
+ goto oom;
+
+ if (!_dbus_string_append (&servicedir_path, ":"))
+ goto oom;
+ }
+ else
+ {
+ if (!_dbus_string_append (&servicedir_path, "/usr/local/share:/usr/share:"))
+ goto oom;
+ }
+
+ /*
+ * add configured datadir to defaults
+ * this may be the same as an xdg dir
+ * however the config parser should take
+ * care of duplicates
+ */
+ if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
+ goto oom;
+
+ if (!_dbus_split_paths_and_append (&servicedir_path,
+ DBUS_UNIX_STANDARD_SESSION_SERVICEDIR,
+ dirs))
+ goto oom;
+
+ _dbus_string_free (&servicedir_path);
+ return TRUE;
+
+ oom:
+ _dbus_string_free (&servicedir_path);
+ return FALSE;
+}
+
+
+/**
+ * Returns the standard directories for a system bus to look for service
+ * activation files
+ *
+ * On UNIX this should be the standard xdg freedesktop.org data directories:
+ *
+ * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
+ *
+ * and
+ *
+ * DBUS_DATADIR
+ *
+ * On Windows there is no system bus and this function can return nothing.
+ *
+ * @param dirs the directory list we are returning
+ * @returns #FALSE on OOM
+ */
+
+dbus_bool_t
+_dbus_get_standard_system_servicedirs (DBusList **dirs)
+{
+ /*
+ * DBUS_DATADIR may be the same as one of the standard directories. However,
+ * the config parser should take care of the duplicates.
+ *
+ * Also, append /lib as counterpart of /usr/share on the root
+ * directory (the root directory does not know /share), in order to
+ * facilitate early boot system bus activation where /usr might not
+ * be available.
+ */
+ static const char standard_search_path[] =
+ "/usr/local/share:"
+ "/usr/share:"
+ DBUS_DATADIR ":"
+ "/lib";
+ DBusString servicedir_path;
+
+ _dbus_string_init_const (&servicedir_path, standard_search_path);
+
+ return _dbus_split_paths_and_append (&servicedir_path,
+ DBUS_UNIX_STANDARD_SYSTEM_SERVICEDIR,
+ dirs);
+}
+
+/**
+ * Append the absolute path of the system.conf file
+ * (there is no system bus on Windows so this can just
+ * return FALSE and print a warning or something)
+ *
+ * @param str the string to append to
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
+_dbus_append_system_config_file (DBusString *str)
+{
+ return _dbus_string_append (str, DBUS_SYSTEM_CONFIG_FILE);
+}
+
+/**
+ * Append the absolute path of the session.conf file.
+ *
+ * @param str the string to append to
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
+_dbus_append_session_config_file (DBusString *str)
+{
+ return _dbus_string_append (str, DBUS_SESSION_CONFIG_FILE);
+}
diff --git a/dbus/dbus-sysdeps-util-win.c b/dbus/dbus-sysdeps-util-win.c
index 111db9ea..4678b11e 100644
--- a/dbus/dbus-sysdeps-util-win.c
+++ b/dbus/dbus-sysdeps-util-win.c
@@ -54,7 +54,7 @@
* Does the chdir, fork, setsid, etc. to become a daemon process.
*
* @param pidfile #NULL, or pidfile to create
- * @param print_pid_fd file descriptor to print daemon's pid to, or -1 for none
+ * @param print_pid_pipe file descriptor to print daemon's pid to, or -1 for none
* @param error return location for errors
* @param keep_umask #TRUE to keep the original umask
* @returns #FALSE on failure
@@ -65,7 +65,9 @@ _dbus_become_daemon (const DBusString *pidfile,
DBusError *error,
dbus_bool_t keep_umask)
{
- return TRUE;
+ dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
+ "Cannot daemonize on Windows");
+ return FALSE;
}
/**
@@ -262,7 +264,7 @@ _dbus_request_file_descriptor_limit (unsigned int limit)
}
void
-_dbus_init_system_log (void)
+_dbus_init_system_log (dbus_bool_t is_daemon)
{
/* OutputDebugStringA doesn't need any special initialization, do nothing */
}
@@ -272,8 +274,6 @@ _dbus_init_system_log (void)
*
* @param severity a severity value
* @param msg a printf-style format string
- * @param args arguments for the format string
- *
*/
void
_dbus_system_log (DBusSystemLogSeverity severity, const char *msg, ...)
@@ -1530,3 +1530,207 @@ _dbus_command_for_pid (unsigned long pid,
// FIXME
return FALSE;
}
+
+/*
+ * replaces the term DBUS_PREFIX in configure_time_path by the
+ * current dbus installation directory. On unix this function is a noop
+ *
+ * @param configure_time_path
+ * @return real path
+ */
+const char *
+_dbus_replace_install_prefix (const char *configure_time_path)
+{
+#ifndef DBUS_PREFIX
+ return configure_time_path;
+#else
+ static char retval[1000];
+ static char runtime_prefix[1000];
+ int len = 1000;
+ int i;
+
+ if (!configure_time_path)
+ return NULL;
+
+ if ((!_dbus_get_install_root(runtime_prefix, len) ||
+ strncmp (configure_time_path, DBUS_PREFIX "/",
+ strlen (DBUS_PREFIX) + 1))) {
+ strcat (retval, configure_time_path);
+ return retval;
+ }
+
+ strcpy (retval, runtime_prefix);
+ strcat (retval, configure_time_path + strlen (DBUS_PREFIX) + 1);
+
+ /* Somehow, in some situations, backslashes get collapsed in the string.
+ * Since windows C library accepts both forward and backslashes as
+ * path separators, convert all backslashes to forward slashes.
+ */
+
+ for(i = 0; retval[i] != '\0'; i++) {
+ if(retval[i] == '\\')
+ retval[i] = '/';
+ }
+ return retval;
+#endif
+}
+
+/**
+ * return the relocated DATADIR
+ *
+ * @returns relocated DATADIR static string
+ */
+
+static const char *
+_dbus_windows_get_datadir (void)
+{
+ return _dbus_replace_install_prefix(DBUS_DATADIR);
+}
+
+#undef DBUS_DATADIR
+#define DBUS_DATADIR _dbus_windows_get_datadir ()
+
+
+#define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
+#define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
+
+/**
+ * Returns the standard directories for a session bus to look for service
+ * activation files
+ *
+ * On Windows this should be data directories:
+ *
+ * %CommonProgramFiles%/dbus
+ *
+ * and
+ *
+ * relocated DBUS_DATADIR
+ *
+ * @param dirs the directory list we are returning
+ * @returns #FALSE on OOM
+ */
+
+dbus_bool_t
+_dbus_get_standard_session_servicedirs (DBusList **dirs)
+{
+ const char *common_progs;
+ DBusString servicedir_path;
+
+ if (!_dbus_string_init (&servicedir_path))
+ return FALSE;
+
+#ifdef DBUS_WINCE
+ {
+ /* On Windows CE, we adjust datadir dynamically to installation location. */
+ const char *data_dir = _dbus_getenv ("DBUS_DATADIR");
+
+ if (data_dir != NULL)
+ {
+ if (!_dbus_string_append (&servicedir_path, data_dir))
+ goto oom;
+
+ if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
+ goto oom;
+ }
+ }
+#else
+/*
+ the code for accessing services requires absolute base pathes
+ in case DBUS_DATADIR is relative make it absolute
+*/
+#ifdef DBUS_WIN
+ {
+ DBusString p;
+
+ _dbus_string_init_const (&p, DBUS_DATADIR);
+
+ if (!_dbus_path_is_absolute (&p))
+ {
+ char install_root[1000];
+ if (_dbus_get_install_root (install_root, sizeof(install_root)))
+ if (!_dbus_string_append (&servicedir_path, install_root))
+ goto oom;
+ }
+ }
+#endif
+ if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
+ goto oom;
+
+ if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
+ goto oom;
+#endif
+
+ common_progs = _dbus_getenv ("CommonProgramFiles");
+
+ if (common_progs != NULL)
+ {
+ if (!_dbus_string_append (&servicedir_path, common_progs))
+ goto oom;
+
+ if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
+ goto oom;
+ }
+
+ if (!_dbus_split_paths_and_append (&servicedir_path,
+ DBUS_STANDARD_SESSION_SERVICEDIR,
+ dirs))
+ goto oom;
+
+ _dbus_string_free (&servicedir_path);
+ return TRUE;
+
+ oom:
+ _dbus_string_free (&servicedir_path);
+ return FALSE;
+}
+
+/**
+ * Returns the standard directories for a system bus to look for service
+ * activation files
+ *
+ * On UNIX this should be the standard xdg freedesktop.org data directories:
+ *
+ * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
+ *
+ * and
+ *
+ * DBUS_DATADIR
+ *
+ * On Windows there is no system bus and this function can return nothing.
+ *
+ * @param dirs the directory list we are returning
+ * @returns #FALSE on OOM
+ */
+
+dbus_bool_t
+_dbus_get_standard_system_servicedirs (DBusList **dirs)
+{
+ *dirs = NULL;
+ return TRUE;
+}
+
+/**
+ * Append the absolute path of the system.conf file
+ * (there is no system bus on Windows so this can just
+ * return FALSE and print a warning or something)
+ *
+ * @param str the string to append to
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
+_dbus_append_system_config_file (DBusString *str)
+{
+ return _dbus_get_config_file_name(str, "system.conf");
+}
+
+/**
+ * Append the absolute path of the session.conf file.
+ *
+ * @param str the string to append to
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
+_dbus_append_session_config_file (DBusString *str)
+{
+ return _dbus_get_config_file_name(str, "session.conf");
+}
diff --git a/dbus/dbus-sysdeps-util.c b/dbus/dbus-sysdeps-util.c
index 4b3d16f2..6b361ef0 100644
--- a/dbus/dbus-sysdeps-util.c
+++ b/dbus/dbus-sysdeps-util.c
@@ -80,7 +80,7 @@ _dbus_get_environment (void)
return environment;
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
check_dirname (const char *filename,
const char *dirname)
@@ -196,4 +196,4 @@ _dbus_sysdeps_test (void)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c
index 397520af..1167e967 100644
--- a/dbus/dbus-sysdeps-win.c
+++ b/dbus/dbus-sysdeps-win.c
@@ -6,7 +6,7 @@
* Copyright (C) 2005 Novell, Inc.
* Copyright (C) 2006 Peter Kümmel <syntheticpp@gmx.net>
* Copyright (C) 2006 Christian Ehrlicher <ch.ehrlicher@gmx.de>
- * Copyright (C) 2006-2010 Ralf Habacker <ralf.habacker@freenet.de>
+ * Copyright (C) 2006-2013 Ralf Habacker <ralf.habacker@freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -54,12 +54,14 @@
#include <windows.h>
#include <ws2tcpip.h>
#include <wincrypt.h>
+#include <iphlpapi.h>
-/* Declarations missing in mingw's headers */
+/* Declarations missing in mingw's and windows sdk 7.0 headers */
extern BOOL WINAPI ConvertStringSidToSidA (LPCSTR StringSid, PSID *Sid);
extern BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid);
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#if HAVE_ERRNO_H
@@ -76,20 +78,15 @@ extern BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid);
#include <ws2tcpip.h>
#endif
-#ifdef HAVE_WSPIAPI_H
-// needed for w2k compatibility (getaddrinfo/freeaddrinfo/getnameinfo)
-#ifdef __GNUC__
-#define _inline
-#include "wspiapi.h"
-#else
-#include <wspiapi.h>
-#endif
-#endif // HAVE_WSPIAPI_H
-
#ifndef O_BINARY
#define O_BINARY 0
#endif
+#ifndef PROCESS_QUERY_LIMITED_INFORMATION
+/* MinGW32 < 4 does not define this value in its headers */
+#define PROCESS_QUERY_LIMITED_INFORMATION (0x1000)
+#endif
+
typedef int socklen_t;
@@ -103,6 +100,203 @@ _dbus_win_set_errno (int err)
#endif
}
+static BOOL is_winxp_sp3_or_lower();
+
+/*
+ * _MIB_TCPROW_EX and friends are not available in system headers
+ * and are mapped to attribute identical ...OWNER_PID typedefs.
+ */
+typedef MIB_TCPROW_OWNER_PID _MIB_TCPROW_EX;
+typedef MIB_TCPTABLE_OWNER_PID MIB_TCPTABLE_EX;
+typedef PMIB_TCPTABLE_OWNER_PID PMIB_TCPTABLE_EX;
+typedef DWORD (WINAPI *ProcAllocateAndGetTcpExtTableFromStack)(PMIB_TCPTABLE_EX*,BOOL,HANDLE,DWORD,DWORD);
+static ProcAllocateAndGetTcpExtTableFromStack lpfnAllocateAndGetTcpExTableFromStack = NULL;
+
+/**
+ * AllocateAndGetTcpExTableFromStack() is undocumented and not exported,
+ * but is the only way to do this in older XP versions.
+ * @return true if the procedures could be loaded
+ */
+static BOOL
+load_ex_ip_helper_procedures(void)
+{
+ HMODULE hModule = LoadLibrary ("iphlpapi.dll");
+ if (hModule == NULL)
+ {
+ _dbus_verbose ("could not load iphlpapi.dll\n");
+ return FALSE;
+ }
+
+ lpfnAllocateAndGetTcpExTableFromStack = (ProcAllocateAndGetTcpExtTableFromStack)GetProcAddress (hModule, "AllocateAndGetTcpExTableFromStack");
+ if (lpfnAllocateAndGetTcpExTableFromStack == NULL)
+ {
+ _dbus_verbose ("could not find function AllocateAndGetTcpExTableFromStack in iphlpapi.dll\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * get pid from localhost tcp connection using peer_port
+ * This function is available on WinXP >= SP3
+ * @param peer_port peers tcp port
+ * @return process id or 0 if connection has not been found
+ */
+static dbus_pid_t
+get_pid_from_extended_tcp_table(int peer_port)
+{
+ dbus_pid_t result;
+ DWORD errorCode, size, i;
+ MIB_TCPTABLE_OWNER_PID *tcp_table;
+
+ if ((errorCode =
+ GetExtendedTcpTable (NULL, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) == ERROR_INSUFFICIENT_BUFFER)
+ {
+ tcp_table = (MIB_TCPTABLE_OWNER_PID *) dbus_malloc (size);
+ if (tcp_table == NULL)
+ {
+ _dbus_verbose ("Error allocating memory\n");
+ return 0;
+ }
+ }
+ else
+ {
+ _dbus_win_warn_win_error ("unexpected error returned from GetExtendedTcpTable", errorCode);
+ return 0;
+ }
+
+ if ((errorCode = GetExtendedTcpTable (tcp_table, &size, TRUE, AF_INET, TCP_TABLE_OWNER_PID_ALL, 0)) != NO_ERROR)
+ {
+ _dbus_verbose ("Error fetching tcp table %d\n", (int)errorCode);
+ dbus_free (tcp_table);
+ return 0;
+ }
+
+ result = 0;
+ for (i = 0; i < tcp_table->dwNumEntries; i++)
+ {
+ MIB_TCPROW_OWNER_PID *p = &tcp_table->table[i];
+ int local_address = ntohl (p->dwLocalAddr);
+ int local_port = ntohs (p->dwLocalPort);
+ if (p->dwState == MIB_TCP_STATE_ESTAB
+ && local_address == INADDR_LOOPBACK && local_port == peer_port)
+ result = p->dwOwningPid;
+ }
+
+ dbus_free (tcp_table);
+ _dbus_verbose ("got pid %lu\n", result);
+ return result;
+}
+
+/**
+ * get pid from localhost tcp connection using peer_port
+ * This function is available on all WinXP versions, but
+ * not in wine (at least version <= 1.6.0)
+ * @param peer_port peers tcp port
+ * @return process id or 0 if connection has not been found
+ */
+static dbus_pid_t
+get_pid_from_tcp_ex_table(int peer_port)
+{
+ dbus_pid_t result;
+ DWORD errorCode, i;
+ PMIB_TCPTABLE_EX tcp_table = NULL;
+
+ if (!load_ex_ip_helper_procedures ())
+ {
+ _dbus_verbose
+ ("Error not been able to load iphelper procedures\n");
+ return 0;
+ }
+
+ errorCode = lpfnAllocateAndGetTcpExTableFromStack (&tcp_table, TRUE, GetProcessHeap(), 0, 2);
+
+ if (errorCode != NO_ERROR)
+ {
+ _dbus_verbose
+ ("Error not been able to call AllocateAndGetTcpExTableFromStack()\n");
+ return 0;
+ }
+
+ result = 0;
+ for (i = 0; i < tcp_table->dwNumEntries; i++)
+ {
+ _MIB_TCPROW_EX *p = &tcp_table->table[i];
+ int local_port = ntohs (p->dwLocalPort);
+ int local_address = ntohl (p->dwLocalAddr);
+ if (local_address == INADDR_LOOPBACK && local_port == peer_port)
+ {
+ result = p->dwOwningPid;
+ break;
+ }
+ }
+
+ HeapFree (GetProcessHeap(), 0, tcp_table);
+ _dbus_verbose ("got pid %lu\n", result);
+ return result;
+}
+
+/**
+ * @brief return peer process id from tcp handle for localhost connections
+ * @param handle tcp socket descriptor
+ * @return process id or 0 in case the process id could not be fetched
+ */
+static dbus_pid_t
+_dbus_get_peer_pid_from_tcp_handle (int handle)
+{
+ struct sockaddr_storage addr;
+ socklen_t len = sizeof (addr);
+ int peer_port;
+
+ dbus_pid_t result;
+ dbus_bool_t is_localhost = FALSE;
+
+ getpeername (handle, (struct sockaddr *) &addr, &len);
+
+ if (addr.ss_family == AF_INET)
+ {
+ struct sockaddr_in *s = (struct sockaddr_in *) &addr;
+ peer_port = ntohs (s->sin_port);
+ is_localhost = (ntohl (s->sin_addr.s_addr) == INADDR_LOOPBACK);
+ }
+ else if (addr.ss_family == AF_INET6)
+ {
+ _dbus_verbose ("FIXME [61922]: IPV6 support not working on windows\n");
+ return 0;
+ /*
+ struct sockaddr_in6 *s = (struct sockaddr_in6 * )&addr;
+ peer_port = ntohs (s->sin6_port);
+ is_localhost = (memcmp(s->sin6_addr.s6_addr, in6addr_loopback.s6_addr, 16) == 0);
+ _dbus_verbose ("IPV6 %08x %08x\n", s->sin6_addr.s6_addr, in6addr_loopback.s6_addr);
+ */
+ }
+ else
+ {
+ _dbus_verbose ("no idea what address family %d is\n", addr.ss_family);
+ return 0;
+ }
+
+ if (!is_localhost)
+ {
+ _dbus_verbose ("could not fetch process id from remote process\n");
+ return 0;
+ }
+
+ if (peer_port == 0)
+ {
+ _dbus_verbose
+ ("Error not been able to fetch tcp peer port from connection\n");
+ return 0;
+ }
+
+ _dbus_verbose ("trying to get peers pid");
+
+ result = get_pid_from_extended_tcp_table (peer_port);
+ if (result > 0)
+ return result;
+ result = get_pid_from_tcp_ex_table (peer_port);
+ return result;
+}
/* Convert GetLastError() to a dbus error. */
const char*
@@ -324,7 +518,7 @@ _dbus_close_socket (int fd,
* on exec. Should be called for all file
* descriptors in D-Bus code.
*
- * @param fd the file descriptor
+ * @param handle the Windows HANDLE
*/
void
_dbus_fd_set_close_on_exec (intptr_t handle)
@@ -340,7 +534,7 @@ _dbus_fd_set_close_on_exec (intptr_t handle)
/**
* Sets a file descriptor to be nonblocking.
*
- * @param fd the file descriptor.
+ * @param handle the file descriptor.
* @param error address of error location.
* @returns #TRUE on success.
*/
@@ -474,21 +668,26 @@ _dbus_connect_named_pipe (const char *path,
#endif
-
-
-void
+/**
+ * @returns #FALSE if no memory
+ */
+dbus_bool_t
_dbus_win_startup_winsock (void)
{
/* Straight from MSDN, deuglified */
+ /* Protected by _DBUS_LOCK_sysdeps */
static dbus_bool_t beenhere = FALSE;
WORD wVersionRequested;
WSADATA wsaData;
int err;
+ if (!_DBUS_LOCK (sysdeps))
+ return FALSE;
+
if (beenhere)
- return;
+ goto out;
wVersionRequested = MAKEWORD (2, 0);
@@ -512,6 +711,10 @@ _dbus_win_startup_winsock (void)
}
beenhere = TRUE;
+
+out:
+ _DBUS_UNLOCK (sysdeps);
+ return TRUE;
}
@@ -538,9 +741,12 @@ int _dbus_printf_string_upper_bound (const char *format,
char buf[1024];
int bufsize;
int len;
+ va_list args_copy;
bufsize = sizeof (buf);
- len = _vsnprintf (buf, bufsize - 1, format, args);
+ DBUS_VA_COPY (args_copy, args);
+ len = _vsnprintf (buf, bufsize - 1, format, args_copy);
+ va_end (args_copy);
while (len == -1) /* try again */
{
@@ -553,7 +759,9 @@ int _dbus_printf_string_upper_bound (const char *format,
if (p == NULL)
return -1;
- len = _vsnprintf (p, bufsize - 1, format, args);
+ DBUS_VA_COPY (args_copy, args);
+ len = _vsnprintf (p, bufsize - 1, format, args_copy);
+ va_end (args_copy);
free (p);
}
@@ -738,22 +946,56 @@ _dbus_pid_for_log (void)
return _dbus_getpid ();
}
-
#ifndef DBUS_WINCE
+
+static BOOL is_winxp_sp3_or_lower()
+{
+ OSVERSIONINFOEX osvi;
+ DWORDLONG dwlConditionMask = 0;
+ int op=VER_LESS_EQUAL;
+
+ // Initialize the OSVERSIONINFOEX structure.
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ osvi.dwMajorVersion = 5;
+ osvi.dwMinorVersion = 1;
+ osvi.wServicePackMajor = 3;
+ osvi.wServicePackMinor = 0;
+
+ // Initialize the condition mask.
+
+ VER_SET_CONDITION( dwlConditionMask, VER_MAJORVERSION, op );
+ VER_SET_CONDITION( dwlConditionMask, VER_MINORVERSION, op );
+ VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMAJOR, op );
+ VER_SET_CONDITION( dwlConditionMask, VER_SERVICEPACKMINOR, op );
+
+ // Perform the test.
+
+ return VerifyVersionInfo(
+ &osvi,
+ VER_MAJORVERSION | VER_MINORVERSION |
+ VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
+ dwlConditionMask);
+}
+
/** Gets our SID
- * @param points to sid buffer, need to be freed with LocalFree()
+ * @param sid points to sid buffer, need to be freed with LocalFree()
+ * @param process_id the process id for which the sid should be returned
* @returns process sid
*/
static dbus_bool_t
-_dbus_getsid(char **sid)
+_dbus_getsid(char **sid, dbus_pid_t process_id)
{
HANDLE process_token = INVALID_HANDLE_VALUE;
TOKEN_USER *token_user = NULL;
DWORD n;
PSID psid;
int retval = FALSE;
-
- if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &process_token))
+
+ HANDLE process_handle = OpenProcess(is_winxp_sp3_or_lower() ? PROCESS_QUERY_INFORMATION : PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id);
+
+ if (!OpenProcessToken (process_handle, TOKEN_QUERY, &process_token))
{
_dbus_win_warn_win_error ("OpenProcessToken failed", GetLastError ());
goto failed;
@@ -781,10 +1023,11 @@ _dbus_getsid(char **sid)
retval = TRUE;
failed:
+ CloseHandle (process_handle);
if (process_token != INVALID_HANDLE_VALUE)
CloseHandle (process_token);
- _dbus_verbose("_dbus_getsid() returns %d\n",retval);
+ _dbus_verbose("_dbus_getsid() got '%s' and returns %d\n", *sid, retval);
return retval;
}
#endif
@@ -816,7 +1059,11 @@ _dbus_full_duplex_pipe (int *fd1,
int len;
u_long arg;
- _dbus_win_startup_winsock ();
+ if (!_dbus_win_startup_winsock ())
+ {
+ _DBUS_SET_OOM (error);
+ return FALSE;
+ }
temp = socket (AF_INET, SOCK_STREAM, 0);
if (temp == INVALID_SOCKET)
@@ -1260,7 +1507,11 @@ _dbus_connect_tcp_socket_with_nonce (const char *host,
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- _dbus_win_startup_winsock ();
+ if (!_dbus_win_startup_winsock ())
+ {
+ _DBUS_SET_OOM (error);
+ return -1;
+ }
_DBUS_ZERO (hints);
@@ -1405,7 +1656,11 @@ _dbus_listen_tcp_socket (const char *host,
*fds_p = NULL;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- _dbus_win_startup_winsock ();
+ if (!_dbus_win_startup_winsock ())
+ {
+ _DBUS_SET_OOM (error);
+ return -1;
+ }
_DBUS_ZERO (hints);
@@ -1665,13 +1920,13 @@ again:
* a byte was read, not whether we got valid credentials. On some
* systems, such as Linux, reading/writing the byte isn't actually
* required, but we do it anyway just to avoid multiple codepaths.
- *
+ *
* Fails if no byte is available, so you must select() first.
*
* The point of the byte is that on some systems we have to
* use sendmsg()/recvmsg() to transmit credentials.
*
- * @param client_fd the client file descriptor
+ * @param handle the client file descriptor
* @param credentials struct to fill with credentials of client
* @param error location to store error code
* @returns #TRUE on success
@@ -1683,22 +1938,41 @@ _dbus_read_credentials_socket (int handle,
{
int bytes_read = 0;
DBusString buf;
-
+
+ char *sid = NULL;
+ dbus_pid_t pid;
+ int retval = FALSE;
+
// could fail due too OOM
- if (_dbus_string_init(&buf))
+ if (_dbus_string_init (&buf))
{
- bytes_read = _dbus_read_socket(handle, &buf, 1 );
+ bytes_read = _dbus_read_socket (handle, &buf, 1 );
if (bytes_read > 0)
- _dbus_verbose("got one zero byte from server");
+ _dbus_verbose ("got one zero byte from server\n");
- _dbus_string_free(&buf);
+ _dbus_string_free (&buf);
}
- _dbus_credentials_add_from_current_process (credentials);
- _dbus_verbose("FIXME: get faked credentials from current process");
+ pid = _dbus_get_peer_pid_from_tcp_handle (handle);
+ if (pid == 0)
+ return TRUE;
- return TRUE;
+ _dbus_credentials_add_pid (credentials, pid);
+
+ if (_dbus_getsid (&sid, pid))
+ {
+ if (!_dbus_credentials_add_windows_sid (credentials, sid))
+ goto out;
+ }
+
+ retval = TRUE;
+
+out:
+ if (sid)
+ LocalFree (sid);
+
+ return retval;
}
/**
@@ -1792,10 +2066,10 @@ _dbus_credentials_add_from_current_process (DBusCredentials *credentials)
dbus_bool_t retval = FALSE;
char *sid = NULL;
- if (!_dbus_getsid(&sid))
+ if (!_dbus_getsid(&sid, _dbus_getpid()))
goto failed;
- if (!_dbus_credentials_add_unix_pid(credentials, _dbus_getpid()))
+ if (!_dbus_credentials_add_pid (credentials, _dbus_getpid()))
goto failed;
if (!_dbus_credentials_add_windows_sid (credentials,sid))
@@ -1830,7 +2104,7 @@ _dbus_append_user_from_current_process (DBusString *str)
dbus_bool_t retval = FALSE;
char *sid = NULL;
- if (!_dbus_getsid(&sid))
+ if (!_dbus_getsid(&sid, _dbus_getpid()))
return FALSE;
retval = _dbus_string_append (str,sid);
@@ -1999,14 +2273,18 @@ _dbus_generate_random_bytes (DBusString *str,
* Gets the temporary files directory by inspecting the environment variables
* TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned
*
- * @returns location of temp directory
+ * @returns location of temp directory, or #NULL if no memory for locking
*/
const char*
_dbus_get_tmpdir(void)
{
+ /* Protected by _DBUS_LOCK_sysdeps */
static const char* tmpdir = NULL;
static char buf[1000];
+ if (!_DBUS_LOCK (sysdeps))
+ return NULL;
+
if (tmpdir == NULL)
{
char *last_slash;
@@ -2028,6 +2306,8 @@ _dbus_get_tmpdir(void)
tmpdir = buf;
}
+ _DBUS_UNLOCK (sysdeps);
+
_dbus_assert(tmpdir != NULL);
return tmpdir;
@@ -2063,51 +2343,7 @@ _dbus_delete_file (const DBusString *filename,
return TRUE;
}
-/*
- * replaces the term DBUS_PREFIX in configure_time_path by the
- * current dbus installation directory. On unix this function is a noop
- *
- * @param configure_time_path
- * @return real path
- */
-const char *
-_dbus_replace_install_prefix (const char *configure_time_path)
-{
-#ifndef DBUS_PREFIX
- return configure_time_path;
-#else
- static char retval[1000];
- static char runtime_prefix[1000];
- int len = 1000;
- int i;
-
- if (!configure_time_path)
- return NULL;
-
- if ((!_dbus_get_install_root(runtime_prefix, len) ||
- strncmp (configure_time_path, DBUS_PREFIX "/",
- strlen (DBUS_PREFIX) + 1))) {
- strcat (retval, configure_time_path);
- return retval;
- }
-
- strcpy (retval, runtime_prefix);
- strcat (retval, configure_time_path + strlen (DBUS_PREFIX) + 1);
-
- /* Somehow, in some situations, backslashes get collapsed in the string.
- * Since windows C library accepts both forward and backslashes as
- * path separators, convert all backslashes to forward slashes.
- */
-
- for(i = 0; retval[i] != '\0'; i++) {
- if(retval[i] == '\\')
- retval[i] = '/';
- }
- return retval;
-#endif
-}
-
-#if !defined (DBUS_DISABLE_ASSERTS) || defined(DBUS_BUILD_TESTS)
+#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_ENABLE_EMBEDDED_TESTS)
#if defined(_MSC_VER) || defined(DBUS_WINCE)
# ifdef BACKTRACES
@@ -2946,142 +3182,6 @@ _dbus_make_file_world_readable(const DBusString *filename,
}
/**
- * return the relocated DATADIR
- *
- * @returns relocated DATADIR static string
- */
-
-static const char *
-_dbus_windows_get_datadir (void)
-{
- return _dbus_replace_install_prefix(DBUS_DATADIR);
-}
-
-#undef DBUS_DATADIR
-#define DBUS_DATADIR _dbus_windows_get_datadir ()
-
-
-#define DBUS_STANDARD_SESSION_SERVICEDIR "/dbus-1/services"
-#define DBUS_STANDARD_SYSTEM_SERVICEDIR "/dbus-1/system-services"
-
-/**
- * Returns the standard directories for a session bus to look for service
- * activation files
- *
- * On Windows this should be data directories:
- *
- * %CommonProgramFiles%/dbus
- *
- * and
- *
- * relocated DBUS_DATADIR
- *
- * @param dirs the directory list we are returning
- * @returns #FALSE on OOM
- */
-
-dbus_bool_t
-_dbus_get_standard_session_servicedirs (DBusList **dirs)
-{
- const char *common_progs;
- DBusString servicedir_path;
-
- if (!_dbus_string_init (&servicedir_path))
- return FALSE;
-
-#ifdef DBUS_WINCE
- {
- /* On Windows CE, we adjust datadir dynamically to installation location. */
- const char *data_dir = _dbus_getenv ("DBUS_DATADIR");
-
- if (data_dir != NULL)
- {
- if (!_dbus_string_append (&servicedir_path, data_dir))
- goto oom;
-
- if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
- goto oom;
- }
- }
-#else
-/*
- the code for accessing services requires absolute base pathes
- in case DBUS_DATADIR is relative make it absolute
-*/
-#ifdef DBUS_WIN
- {
- DBusString p;
-
- _dbus_string_init_const (&p, DBUS_DATADIR);
-
- if (!_dbus_path_is_absolute (&p))
- {
- char install_root[1000];
- if (_dbus_get_install_root (install_root, sizeof(install_root)))
- if (!_dbus_string_append (&servicedir_path, install_root))
- goto oom;
- }
- }
-#endif
- if (!_dbus_string_append (&servicedir_path, DBUS_DATADIR))
- goto oom;
-
- if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
- goto oom;
-#endif
-
- common_progs = _dbus_getenv ("CommonProgramFiles");
-
- if (common_progs != NULL)
- {
- if (!_dbus_string_append (&servicedir_path, common_progs))
- goto oom;
-
- if (!_dbus_string_append (&servicedir_path, _DBUS_PATH_SEPARATOR))
- goto oom;
- }
-
- if (!_dbus_split_paths_and_append (&servicedir_path,
- DBUS_STANDARD_SESSION_SERVICEDIR,
- dirs))
- goto oom;
-
- _dbus_string_free (&servicedir_path);
- return TRUE;
-
- oom:
- _dbus_string_free (&servicedir_path);
- return FALSE;
-}
-
-/**
- * Returns the standard directories for a system bus to look for service
- * activation files
- *
- * On UNIX this should be the standard xdg freedesktop.org data directories:
- *
- * XDG_DATA_DIRS=${XDG_DATA_DIRS-/usr/local/share:/usr/share}
- *
- * and
- *
- * DBUS_DATADIR
- *
- * On Windows there is no system bus and this function can return nothing.
- *
- * @param dirs the directory list we are returning
- * @returns #FALSE on OOM
- */
-
-dbus_bool_t
-_dbus_get_standard_system_servicedirs (DBusList **dirs)
-{
- *dirs = NULL;
- return TRUE;
-}
-
-_DBUS_DEFINE_GLOBAL_LOCK (atomic);
-
-/**
* Atomically increments an integer
*
* @param atomic pointer to the integer to increment
@@ -3121,8 +3221,18 @@ _dbus_atomic_dec (DBusAtomic *atomic)
dbus_int32_t
_dbus_atomic_get (DBusAtomic *atomic)
{
- /* this is what GLib does, hopefully it's right... */
- MemoryBarrier ();
+ /* In this situation, GLib issues a MemoryBarrier() and then returns
+ * atomic->value. However, mingw from mingw.org (not to be confused with
+ * mingw-w64 from mingw-w64.sf.net) does not have MemoryBarrier in its
+ * headers, so we have to get a memory barrier some other way.
+ *
+ * InterlockedIncrement is older, and is documented on MSDN to be a full
+ * memory barrier, so let's use that.
+ */
+ long dummy = 0;
+
+ InterlockedExchange (&dummy, 1);
+
return atomic->value;
}
@@ -3153,7 +3263,7 @@ _dbus_get_is_errno_eagain_or_ewouldblock (void)
/**
* return the absolute path of the dbus installation
*
- * @param s buffer for installation path
+ * @param prefix buffer for installation path
* @param len length of buffer
* @returns #FALSE on failure
*/
@@ -3258,32 +3368,6 @@ _dbus_get_config_file_name(DBusString *config_file, char *s)
return TRUE;
}
-/**
- * Append the absolute path of the system.conf file
- * (there is no system bus on Windows so this can just
- * return FALSE and print a warning or something)
- *
- * @param str the string to append to
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_append_system_config_file (DBusString *str)
-{
- return _dbus_get_config_file_name(str, "system.conf");
-}
-
-/**
- * Append the absolute path of the session.conf file.
- *
- * @param str the string to append to
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_append_session_config_file (DBusString *str)
-{
- return _dbus_get_config_file_name(str, "session.conf");
-}
-
/* See comment in dbus-sysdeps-unix.c */
dbus_bool_t
_dbus_lookup_session_address (dbus_bool_t *supported,
@@ -3335,7 +3419,7 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
_dbus_string_append(&homedir,homepath);
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
{
const char *override;
@@ -3351,6 +3435,8 @@ _dbus_append_keyring_directory_for_credentials (DBusString *directory,
}
else
{
+ /* Not strictly thread-safe, but if we fail at thread-safety here,
+ * the worst that will happen is some extra warnings. */
static dbus_bool_t already_warned = FALSE;
if (!already_warned)
{
@@ -3575,7 +3661,7 @@ _dbus_win_set_error_from_win_error (DBusError *error,
void
_dbus_win_warn_win_error (const char *message,
- int code)
+ unsigned long code)
{
DBusError error;
@@ -3632,6 +3718,12 @@ _dbus_path_is_absolute (const DBusString *filename)
return FALSE;
}
+dbus_bool_t
+_dbus_check_setuid (void)
+{
+ return FALSE;
+}
+
/** @} end of sysdeps-win */
/* tests in dbus-sysdeps-util.c */
diff --git a/dbus/dbus-sysdeps-win.h b/dbus/dbus-sysdeps-win.h
index 74624b75..02e7a83f 100644
--- a/dbus/dbus-sysdeps-win.h
+++ b/dbus/dbus-sysdeps-win.h
@@ -27,7 +27,7 @@
#define DBUS_SYSDEPS_WIN_H
extern void *_dbus_win_get_dll_hmodule (void);
-#define _WINSOCKAPI_
+#define WIN32_LEAN_AND_MEAN
#include "dbus-hash.h"
#include "dbus-string.h"
@@ -42,9 +42,9 @@ extern void *_dbus_win_get_dll_hmodule (void);
void _dbus_win_set_errno (int err);
const char* _dbus_win_error_from_last_error (void);
-void _dbus_win_startup_winsock (void);
+dbus_bool_t _dbus_win_startup_winsock (void);
void _dbus_win_warn_win_error (const char *message,
- int code);
+ unsigned long code);
char * _dbus_win_error_string (int error_number);
void _dbus_win_free_error_string (char *string);
@@ -85,6 +85,9 @@ dbus_bool_t _dbus_get_config_file_name(DBusString *config_file,
dbus_bool_t _dbus_get_install_root(char *prefix, int len);
+void _dbus_threads_windows_init_global (void);
+void _dbus_threads_windows_ensure_ctor_linked (void);
+
#endif
/** @} end of sysdeps-win.h */
diff --git a/dbus/dbus-sysdeps-wince-glue.c b/dbus/dbus-sysdeps-wince-glue.c
index 74b1371f..e276f046 100644
--- a/dbus/dbus-sysdeps-wince-glue.c
+++ b/dbus/dbus-sysdeps-wince-glue.c
@@ -491,7 +491,7 @@ SearchPathA (LPCSTR lpPath, LPCSTR lpFileName, LPCSTR lpExtension,
/** Gets our SID
- * @param points to sid buffer, need to be freed with LocalFree()
+ * @param sid points to sid buffer, need to be freed with LocalFree()
* @returns process sid
*/
dbus_bool_t
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index 861bfec9..de3a18cb 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -29,6 +29,7 @@
#include "dbus-protocol.h"
#include "dbus-string.h"
#include "dbus-list.h"
+#include "dbus-misc.h"
/* NOTE: If you include any unix/windows-specific headers here, you are probably doing something
* wrong and should be putting some code in dbus-sysdeps-unix.c or dbus-sysdeps-win.c.
@@ -46,10 +47,6 @@
#include <errno.h>
#endif
-_DBUS_DEFINE_GLOBAL_LOCK (win_fds);
-_DBUS_DEFINE_GLOBAL_LOCK (sid_atom_cache);
-_DBUS_DEFINE_GLOBAL_LOCK (system_users);
-
#ifdef DBUS_WIN
#include <stdlib.h>
#elif (defined __APPLE__)
@@ -96,6 +93,8 @@ _dbus_abort (void)
}
/**
+ * @ingroup DBusMisc
+ *
* Wrapper for setenv(). If the value is #NULL, unsets
* the environment variable.
*
@@ -104,13 +103,16 @@ _dbus_abort (void)
* we can not rely on internal implementation details of
* the underlying libc library.
*
+ * This function is not thread-safe, because altering the environment
+ * in Unix is not thread-safe in general.
+ *
* @param varname name of environment variable
- * @param value value of environment variable
- * @returns #TRUE on success.
+ * @param value value of environment variable, or #NULL to unset
+ * @returns #TRUE on success, #FALSE if not enough memory.
*/
dbus_bool_t
-_dbus_setenv (const char *varname,
- const char *value)
+dbus_setenv (const char *varname,
+ const char *value)
{
_dbus_assert (varname != NULL);
@@ -182,6 +184,11 @@ _dbus_setenv (const char *varname,
const char*
_dbus_getenv (const char *varname)
{
+ /* Don't respect any environment variables if the current process is
+ * setuid. This is the equivalent of glibc's __secure_getenv().
+ */
+ if (_dbus_check_setuid ())
+ return NULL;
return getenv (varname);
}
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index c03e2f54..e586946f 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -87,9 +87,8 @@ typedef struct DBusPipe DBusPipe;
void _dbus_abort (void) _DBUS_GNUC_NORETURN;
+dbus_bool_t _dbus_check_setuid (void);
const char* _dbus_getenv (const char *varname);
-dbus_bool_t _dbus_setenv (const char *varname,
- const char *value);
dbus_bool_t _dbus_clearenv (void);
char ** _dbus_get_environment (void);
@@ -277,6 +276,19 @@ dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
#define _DBUS_POLLHUP 0x0080
/** Invalid request: fd not open */
#define _DBUS_POLLNVAL 0x1000
+#elif defined(__QNX__)
+/** Writing now will not block */
+#define _DBUS_POLLOUT 0x0002
+/** There is data to read */
+#define _DBUS_POLLIN 0x0005
+/** There is urgent data to read */
+#define _DBUS_POLLPRI 0x0008
+/** Error condition */
+#define _DBUS_POLLERR 0x0020
+/** Hung up */
+#define _DBUS_POLLHUP 0x0040
+/** Invalid request: fd not open */
+#define _DBUS_POLLNVAL 0x1000
#else
/** There is data to read */
#define _DBUS_POLLIN 0x0001
@@ -308,12 +320,12 @@ int _dbus_poll (DBusPollFD *fds,
void _dbus_sleep_milliseconds (int milliseconds);
-void _dbus_get_real_time (long *tv_sec,
- long *tv_usec);
-
void _dbus_get_monotonic_time (long *tv_sec,
long *tv_usec);
+void _dbus_get_real_time (long *tv_sec,
+ long *tv_usec);
+
/**
* directory interface
*/
@@ -436,7 +448,7 @@ void _dbus_set_signal_handler (int sig,
dbus_bool_t _dbus_user_at_console (const char *username,
DBusError *error);
-void _dbus_init_system_log (void);
+void _dbus_init_system_log (dbus_bool_t is_daemon);
typedef enum {
DBUS_SYSTEM_LOG_INFO,
@@ -506,6 +518,16 @@ dbus_bool_t _dbus_read_local_machine_uuid (DBusGUID *machine_id,
*/
dbus_bool_t _dbus_threads_init_platform_specific (void);
+/**
+ * Lock a static mutex used to protect _dbus_threads_init_platform_specific().
+ */
+void _dbus_threads_lock_platform_specific (void);
+
+/**
+ * Undo _dbus_threads_lock_platform_specific().
+ */
+void _dbus_threads_unlock_platform_specific (void);
+
dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs,
const char *suffix,
DBusList **dir_list);
diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c
index 224a6c8c..5990d6ec 100644
--- a/dbus/dbus-test.c
+++ b/dbus/dbus-test.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static void
die (const char *failure)
{
@@ -41,7 +41,7 @@ check_memleaks (void)
{
dbus_shutdown ();
- printf ("%s: checking for memleaks\n", "dbus-test");
+ printf ("%s: checking for memleaks\n", "test-dbus");
if (_dbus_get_malloc_blocks_outstanding () != 0)
{
_dbus_warn ("%d dbus_malloc blocks were not freed\n",
@@ -60,7 +60,7 @@ run_test (const char *test_name,
{
if (!specific_test || strcmp (specific_test, test_name) == 0)
{
- printf ("%s: running %s tests\n", "dbus-test", test_name);
+ printf ("%s: running %s tests\n", "test-dbus", test_name);
if (!test ())
die (test_name);
@@ -76,7 +76,7 @@ run_data_test (const char *test_name,
{
if (!specific_test || strcmp (specific_test, test_name) == 0)
{
- printf ("%s: running %s tests\n", "dbus-test", test_name);
+ printf ("%s: running %s tests\n", "test-dbus", test_name);
if (!test (test_data_dir))
die (test_name);
@@ -84,7 +84,7 @@ run_data_test (const char *test_name,
}
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
/**
* An exported symbol to be run in order to execute
@@ -94,11 +94,12 @@ run_data_test (const char *test_name,
* (with --enable-tests=no)
*
* @param test_data_dir the directory with test data (test/data normally)
+ * @param specific_test run specific test or #NULL to run all tests
*/
void
dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *specific_test)
{
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
if (!_dbus_threads_init_debug ())
die ("debug threads init");
@@ -164,7 +165,7 @@ dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *speci
run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
- printf ("%s: completed successfully\n", "dbus-test");
+ printf ("%s: completed successfully\n", "test-dbus");
#else
printf ("Not compiled with unit tests, not running any\n");
#endif
diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c
index bb1169db..12d40493 100644
--- a/dbus/dbus-threads.c
+++ b/dbus/dbus-threads.c
@@ -27,18 +27,6 @@
#include "dbus-list.h"
static int thread_init_generation = 0;
-
-static DBusList *uninitialized_rmutex_list = NULL;
-static DBusList *uninitialized_cmutex_list = NULL;
-static DBusList *uninitialized_condvar_list = NULL;
-
-/** This is used for the no-op default mutex pointer, just to be distinct from #NULL */
-#define _DBUS_DUMMY_MUTEX ((DBusMutex*)0xABCDEF)
-#define _DBUS_DUMMY_RMUTEX ((DBusRMutex *) _DBUS_DUMMY_MUTEX)
-#define _DBUS_DUMMY_CMUTEX ((DBusCMutex *) _DBUS_DUMMY_MUTEX)
-
-/** This is used for the no-op default mutex pointer, just to be distinct from #NULL */
-#define _DBUS_DUMMY_CONDVAR ((DBusCondVar*)0xABCDEF2)
/**
* @defgroup DBusThreadsInternals Thread functions
@@ -59,11 +47,6 @@ static DBusList *uninitialized_condvar_list = NULL;
* If possible, the mutex returned by this function is recursive, to
* avoid deadlocks. However, that cannot be relied on.
*
- * The extra level of indirection given by allocating a pointer
- * to point to the mutex location allows the threading
- * module to swap out dummy mutexes for a real mutex so libraries
- * can initialize threads even after the D-Bus API has been used.
- *
* @param location_p the location of the new mutex, can return #NULL on OOM
*/
void
@@ -71,17 +54,13 @@ _dbus_rmutex_new_at_location (DBusRMutex **location_p)
{
_dbus_assert (location_p != NULL);
- if (thread_init_generation == _dbus_current_generation)
+ if (!dbus_threads_init_default ())
{
- *location_p = _dbus_platform_rmutex_new ();
+ *location_p = NULL;
+ return;
}
- else
- {
- *location_p = _DBUS_DUMMY_RMUTEX;
- if (!_dbus_list_append (&uninitialized_rmutex_list, location_p))
- *location_p = NULL;
- }
+ *location_p = _dbus_platform_rmutex_new ();
}
/**
@@ -92,11 +71,6 @@ _dbus_rmutex_new_at_location (DBusRMutex **location_p)
*
* The returned mutex is suitable for use with condition variables.
*
- * The extra level of indirection given by allocating a pointer
- * to point to the mutex location allows the threading
- * module to swap out dummy mutexes for a real mutex so libraries
- * can initialize threads even after the D-Bus API has been used.
- *
* @param location_p the location of the new mutex, can return #NULL on OOM
*/
void
@@ -104,22 +78,17 @@ _dbus_cmutex_new_at_location (DBusCMutex **location_p)
{
_dbus_assert (location_p != NULL);
- if (thread_init_generation == _dbus_current_generation)
+ if (!dbus_threads_init_default ())
{
- *location_p = _dbus_platform_cmutex_new ();
+ *location_p = NULL;
+ return;
}
- else
- {
- *location_p = _DBUS_DUMMY_CMUTEX;
- if (!_dbus_list_append (&uninitialized_cmutex_list, location_p))
- *location_p = NULL;
- }
+ *location_p = _dbus_platform_cmutex_new ();
}
/**
- * Frees a DBusRMutex or removes it from the uninitialized mutex list;
- * does nothing if passed a #NULL pointer.
+ * Frees a DBusRMutex; does nothing if passed a #NULL pointer.
*/
void
_dbus_rmutex_free_at_location (DBusRMutex **location_p)
@@ -127,23 +96,12 @@ _dbus_rmutex_free_at_location (DBusRMutex **location_p)
if (location_p == NULL)
return;
- if (thread_init_generation == _dbus_current_generation)
- {
- if (*location_p != NULL)
- _dbus_platform_rmutex_free (*location_p);
- }
- else
- {
- _dbus_assert (*location_p == NULL || *location_p == _DBUS_DUMMY_RMUTEX);
-
- _dbus_list_remove (&uninitialized_rmutex_list, location_p);
- }
+ if (*location_p != NULL)
+ _dbus_platform_rmutex_free (*location_p);
}
/**
- * Frees a DBusCMutex and removes it from the
- * uninitialized mutex list;
- * does nothing if passed a #NULL pointer.
+ * Frees a DBusCMutex; does nothing if passed a #NULL pointer.
*/
void
_dbus_cmutex_free_at_location (DBusCMutex **location_p)
@@ -151,17 +109,8 @@ _dbus_cmutex_free_at_location (DBusCMutex **location_p)
if (location_p == NULL)
return;
- if (thread_init_generation == _dbus_current_generation)
- {
- if (*location_p != NULL)
- _dbus_platform_cmutex_free (*location_p);
- }
- else
- {
- _dbus_assert (*location_p == NULL || *location_p == _DBUS_DUMMY_CMUTEX);
-
- _dbus_list_remove (&uninitialized_cmutex_list, location_p);
- }
+ if (*location_p != NULL)
+ _dbus_platform_cmutex_free (*location_p);
}
/**
@@ -172,8 +121,10 @@ _dbus_cmutex_free_at_location (DBusCMutex **location_p)
void
_dbus_rmutex_lock (DBusRMutex *mutex)
{
- if (mutex && thread_init_generation == _dbus_current_generation)
- _dbus_platform_rmutex_lock (mutex);
+ if (mutex == NULL)
+ return;
+
+ _dbus_platform_rmutex_lock (mutex);
}
/**
@@ -184,8 +135,10 @@ _dbus_rmutex_lock (DBusRMutex *mutex)
void
_dbus_cmutex_lock (DBusCMutex *mutex)
{
- if (mutex && thread_init_generation == _dbus_current_generation)
- _dbus_platform_cmutex_lock (mutex);
+ if (mutex == NULL)
+ return;
+
+ _dbus_platform_cmutex_lock (mutex);
}
/**
@@ -196,8 +149,10 @@ _dbus_cmutex_lock (DBusCMutex *mutex)
void
_dbus_rmutex_unlock (DBusRMutex *mutex)
{
- if (mutex && thread_init_generation == _dbus_current_generation)
- _dbus_platform_rmutex_unlock (mutex);
+ if (mutex == NULL)
+ return;
+
+ _dbus_platform_rmutex_unlock (mutex);
}
/**
@@ -208,8 +163,10 @@ _dbus_rmutex_unlock (DBusRMutex *mutex)
void
_dbus_cmutex_unlock (DBusCMutex *mutex)
{
- if (mutex && thread_init_generation == _dbus_current_generation)
- _dbus_platform_cmutex_unlock (mutex);
+ if (mutex == NULL)
+ return;
+
+ _dbus_platform_cmutex_unlock (mutex);
}
/**
@@ -223,19 +180,17 @@ _dbus_cmutex_unlock (DBusCMutex *mutex)
DBusCondVar *
_dbus_condvar_new (void)
{
- if (thread_init_generation == _dbus_current_generation)
- return _dbus_platform_condvar_new ();
- else
- return _DBUS_DUMMY_CONDVAR;
+ if (!dbus_threads_init_default ())
+ return NULL;
+
+ return _dbus_platform_condvar_new ();
}
/**
* This does the same thing as _dbus_condvar_new. It however
* gives another level of indirection by allocating a pointer
- * to point to the condvar location. This allows the threading
- * module to swap out dummy condvars for a real condvar so libraries
- * can initialize threads even after the D-Bus API has been used.
+ * to point to the condvar location; this used to be useful.
*
* @returns the location of a new condvar or #NULL on OOM
*/
@@ -245,17 +200,7 @@ _dbus_condvar_new_at_location (DBusCondVar **location_p)
{
_dbus_assert (location_p != NULL);
- if (thread_init_generation == _dbus_current_generation)
- {
- *location_p = _dbus_condvar_new();
- }
- else
- {
- *location_p = _DBUS_DUMMY_CONDVAR;
-
- if (!_dbus_list_append (&uninitialized_condvar_list, location_p))
- *location_p = NULL;
- }
+ *location_p = _dbus_condvar_new();
}
@@ -266,14 +211,14 @@ _dbus_condvar_new_at_location (DBusCondVar **location_p)
void
_dbus_condvar_free (DBusCondVar *cond)
{
- if (cond && thread_init_generation == _dbus_current_generation)
- _dbus_platform_condvar_free (cond);
+ if (cond == NULL)
+ return;
+
+ _dbus_platform_condvar_free (cond);
}
/**
- * Frees a conditional variable and removes it from the
- * uninitialized_condvar_list;
- * does nothing if passed a #NULL pointer.
+ * Frees a condition variable; does nothing if passed a #NULL pointer.
*/
void
_dbus_condvar_free_at_location (DBusCondVar **location_p)
@@ -281,17 +226,8 @@ _dbus_condvar_free_at_location (DBusCondVar **location_p)
if (location_p == NULL)
return;
- if (thread_init_generation == _dbus_current_generation)
- {
- if (*location_p != NULL)
- _dbus_platform_condvar_free (*location_p);
- }
- else
- {
- _dbus_assert (*location_p == NULL || *location_p == _DBUS_DUMMY_CONDVAR);
-
- _dbus_list_remove (&uninitialized_condvar_list, location_p);
- }
+ if (*location_p != NULL)
+ _dbus_platform_condvar_free (*location_p);
}
/**
@@ -304,8 +240,10 @@ void
_dbus_condvar_wait (DBusCondVar *cond,
DBusCMutex *mutex)
{
- if (cond && mutex && thread_init_generation == _dbus_current_generation)
- _dbus_platform_condvar_wait (cond, mutex);
+ if (cond == NULL || mutex == NULL)
+ return;
+
+ _dbus_platform_condvar_wait (cond, mutex);
}
/**
@@ -324,11 +262,11 @@ _dbus_condvar_wait_timeout (DBusCondVar *cond,
DBusCMutex *mutex,
int timeout_milliseconds)
{
- if (cond && mutex && thread_init_generation == _dbus_current_generation)
- return _dbus_platform_condvar_wait_timeout (cond, mutex,
- timeout_milliseconds);
- else
+ if (cond == NULL || mutex == NULL)
return TRUE;
+
+ return _dbus_platform_condvar_wait_timeout (cond, mutex,
+ timeout_milliseconds);
}
/**
@@ -339,215 +277,83 @@ _dbus_condvar_wait_timeout (DBusCondVar *cond,
void
_dbus_condvar_wake_one (DBusCondVar *cond)
{
- if (cond && thread_init_generation == _dbus_current_generation)
- _dbus_platform_condvar_wake_one (cond);
+ if (cond == NULL)
+ return;
+
+ _dbus_platform_condvar_wake_one (cond);
}
+static DBusRMutex *global_locks[_DBUS_N_GLOBAL_LOCKS] = { NULL };
+
static void
-shutdown_global_locks (void *data)
+shutdown_global_locks (void *nil)
{
- DBusRMutex ***locks = data;
int i;
- i = 0;
- while (i < _DBUS_N_GLOBAL_LOCKS)
+ for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
{
- if (*(locks[i]) != NULL)
- _dbus_platform_rmutex_free (*(locks[i]));
-
- *(locks[i]) = NULL;
- ++i;
+ _dbus_assert (global_locks[i] != NULL);
+ _dbus_platform_rmutex_free (global_locks[i]);
+ global_locks[i] = NULL;
}
-
- dbus_free (locks);
-}
-
-static void
-shutdown_uninitialized_locks (void *data)
-{
- _dbus_list_clear (&uninitialized_rmutex_list);
- _dbus_list_clear (&uninitialized_cmutex_list);
- _dbus_list_clear (&uninitialized_condvar_list);
}
static dbus_bool_t
-init_uninitialized_locks (void)
+init_global_locks (void)
{
- DBusList *link;
-
- _dbus_assert (thread_init_generation != _dbus_current_generation);
-
- link = uninitialized_rmutex_list;
- while (link != NULL)
- {
- DBusRMutex **mp;
-
- mp = link->data;
- _dbus_assert (*mp == _DBUS_DUMMY_RMUTEX);
-
- *mp = _dbus_platform_rmutex_new ();
- if (*mp == NULL)
- goto fail_mutex;
-
- link = _dbus_list_get_next_link (&uninitialized_rmutex_list, link);
- }
-
- link = uninitialized_cmutex_list;
- while (link != NULL)
- {
- DBusCMutex **mp;
-
- mp = link->data;
- _dbus_assert (*mp == _DBUS_DUMMY_CMUTEX);
-
- *mp = _dbus_platform_cmutex_new ();
- if (*mp == NULL)
- goto fail_mutex;
-
- link = _dbus_list_get_next_link (&uninitialized_cmutex_list, link);
- }
+ int i;
+ dbus_bool_t ok;
- link = uninitialized_condvar_list;
- while (link != NULL)
+ for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
{
- DBusCondVar **cp;
-
- cp = (DBusCondVar **)link->data;
- _dbus_assert (*cp == _DBUS_DUMMY_CONDVAR);
+ _dbus_assert (global_locks[i] == NULL);
- *cp = _dbus_platform_condvar_new ();
- if (*cp == NULL)
- goto fail_condvar;
+ global_locks[i] = _dbus_platform_rmutex_new ();
- link = _dbus_list_get_next_link (&uninitialized_condvar_list, link);
+ if (global_locks[i] == NULL)
+ goto failed;
}
- _dbus_list_clear (&uninitialized_rmutex_list);
- _dbus_list_clear (&uninitialized_cmutex_list);
- _dbus_list_clear (&uninitialized_condvar_list);
+ _dbus_platform_rmutex_lock (global_locks[_DBUS_LOCK_shutdown_funcs]);
+ ok = _dbus_register_shutdown_func_unlocked (shutdown_global_locks, NULL);
+ _dbus_platform_rmutex_unlock (global_locks[_DBUS_LOCK_shutdown_funcs]);
- if (!_dbus_register_shutdown_func (shutdown_uninitialized_locks,
- NULL))
- goto fail_condvar;
+ if (!ok)
+ goto failed;
return TRUE;
- fail_condvar:
- link = uninitialized_condvar_list;
- while (link != NULL)
- {
- DBusCondVar **cp;
-
- cp = link->data;
-
- if (*cp != _DBUS_DUMMY_CONDVAR && *cp != NULL)
- _dbus_platform_condvar_free (*cp);
-
- *cp = _DBUS_DUMMY_CONDVAR;
-
- link = _dbus_list_get_next_link (&uninitialized_condvar_list, link);
- }
-
- fail_mutex:
- link = uninitialized_rmutex_list;
- while (link != NULL)
- {
- DBusRMutex **mp;
-
- mp = link->data;
-
- if (*mp != _DBUS_DUMMY_RMUTEX && *mp != NULL)
- _dbus_platform_rmutex_free (*mp);
-
- *mp = _DBUS_DUMMY_RMUTEX;
-
- link = _dbus_list_get_next_link (&uninitialized_rmutex_list, link);
- }
-
- link = uninitialized_cmutex_list;
- while (link != NULL)
+ failed:
+ for (i = i - 1; i >= 0; i--)
{
- DBusCMutex **mp;
-
- mp = link->data;
-
- if (*mp != _DBUS_DUMMY_CMUTEX && *mp != NULL)
- _dbus_platform_cmutex_free (*mp);
-
- *mp = _DBUS_DUMMY_CMUTEX;
-
- link = _dbus_list_get_next_link (&uninitialized_cmutex_list, link);
+ _dbus_platform_rmutex_free (global_locks[i]);
+ global_locks[i] = NULL;
}
return FALSE;
}
-static dbus_bool_t
-init_locks (void)
+dbus_bool_t
+_dbus_lock (DBusGlobalLock lock)
{
- int i;
- DBusRMutex ***dynamic_global_locks;
- DBusRMutex **global_locks[] = {
-#define LOCK_ADDR(name) (& _dbus_lock_##name)
- LOCK_ADDR (win_fds),
- LOCK_ADDR (sid_atom_cache),
- LOCK_ADDR (list),
- LOCK_ADDR (connection_slots),
- LOCK_ADDR (pending_call_slots),
- LOCK_ADDR (server_slots),
- LOCK_ADDR (message_slots),
-#if !DBUS_USE_SYNC
- LOCK_ADDR (atomic),
-#endif
- LOCK_ADDR (bus),
- LOCK_ADDR (bus_datas),
- LOCK_ADDR (shutdown_funcs),
- LOCK_ADDR (system_users),
- LOCK_ADDR (message_cache),
- LOCK_ADDR (shared_connections),
- LOCK_ADDR (machine_uuid)
-#undef LOCK_ADDR
- };
-
- _dbus_assert (_DBUS_N_ELEMENTS (global_locks) ==
- _DBUS_N_GLOBAL_LOCKS);
-
- i = 0;
-
- dynamic_global_locks = dbus_new (DBusRMutex**, _DBUS_N_GLOBAL_LOCKS);
- if (dynamic_global_locks == NULL)
- goto failed;
-
- while (i < _DBUS_N_ELEMENTS (global_locks))
- {
- *global_locks[i] = _dbus_platform_rmutex_new ();
-
- if (*global_locks[i] == NULL)
- goto failed;
+ _dbus_assert (lock >= 0);
+ _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS);
- dynamic_global_locks[i] = global_locks[i];
-
- ++i;
- }
-
- if (!_dbus_register_shutdown_func (shutdown_global_locks,
- dynamic_global_locks))
- goto failed;
+ if (thread_init_generation != _dbus_current_generation &&
+ !dbus_threads_init_default ())
+ return FALSE;
- if (!init_uninitialized_locks ())
- goto failed;
-
+ _dbus_platform_rmutex_lock (global_locks[lock]);
return TRUE;
+}
- failed:
- dbus_free (dynamic_global_locks);
-
- for (i = i - 1; i >= 0; i--)
- {
- _dbus_platform_rmutex_free (*global_locks[i]);
- *global_locks[i] = NULL;
- }
- return FALSE;
+void
+_dbus_unlock (DBusGlobalLock lock)
+{
+ _dbus_assert (lock >= 0);
+ _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS);
+
+ _dbus_platform_rmutex_unlock (global_locks[lock]);
}
/** @} */ /* end of internals */
@@ -584,14 +390,24 @@ init_locks (void)
dbus_bool_t
dbus_threads_init (const DBusThreadFunctions *functions)
{
+ _dbus_threads_lock_platform_specific ();
+
if (thread_init_generation == _dbus_current_generation)
- return TRUE;
+ {
+ _dbus_threads_unlock_platform_specific ();
+ return TRUE;
+ }
- if (!init_locks ())
- return FALSE;
+ if (!_dbus_threads_init_platform_specific() ||
+ !init_global_locks ())
+ {
+ _dbus_threads_unlock_platform_specific ();
+ return FALSE;
+ }
thread_init_generation = _dbus_current_generation;
-
+
+ _dbus_threads_unlock_platform_specific ();
return TRUE;
}
@@ -602,11 +418,16 @@ dbus_threads_init (const DBusThreadFunctions *functions)
/**
* Initializes threads. If this function is not called, the D-Bus
* library will not lock any data structures. If it is called, D-Bus
- * will do locking, at some cost in efficiency. Note that this
- * function must be called BEFORE the second thread is started.
+ * will do locking, at some cost in efficiency.
+ *
+ * Since D-Bus 1.7 it is safe to call this function from any thread,
+ * any number of times (but it must be called before any other
+ * libdbus API is used).
*
- * It's safe to call dbus_threads_init_default() as many times as you
- * want, but only the first time will have an effect.
+ * In D-Bus 1.6 or older, this function must be called in the main thread
+ * before any other thread starts. As a result, it is not sufficient to
+ * call this function in a library or plugin, unless the library or plugin
+ * imposes a similar requirement on its callers.
*
* dbus_shutdown() reverses the effects of this function when it
* resets all global state in libdbus.
@@ -616,18 +437,18 @@ dbus_threads_init (const DBusThreadFunctions *functions)
dbus_bool_t
dbus_threads_init_default (void)
{
- return _dbus_threads_init_platform_specific ();
+ return dbus_threads_init (NULL);
}
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
dbus_bool_t
_dbus_threads_init_debug (void)
{
- return _dbus_threads_init_platform_specific();
+ return dbus_threads_init (NULL);
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-transport-protected.h b/dbus/dbus-transport-protected.h
index 44b9d785..396f0ffd 100644
--- a/dbus/dbus-transport-protected.h
+++ b/dbus/dbus-transport-protected.h
@@ -111,7 +111,7 @@ struct DBusTransport
DBusFreeFunction free_windows_user_data; /**< Function to free windows_user_data */
unsigned int disconnected : 1; /**< #TRUE if we are disconnected. */
- unsigned int authenticated : 1; /**< Cache of auth state; use _dbus_transport_get_is_authenticated() to query value */
+ unsigned int authenticated : 1; /**< Cache of auth state; use _dbus_transport_peek_is_authenticated() to query value */
unsigned int send_credentials_pending : 1; /**< #TRUE if we need to send credentials */
unsigned int receive_credentials_pending : 1; /**< #TRUE if we need to receive credentials */
unsigned int is_server : 1; /**< #TRUE if on the server side */
diff --git a/dbus/dbus-transport-socket.c b/dbus/dbus-transport-socket.c
index 0673a8ce..774f4598 100644
--- a/dbus/dbus-transport-socket.c
+++ b/dbus/dbus-transport-socket.c
@@ -135,7 +135,7 @@ check_write_watch (DBusTransport *transport)
_dbus_transport_ref (transport);
- if (_dbus_transport_get_is_authenticated (transport))
+ if (_dbus_transport_try_to_authenticate (transport))
needed = _dbus_connection_has_messages_to_send_unlocked (transport->connection);
else
{
@@ -190,7 +190,7 @@ check_read_watch (DBusTransport *transport)
_dbus_transport_ref (transport);
- if (_dbus_transport_get_is_authenticated (transport))
+ if (_dbus_transport_try_to_authenticate (transport))
need_read_watch =
(_dbus_counter_get_size_value (transport->live_messages) < transport->max_live_messages_size) &&
(_dbus_counter_get_unix_fd_value (transport->live_messages) < transport->max_live_messages_unix_fds);
@@ -255,8 +255,7 @@ read_data_into_auth (DBusTransport *transport,
bytes_read = _dbus_read_socket (socket_transport->fd,
buffer, socket_transport->max_bytes_read_per_iteration);
- _dbus_auth_return_buffer (transport->auth, buffer,
- bytes_read > 0 ? bytes_read : 0);
+ _dbus_auth_return_buffer (transport->auth, buffer);
if (bytes_read > 0)
{
@@ -404,7 +403,7 @@ do_authentication (DBusTransport *transport,
oom = FALSE;
- orig_auth_state = _dbus_transport_get_is_authenticated (transport);
+ orig_auth_state = _dbus_transport_try_to_authenticate (transport);
/* This is essential to avoid the check_write_watch() at the end,
* we don't want to add a write watch in do_iteration before
@@ -419,7 +418,7 @@ do_authentication (DBusTransport *transport,
_dbus_transport_ref (transport);
- while (!_dbus_transport_get_is_authenticated (transport) &&
+ while (!_dbus_transport_try_to_authenticate (transport) &&
_dbus_transport_get_is_connected (transport))
{
if (!exchange_credentials (transport, do_reading, do_writing))
@@ -477,7 +476,7 @@ do_authentication (DBusTransport *transport,
out:
if (auth_completed)
- *auth_completed = (orig_auth_state != _dbus_transport_get_is_authenticated (transport));
+ *auth_completed = (orig_auth_state != _dbus_transport_try_to_authenticate (transport));
check_read_watch (transport);
check_write_watch (transport);
@@ -498,7 +497,7 @@ do_writing (DBusTransport *transport)
dbus_bool_t oom;
/* No messages without authentication! */
- if (!_dbus_transport_get_is_authenticated (transport))
+ if (!_dbus_transport_try_to_authenticate (transport))
{
_dbus_verbose ("Not authenticated, not writing anything\n");
return TRUE;
@@ -703,7 +702,7 @@ do_reading (DBusTransport *transport)
_dbus_verbose ("fd = %d\n",socket_transport->fd);
/* No messages without authentication! */
- if (!_dbus_transport_get_is_authenticated (transport))
+ if (!_dbus_transport_try_to_authenticate (transport))
return TRUE;
oom = FALSE;
@@ -748,29 +747,23 @@ do_reading (DBusTransport *transport)
if (bytes_read > 0)
{
- int orig_len;
-
_dbus_message_loader_get_buffer (transport->loader,
&buffer);
- orig_len = _dbus_string_get_length (buffer);
-
if (!_dbus_auth_decode_data (transport->auth,
&socket_transport->encoded_incoming,
buffer))
{
_dbus_verbose ("Out of memory decoding incoming data\n");
_dbus_message_loader_return_buffer (transport->loader,
- buffer,
- _dbus_string_get_length (buffer) - orig_len);
+ buffer);
oom = TRUE;
goto out;
}
_dbus_message_loader_return_buffer (transport->loader,
- buffer,
- _dbus_string_get_length (buffer) - orig_len);
+ buffer);
_dbus_string_set_length (&socket_transport->encoded_incoming, 0);
_dbus_string_compact (&socket_transport->encoded_incoming, 2048);
@@ -789,7 +782,7 @@ do_reading (DBusTransport *transport)
if (!_dbus_message_loader_get_unix_fds(transport->loader, &fds, &n_fds))
{
_dbus_verbose ("Out of memory reading file descriptors\n");
- _dbus_message_loader_return_buffer (transport->loader, buffer, 0);
+ _dbus_message_loader_return_buffer (transport->loader, buffer);
oom = TRUE;
goto out;
}
@@ -812,8 +805,7 @@ do_reading (DBusTransport *transport)
}
_dbus_message_loader_return_buffer (transport->loader,
- buffer,
- bytes_read < 0 ? 0 : bytes_read);
+ buffer);
}
if (bytes_read < 0)
@@ -1055,7 +1047,7 @@ socket_do_iteration (DBusTransport *transport,
poll_fd.fd = socket_transport->fd;
poll_fd.events = 0;
- if (_dbus_transport_get_is_authenticated (transport))
+ if (_dbus_transport_try_to_authenticate (transport))
{
/* This is kind of a hack; if we have stuff to write, then try
* to avoid the poll. This is probably about a 5% speedup on an
@@ -1299,7 +1291,7 @@ _dbus_transport_new_for_socket (int fd,
* @param host the host to connect to
* @param port the port to connect to
* @param family the address family to connect to
- * @param path to nonce file
+ * @param noncefile path to nonce file
* @param error location to store reason for failure.
* @returns a new transport, or #NULL on failure.
*/
@@ -1337,12 +1329,12 @@ _dbus_transport_new_for_tcp_socket (const char *host,
goto error;
if (family != NULL &&
- (!_dbus_string_append (&address, "family=") ||
+ (!_dbus_string_append (&address, ",family=") ||
!_dbus_string_append (&address, family)))
goto error;
if (noncefile != NULL &&
- (!_dbus_string_append (&address, "noncefile=") ||
+ (!_dbus_string_append (&address, ",noncefile=") ||
!_dbus_string_append (&address, noncefile)))
goto error;
diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c
index 6ba5c0b5..9a9fea50 100644
--- a/dbus/dbus-transport-unix.c
+++ b/dbus/dbus-transport-unix.c
@@ -412,7 +412,7 @@ _dbus_transport_open_platform_specific (DBusAddressEntry *entry,
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
dbus_bool_t
_dbus_transport_unix_test (void)
diff --git a/dbus/dbus-transport-win.c b/dbus/dbus-transport-win.c
index faaf1bd2..8fc15749 100644
--- a/dbus/dbus-transport-win.c
+++ b/dbus/dbus-transport-win.c
@@ -51,39 +51,8 @@ _dbus_transport_open_platform_specific (DBusAddressEntry *entry,
DBusTransport **transport_p,
DBusError *error)
{
- const char *method;
-
- const char *host = dbus_address_entry_get_value (entry, "host");
- const char *port = dbus_address_entry_get_value (entry, "port");
- const char *family = dbus_address_entry_get_value (entry, "family");
- const char *noncefile = dbus_address_entry_get_value (entry, "noncefile");
-
- method = dbus_address_entry_get_method (entry);
- _dbus_assert (method != NULL);
-
- if (strcmp (method, "nonce-tcp") != 0)
- {
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
- return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
- }
-
- if (port == NULL)
- {
- _dbus_set_bad_address (error, "nonce-tcp", "port", NULL);
- return DBUS_TRANSPORT_OPEN_BAD_ADDRESS;
- }
-
- *transport_p = _dbus_transport_new_for_tcp_socket (host, port, family, noncefile, error);
- if (*transport_p == NULL)
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- return DBUS_TRANSPORT_OPEN_DID_NOT_CONNECT;
- }
- else
- {
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
- return DBUS_TRANSPORT_OPEN_OK;
- }
+ /* currently no Windows-specific transports */
+ return DBUS_TRANSPORT_OPEN_NOT_HANDLED;
}
/** @} */
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c
index ba720f25..ecc31827 100644
--- a/dbus/dbus-transport.c
+++ b/dbus/dbus-transport.c
@@ -32,7 +32,7 @@
#include "dbus-credentials.h"
#include "dbus-mainloop.h"
#include "dbus-message.h"
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include "dbus-server-debug-pipe.h"
#endif
@@ -242,6 +242,7 @@ _dbus_transport_finalize_base (DBusTransport *transport)
* opened DBusTransport object. If it isn't, returns #NULL
* and sets @p error.
*
+ * @param address the address to be checked.
* @param error address where an error can be returned.
* @returns a new transport, or #NULL on failure.
*/
@@ -253,7 +254,6 @@ check_address (const char *address, DBusError *error)
int len, i;
_dbus_assert (address != NULL);
- _dbus_assert (*address != '\0');
if (!dbus_parse_address (address, &entries, &len, error))
return NULL; /* not a valid address */
@@ -273,6 +273,7 @@ check_address (const char *address, DBusError *error)
* Creates a new transport for the "autostart" method.
* This creates a client-side of a transport.
*
+ * @param scope scope of autolaunch (Windows only)
* @param error address where an error can be returned.
* @returns a new transport, or #NULL on failure.
*/
@@ -349,7 +350,7 @@ static const struct {
{ _dbus_transport_open_socket },
{ _dbus_transport_open_platform_specific },
{ _dbus_transport_open_autolaunch }
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
, { _dbus_transport_open_debug_pipe }
#endif
};
@@ -685,10 +686,33 @@ auth_via_default_rules (DBusTransport *transport)
return allow;
}
+/**
+ * Returns #TRUE if we have been authenticated. It will return #TRUE even if
+ * the transport is now disconnected, but was ever authenticated before
+ * disconnecting.
+ *
+ * This replaces the older _dbus_transport_get_is_authenticated() which
+ * had side-effects.
+ *
+ * @param transport the transport
+ * @returns whether we're authenticated
+ */
+dbus_bool_t
+_dbus_transport_peek_is_authenticated (DBusTransport *transport)
+{
+ return transport->authenticated;
+}
/**
- * Returns #TRUE if we have been authenticated. Will return #TRUE
- * even if the transport is disconnected.
+ * Returns #TRUE if we have been authenticated. It will return #TRUE even if
+ * the transport is now disconnected, but was ever authenticated before
+ * disconnecting.
+ *
+ * If we have not finished authenticating, but we have enough buffered input
+ * to finish the job, then this function will do so before it returns.
+ *
+ * This used to be called _dbus_transport_get_is_authenticated(), but that
+ * name seems inappropriate for a function with side-effects.
*
* @todo we drop connection->mutex when calling the unix_user_function,
* and windows_user_function, which may not be safe really.
@@ -697,7 +721,7 @@ auth_via_default_rules (DBusTransport *transport)
* @returns whether we're authenticated
*/
dbus_bool_t
-_dbus_transport_get_is_authenticated (DBusTransport *transport)
+_dbus_transport_try_to_authenticate (DBusTransport *transport)
{
if (transport->authenticated)
return TRUE;
@@ -1021,9 +1045,7 @@ recover_unused_bytes (DBusTransport *transport)
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
- buffer,
- _dbus_string_get_length (buffer) -
- orig_len);
+ buffer);
_dbus_auth_delete_unused_bytes (transport->auth);
@@ -1053,9 +1075,7 @@ recover_unused_bytes (DBusTransport *transport)
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
- buffer,
- _dbus_string_get_length (buffer) -
- orig_len);
+ buffer);
if (succeeded)
_dbus_auth_delete_unused_bytes (transport->auth);
@@ -1084,12 +1104,12 @@ _dbus_transport_get_dispatch_status (DBusTransport *transport)
_dbus_counter_get_unix_fd_value (transport->live_messages) >= transport->max_live_messages_unix_fds)
return DBUS_DISPATCH_COMPLETE; /* complete for now */
- if (!_dbus_transport_get_is_authenticated (transport))
+ if (!_dbus_transport_try_to_authenticate (transport))
{
if (_dbus_auth_do_work (transport->auth) ==
DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
return DBUS_DISPATCH_NEED_MEMORY;
- else if (!_dbus_transport_get_is_authenticated (transport))
+ else if (!_dbus_transport_try_to_authenticate (transport))
return DBUS_DISPATCH_COMPLETE;
}
@@ -1338,7 +1358,7 @@ _dbus_transport_get_unix_process_id (DBusTransport *transport,
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_UNIX_PROCESS_ID))
{
- *pid = _dbus_credentials_get_unix_pid (auth_identity);
+ *pid = _dbus_credentials_get_pid (auth_identity);
return TRUE;
}
else
diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h
index 4b821517..80fa24ef 100644
--- a/dbus/dbus-transport.h
+++ b/dbus/dbus-transport.h
@@ -38,7 +38,8 @@ DBusTransport* _dbus_transport_ref (DBusTransport
void _dbus_transport_unref (DBusTransport *transport);
void _dbus_transport_disconnect (DBusTransport *transport);
dbus_bool_t _dbus_transport_get_is_connected (DBusTransport *transport);
-dbus_bool_t _dbus_transport_get_is_authenticated (DBusTransport *transport);
+dbus_bool_t _dbus_transport_peek_is_authenticated (DBusTransport *transport);
+dbus_bool_t _dbus_transport_try_to_authenticate (DBusTransport *transport);
dbus_bool_t _dbus_transport_get_is_anonymous (DBusTransport *transport);
dbus_bool_t _dbus_transport_can_pass_unix_fd (DBusTransport *transport);
diff --git a/dbus/dbus-types.h b/dbus/dbus-types.h
index 57fc586a..021a55af 100644
--- a/dbus/dbus-types.h
+++ b/dbus/dbus-types.h
@@ -79,43 +79,23 @@ typedef dbus_uint32_t dbus_bool_t;
/**
* @typedef dbus_uint64_t
*
- * A 64-bit unsigned integer on all platforms that support it.
- * If supported, #DBUS_HAVE_INT64 will be defined.
- *
- * C99 requires a 64-bit type and most likely all interesting
- * compilers support one. GLib for example flat-out requires
- * a 64-bit type.
- *
- * You probably want to just assume #DBUS_HAVE_INT64 is always defined.
+ * A 64-bit unsigned integer.
*/
/**
* @typedef dbus_int64_t
*
- * A 64-bit signed integer on all platforms that support it.
- * If supported, #DBUS_HAVE_INT64 will be defined.
- *
- * C99 requires a 64-bit type and most likely all interesting
- * compilers support one. GLib for example flat-out requires
- * a 64-bit type.
- *
- * You probably want to just assume #DBUS_HAVE_INT64 is always defined.
+ * A 64-bit signed integer.
*/
/**
* @def DBUS_HAVE_INT64
*
- * Defined if 64-bit integers are available. Will be defined
- * on any platform you care about, unless you care about
- * some truly ancient UNIX, or some bizarre embedded platform.
+ * Always defined.
*
- * C99 requires a 64-bit type and most likely all interesting
- * compilers support one. GLib for example flat-out requires
- * a 64-bit type.
- *
- * You should feel comfortable ignoring this macro and just using
- * int64 unconditionally.
- *
+ * In older libdbus versions, this would be undefined if there was no
+ * 64-bit integer type on that platform. libdbus no longer supports
+ * such platforms.
*/
/**
@@ -136,7 +116,7 @@ typedef dbus_uint32_t dbus_bool_t;
/**
* An 8-byte struct you could use to access int64 without having
- * int64 support
+ * int64 support. Use #dbus_int64_t or #dbus_uint64_t instead.
*/
typedef struct
{
@@ -162,10 +142,8 @@ typedef union
dbus_int32_t i32; /**< as int32 */
dbus_uint32_t u32; /**< as int32 */
dbus_bool_t bool_val; /**< as boolean */
-#ifdef DBUS_HAVE_INT64
dbus_int64_t i64; /**< as int64 */
dbus_uint64_t u64; /**< as int64 */
-#endif
DBus8ByteStruct eight; /**< as 8-byte struct */
double dbl; /**< as double */
unsigned char byt; /**< as byte */
diff --git a/dbus/dbus-userdb-util.c b/dbus/dbus-userdb-util.c
index 16bf2291..888a23e9 100644
--- a/dbus/dbus-userdb-util.c
+++ b/dbus/dbus-userdb-util.c
@@ -21,6 +21,7 @@
*
*/
#include <config.h>
+#include <unistd.h>
#define DBUS_USERDB_INCLUDES_PRIVATE 1
#include "dbus-userdb.h"
#include "dbus-test.h"
@@ -29,7 +30,6 @@
#include <string.h>
#if HAVE_SYSTEMD
-#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
#endif
@@ -55,7 +55,8 @@ _dbus_is_console_user (dbus_uid_t uid,
dbus_bool_t result = FALSE;
#ifdef HAVE_SYSTEMD
- if (sd_booted () > 0)
+ /* check if we have logind */
+ if (access ("/run/systemd/seats/", F_OK) >= 0)
{
int r;
@@ -103,7 +104,11 @@ _dbus_is_console_user (dbus_uid_t uid,
#endif /* HAVE_CONSOLE_OWNER_FILE */
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ {
+ _DBUS_SET_OOM (error);
+ return FALSE;
+ }
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -157,7 +162,10 @@ _dbus_get_group_id (const DBusString *groupname,
{
DBusUserDatabase *db;
const DBusGroupInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -194,7 +202,10 @@ _dbus_get_user_id_and_primary_group (const DBusString *username,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -250,7 +261,6 @@ _dbus_user_database_lookup_group (DBusUserDatabase *db,
gid = n;
}
-#ifdef DBUS_ENABLE_USERDB_CACHE
if (gid != DBUS_GID_UNSET)
info = _dbus_hash_table_lookup_uintptr (db->groups, gid);
else
@@ -263,9 +273,6 @@ _dbus_user_database_lookup_group (DBusUserDatabase *db,
return info;
}
else
-#else
- if (1)
-#endif
{
if (gid != DBUS_GID_UNSET)
_dbus_verbose ("No cache for GID "DBUS_GID_FORMAT"\n",
@@ -387,7 +394,9 @@ _dbus_groups_from_uid (dbus_uid_t uid,
*group_ids = NULL;
*n_group_ids = 0;
- _dbus_user_database_lock_system ();
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -424,7 +433,7 @@ _dbus_groups_from_uid (dbus_uid_t uid,
}
/** @} */
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
#include <stdio.h>
/**
@@ -477,4 +486,4 @@ _dbus_userdb_test (const char *test_data_dir)
return TRUE;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c
index 4e8b39aa..52f927a3 100644
--- a/dbus/dbus-userdb.c
+++ b/dbus/dbus-userdb.c
@@ -144,7 +144,6 @@ _dbus_user_database_lookup (DBusUserDatabase *db,
uid = n;
}
-#ifdef DBUS_ENABLE_USERDB_CACHE
if (uid != DBUS_UID_UNSET)
info = _dbus_hash_table_lookup_uintptr (db->users, uid);
else
@@ -157,9 +156,6 @@ _dbus_user_database_lookup (DBusUserDatabase *db,
return info;
}
else
-#else
- if (1)
-#endif
{
if (uid != DBUS_UID_UNSET)
_dbus_verbose ("No cache for UID "DBUS_UID_FORMAT"\n",
@@ -306,11 +302,18 @@ init_system_db (void)
/**
* Locks global system user database.
*/
-void
+dbus_bool_t
_dbus_user_database_lock_system (void)
{
- _DBUS_LOCK (system_users);
- database_locked = TRUE;
+ if (_DBUS_LOCK (system_users))
+ {
+ database_locked = TRUE;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
/**
@@ -345,8 +348,12 @@ _dbus_user_database_get_system (void)
void
_dbus_user_database_flush_system (void)
{
- _dbus_user_database_lock_system ();
-
+ if (!_dbus_user_database_lock_system ())
+ {
+ /* nothing to flush */
+ return;
+ }
+
if (system_db != NULL)
_dbus_user_database_flush (system_db);
@@ -363,7 +370,9 @@ _dbus_user_database_flush_system (void)
dbus_bool_t
_dbus_username_from_current_process (const DBusString **username)
{
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
+
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@ -385,7 +394,9 @@ _dbus_username_from_current_process (const DBusString **username)
dbus_bool_t
_dbus_homedir_from_current_process (const DBusString **homedir)
{
- _dbus_user_database_lock_system ();
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
+
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@ -410,7 +421,10 @@ _dbus_homedir_from_username (const DBusString *username,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -449,7 +463,10 @@ _dbus_homedir_from_uid (dbus_uid_t uid,
{
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -496,7 +513,9 @@ _dbus_credentials_add_from_user (DBusCredentials *credentials,
DBusUserDatabase *db;
const DBusUserInfo *info;
- _dbus_user_database_lock_system ();
+ /* FIXME: this can't distinguish ENOMEM from other errors */
+ if (!_dbus_user_database_lock_system ())
+ return FALSE;
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -579,7 +598,7 @@ _dbus_user_database_flush (DBusUserDatabase *db)
_dbus_hash_table_remove_all(db->groups);
}
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
/**
* Increments refcount of user database.
* @param db the database
@@ -594,7 +613,7 @@ _dbus_user_database_ref (DBusUserDatabase *db)
return db;
}
-#endif /* DBUS_BUILD_TESTS */
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
/**
* Decrements refcount of user database.
diff --git a/dbus/dbus-userdb.h b/dbus/dbus-userdb.h
index cb49d9e7..d6b72d8c 100644
--- a/dbus/dbus-userdb.h
+++ b/dbus/dbus-userdb.h
@@ -86,7 +86,7 @@ void _dbus_group_info_free_allocated (DBusGroupInfo *info);
#endif /* DBUS_USERDB_INCLUDES_PRIVATE */
DBusUserDatabase* _dbus_user_database_get_system (void);
-void _dbus_user_database_lock_system (void);
+dbus_bool_t _dbus_user_database_lock_system (void) _DBUS_GNUC_WARN_UNUSED_RESULT;
void _dbus_user_database_unlock_system (void);
void _dbus_user_database_flush_system (void);
diff --git a/dbus/dbus-valgrind-internal.h b/dbus/dbus-valgrind-internal.h
index 55566ec0..6760b40d 100644
--- a/dbus/dbus-valgrind-internal.h
+++ b/dbus/dbus-valgrind-internal.h
@@ -32,10 +32,10 @@
# include <memcheck.h>
# include <valgrind.h>
#else
-# define VALGRIND_CREATE_MEMPOOL(_1, _2, _3) /* nothing */
-# define VALGRIND_DESTROY_MEMPOOL(_1) /* nothing */
-# define VALGRIND_MEMPOOL_ALLOC(_1, _2, _3) /* nothing */
-# define VALGRIND_MEMPOOL_FREE(_1, _2) /* nothing */
+# define VALGRIND_CREATE_MEMPOOL(_1, _2, _3) do { } while (0)
+# define VALGRIND_DESTROY_MEMPOOL(_1) do { } while (0)
+# define VALGRIND_MEMPOOL_ALLOC(_1, _2, _3) do { } while (0)
+# define VALGRIND_MEMPOOL_FREE(_1, _2) do { } while (0)
/* Recent gcc will warn if you have a statement that's just a macro
* expanding to (0), but not if you have an inline stub function that
diff --git a/dbus/dbus-watch.c b/dbus/dbus-watch.c
index b9f4ac23..b82c57d4 100644
--- a/dbus/dbus-watch.c
+++ b/dbus/dbus-watch.c
@@ -259,6 +259,25 @@ _dbus_watch_list_free (DBusWatchList *watch_list)
dbus_free (watch_list);
}
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+static const char*
+watch_flags_to_string (int flags)
+{
+ const char *watch_type;
+
+ if ((flags & DBUS_WATCH_READABLE) &&
+ (flags & DBUS_WATCH_WRITABLE))
+ watch_type = "readwrite";
+ else if (flags & DBUS_WATCH_READABLE)
+ watch_type = "read";
+ else if (flags & DBUS_WATCH_WRITABLE)
+ watch_type = "write";
+ else
+ watch_type = "not read or write";
+ return watch_type;
+}
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
+
/**
* Sets the watch functions. This function is the "backend"
* for dbus_connection_set_watch_functions() and
@@ -292,27 +311,9 @@ _dbus_watch_list_set_functions (DBusWatchList *watch_list,
DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
link);
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- {
- const char *watch_type;
- int flags;
-
- flags = dbus_watch_get_flags (link->data);
- if ((flags & DBUS_WATCH_READABLE) &&
- (flags & DBUS_WATCH_WRITABLE))
- watch_type = "readwrite";
- else if (flags & DBUS_WATCH_READABLE)
- watch_type = "read";
- else if (flags & DBUS_WATCH_WRITABLE)
- watch_type = "write";
- else
- watch_type = "not read or write";
-
- _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n",
- watch_type,
- dbus_watch_get_socket (link->data));
- }
-#endif /* DBUS_ENABLE_VERBOSE_MODE */
+ _dbus_verbose ("Adding a %s watch on fd %d using newly-set add watch function\n",
+ watch_flags_to_string (dbus_watch_get_flags (link->data)),
+ dbus_watch_get_socket (link->data));
if (!(* add_function) (link->data, data))
{
diff --git a/dbus/sd-daemon.c b/dbus/sd-daemon.c
index 9c23b917..485b3010 100644
--- a/dbus/sd-daemon.c
+++ b/dbus/sd-daemon.c
@@ -25,14 +25,14 @@
***/
#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+# define _GNU_SOURCE
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
-#include <sys/fcntl.h>
+#include <fcntl.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <errno.h>
@@ -40,10 +40,28 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stddef.h>
+#include <limits.h>
+
+#if defined(__linux__) && !defined(SD_DAEMON_DISABLE_MQ)
+# include <mqueue.h>
+#endif
#include "sd-daemon.h"
-int sd_listen_fds(int unset_environment) {
+#if (__GNUC__ >= 4)
+# ifdef SD_EXPORT_SYMBOLS
+/* Export symbols */
+# define _sd_export_ __attribute__ ((visibility("default")))
+# else
+/* Don't export the symbols */
+# define _sd_export_ __attribute__ ((visibility("hidden")))
+# endif
+#else
+# define _sd_export_
+#endif
+
+_sd_export_ int sd_listen_fds(int unset_environment) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
return 0;
@@ -53,7 +71,8 @@ int sd_listen_fds(int unset_environment) {
char *p = NULL;
unsigned long l;
- if (!(e = getenv("LISTEN_PID"))) {
+ e = getenv("LISTEN_PID");
+ if (!e) {
r = 0;
goto finish;
}
@@ -61,12 +80,12 @@ int sd_listen_fds(int unset_environment) {
errno = 0;
l = strtoul(e, &p, 10);
- if (errno != 0) {
+ if (errno > 0) {
r = -errno;
goto finish;
}
- if (!p || *p || l <= 0) {
+ if (!p || p == e || *p || l <= 0) {
r = -EINVAL;
goto finish;
}
@@ -77,7 +96,8 @@ int sd_listen_fds(int unset_environment) {
goto finish;
}
- if (!(e = getenv("LISTEN_FDS"))) {
+ e = getenv("LISTEN_FDS");
+ if (!e) {
r = 0;
goto finish;
}
@@ -85,12 +105,12 @@ int sd_listen_fds(int unset_environment) {
errno = 0;
l = strtoul(e, &p, 10);
- if (errno != 0) {
+ if (errno > 0) {
r = -errno;
goto finish;
}
- if (!p || *p) {
+ if (!p || p == e || *p) {
r = -EINVAL;
goto finish;
}
@@ -98,7 +118,8 @@ int sd_listen_fds(int unset_environment) {
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
int flags;
- if ((flags = fcntl(fd, F_GETFD)) < 0) {
+ flags = fcntl(fd, F_GETFD);
+ if (flags < 0) {
r = -errno;
goto finish;
}
@@ -124,13 +145,12 @@ finish:
#endif
}
-int sd_is_fifo(int fd, const char *path) {
+_sd_export_ int sd_is_fifo(int fd, const char *path) {
struct stat st_fd;
if (fd < 0)
return -EINVAL;
- memset(&st_fd, 0, sizeof(st_fd));
if (fstat(fd, &st_fd) < 0)
return -errno;
@@ -140,7 +160,6 @@ int sd_is_fifo(int fd, const char *path) {
if (path) {
struct stat st_path;
- memset(&st_path, 0, sizeof(st_path));
if (stat(path, &st_path) < 0) {
if (errno == ENOENT || errno == ENOTDIR)
@@ -157,6 +176,42 @@ int sd_is_fifo(int fd, const char *path) {
return 1;
}
+_sd_export_ int sd_is_special(int fd, const char *path) {
+ struct stat st_fd;
+
+ if (fd < 0)
+ return -EINVAL;
+
+ if (fstat(fd, &st_fd) < 0)
+ return -errno;
+
+ if (!S_ISREG(st_fd.st_mode) && !S_ISCHR(st_fd.st_mode))
+ return 0;
+
+ if (path) {
+ struct stat st_path;
+
+ if (stat(path, &st_path) < 0) {
+
+ if (errno == ENOENT || errno == ENOTDIR)
+ return 0;
+
+ return -errno;
+ }
+
+ if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode))
+ return
+ st_path.st_dev == st_fd.st_dev &&
+ st_path.st_ino == st_fd.st_ino;
+ else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode))
+ return st_path.st_rdev == st_fd.st_rdev;
+ else
+ return 0;
+ }
+
+ return 1;
+}
+
static int sd_is_socket_internal(int fd, int type, int listening) {
struct stat st_fd;
@@ -208,21 +263,19 @@ union sockaddr_union {
struct sockaddr_storage storage;
};
-int sd_is_socket(int fd, int family, int type, int listening) {
+_sd_export_ int sd_is_socket(int fd, int family, int type, int listening) {
int r;
if (family < 0)
return -EINVAL;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
if (family > 0) {
- union sockaddr_union sockaddr;
- socklen_t l;
-
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -236,20 +289,18 @@ int sd_is_socket(int fd, int family, int type, int listening) {
return 1;
}
-int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
- union sockaddr_union sockaddr;
- socklen_t l;
+_sd_export_ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
int r;
if (family != 0 && family != AF_INET && family != AF_INET6)
return -EINVAL;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
-
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -281,17 +332,15 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
return 1;
}
-int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
- union sockaddr_union sockaddr;
- socklen_t l;
+_sd_export_ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
+ union sockaddr_union sockaddr = {};
+ socklen_t l = sizeof(sockaddr);
int r;
- if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ r = sd_is_socket_internal(fd, type, listening);
+ if (r <= 0)
return r;
- memset(&sockaddr, 0, sizeof(sockaddr));
- l = sizeof(sockaddr);
-
if (getsockname(fd, &sockaddr.sa, &l) < 0)
return -errno;
@@ -302,29 +351,66 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
return 0;
if (path) {
- if (length <= 0)
+ if (length == 0)
length = strlen(path);
- if (length <= 0)
+ if (length == 0)
/* Unnamed socket */
- return l == sizeof(sa_family_t);
+ return l == offsetof(struct sockaddr_un, sun_path);
if (path[0])
/* Normal path socket */
return
- (l >= sizeof(sa_family_t) + length + 1) &&
+ (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
memcmp(path, sockaddr.un.sun_path, length+1) == 0;
else
/* Abstract namespace socket */
return
- (l == sizeof(sa_family_t) + length) &&
+ (l == offsetof(struct sockaddr_un, sun_path) + length) &&
memcmp(path, sockaddr.un.sun_path, length) == 0;
}
return 1;
}
-int sd_notify(int unset_environment, const char *state) {
+_sd_export_ int sd_is_mq(int fd, const char *path) {
+#if !defined(__linux__) || defined(SD_DAEMON_DISABLE_MQ)
+ return 0;
+#else
+ struct mq_attr attr;
+
+ if (fd < 0)
+ return -EINVAL;
+
+ if (mq_getattr(fd, &attr) < 0)
+ return -errno;
+
+ if (path) {
+ char fpath[PATH_MAX];
+ struct stat a, b;
+
+ if (path[0] != '/')
+ return -EINVAL;
+
+ if (fstat(fd, &a) < 0)
+ return -errno;
+
+ strncpy(stpcpy(fpath, "/dev/mqueue"), path, sizeof(fpath) - 12);
+ fpath[sizeof(fpath)-1] = 0;
+
+ if (stat(fpath, &b) < 0)
+ return -errno;
+
+ if (a.st_dev != b.st_dev ||
+ a.st_ino != b.st_ino)
+ return 0;
+ }
+
+ return 1;
+#endif
+}
+
+_sd_export_ int sd_notify(int unset_environment, const char *state) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
return 0;
#else
@@ -339,7 +425,8 @@ int sd_notify(int unset_environment, const char *state) {
goto finish;
}
- if (!(e = getenv("NOTIFY_SOCKET")))
+ e = getenv("NOTIFY_SOCKET");
+ if (!e)
return 0;
/* Must be an abstract socket, or an absolute path */
@@ -348,7 +435,8 @@ int sd_notify(int unset_environment, const char *state) {
goto finish;
}
- if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
+ fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+ if (fd < 0) {
r = -errno;
goto finish;
}
@@ -366,7 +454,7 @@ int sd_notify(int unset_environment, const char *state) {
memset(&msghdr, 0, sizeof(msghdr));
msghdr.msg_name = &sockaddr;
- msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e);
+ msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
msghdr.msg_namelen = sizeof(struct sockaddr_un);
@@ -392,7 +480,7 @@ finish:
#endif
}
-int sd_notifyf(int unset_environment, const char *format, ...) {
+_sd_export_ int sd_notifyf(int unset_environment, const char *format, ...) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
return 0;
#else
@@ -414,22 +502,19 @@ int sd_notifyf(int unset_environment, const char *format, ...) {
#endif
}
-int sd_booted(void) {
+_sd_export_ int sd_booted(void) {
#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
return 0;
#else
+ struct stat st;
- struct stat a, b;
-
- /* We simply test whether the systemd cgroup hierarchy is
- * mounted */
-
- if (lstat("/sys/fs/cgroup", &a) < 0)
- return 0;
+ /* We test whether the runtime unit file directory has been
+ * created. This takes place in mount-setup.c, so is
+ * guaranteed to happen very early during boot. */
- if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
+ if (lstat("/run/systemd/system/", &st) < 0)
return 0;
- return a.st_dev != b.st_dev;
+ return !!S_ISDIR(st.st_mode);
#endif
}
diff --git a/dbus/sd-daemon.h b/dbus/sd-daemon.h
index c68c96d2..fb7456d5 100644
--- a/dbus/sd-daemon.h
+++ b/dbus/sd-daemon.h
@@ -58,21 +58,21 @@ extern "C" {
You may find an up-to-date version of these source files online:
- http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h
- http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c
+ http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h
+ http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c
This should compile on non-Linux systems, too, but with the
exception of the sd_is_xxx() calls all functions will become NOPs.
- See sd-daemon(7) for more information.
+ See sd-daemon(3) for more information.
*/
+#ifndef _sd_printf_attr_
#if __GNUC__ >= 4
#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
-#define _sd_hidden_ __attribute__ ((visibility("hidden")))
#else
#define _sd_printf_attr_(a,b)
-#define _sd_hidden_
+#endif
#endif
/*
@@ -109,7 +109,7 @@ extern "C" {
See sd_listen_fds(3) for more information.
*/
-int sd_listen_fds(int unset_environment) _sd_hidden_;
+int sd_listen_fds(int unset_environment);
/*
Helper call for identifying a passed file descriptor. Returns 1 if
@@ -121,7 +121,19 @@ int sd_listen_fds(int unset_environment) _sd_hidden_;
See sd_is_fifo(3) for more information.
*/
-int sd_is_fifo(int fd, const char *path) _sd_hidden_;
+int sd_is_fifo(int fd, const char *path);
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is a special character device on the file
+ system stored under the specified path, 0 otherwise.
+ If path is NULL a path name check will not be done and the call
+ only verifies if the file descriptor refers to a special character.
+ Returns a negative errno style error code on failure.
+
+ See sd_is_special(3) for more information.
+*/
+int sd_is_special(int fd, const char *path);
/*
Helper call for identifying a passed file descriptor. Returns 1 if
@@ -137,7 +149,7 @@ int sd_is_fifo(int fd, const char *path) _sd_hidden_;
See sd_is_socket(3) for more information.
*/
-int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
+int sd_is_socket(int fd, int family, int type, int listening);
/*
Helper call for identifying a passed file descriptor. Returns 1 if
@@ -151,7 +163,7 @@ int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
See sd_is_socket_inet(3) for more information.
*/
-int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) _sd_hidden_;
+int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
/*
Helper call for identifying a passed file descriptor. Returns 1 if
@@ -167,17 +179,25 @@ int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port
See sd_is_socket_unix(3) for more information.
*/
-int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_;
+int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is a POSIX Message Queue of the specified name,
+ 0 otherwise. If path is NULL a message queue name check is not
+ done. Returns a negative errno style error code on failure.
+*/
+int sd_is_mq(int fd, const char *path);
/*
Informs systemd about changed daemon state. This takes a number of
- newline seperated environment-style variable assignments in a
+ newline separated environment-style variable assignments in a
string. The following variables are known:
READY=1 Tells systemd that daemon startup is finished (only
relevant for services of Type=notify). The passed
argument is a boolean "1" or "0". Since there is
- little value in signalling non-readiness the only
+ little value in signaling non-readiness the only
value daemons should send is "READY=1".
STATUS=... Passes a single-line status string back to systemd
@@ -197,8 +217,13 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
MAINPID=... The main pid of a daemon, in case systemd did not
fork off the process itself. Example: "MAINPID=4711"
+ WATCHDOG=1 Tells systemd to update the watchdog timestamp.
+ Services using this feature should do this in
+ regular intervals. A watchdog framework can use the
+ timestamps to detect failed services.
+
Daemons can choose to send additional variables. However, it is
- recommened to prefix variable names not listed above with X_.
+ recommended to prefix variable names not listed above with X_.
Returns a negative errno-style error code on failure. Returns > 0
if systemd could be notified, 0 if it couldn't possibly because
@@ -213,7 +238,7 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
See sd_notify(3) for more information.
*/
-int sd_notify(int unset_environment, const char *state) _sd_hidden_;
+int sd_notify(int unset_environment, const char *state);
/*
Similar to sd_notify() but takes a format string.
@@ -235,7 +260,7 @@ int sd_notify(int unset_environment, const char *state) _sd_hidden_;
See sd_notifyf(3) for more information.
*/
-int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_;
+int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3);
/*
Returns > 0 if the system was booted with systemd. Returns < 0 on
@@ -244,11 +269,11 @@ int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(
fine. You should NOT protect them with a call to this function. Also
note that this function checks whether the system, not the user
session is controlled by systemd. However the functions above work
- for both session and system services.
+ for both user and system services.
See sd_booted(3) for more information.
*/
-int sd_booted(void) _sd_hidden_;
+int sd_booted(void);
#ifdef __cplusplus
}
diff --git a/doc/.gitignore b/doc/.gitignore
index 1afe0141..708fe36f 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -2,6 +2,8 @@
.libs
Makefile
Makefile.in
+*.1
+*.1.xml
*.1.html
*.lo
*.la
@@ -12,7 +14,6 @@ dbus-specification.html
dbus-test-plan.html
dbus-tutorial.html
dbus-faq.html
-dbus-daemon.1
dbus-docs
dbus-docs.tar.gz
doxygen.stamp
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 591efc99..b9a4c106 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,28 +1,22 @@
apidir = @htmldir@/api
-# automake normally assumes that man pages are generated files;
-# these ones aren't, so we need the dist_ prefix to say that they're
-# their own source code
-dist_man1_MANS = \
+man_pages = \
dbus-cleanup-sockets.1 \
+ dbus-daemon.1 \
dbus-launch.1 \
dbus-monitor.1 \
+ dbus-run-session.1 \
dbus-send.1 \
- dbus-uuidgen.1
+ dbus-uuidgen.1 \
+ $(NULL)
-# on the other hand, this one is generated
-man1_MANS = \
- dbus-daemon.1
+MAN_XML_FILES = $(patsubst %.1,%.1.xml,$(man_pages))
-MAN_IN_FILES = dbus-daemon.1.in
+if DBUS_XML_DOCS_ENABLED
+man1_MANS = $(man_pages)
+endif
-MAN_HTML_FILES = \
- dbus-cleanup-sockets.1.html \
- dbus-daemon.1.html \
- dbus-launch.1.html \
- dbus-monitor.1.html \
- dbus-send.1.html \
- dbus-uuidgen.1.html
+MAN_HTML_FILES = $(patsubst %.1,%.1.html,$(man_pages))
DTDS = \
busconfig.dtd \
@@ -43,8 +37,7 @@ STATIC_DOCS = \
EXTRA_DIST = \
file-boilerplate.c \
doxygen_to_devhelp.xsl \
- $(STATIC_DOCS) \
- $(MAN_IN_FILES)
+ $(STATIC_DOCS)
html_DATA =
@@ -59,27 +52,22 @@ STATIC_HTML = \
dist_html_DATA += $(STATIC_HTML)
-# we distribute these in the tarball so users don't necessarily need xmlto
-dist_html_DATA += $(XMLTO_OUTPUT)
-
-XMLTO_OUTPUT= \
+XMLTO_HTML = \
dbus-faq.html \
dbus-specification.html \
dbus-test-plan.html \
- dbus-tutorial.html
+ dbus-tutorial.html \
+ $(MAN_HTML_FILES) \
+ $(NULL)
if DBUS_XML_DOCS_ENABLED
-dbus-specification.html: dbus-specification.xml
- $(XMLTO) html-nochunks $<
-
-dbus-test-plan.html: dbus-test-plan.xml
- $(XMLTO) html-nochunks $<
+html_DATA += $(XMLTO_HTML)
-dbus-tutorial.html: dbus-tutorial.xml
+%.html: %.xml
$(XMLTO) html-nochunks $<
-dbus-faq.html: dbus-faq.xml
- $(XMLTO) html-nochunks $<
+%.1: %.1.xml
+ $(XMLTO) man $<
endif
if DBUS_DOXYGEN_DOCS_ENABLED
@@ -106,6 +94,7 @@ uninstall-local::
rm -f $(DESTDIR)$(apidir)/*.html
rm -f $(DESTDIR)$(apidir)/*.png
rm -f $(DESTDIR)$(apidir)/*.css
+ rm -f $(DESTDIR)$(apidir)/*.js
rm -f $(DESTDIR)$(htmldir)/*.html
rm -f $(DESTDIR)$(docdir)/*.txt
rm -f $(DESTDIR)$(htmldir)/*.png
@@ -114,13 +103,6 @@ uninstall-local::
rmdir $(DESTDIR)$(apidir)
endif
-if DBUS_HAVE_MAN2HTML
-html_DATA += $(MAN_HTML_FILES)
-
-%.1.html: %.1
- $(AM_V_GEN)( $(MAN2HTML) < $< > $@.tmp && mv $@.tmp $@ )
-endif
-
if DBUS_CAN_UPLOAD_DOCS
BONUS_FILES = \
$(top_srcdir)/README \
@@ -130,14 +112,15 @@ BONUS_FILES = \
$(top_srcdir)/COPYING \
$(top_srcdir)/ChangeLog
-dbus-docs: $(STATIC_DOCS) $(dist_doc_DATA) $(dist_html_DATA) $(MAN_HTML_FILES) $(BONUS_FILES) doxygen.stamp
+dbus-docs: $(STATIC_DOCS) $(MAN_XML_FILES) $(dist_doc_DATA) $(dist_html_DATA) $(MAN_HTML_FILES) $(BONUS_FILES) doxygen.stamp $(XMLTO_HTML)
$(AM_V_at)rm -rf $@ $@.tmp
$(AM_V_GEN)$(MKDIR_P) $@.tmp/api
$(AM_V_at)cd $(srcdir) && cp $(STATIC_DOCS) @abs_builddir@/$@.tmp
$(AM_V_at)cd $(srcdir) && cp $(dist_doc_DATA) @abs_builddir@/$@.tmp
$(AM_V_at)cd $(srcdir) && cp $(STATIC_HTML) @abs_builddir@/$@.tmp
- $(AM_V_at)cp $(XMLTO_OUTPUT) @abs_builddir@/$@.tmp
+ $(AM_V_at)cp $(XMLTO_HTML) @abs_builddir@/$@.tmp
$(AM_V_at)cp $(MAN_HTML_FILES) @abs_builddir@/$@.tmp
+ $(AM_V_at)cp $(MAN_XML_FILES) @abs_builddir@/$@.tmp
$(AM_V_at)cp $(BONUS_FILES) @abs_builddir@/$@.tmp
$(AM_V_at)cp -r api/html @abs_builddir@/$@.tmp/api
$(AM_V_at)mv $@.tmp $@
@@ -164,12 +147,15 @@ maintainer-upload-docs:
@false
endif
+CLEANFILES = \
+ $(man1_MANS) \
+ $(MAN_XML_FILES) \
+ $(XMLTO_HTML) \
+ $(NULL)
+
clean-local:
rm -f $(html_DATA)
rm -rf api
rm -rf dbus-docs dbus-docs.tmp
rm -f *.1.html
rm -f doxygen.stamp
-
-maintainer-clean-local:
- rm -f $(XMLTO_OUTPUT)
diff --git a/doc/dbus-cleanup-sockets.1 b/doc/dbus-cleanup-sockets.1
deleted file mode 100644
index a062d498..00000000
--- a/doc/dbus-cleanup-sockets.1
+++ /dev/null
@@ -1,43 +0,0 @@
-.\"
-.\" dbus\-cleanup\-sockets manual page.
-.\" Copyright (C) 2003 Red Hat, Inc.
-.\"
-.TH dbus\-cleanup\-sockets 1
-.SH NAME
-dbus\-cleanup\-sockets \- clean up leftover sockets in a directory
-.SH SYNOPSIS
-.PP
-.B dbus\-cleanup\-sockets [DIRECTORY]
-
-.SH DESCRIPTION
-
-The \fIdbus\-cleanup\-sockets\fP command cleans up unused D\-Bus
-connection sockets. See http://www.freedesktop.org/software/dbus/ for
-more information about the big picture.
-
-.PP
-If given no arguments, \fIdbus\-cleanup\-sockets\fP cleans up sockets
-in the standard default socket directory for the
-per\-user\-login\-session message bus; this is usually /tmp.
-Optionally, you can pass a different directory on the command line.
-
-.PP
-On Linux, this program is essentially useless, because D\-Bus defaults
-to using "abstract sockets" that exist only in memory and don't have a
-corresponding file in /tmp.
-
-.PP
-On most other flavors of UNIX, it's possible for the socket files to
-leak when programs using D\-Bus exit abnormally or without closing
-their D\-Bus connections. Thus, it might be interesting to run
-dbus\-cleanup\-sockets in a cron job to mop up any leaked sockets.
-Or you can just ignore the leaked sockets, they aren't really hurting
-anything, other than cluttering the output of "ls /tmp"
-
-.SH AUTHOR
-dbus\-cleanup\-sockets was adapted by Havoc Pennington from
-linc\-cleanup\-sockets written by Michael Meeks.
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/doc/dbus-cleanup-sockets.1.xml.in b/doc/dbus-cleanup-sockets.1.xml.in
new file mode 100644
index 00000000..6d98083d
--- /dev/null
+++ b/doc/dbus-cleanup-sockets.1.xml.in
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<refentry id='dbuscleanupsockets1'>
+
+<!-- dbus&bsol;-cleanup&bsol;-sockets manual page.
+ Copyright (C) 2003 Red Hat, Inc. -->
+
+<refmeta>
+<refentrytitle>dbus-cleanup-sockets</refentrytitle>
+<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>dbus-cleanup-sockets</refname>
+<refpurpose>clean up leftover sockets in a directory</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+<refsynopsisdiv id='synopsis'>
+<cmdsynopsis>
+ <command>dbus-cleanup-sockets</command> <arg choice='opt'><replaceable>DIRECTORY</replaceable></arg>
+ <sbr/>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<refsect1 id='description'><title>DESCRIPTION</title>
+<para>The <command>dbus-cleanup-sockets</command> command cleans up unused D-Bus
+connection sockets. See <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for
+more information about the big picture.</para>
+
+
+<para>If given no arguments, <command>dbus-cleanup-sockets</command> cleans up sockets
+in the standard default socket directory for the
+per-user-login-session message bus; this is usually /tmp.
+Optionally, you can pass a different directory on the command line.</para>
+
+
+<para>On Linux, this program is essentially useless, because D-Bus defaults
+to using "abstract sockets" that exist only in memory and don't have a
+corresponding file in /tmp.</para>
+
+
+<para>On most other flavors of UNIX, it's possible for the socket files to
+leak when programs using D-Bus exit abnormally or without closing
+their D-Bus connections. Thus, it might be interesting to run
+dbus-cleanup-sockets in a cron job to mop up any leaked sockets.
+Or you can just ignore the leaked sockets, they aren't really hurting
+anything, other than cluttering the output of "ls /tmp"</para>
+
+</refsect1>
+
+<refsect1 id='author'><title>AUTHOR</title>
+<para>dbus-cleanup-sockets was adapted by Havoc Pennington from
+linc-cleanup-sockets written by Michael Meeks.</para>
+
+</refsect1>
+
+<refsect1 id='bugs'><title>BUGS</title>
+<para>Please send bug reports to the D-Bus mailing list or bug tracker,
+see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
+</refsect1>
+</refentry>
diff --git a/doc/dbus-daemon.1.in b/doc/dbus-daemon.1.in
deleted file mode 100644
index 53856e91..00000000
--- a/doc/dbus-daemon.1.in
+++ /dev/null
@@ -1,766 +0,0 @@
-.\"
-.\" dbus\-daemon manual page.
-.\" Copyright (C) 2003,2008 Red Hat, Inc.
-.\"
-.TH dbus\-daemon 1
-.SH NAME
-dbus\-daemon \- Message bus daemon
-.SH SYNOPSIS
-.PP
-.B dbus\-daemon
-dbus\-daemon [\-\-version] [\-\-session] [\-\-system] [\-\-config\-file=FILE]
-[\-\-print\-address[=DESCRIPTOR]] [\-\-print\-pid[=DESCRIPTOR]] [\-\-fork]
-
-.SH DESCRIPTION
-\fIdbus\-daemon\fP is the D\-Bus message bus daemon. See
-http://www.freedesktop.org/software/dbus/ for more information about
-the big picture. D\-Bus is first a library that provides one\-to\-one
-communication between any two applications; \fIdbus\-daemon\fP is an
-application that uses this library to implement a message bus
-daemon. Multiple programs connect to the message bus daemon and can
-exchange messages with one another.
-.PP
-There are two standard message bus instances: the systemwide message bus
-(installed on many systems as the "messagebus" init service) and the
-per\-user\-login\-session message bus (started each time a user logs in).
-\fIdbus\-daemon\fP is used for both of these instances, but with
-a different configuration file.
-.PP
-The \-\-session option is equivalent to
-"\-\-config\-file=@EXPANDED_SYSCONFDIR@/dbus\-1/session.conf" and the \-\-system
-option is equivalent to
-"\-\-config\-file=@EXPANDED_SYSCONFDIR@/dbus\-1/system.conf". By creating
-additional configuration files and using the \-\-config\-file option,
-additional special\-purpose message bus daemons could be created.
-.PP
-The systemwide daemon is normally launched by an init script,
-standardly called simply "messagebus".
-.PP
-The systemwide daemon is largely used for broadcasting system events,
-such as changes to the printer queue, or adding/removing devices.
-.PP
-The per\-session daemon is used for various interprocess communication
-among desktop applications (however, it is not tied to X or the GUI
-in any way).
-.PP
-SIGHUP will cause the D\-Bus daemon to PARTIALLY reload its
-configuration file and to flush its user/group information caches. Some
-configuration changes would require kicking all apps off the bus; so they will
-only take effect if you restart the daemon. Policy changes should take effect
-with SIGHUP.
-
-.SH OPTIONS
-The following options are supported:
-.TP
-.I "\-\-config\-file=FILE"
-Use the given configuration file.
-.TP
-.I "\-\-fork"
-Force the message bus to fork and become a daemon, even if
-the configuration file does not specify that it should.
-In most contexts the configuration file already gets this
-right, though.
-.I "\-\-nofork"
-Force the message bus not to fork and become a daemon, even if
-the configuration file specifies that it should.
-.TP
-.I "\-\-print\-address[=DESCRIPTOR]"
-Print the address of the message bus to standard output, or
-to the given file descriptor. This is used by programs that
-launch the message bus.
-.TP
-.I "\-\-print\-pid[=DESCRIPTOR]"
-Print the process ID of the message bus to standard output, or
-to the given file descriptor. This is used by programs that
-launch the message bus.
-.TP
-.I "\-\-session"
-Use the standard configuration file for the per\-login\-session message
-bus.
-.TP
-.I "\-\-system"
-Use the standard configuration file for the systemwide message bus.
-.TP
-.I "\-\-version"
-Print the version of the daemon.
-.TP
-.I "\-\-introspect"
-Print the introspection information for all D\-Bus internal interfaces.
-.TP
-.I "\-\-address[=ADDRESS]"
-Set the address to listen on. This option overrides the address
-configured in the configuration file.
-.TP
-.I "\-\-systemd\-activation"
-Enable systemd\-style service activation. Only useful in conjunction
-with the systemd system and session manager on Linux.
-.TP
-.I "\-\-nopidfile"
-Don't write a PID file even if one is configured in the configuration
-files.
-
-.SH CONFIGURATION FILE
-
-A message bus daemon has a configuration file that specializes it
-for a particular application. For example, one configuration
-file might set up the message bus to be a systemwide message bus,
-while another might set it up to be a per\-user\-login\-session bus.
-.PP
-The configuration file also establishes resource limits, security
-parameters, and so forth.
-.PP
-The configuration file is not part of any interoperability
-specification and its backward compatibility is not guaranteed; this
-document is documentation, not specification.
-.PP
-The standard systemwide and per\-session message bus setups are
-configured in the files "@EXPANDED_SYSCONFDIR@/dbus\-1/system.conf" and
-"@EXPANDED_SYSCONFDIR@/dbus\-1/session.conf". These files normally
-<include> a system\-local.conf or session\-local.conf; you can put local
-overrides in those files to avoid modifying the primary configuration
-files.
-
-.PP
-The configuration file is an XML document. It must have the following
-doctype declaration:
-.nf
-
- <!DOCTYPE busconfig PUBLIC "\-//freedesktop//DTD D\-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-
-.fi
-
-.PP
-The following elements may be present in the configuration file.
-
-.TP
-.I "<busconfig>"
-
-.PP
-Root element.
-
-.TP
-.I "<type>"
-
-.PP
-The well\-known type of the message bus. Currently known values are
-"system" and "session"; if other values are set, they should be
-either added to the D\-Bus specification, or namespaced. The last
-<type> element "wins" (previous values are ignored). This element
-only controls which message bus specific environment variables are
-set in activated clients. Most of the policy that distinguishes a
-session bus from the system bus is controlled from the other elements
-in the configuration file.
-
-.PP
-If the well\-known type of the message bus is "session", then the
-DBUS_STARTER_BUS_TYPE environment variable will be set to "session"
-and the DBUS_SESSION_BUS_ADDRESS environment variable will be set
-to the address of the session bus. Likewise, if the type of the
-message bus is "system", then the DBUS_STARTER_BUS_TYPE environment
-variable will be set to "system" and the DBUS_SESSION_BUS_ADDRESS
-environment variable will be set to the address of the system bus
-(which is normally well known anyway).
-
-.PP
-Example: <type>session</type>
-
-.TP
-.I "<include>"
-
-.PP
-Include a file <include>filename.conf</include> at this point. If the
-filename is relative, it is located relative to the configuration file
-doing the including.
-
-.PP
-<include> has an optional attribute "ignore_missing=(yes|no)"
-which defaults to "no" if not provided. This attribute
-controls whether it's a fatal error for the included file
-to be absent.
-
-.TP
-.I "<includedir>"
-
-.PP
-Include all files in <includedir>foo.d</includedir> at this
-point. Files in the directory are included in undefined order.
-Only files ending in ".conf" are included.
-
-.PP
-This is intended to allow extension of the system bus by particular
-packages. For example, if CUPS wants to be able to send out
-notification of printer queue changes, it could install a file to
-@EXPANDED_SYSCONFDIR@/dbus\-1/system.d that allowed all apps to receive
-this message and allowed the printer daemon user to send it.
-
-.TP
-.I "<user>"
-
-.PP
-The user account the daemon should run as, as either a username or a
-UID. If the daemon cannot change to this UID on startup, it will exit.
-If this element is not present, the daemon will not change or care
-about its UID.
-
-.PP
-The last <user> entry in the file "wins", the others are ignored.
-
-.PP
-The user is changed after the bus has completed initialization. So
-sockets etc. will be created before changing user, but no data will be
-read from clients before changing user. This means that sockets
-and PID files can be created in a location that requires root
-privileges for writing.
-
-.TP
-.I "<fork>"
-
-.PP
-If present, the bus daemon becomes a real daemon (forks
-into the background, etc.). This is generally used
-rather than the \-\-fork command line option.
-
-.TP
-.I "<keep_umask>"
-
-.PP
-If present, the bus daemon keeps its original umask when forking.
-This may be useful to avoid affecting the behavior of child processes.
-
-.TP
-.I "<listen>"
-
-.PP
-Add an address that the bus should listen on. The
-address is in the standard D\-Bus format that contains
-a transport name plus possible parameters/options.
-
-.PP
-Example: <listen>unix:path=/tmp/foo</listen>
-
-.PP
-Example: <listen>tcp:host=localhost,port=1234</listen>
-
-.PP
-If there are multiple <listen> elements, then the bus listens
-on multiple addresses. The bus will pass its address to
-started services or other interested parties with
-the last address given in <listen> first. That is,
-apps will try to connect to the last <listen> address first.
-
-.PP
-tcp sockets can accept IPv4 addresses, IPv6 addresses or hostnames.
-If a hostname resolves to multiple addresses, the server will bind
-to all of them. The family=ipv4 or family=ipv6 options can be used
-to force it to bind to a subset of addresses
-
-.PP
-Example: <listen>tcp:host=localhost,port=0,family=ipv4</listen>
-
-.PP
-A special case is using a port number of zero (or omitting the port),
-which means to choose an available port selected by the operating
-system. The port number chosen can be obtained with the
-\-\-print\-address command line parameter and will be present in other
-cases where the server reports its own address, such as when
-DBUS_SESSION_BUS_ADDRESS is set.
-
-.PP
-Example: <listen>tcp:host=localhost,port=0</listen>
-
-.PP
-tcp addresses also allow a bind=hostname option, which will override
-the host option specifying what address to bind to, without changing
-the address reported by the bus. The bind option can also take a
-special name '*' to cause the bus to listen on all local address
-(INADDR_ANY). The specified host should be a valid name of the local
-machine or weird stuff will happen.
-
-.PP
-Example: <listen>tcp:host=localhost,bind=*,port=0</listen>
-
-.TP
-.I "<auth>"
-
-.PP
-Lists permitted authorization mechanisms. If this element doesn't
-exist, then all known mechanisms are allowed. If there are multiple
-<auth> elements, all the listed mechanisms are allowed. The order in
-which mechanisms are listed is not meaningful.
-
-.PP
-Example: <auth>EXTERNAL</auth>
-
-.PP
-Example: <auth>DBUS_COOKIE_SHA1</auth>
-
-.TP
-.I "<servicedir>"
-
-.PP
-Adds a directory to scan for .service files. Directories are
-scanned starting with the last to appear in the config file
-(the first .service file found that provides a particular
-service will be used).
-
-.PP
-Service files tell the bus how to automatically start a program.
-They are primarily used with the per\-user\-session bus,
-not the systemwide bus.
-
-.TP
-.I "<standard_session_servicedirs/>"
-
-.PP
-<standard_session_servicedirs/> is equivalent to specifying a series
-of <servicedir/> elements for each of the data directories in the "XDG
-Base Directory Specification" with the subdirectory "dbus\-1/services",
-so for example "/usr/share/dbus\-1/services" would be among the
-directories searched.
-
-.PP
-The "XDG Base Directory Specification" can be found at
-http://freedesktop.org/wiki/Standards/basedir\-spec if it hasn't moved,
-otherwise try your favorite search engine.
-
-.PP
-The <standard_session_servicedirs/> option is only relevant to the
-per\-user\-session bus daemon defined in
-@EXPANDED_SYSCONFDIR@/dbus\-1/session.conf. Putting it in any other
-configuration file would probably be nonsense.
-
-.TP
-.I "<standard_system_servicedirs/>"
-
-.PP
-<standard_system_servicedirs/> specifies the standard system\-wide
-activation directories that should be searched for service files.
-This option defaults to @EXPANDED_DATADIR@/dbus\-1/system\-services.
-
-.PP
-The <standard_system_servicedirs/> option is only relevant to the
-per\-system bus daemon defined in
-@EXPANDED_SYSCONFDIR@/dbus\-1/system.conf. Putting it in any other
-configuration file would probably be nonsense.
-
-.TP
-.I "<servicehelper/>"
-
-.PP
-<servicehelper/> specifies the setuid helper that is used to launch
-system daemons with an alternate user. Typically this should be
-the dbus\-daemon\-launch\-helper executable in located in libexec.
-
-.PP
-The <servicehelper/> option is only relevant to the per\-system bus daemon
-defined in @EXPANDED_SYSCONFDIR@/dbus\-1/system.conf. Putting it in any other
-configuration file would probably be nonsense.
-
-.TP
-.I "<limit>"
-
-.PP
-<limit> establishes a resource limit. For example:
-.nf
- <limit name="max_message_size">64</limit>
- <limit name="max_completed_connections">512</limit>
-.fi
-
-.PP
-The name attribute is mandatory.
-Available limit names are:
-.nf
- "max_incoming_bytes" : total size in bytes of messages
- incoming from a single connection
- "max_incoming_unix_fds" : total number of unix fds of messages
- incoming from a single connection
- "max_outgoing_bytes" : total size in bytes of messages
- queued up for a single connection
- "max_outgoing_unix_fds" : total number of unix fds of messages
- queued up for a single connection
- "max_message_size" : max size of a single message in
- bytes
- "max_message_unix_fds" : max unix fds of a single message
- "service_start_timeout" : milliseconds (thousandths) until
- a started service has to connect
- "auth_timeout" : milliseconds (thousandths) a
- connection is given to
- authenticate
- "max_completed_connections" : max number of authenticated connections
- "max_incomplete_connections" : max number of unauthenticated
- connections
- "max_connections_per_user" : max number of completed connections from
- the same user
- "max_pending_service_starts" : max number of service launches in
- progress at the same time
- "max_names_per_connection" : max number of names a single
- connection can own
- "max_match_rules_per_connection": max number of match rules for a single
- connection
- "max_replies_per_connection" : max number of pending method
- replies per connection
- (number of calls\-in\-progress)
- "reply_timeout" : milliseconds (thousandths)
- until a method call times out
-.fi
-
-.PP
-The max incoming/outgoing queue sizes allow a new message to be queued
-if one byte remains below the max. So you can in fact exceed the max
-by max_message_size.
-
-.PP
-max_completed_connections divided by max_connections_per_user is the
-number of users that can work together to denial\-of\-service all other users by using
-up all connections on the systemwide bus.
-
-.PP
-Limits are normally only of interest on the systemwide bus, not the user session
-buses.
-
-.TP
-.I "<policy>"
-
-.PP
-The <policy> element defines a security policy to be applied to a particular
-set of connections to the bus. A policy is made up of
-<allow> and <deny> elements. Policies are normally used with the systemwide bus;
-they are analogous to a firewall in that they allow expected traffic
-and prevent unexpected traffic.
-
-.PP
-Currently, the system bus has a default\-deny policy for sending method calls
-and owning bus names. Everything else, in particular reply messages, receive
-checks, and signals has a default allow policy.
-
-.PP
-In general, it is best to keep system services as small, targeted programs which
-run in their own process and provide a single bus name. Then, all that is needed
-is an <allow> rule for the "own" permission to let the process claim the bus
-name, and a "send_destination" rule to allow traffic from some or all uids to
-your service.
-
-.PP
-The <policy> element has one of four attributes:
-.nf
- context="(default|mandatory)"
- at_console="(true|false)"
- user="username or userid"
- group="group name or gid"
-.fi
-
-.PP
-Policies are applied to a connection as follows:
-.nf
- \- all context="default" policies are applied
- \- all group="connection's user's group" policies are applied
- in undefined order
- \- all user="connection's auth user" policies are applied
- in undefined order
- \- all at_console="true" policies are applied
- \- all at_console="false" policies are applied
- \- all context="mandatory" policies are applied
-.fi
-
-.PP
-Policies applied later will override those applied earlier,
-when the policies overlap. Multiple policies with the same
-user/group/context are applied in the order they appear
-in the config file.
-
-.TP
-.I "<deny>"
-.I "<allow>"
-
-.PP
-A <deny> element appears below a <policy> element and prohibits some
-action. The <allow> element makes an exception to previous <deny>
-statements, and works just like <deny> but with the inverse meaning.
-
-.PP
-The possible attributes of these elements are:
-.nf
- send_interface="interface_name"
- send_member="method_or_signal_name"
- send_error="error_name"
- send_destination="name"
- send_type="method_call" | "method_return" | "signal" | "error"
- send_path="/path/name"
-
- receive_interface="interface_name"
- receive_member="method_or_signal_name"
- receive_error="error_name"
- receive_sender="name"
- receive_type="method_call" | "method_return" | "signal" | "error"
- receive_path="/path/name"
-
- send_requested_reply="true" | "false"
- receive_requested_reply="true" | "false"
-
- eavesdrop="true" | "false"
-
- own="name"
- own_prefix="name"
- user="username"
- group="groupname"
-.fi
-
-.PP
-Examples:
-.nf
- <deny send_destination="org.freedesktop.Service" send_interface="org.freedesktop.System" send_member="Reboot"/>
- <deny send_destination="org.freedesktop.System"/>
- <deny receive_sender="org.freedesktop.System"/>
- <deny user="john"/>
- <deny group="enemies"/>
-.fi
-
-.PP
-The <deny> element's attributes determine whether the deny "matches" a
-particular action. If it matches, the action is denied (unless later
-rules in the config file allow it).
-.PP
-send_destination and receive_sender rules mean that messages may not be
-sent to or received from the *owner* of the given name, not that
-they may not be sent *to that name*. That is, if a connection
-owns services A, B, C, and sending to A is denied, sending to B or C
-will not work either.
-.PP
-The other send_* and receive_* attributes are purely textual/by\-value
-matches against the given field in the message header.
-.PP
-"Eavesdropping" occurs when an application receives a message that
-was explicitly addressed to a name the application does not own, or
-is a reply to such a message. Eavesdropping thus only applies to
-messages that are addressed to services and replies to such messages
-(i.e. it does not apply to signals).
-.PP
-For <allow>, eavesdrop="true" indicates that the rule matches even
-when eavesdropping. eavesdrop="false" is the default and means that
-the rule only allows messages to go to their specified recipient.
-For <deny>, eavesdrop="true" indicates that the rule matches
-only when eavesdropping. eavesdrop="false" is the default for <deny>
-also, but here it means that the rule applies always, even when
-not eavesdropping. The eavesdrop attribute can only be combined with
-send and receive rules (with send_* and receive_* attributes).
-.PP
-The [send|receive]_requested_reply attribute works similarly to the eavesdrop
-attribute. It controls whether the <deny> or <allow> matches a reply
-that is expected (corresponds to a previous method call message).
-This attribute only makes sense for reply messages (errors and method
-returns), and is ignored for other message types.
-
-.PP
-For <allow>, [send|receive]_requested_reply="true" is the default and indicates that
-only requested replies are allowed by the
-rule. [send|receive]_requested_reply="false" means that the rule allows any reply
-even if unexpected.
-
-.PP
-For <deny>, [send|receive]_requested_reply="false" is the default but indicates that
-the rule matches only when the reply was not
-requested. [send|receive]_requested_reply="true" indicates that the rule applies
-always, regardless of pending reply state.
-
-.PP
-user and group denials mean that the given user or group may
-not connect to the message bus.
-
-.PP
-For "name", "username", "groupname", etc.
-the character "*" can be substituted, meaning "any." Complex globs
-like "foo.bar.*" aren't allowed for now because they'd be work to
-implement and maybe encourage sloppy security anyway.
-
-.PP
-<allow own_prefix="a.b"/> allows you to own the name "a.b" or any
-name whose first dot-separated elements are "a.b": in particular,
-you can own "a.b.c" or "a.b.c.d", but not "a.bc" or "a.c".
-This is useful when services like Telepathy and ReserveDevice
-define a meaning for subtrees of well-known names, such as
-org.freedesktop.Telepathy.ConnectionManager.(anything)
-and org.freedesktop.ReserveDevice1.(anything).
-
-.PP
-It does not make sense to deny a user or group inside a <policy>
-for a user or group; user/group denials can only be inside
-context="default" or context="mandatory" policies.
-
-.PP
-A single <deny> rule may specify combinations of attributes such as
-send_destination and send_interface and send_type. In this case, the
-denial applies only if both attributes match the message being denied.
-e.g. <deny send_interface="foo.bar" send_destination="foo.blah"/> would
-deny messages with the given interface AND the given bus name.
-To get an OR effect you specify multiple <deny> rules.
-
-.PP
-You can't include both send_ and receive_ attributes on the same
-rule, since "whether the message can be sent" and "whether it can be
-received" are evaluated separately.
-
-.PP
-Be careful with send_interface/receive_interface, because the
-interface field in messages is optional. In particular, do NOT
-specify <deny send_interface="org.foo.Bar"/>! This will cause
-no\-interface messages to be blocked for all services, which is
-almost certainly not what you intended. Always use rules of
-the form: <deny send_interface="org.foo.Bar" send_destination="org.foo.Service"/>
-
-.TP
-.I "<selinux>"
-
-.PP
-The <selinux> element contains settings related to Security Enhanced Linux.
-More details below.
-
-.TP
-.I "<associate>"
-
-.PP
-An <associate> element appears below an <selinux> element and
-creates a mapping. Right now only one kind of association is possible:
-.nf
- <associate own="org.freedesktop.Foobar" context="foo_t"/>
-.fi
-
-.PP
-This means that if a connection asks to own the name
-"org.freedesktop.Foobar" then the source context will be the context
-of the connection and the target context will be "foo_t" \- see the
-short discussion of SELinux below.
-
-.PP
-Note, the context here is the target context when requesting a name,
-NOT the context of the connection owning the name.
-
-.PP
-There's currently no way to set a default for owning any name, if
-we add this syntax it will look like:
-.nf
- <associate own="*" context="foo_t"/>
-.fi
-If you find a reason this is useful, let the developers know.
-Right now the default will be the security context of the bus itself.
-
-.PP
-If two <associate> elements specify the same name, the element
-appearing later in the configuration file will be used.
-
-.SH SELinux
-
-.PP
-See http://www.nsa.gov/selinux/ for full details on SELinux. Some useful excerpts:
-
-.IP "" 8
-Every subject (process) and object (e.g. file, socket, IPC object,
-etc) in the system is assigned a collection of security attributes,
-known as a security context. A security context contains all of the
-security attributes associated with a particular subject or object
-that are relevant to the security policy.
-
-.IP "" 8
-In order to better encapsulate security contexts and to provide
-greater efficiency, the policy enforcement code of SELinux typically
-handles security identifiers (SIDs) rather than security contexts. A
-SID is an integer that is mapped by the security server to a security
-context at runtime.
-
-.IP "" 8
-When a security decision is required, the policy enforcement code
-passes a pair of SIDs (typically the SID of a subject and the SID of
-an object, but sometimes a pair of subject SIDs or a pair of object
-SIDs), and an object security class to the security server. The object
-security class indicates the kind of object, e.g. a process, a regular
-file, a directory, a TCP socket, etc.
-
-.IP "" 8
-Access decisions specify whether or not a permission is granted for a
-given pair of SIDs and class. Each object class has a set of
-associated permissions defined to control operations on objects with
-that class.
-
-.PP
-D\-Bus performs SELinux security checks in two places.
-
-.PP
-First, any time a message is routed from one connection to another
-connection, the bus daemon will check permissions with the security context of
-the first connection as source, security context of the second connection
-as target, object class "dbus" and requested permission "send_msg".
-
-.PP
-If a security context is not available for a connection
-(impossible when using UNIX domain sockets), then the target
-context used is the context of the bus daemon itself.
-There is currently no way to change this default, because we're
-assuming that only UNIX domain sockets will be used to
-connect to the systemwide bus. If this changes, we'll
-probably add a way to set the default connection context.
-
-.PP
-Second, any time a connection asks to own a name,
-the bus daemon will check permissions with the security
-context of the connection as source, the security context specified
-for the name in the config file as target, object
-class "dbus" and requested permission "acquire_svc".
-
-.PP
-The security context for a bus name is specified with the
-<associate> element described earlier in this document.
-If a name has no security context associated in the
-configuration file, the security context of the bus daemon
-itself will be used.
-
-.SH DEBUGGING
-
-.PP
-If you're trying to figure out where your messages are going or why
-you aren't getting messages, there are several things you can try.
-.PP
-Remember that the system bus is heavily locked down and if you
-haven't installed a security policy file to allow your message
-through, it won't work. For the session bus, this is not a concern.
-.PP
-The simplest way to figure out what's happening on the bus is to run
-the \fIdbus\-monitor\fP program, which comes with the D\-Bus
-package. You can also send test messages with \fIdbus\-send\fP. These
-programs have their own man pages.
-.PP
-If you want to know what the daemon itself is doing, you might consider
-running a separate copy of the daemon to test against. This will allow you
-to put the daemon under a debugger, or run it with verbose output, without
-messing up your real session and system daemons.
-.PP
-To run a separate test copy of the daemon, for example you might open a terminal
-and type:
-.nf
- DBUS_VERBOSE=1 dbus\-daemon \-\-session \-\-print\-address
-.fi
-.PP
-The test daemon address will be printed when the daemon starts. You will need
-to copy\-and\-paste this address and use it as the value of the
-DBUS_SESSION_BUS_ADDRESS environment variable when you launch the applications
-you want to test. This will cause those applications to connect to your
-test bus instead of the DBUS_SESSION_BUS_ADDRESS of your real session bus.
-.PP
-DBUS_VERBOSE=1 will have NO EFFECT unless your copy of D\-Bus
-was compiled with verbose mode enabled. This is not recommended in
-production builds due to performance impact. You may need to rebuild
-D\-Bus if your copy was not built with debugging in mind. (DBUS_VERBOSE
-also affects the D\-Bus library and thus applications using D\-Bus; it may
-be useful to see verbose output on both the client side and from the daemon.)
-.PP
-If you want to get fancy, you can create a custom bus
-configuration for your test bus (see the session.conf and system.conf
-files that define the two default configurations for example). This
-would allow you to specify a different directory for .service files,
-for example.
-
-.SH AUTHOR
-See http://www.freedesktop.org/software/dbus/doc/AUTHORS
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/cmake/bus/dbus-daemon.xml b/doc/dbus-daemon.1.xml.in
index f331699c..7b7f4a1b 100644
--- a/cmake/bus/dbus-daemon.xml
+++ b/doc/dbus-daemon.1.xml.in
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<!-- lifted from troff+man by doclifter -->
-<refentry id='dbus-daemon'>
-<!-- -->
-<!-- dbus\-daemon manual page. -->
-<!-- Copyright (C) 2003 Red Hat, Inc. -->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<refentry id='dbusdaemon1'>
+
+<!-- dbus&bsol;-daemon manual page.
+ Copyright (C) 2003,2008 Red Hat, Inc. -->
<refmeta>
<refentrytitle>dbus-daemon</refentrytitle>
<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
</refmeta>
-<refnamediv id='name'>
+<refnamediv>
<refname>dbus-daemon</refname>
<refpurpose>Message bus daemon</refpurpose>
</refnamediv>
@@ -41,35 +43,29 @@ application that uses this library to implement a message bus
daemon. Multiple programs connect to the message bus daemon and can
exchange messages with one another.</para>
-
-<para>There are two standard message bus instances: the systemwide message bus
-(installed on many systems as the "messagebus" init service) and the
+<para>There are two standard message bus instances: the systemwide message bus
+(installed on many systems as the "messagebus" init service) and the
per-user-login-session message bus (started each time a user logs in).
-<command>dbus-daemon</command> is used for both of these instances, but with
+<command>dbus-daemon</command> is used for both of these instances, but with
a different configuration file.</para>
-
<para>The --session option is equivalent to
-"--config-file=/etc/dbus-1/session.conf" and the --system
+"--config-file=@EXPANDED_SYSCONFDIR@/dbus-1/session.conf" and the --system
option is equivalent to
-"--config-file=/etc/dbus-1/system.conf". By creating
+"--config-file=@EXPANDED_SYSCONFDIR@/dbus-1/system.conf". By creating
additional configuration files and using the --config-file option,
additional special-purpose message bus daemons could be created.</para>
+<para>The systemwide daemon is normally launched by an init script,
+standardly called simply "messagebus".</para>
-<para>The systemwide daemon is normally launched by an init script,
-standardly called simply "messagebus".</para>
-
-
-<para>The systemwide daemon is largely used for broadcasting system events,
+<para>The systemwide daemon is largely used for broadcasting system events,
such as changes to the printer queue, or adding/removing devices.</para>
-
-<para>The per-session daemon is used for various interprocess communication
-among desktop applications (however, it is not tied to X or the GUI
+<para>The per-session daemon is used for various interprocess communication
+among desktop applications (however, it is not tied to X or the GUI
in any way).</para>
-
<para>SIGHUP will cause the D-Bus daemon to PARTIALLY reload its
configuration file and to flush its user/group information caches. Some
configuration changes would require kicking all apps off the bus; so they will
@@ -90,25 +86,34 @@ with SIGHUP.</para>
<varlistentry>
<term><option>--fork</option></term>
<listitem>
-<para>Force the message bus to fork and become a daemon, even if
+<para>Force the message bus to fork and become a daemon, even if
the configuration file does not specify that it should.
In most contexts the configuration file already gets this
-right, though.</para>
+right, though. This option is not supported on Windows.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--nofork</option></term>
+ <listitem>
+ <para>Force the message bus not to fork and become a daemon, even if
+ the configuration file specifies that it should. On Windows,
+ the dbus-daemon never forks, so this option is allowed but does
+ nothing.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--print-address[=DESCRIPTOR]</option></term>
<listitem>
-<para>Print the address of the message bus to standard output, or
-to the given file descriptor. This is used by programs that
+<para>Print the address of the message bus to standard output, or
+to the given file descriptor. This is used by programs that
launch the message bus.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--print-pid[=DESCRIPTOR]</option></term>
<listitem>
-<para>Print the process ID of the message bus to standard output, or
-to the given file descriptor. This is used by programs that
+<para>Print the process ID of the message bus to standard output, or
+to the given file descriptor. This is used by programs that
launch the message bus.</para>
</listitem>
</varlistentry>
@@ -129,6 +134,33 @@ bus.</para>
<term><option>--version</option></term>
<listitem>
<para>Print the version of the daemon.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--introspect</option></term>
+ <listitem>
+<para>Print the introspection information for all D-Bus internal interfaces.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--address[=ADDRESS]</option></term>
+ <listitem>
+<para>Set the address to listen on. This option overrides the address
+configured in the configuration file.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--systemd-activation</option></term>
+ <listitem>
+<para>Enable systemd-style service activation. Only useful in conjunction
+with the systemd system and session manager on Linux.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--nopidfile</option></term>
+ <listitem>
+<para>Don't write a PID file even if one is configured in the configuration
+files.</para>
</listitem>
</varlistentry>
@@ -137,23 +169,20 @@ bus.</para>
<refsect1 id='configuration_file'><title>CONFIGURATION FILE</title>
<para>A message bus daemon has a configuration file that specializes it
-for a particular application. For example, one configuration
-file might set up the message bus to be a systemwide message bus,
+for a particular application. For example, one configuration
+file might set up the message bus to be a systemwide message bus,
while another might set it up to be a per-user-login-session bus.</para>
-
<para>The configuration file also establishes resource limits, security
parameters, and so forth.</para>
-
<para>The configuration file is not part of any interoperability
specification and its backward compatibility is not guaranteed; this
document is documentation, not specification.</para>
-
<para>The standard systemwide and per-session message bus setups are
-configured in the files "/etc/dbus-1/system.conf" and
-"/etc/dbus-1/session.conf". These files normally
+configured in the files "@EXPANDED_SYSCONFDIR@/dbus-1/system.conf" and
+"@EXPANDED_SYSCONFDIR@/dbus-1/session.conf". These files normally
&lt;include&gt; a system-local.conf or session-local.conf; you can put local
overrides in those files to avoid modifying the primary configuration
files.</para>
@@ -171,43 +200,50 @@ doctype declaration:</para>
<para>The following elements may be present in the configuration file.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;busconfig&gt;</emphasis></term>
- <listitem>
-<para></para>
- </listitem>
- </varlistentry>
-</variablelist>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;busconfig&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>Root element.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;type&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;type&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>The well-known type of the message bus. Currently known values are
"system" and "session"; if other values are set, they should be
either added to the D-Bus specification, or namespaced. The last
-&lt;type&gt; element "wins" (previous values are ignored).</para>
+&lt;type&gt; element "wins" (previous values are ignored). This element
+only controls which message bus specific environment variables are
+set in activated clients. Most of the policy that distinguishes a
+session bus from the system bus is controlled from the other elements
+in the configuration file.</para>
+
+
+<para>If the well-known type of the message bus is "session", then the
+DBUS_STARTER_BUS_TYPE environment variable will be set to "session"
+and the DBUS_SESSION_BUS_ADDRESS environment variable will be set
+to the address of the session bus. Likewise, if the type of the
+message bus is "system", then the DBUS_STARTER_BUS_TYPE environment
+variable will be set to "system" and the DBUS_SESSION_BUS_ADDRESS
+environment variable will be set to the address of the system bus
+(which is normally well known anyway).</para>
<para>Example: &lt;type&gt;session&lt;/type&gt;</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;include&gt;</emphasis></term>
- <listitem>
-<para></para>
- </listitem>
- </varlistentry>
-</variablelist>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;include&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>Include a file &lt;include&gt;filename.conf&lt;/include&gt; at this point. If the
filename is relative, it is located relative to the configuration file
@@ -215,19 +251,16 @@ doing the including.</para>
<para>&lt;include&gt; has an optional attribute "ignore_missing=(yes|no)"
-which defaults to "no" if not provided. This attribute
-controls whether it's a fatal error for the included file
+which defaults to "no" if not provided. This attribute
+controls whether it's a fatal error for the included file
to be absent.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;includedir&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;includedir&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>Include all files in &lt;includedir&gt;foo.d&lt;/includedir&gt; at this
point. Files in the directory are included in undefined order.
@@ -237,18 +270,15 @@ Only files ending in ".conf" are included.</para>
<para>This is intended to allow extension of the system bus by particular
packages. For example, if CUPS wants to be able to send out
notification of printer queue changes, it could install a file to
-/etc/dbus-1/system.d that allowed all apps to receive
+@EXPANDED_SYSCONFDIR@/dbus-1/system.d that allowed all apps to receive
this message and allowed the printer daemon user to send it.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;user&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;user&gt;</emphasis></para></listitem>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+
+</itemizedlist>
<para>The user account the daemon should run as, as either a username or a
UID. If the daemon cannot change to this UID on startup, it will exit.
@@ -261,97 +291,159 @@ about its UID.</para>
<para>The user is changed after the bus has completed initialization. So
sockets etc. will be created before changing user, but no data will be
-read from clients before changing user. This means that sockets
-and PID files can be created in a location that requires root
+read from clients before changing user. This means that sockets
+and PID files can be created in a location that requires root
privileges for writing.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;fork&gt;</emphasis></term>
- <listitem>
-<para></para>
- </listitem>
- </varlistentry>
-</variablelist>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;fork&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
-<para>If present, the bus daemon becomes a real daemon (forks
-into the background, etc.). This is generally used
+<para>If present, the bus daemon becomes a real daemon (forks
+into the background, etc.). This is generally used
rather than the --fork command line option.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;listen&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;keep_umask&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>If present, the bus daemon keeps its original umask when forking.
+This may be useful to avoid affecting the behavior of child processes.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;syslog&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>If present, the bus daemon will log to syslog.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;pidfile&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>If present, the bus daemon will write its pid to the specified file.
+The --nopidfile command-line option takes precedence over this setting.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;allow_anonymous&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>If present, connections that authenticated using the ANONYMOUS
+mechanism will be authorized to connect. This option has no practical
+effect unless the ANONYMOUS mechanism has also been enabled using the
+<emphasis remap='I'>&lt;auth&gt;</emphasis> element, described below.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;listen&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
-<para>Add an address that the bus should listen on. The
-address is in the standard D-Bus format that contains
+<para>Add an address that the bus should listen on. The
+address is in the standard D-Bus format that contains
a transport name plus possible parameters/options.</para>
<para>Example: &lt;listen&gt;unix:path=/tmp/foo&lt;/listen&gt;</para>
-<para>If there are multiple &lt;listen&gt; elements, then the bus listens
-on multiple addresses. The bus will pass its address to
-started services or other interested parties with
-the last address given in &lt;listen&gt; first. That is,
+<para>Example: &lt;listen&gt;tcp:host=localhost,port=1234&lt;/listen&gt;</para>
+
+
+<para>If there are multiple &lt;listen&gt; elements, then the bus listens
+on multiple addresses. The bus will pass its address to
+started services or other interested parties with
+the last address given in &lt;listen&gt; first. That is,
apps will try to connect to the last &lt;listen&gt; address first.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;auth&gt;</emphasis></term>
- <listitem>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+<para>tcp sockets can accept IPv4 addresses, IPv6 addresses or hostnames.
+If a hostname resolves to multiple addresses, the server will bind
+to all of them. The family=ipv4 or family=ipv6 options can be used
+to force it to bind to a subset of addresses</para>
+
+
+<para>Example: &lt;listen&gt;tcp:host=localhost,port=0,family=ipv4&lt;/listen&gt;</para>
+
+
+<para>A special case is using a port number of zero (or omitting the port),
+which means to choose an available port selected by the operating
+system. The port number chosen can be obtained with the
+--print-address command line parameter and will be present in other
+cases where the server reports its own address, such as when
+DBUS_SESSION_BUS_ADDRESS is set.</para>
+
+
+<para>Example: &lt;listen&gt;tcp:host=localhost,port=0&lt;/listen&gt;</para>
+
+
+<para>tcp/nonce-tcp addresses also allow a bind=hostname option,
+used in a listenable address to configure the interface on which
+the server will listen: either the hostname is the IP address of
+one of the local machine's interfaces (most commonly 127.0.0.1),
+or a DNS name that resolves to one of those IP addresses, or '*'
+to listen on all interfaces simultaneously. If not specified,
+the default is the same value as "host".</para>
+
+
+<para>Example: &lt;listen&gt;tcp:host=localhost,bind=*,port=0&lt;/listen&gt;</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;auth&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>Lists permitted authorization mechanisms. If this element doesn't
exist, then all known mechanisms are allowed. If there are multiple
&lt;auth&gt; elements, all the listed mechanisms are allowed. The order in
which mechanisms are listed is not meaningful.</para>
-
+
<para>Example: &lt;auth&gt;EXTERNAL&lt;/auth&gt;</para>
<para>Example: &lt;auth&gt;DBUS_COOKIE_SHA1&lt;/auth&gt;</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;servicedir&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;servicedir&gt;</emphasis></para></listitem>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+
+</itemizedlist>
<para>Adds a directory to scan for .service files. Directories are
-scanned starting with the last to appear in the config file
-(the first .service file found that provides a particular
+scanned starting with the first to appear in the config file
+(the first .service file found that provides a particular
service will be used).</para>
<para>Service files tell the bus how to automatically start a program.
-They are primarily used with the per-user-session bus,
+They are primarily used with the per-user-session bus,
not the systemwide bus.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;standard_session_servicedirs/&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;standard_session_servicedirs/&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>&lt;standard_session_servicedirs/&gt; is equivalent to specifying a series
of &lt;servicedir/&gt; elements for each of the data directories in the "XDG
@@ -367,18 +459,48 @@ otherwise try your favorite search engine.</para>
<para>The &lt;standard_session_servicedirs/&gt; option is only relevant to the
per-user-session bus daemon defined in
-/etc/dbus-1/session.conf. Putting it in any other
+@EXPANDED_SYSCONFDIR@/dbus-1/session.conf. Putting it in any other
configuration file would probably be nonsense.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;limit&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;standard_system_servicedirs/&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>&lt;standard_system_servicedirs/&gt; specifies the standard system-wide
+activation directories that should be searched for service files.
+This option defaults to @EXPANDED_DATADIR@/dbus-1/system-services.</para>
+
+
+<para>The &lt;standard_system_servicedirs/&gt; option is only relevant to the
+per-system bus daemon defined in
+@EXPANDED_SYSCONFDIR@/dbus-1/system.conf. Putting it in any other
+configuration file would probably be nonsense.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;servicehelper/&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
+
+<para>&lt;servicehelper/&gt; specifies the setuid helper that is used to launch
+system daemons with an alternate user. Typically this should be
+the dbus-daemon-launch-helper executable in located in libexec.</para>
+
+
+<para>The &lt;servicehelper/&gt; option is only relevant to the per-system bus daemon
+defined in @EXPANDED_SYSCONFDIR@/dbus-1/system.conf. Putting it in any other
+configuration file would probably be nonsense.</para>
+
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;limit&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>&lt;limit&gt; establishes a resource limit. For example:</para>
<literallayout remap='.nf'>
@@ -392,31 +514,36 @@ Available limit names are:</para>
<literallayout remap='.nf'>
"max_incoming_bytes" : total size in bytes of messages
incoming from a single connection
+ "max_incoming_unix_fds" : total number of unix fds of messages
+ incoming from a single connection
"max_outgoing_bytes" : total size in bytes of messages
queued up for a single connection
+ "max_outgoing_unix_fds" : total number of unix fds of messages
+ queued up for a single connection
"max_message_size" : max size of a single message in
bytes
- "service_start_timeout" : milliseconds (thousandths) until
+ "max_message_unix_fds" : max unix fds of a single message
+ "service_start_timeout" : milliseconds (thousandths) until
a started service has to connect
"auth_timeout" : milliseconds (thousandths) a
connection is given to
authenticate
- "max_completed_connections" : max number of authenticated connections
+ "max_completed_connections" : max number of authenticated connections
"max_incomplete_connections" : max number of unauthenticated
connections
"max_connections_per_user" : max number of completed connections from
the same user
"max_pending_service_starts" : max number of service launches in
progress at the same time
- "max_names_per_connection" : max number of names a single
+ "max_names_per_connection" : max number of names a single
connection can own
- "max_match_rules_per_connection": max number of match rules for a single
+ "max_match_rules_per_connection": max number of match rules for a single
connection
- "max_replies_per_connection" : max number of pending method
+ "max_replies_per_connection" : max number of pending method
replies per connection
(number of calls-in-progress)
- "reply_timeout" : milliseconds (thousandths)
- until a method call times out
+ "reply_timeout" : milliseconds (thousandths)
+ until a method call times out
</literallayout> <!-- .fi -->
@@ -430,49 +557,60 @@ number of users that can work together to denial-of-service all other users by u
up all connections on the systemwide bus.</para>
-<para>Limits are normally only of interest on the systemwide bus, not the user session
+<para>Limits are normally only of interest on the systemwide bus, not the user session
buses.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;policy&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;policy&gt;</emphasis></para></listitem>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+
+</itemizedlist>
<para>The &lt;policy&gt; element defines a security policy to be applied to a particular
set of connections to the bus. A policy is made up of
&lt;allow&gt; and &lt;deny&gt; elements. Policies are normally used with the systemwide bus;
-they are analogous to a firewall in that they allow expected traffic
+they are analogous to a firewall in that they allow expected traffic
and prevent unexpected traffic.</para>
-<para>The &lt;policy&gt; element has one of three attributes:</para>
+<para>Currently, the system bus has a default-deny policy for sending method calls
+and owning bus names. Everything else, in particular reply messages, receive
+checks, and signals has a default allow policy.</para>
+
+
+<para>In general, it is best to keep system services as small, targeted programs which
+run in their own process and provide a single bus name. Then, all that is needed
+is an &lt;allow&gt; rule for the "own" permission to let the process claim the bus
+name, and a "send_destination" rule to allow traffic from some or all uids to
+your service.</para>
+
+
+<para>The &lt;policy&gt; element has one of four attributes:</para>
<literallayout remap='.nf'>
context="(default|mandatory)"
+ at_console="(true|false)"
user="username or userid"
group="group name or gid"
</literallayout> <!-- .fi -->
-<para>
-Policies are applied to a connection as follows:</para>
+<para>Policies are applied to a connection as follows:</para>
<literallayout remap='.nf'>
- all context="default" policies are applied
- all group="connection's user's group" policies are applied
in undefined order
- all user="connection's auth user" policies are applied
in undefined order
+ - all at_console="true" policies are applied
+ - all at_console="false" policies are applied
- all context="mandatory" policies are applied
</literallayout> <!-- .fi -->
-<para>Policies applied later will override those applied earlier,
-when the policies overlap. Multiple policies with the same
-user/group/context are applied in the order they appear
+<para>Policies applied later will override those applied earlier,
+when the policies overlap. Multiple policies with the same
+user/group/context are applied in the order they appear
in the config file.</para>
<variablelist remap='TP'>
@@ -493,16 +631,16 @@ statements, and works just like &lt;deny&gt; but with the inverse meaning.</para
<para>The possible attributes of these elements are:</para>
<literallayout remap='.nf'>
send_interface="interface_name"
- send_member="method_or_signal_name"
- send_error="error_name"
- send_destination="name"
- send_type="method_call" | "method_return" | "signal" | "error"
+ send_member="method_or_signal_name"
+ send_error="error_name"
+ send_destination="name"
+ send_type="method_call" | "method_return" | "signal" | "error"
send_path="/path/name"
receive_interface="interface_name"
- receive_member="method_or_signal_name"
- receive_error="error_name"
- receive_sender="name"
+ receive_member="method_or_signal_name"
+ receive_error="error_name"
+ receive_sender="name"
receive_type="method_call" | "method_return" | "signal" | "error"
receive_path="/path/name"
@@ -520,9 +658,7 @@ statements, and works just like &lt;deny&gt; but with the inverse meaning.</para
<para>Examples:</para>
<literallayout remap='.nf'>
- &lt;deny send_interface="org.freedesktop.System" send_member="Reboot"/&gt;
- &lt;deny receive_interface="org.freedesktop.System" receive_member="Reboot"/&gt;
- &lt;deny own="org.freedesktop.System"/&gt;
+ &lt;deny send_destination="org.freedesktop.Service" send_interface="org.freedesktop.System" send_member="Reboot"/&gt;
&lt;deny send_destination="org.freedesktop.System"/&gt;
&lt;deny receive_sender="org.freedesktop.System"/&gt;
&lt;deny user="john"/&gt;
@@ -534,34 +670,29 @@ statements, and works just like &lt;deny&gt; but with the inverse meaning.</para
particular action. If it matches, the action is denied (unless later
rules in the config file allow it).</para>
-
<para>send_destination and receive_sender rules mean that messages may not be
sent to or received from the *owner* of the given name, not that
they may not be sent *to that name*. That is, if a connection
owns services A, B, C, and sending to A is denied, sending to B or C
will not work either.</para>
-
<para>The other send_* and receive_* attributes are purely textual/by-value
matches against the given field in the message header.</para>
-
<para>"Eavesdropping" occurs when an application receives a message that
-was explicitly addressed to a name the application does not own.
-Eavesdropping thus only applies to messages that are addressed to
-services (i.e. it does not apply to signals).</para>
-
+was explicitly addressed to a name the application does not own, or
+is a reply to such a message. Eavesdropping thus only applies to
+messages that are addressed to services and replies to such messages
+(i.e. it does not apply to signals).</para>
-<para>For &lt;allow&gt;, eavesdrop="true" indicates that the rule matches even
-when eavesdropping. eavesdrop="false" is the default and means that
+<para>For &lt;allow&gt;, eavesdrop="true" indicates that the rule matches even
+when eavesdropping. eavesdrop="false" is the default and means that
the rule only allows messages to go to their specified recipient.
-For &lt;deny&gt;, eavesdrop="true" indicates that the rule matches
+For &lt;deny&gt;, eavesdrop="true" indicates that the rule matches
only when eavesdropping. eavesdrop="false" is the default for &lt;deny&gt;
-also, but here it means that the rule applies always, even when
+also, but here it means that the rule applies always, even when
not eavesdropping. The eavesdrop attribute can only be combined with
-receive rules (with receive_* attributes).</para>
-
-
+send and receive rules (with send_* and receive_* attributes).</para>
<para>The [send|receive]_requested_reply attribute works similarly to the eavesdrop
attribute. It controls whether the &lt;deny&gt; or &lt;allow&gt; matches a reply
@@ -582,7 +713,7 @@ requested. [send|receive]_requested_reply="true" indicates that the rule applies
always, regardless of pending reply state.</para>
-<para>user and group denials mean that the given user or group may
+<para>user and group denials mean that the given user or group may
not connect to the message bus.</para>
@@ -591,6 +722,7 @@ the character "*" can be substituted, meaning "any." Complex globs
like "foo.bar.*" aren't allowed for now because they'd be work to
implement and maybe encourage sloppy security anyway.</para>
+
<para>&lt;allow own_prefix="a.b"/&gt; allows you to own the name "a.b" or any
name whose first dot-separated elements are "a.b": in particular,
you can own "a.b.c" or "a.b.c.d", but not "a.bc" or "a.c".
@@ -599,6 +731,7 @@ define a meaning for subtrees of well-known names, such as
org.freedesktop.Telepathy.ConnectionManager.(anything)
and org.freedesktop.ReserveDevice1.(anything).</para>
+
<para>It does not make sense to deny a user or group inside a &lt;policy&gt;
for a user or group; user/group denials can only be inside
context="default" or context="mandatory" policies.</para>
@@ -617,42 +750,40 @@ rule, since "whether the message can be sent" and "whether it can be
received" are evaluated separately.</para>
-<para>Be careful with send_interface/receive_interface, because the
-interface field in messages is optional.</para>
+<para>Be careful with send_interface/receive_interface, because the
+interface field in messages is optional. In particular, do NOT
+specify &lt;deny send_interface="org.foo.Bar"/&gt;! This will cause
+no-interface messages to be blocked for all services, which is
+almost certainly not what you intended. Always use rules of
+the form: &lt;deny send_interface="org.foo.Bar" send_destination="org.foo.Service"/&gt;</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;selinux&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+ <listitem><para><emphasis remap='I'>&lt;selinux&gt;</emphasis></para></listitem>
+
+
+</itemizedlist>
<para>The &lt;selinux&gt; element contains settings related to Security Enhanced Linux.
More details below.</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'>&lt;associate&gt;</emphasis></term>
- <listitem>
+<itemizedlist remap='TP'>
+
+ <listitem><para><emphasis remap='I'>&lt;associate&gt;</emphasis></para></listitem>
-<para></para> <!-- FIXME: blank list item -->
- </listitem>
- </varlistentry>
-</variablelist>
+
+</itemizedlist>
<para>An &lt;associate&gt; element appears below an &lt;selinux&gt; element and
creates a mapping. Right now only one kind of association is possible:</para>
<literallayout remap='.nf'>
- &lt;associate own="org.freedesktop.Foobar" context="foo_t"/&gt;
+ &lt;associate own="org.freedesktop.Foobar" context="foo_t"/&gt;
</literallayout> <!-- .fi -->
<para>This means that if a connection asks to own the name
"org.freedesktop.Foobar" then the source context will be the context
-of the connection and the target context will be "foo_t" - see the
+of the connection and the target context will be "foo_t" - see the
short discussion of SELinux below.</para>
@@ -663,7 +794,7 @@ NOT the context of the connection owning the name.</para>
<para>There's currently no way to set a default for owning any name, if
we add this syntax it will look like:</para>
<literallayout remap='.nf'>
- &lt;associate own="*" context="foo_t"/&gt;
+ &lt;associate own="*" context="foo_t"/&gt;
</literallayout> <!-- .fi -->
<para>If you find a reason this is useful, let the developers know.
Right now the default will be the security context of the bus itself.</para>
@@ -715,30 +846,75 @@ the first connection as source, security context of the second connection
as target, object class "dbus" and requested permission "send_msg".</para>
-<para>If a security context is not available for a connection
-(impossible when using UNIX domain sockets), then the target
+<para>If a security context is not available for a connection
+(impossible when using UNIX domain sockets), then the target
context used is the context of the bus daemon itself.
-There is currently no way to change this default, because we're
-assuming that only UNIX domain sockets will be used to
-connect to the systemwide bus. If this changes, we'll
+There is currently no way to change this default, because we're
+assuming that only UNIX domain sockets will be used to
+connect to the systemwide bus. If this changes, we'll
probably add a way to set the default connection context.</para>
-<para>Second, any time a connection asks to own a name,
-the bus daemon will check permissions with the security
+<para>Second, any time a connection asks to own a name,
+the bus daemon will check permissions with the security
context of the connection as source, the security context specified
-for the name in the config file as target, object
+for the name in the config file as target, object
class "dbus" and requested permission "acquire_svc".</para>
-<para>The security context for a bus name is specified with the
+<para>The security context for a bus name is specified with the
&lt;associate&gt; element described earlier in this document.
-If a name has no security context associated in the
-configuration file, the security context of the bus daemon
+If a name has no security context associated in the
+configuration file, the security context of the bus daemon
itself will be used.</para>
</refsect1>
+<refsect1 id='debugging'><title>DEBUGGING</title>
+<para>If you're trying to figure out where your messages are going or why
+you aren't getting messages, there are several things you can try.</para>
+
+<para>Remember that the system bus is heavily locked down and if you
+haven't installed a security policy file to allow your message
+through, it won't work. For the session bus, this is not a concern.</para>
+
+<para>The simplest way to figure out what's happening on the bus is to run
+the <emphasis remap='I'>dbus-monitor</emphasis> program, which comes with the D-Bus
+package. You can also send test messages with <emphasis remap='I'>dbus-send</emphasis>. These
+programs have their own man pages.</para>
+
+<para>If you want to know what the daemon itself is doing, you might consider
+running a separate copy of the daemon to test against. This will allow you
+to put the daemon under a debugger, or run it with verbose output, without
+messing up your real session and system daemons.</para>
+
+<para>To run a separate test copy of the daemon, for example you might open a terminal
+and type:</para>
+<literallayout remap='.nf'>
+ DBUS_VERBOSE=1 dbus-daemon --session --print-address
+</literallayout> <!-- .fi -->
+
+<para>The test daemon address will be printed when the daemon starts. You will need
+to copy-and-paste this address and use it as the value of the
+DBUS_SESSION_BUS_ADDRESS environment variable when you launch the applications
+you want to test. This will cause those applications to connect to your
+test bus instead of the DBUS_SESSION_BUS_ADDRESS of your real session bus.</para>
+
+<para>DBUS_VERBOSE=1 will have NO EFFECT unless your copy of D-Bus
+was compiled with verbose mode enabled. This is not recommended in
+production builds due to performance impact. You may need to rebuild
+D-Bus if your copy was not built with debugging in mind. (DBUS_VERBOSE
+also affects the D-Bus library and thus applications using D-Bus; it may
+be useful to see verbose output on both the client side and from the daemon.)</para>
+
+<para>If you want to get fancy, you can create a custom bus
+configuration for your test bus (see the session.conf and system.conf
+files that define the two default configurations for example). This
+would allow you to specify a different directory for .service files,
+for example.</para>
+
+</refsect1>
+
<refsect1 id='author'><title>AUTHOR</title>
<para>See <ulink url='http://www.freedesktop.org/software/dbus/doc/AUTHORS'>http://www.freedesktop.org/software/dbus/doc/AUTHORS</ulink></para>
@@ -749,4 +925,3 @@ itself will be used.</para>
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>
-
diff --git a/doc/dbus-faq.xml b/doc/dbus-faq.xml
index 69ac3f15..0d296d92 100644
--- a/doc/dbus-faq.xml
+++ b/doc/dbus-faq.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
]>
diff --git a/doc/dbus-launch.1 b/doc/dbus-launch.1
deleted file mode 100644
index a7687cad..00000000
--- a/doc/dbus-launch.1
+++ /dev/null
@@ -1,183 +0,0 @@
-.\"
-.\" dbus\-launch manual page.
-.\" Copyright (C) 2003 Red Hat, Inc.
-.\"
-.TH dbus\-launch 1
-.SH NAME
-dbus\-launch \- Utility to start a message bus from a shell script
-.SH SYNOPSIS
-.PP
-.B dbus\-launch [\-\-version] [\-\-sh\-syntax] [\-\-csh\-syntax] [\-\-auto\-syntax] [\-\-exit\-with\-session] [\-\-autolaunch=MACHINEID] [\-\-config\-file=FILENAME] [PROGRAM] [ARGS...]
-
-.SH DESCRIPTION
-
-The \fIdbus\-launch\fP command is used to start a session bus
-instance of \fIdbus\-daemon\fP from a shell script.
-It would normally be called from a user's login
-scripts. Unlike the daemon itself, \fIdbus\-launch\fP exits, so
-backticks or the $() construct can be used to read information from
-\fIdbus\-launch\fP.
-
-With no arguments, \fIdbus\-launch\fP will launch a session bus
-instance and print the address and PID of that instance to standard
-output.
-
-You may specify a program to be run; in this case, \fIdbus\-launch\fP
-will launch a session bus instance, set the appropriate environment
-variables so the specified program can find the bus, and then execute the
-specified program, with the specified arguments. See below for
-examples.
-
-If you launch a program, \fIdbus\-launch\fP will not print the
-information about the new bus to standard output.
-
-When \fIdbus\-launch\fP prints bus information to standard output, by
-default it is in a simple key\-value pairs format. However, you may
-request several alternate syntaxes using the \-\-sh\-syntax, \-\-csh\-syntax,
-\-\-binary\-syntax, or
-\-\-auto\-syntax options. Several of these cause \fIdbus\-launch\fP to emit shell code
-to set up the environment.
-
-With the \-\-auto\-syntax option, \fIdbus\-launch\fP looks at the value
-of the SHELL environment variable to determine which shell syntax
-should be used. If SHELL ends in "csh", then csh\-compatible code is
-emitted; otherwise Bourne shell code is emitted. Instead of passing
-\-\-auto\-syntax, you may explicitly specify a particular one by using
-\-\-sh\-syntax for Bourne syntax, or \-\-csh\-syntax for csh syntax.
-In scripts, it's more robust to avoid \-\-auto\-syntax and you hopefully
-know which shell your script is written in.
-
-.PP
-See http://www.freedesktop.org/software/dbus/ for more information
-about D\-Bus. See also the man page for \fIdbus\-daemon\fP.
-
-.PP
-Here is an example of how to use \fIdbus\-launch\fP with an
-sh\-compatible shell to start the per\-session bus daemon:
-.nf
-
- ## test for an existing bus daemon, just to be safe
- if test \-z "$DBUS_SESSION_BUS_ADDRESS" ; then
- ## if not found, launch a new one
- eval `dbus\-launch \-\-sh\-syntax \-\-exit\-with\-session`
- echo "D\-Bus per\-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
- fi
-
-.fi
-You might run something like that in your login scripts.
-
-.PP
-Another way to use \fIdbus\-launch\fP is to run your main session
-program, like so:
-.nf
-
-dbus\-launch gnome\-session
-
-.fi
-The above would likely be appropriate for ~/.xsession or ~/.Xclients.
-
-.SH AUTOMATIC LAUNCHING
-
-.PP
-If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use
-D\-Bus, by default the process will attempt to invoke dbus\-launch with
-the \-\-autolaunch option to start up a new session bus or find the
-existing bus address on the X display or in a file in
-~/.dbus/session\-bus/
-
-.PP
-Whenever an autolaunch occurs, the application that had to
-start a new bus will be in its own little world; it can effectively
-end up starting a whole new session if it tries to use a lot of
-bus services. This can be suboptimal or even totally broken, depending
-on the app and what it tries to do.
-
-.PP
-There are two common reasons for autolaunch. One is ssh to a remote
-machine. The ideal fix for that would be forwarding of
-DBUS_SESSION_BUS_ADDRESS in the same way that DISPLAY is forwarded.
-In the meantime, you can edit the session.conf config file to
-have your session bus listen on TCP, and manually set
-DBUS_SESSION_BUS_ADDRESS, if you like.
-
-.PP
-The second common reason for autolaunch is an su to another user, and
-display of X applications running as the second user on the display
-belonging to the first user. Perhaps the ideal fix in this case
-would be to allow the second user to connect to the session bus of the
-first user, just as they can connect to the first user's display.
-However, a mechanism for that has not been coded.
-
-.PP
-You can always avoid autolaunch by manually setting
-DBUS_SESSION_BUS_ADDRESS. Autolaunch happens because the default
-address if none is set is "autolaunch:", so if any other address is
-set there will be no autolaunch. You can however include autolaunch in
-an explicit session bus address as a fallback, for example
-DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:" \- in that case if
-the first address doesn't work, processes will autolaunch. (The bus
-address variable contains a comma\-separated list of addresses to try.)
-
-.PP
-The \-\-autolaunch option is considered an internal implementation
-detail of libdbus, and in fact there are plans to change it. There's
-no real reason to use it outside of the libdbus implementation anyhow.
-
-.SH OPTIONS
-The following options are supported:
-.TP
-.I "\-\-auto\-syntax"
-Choose \-\-csh\-syntax or \-\-sh\-syntax based on the SHELL environment variable.
-
-.I "\-\-binary\-syntax"
-Write to stdout a nul\-terminated bus address, then the bus PID as a
-binary integer of size sizeof(pid_t), then the bus X window ID as a
-binary integer of size sizeof(long). Integers are in the machine's
-byte order, not network byte order or any other canonical byte order.
-
-.TP
-.I "\-\-close\-stderr"
-Close the standard error output stream before starting the D\-Bus
-daemon. This is useful if you want to capture dbus\-launch error
-messages but you don't want dbus\-daemon to keep the stream open to
-your application.
-
-.TP
-.I "\-\-config\-file=FILENAME"
-Pass \-\-config\-file=FILENAME to the bus daemon, instead of passing it
-the \-\-session argument. See the man page for dbus\-daemon
-
-.TP
-.I "\-\-csh\-syntax"
-Emit csh compatible code to set up environment variables.
-
-.TP
-.I "\-\-exit\-with\-session"
-If this option is provided, a persistent "babysitter" process will be
-created that watches stdin for HUP and tries to connect to the X
-server. If this process gets a HUP on stdin or loses its X connection,
-it kills the message bus daemon.
-
-.TP
-.I "\-\-autolaunch=MACHINEID"
-This option implies that \fIdbus\-launch\fP should scan for a
-previously\-started session and reuse the values found there. If no
-session is found, it will start a new session. The
-\-\-exit\-with\-session option is implied if \-\-autolaunch is given.
-This option is for the exclusive use of libdbus, you do not want to
-use it manually. It may change in the future.
-
-.TP
-.I "\-\-sh\-syntax"
-Emit Bourne\-shell compatible code to set up environment variables.
-
-.TP
-.I "\-\-version"
-Print the version of dbus\-launch
-
-.SH AUTHOR
-See http://www.freedesktop.org/software/dbus/doc/AUTHORS
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/cmake/tools/dbus-launch.xml b/doc/dbus-launch.1.xml.in
index dc34898f..31dd6eac 100644
--- a/cmake/tools/dbus-launch.xml
+++ b/doc/dbus-launch.1.xml.in
@@ -1,27 +1,33 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<!-- lifted from troff+man by doclifter -->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<refentry id='dbuslaunch1'>
-<!-- -->
-<!-- dbus\-launch manual page. -->
-<!-- Copyright (C) 2003 Red Hat, Inc. -->
+
+<!-- dbus&bsol;-launch manual page.
+ Copyright (C) 2003 Red Hat, Inc. -->
<refmeta>
<refentrytitle>dbus-launch</refentrytitle>
<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
</refmeta>
-<refnamediv id='name'>
+<refnamediv>
<refname>dbus-launch</refname>
<refpurpose>Utility to start a message bus from a shell script</refpurpose>
</refnamediv>
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
- <command>dbus-launch</command> <arg choice='opt'>--version </arg>
+ <command>dbus-launch</command>
+ <arg choice='opt'>--version </arg>
+ <arg choice='opt'>--help </arg>
<arg choice='opt'>--sh-syntax </arg>
<arg choice='opt'>--csh-syntax </arg>
<arg choice='opt'>--auto-syntax </arg>
+ <arg choice='opt'>--binary-syntax </arg>
+ <arg choice='opt'>--close-stderr </arg>
<arg choice='opt'>--exit-with-session </arg>
<arg choice='opt'>--autolaunch=<replaceable>MACHINEID</replaceable></arg>
<arg choice='opt'>--config-file=<replaceable>FILENAME</replaceable></arg>
@@ -33,7 +39,7 @@
<refsect1 id='description'><title>DESCRIPTION</title>
-<para>The <command>dbus-launch</command> command is used to start a session bus
+<para>The <command>dbus-launch</command> command is used to start a session bus
instance of <emphasis remap='I'>dbus-daemon</emphasis> from a shell script.
It would normally be called from a user's login
scripts. Unlike the daemon itself, <command>dbus-launch</command> exits, so
@@ -41,7 +47,7 @@ backticks or the $() construct can be used to read information from
<command>dbus-launch</command>.</para>
<para>With no arguments, <command>dbus-launch</command> will launch a session bus
-instance and print the address and pid of that instance to standard
+instance and print the address and PID of that instance to standard
output.</para>
<para>You may specify a program to be run; in this case, <command>dbus-launch</command>
@@ -54,7 +60,7 @@ examples.</para>
information about the new bus to standard output.</para>
<para>When <command>dbus-launch</command> prints bus information to standard output, by
-default it is in a simple key-value pairs format. However, you may
+default it is in a simple key-value pairs format. However, you may
request several alternate syntaxes using the --sh-syntax, --csh-syntax,
--binary-syntax, or
--auto-syntax options. Several of these cause <command>dbus-launch</command> to emit shell code
@@ -64,7 +70,7 @@ to set up the environment.</para>
of the SHELL environment variable to determine which shell syntax
should be used. If SHELL ends in "csh", then csh-compatible code is
emitted; otherwise Bourne shell code is emitted. Instead of passing
---auto-syntax, you may explicity specify a particular one by using
+--auto-syntax, you may explicitly specify a particular one by using
--sh-syntax for Bourne syntax, or --csh-syntax for csh syntax.
In scripts, it's more robust to avoid --auto-syntax and you hopefully
know which shell your script is written in.</para>
@@ -73,44 +79,62 @@ know which shell your script is written in.</para>
<para>See <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more information
about D-Bus. See also the man page for <emphasis remap='I'>dbus-daemon</emphasis>.</para>
+</refsect1>
-<para>Here is an example of how to use <command>dbus-launch</command> with an
-sh-compatible shell to start the per-session bus daemon:</para>
-<literallayout remap='.nf'>
+<refsect1 id='examples'><title>EXAMPLES</title>
+<para>Distributions running
+<command>dbus-launch</command>
+as part of a standard X session should run
+<emphasis remap='B'>dbus-launch --exit-with-session</emphasis>
+after the X server has started and become available, as a wrapper around
+the "main" X client (typically a session manager or window manager), as in
+these examples:</para>
- ## test for an existing bus daemon, just to be safe
- if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
- ## if not found, launch a new one
- eval `dbus-launch --sh-syntax --exit-with-session`
- echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
- fi
+ <blockquote remap='RS'>
+<para><emphasis remap='B'>dbus-launch --exit-with-session gnome-session</emphasis></para>
-</literallayout> <!-- .fi -->
-<para>You might run something like that in your login scripts.</para>
+<para><emphasis remap='B'>dbus-launch --exit-with-session openbox</emphasis></para>
+<para><emphasis remap='B'>dbus-launch --exit-with-session ~/.xsession</emphasis>
+ </para></blockquote> <!-- remap='RE' -->
-<para>Another way to use <command>dbus-launch</command> is to run your main session
-program, like so:</para>
-<literallayout remap='.nf'>
+<para>If your distribution does not do this, you can achieve similar results
+by running your session or window manager in the same way in a script
+run by your X session, such as
+<filename>~/.xsession</filename>,
+<filename>~/.xinitrc</filename>
+or
+<filename>~/.Xclients</filename>.</para>
-dbus-launch gnome-session
+<para>To start a D-Bus session within a text\(hymode session,
+ do not use <emphasis remap='B'>dbus-launch</emphasis>.
+ Instead, see <citerefentry><refentrytitle>dbus-run-session</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
+</para>
+<literallayout remap='.nf'>
+ ## test for an existing bus daemon, just to be safe
+ if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
+ ## if not found, launch a new one
+ eval `dbus-launch --sh-syntax`
+ echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
+ fi
</literallayout> <!-- .fi -->
-<para>The above would likely be appropriate for ~/.xsession or ~/.Xclients.</para>
+<para>Note that in this case, dbus-launch will exit, and dbus-daemon will not be
+terminated automatically on logout.</para>
</refsect1>
<refsect1 id='automatic_launching'><title>AUTOMATIC LAUNCHING</title>
<para>If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use
D-Bus, by default the process will attempt to invoke dbus-launch with
-the --autolaunch option to start up a new session bus or find the
+the --autolaunch option to start up a new session bus or find the
existing bus address on the X display or in a file in
~/.dbus/session-bus/</para>
<para>Whenever an autolaunch occurs, the application that had to
start a new bus will be in its own little world; it can effectively
-end up starting a whole new session if it tries to use a lot of
+end up starting a whole new session if it tries to use a lot of
bus services. This can be suboptimal or even totally broken, depending
on the app and what it tries to do.</para>
@@ -118,7 +142,7 @@ on the app and what it tries to do.</para>
<para>There are two common reasons for autolaunch. One is ssh to a remote
machine. The ideal fix for that would be forwarding of
DBUS_SESSION_BUS_ADDRESS in the same way that DISPLAY is forwarded.
-In the meantime, you can edit the session.conf config file to
+In the meantime, you can edit the session.conf config file to
have your session bus listen on TCP, and manually set
DBUS_SESSION_BUS_ADDRESS, if you like.</para>
@@ -155,8 +179,12 @@ no real reason to use it outside of the libdbus implementation anyhow.</para>
<listitem>
<para>Choose --csh-syntax or --sh-syntax based on the SHELL environment variable.</para>
-<para><option>--binary-syntax</option>
-Write to stdout a nul-terminated bus address, then the bus PID as a
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--binary-syntax</option></term>
+ <listitem>
+<para>Write to stdout a nul-terminated bus address, then the bus PID as a
binary integer of size sizeof(pid_t), then the bus X window ID as a
binary integer of size sizeof(long). Integers are in the machine's
byte order, not network byte order or any other canonical byte order.</para>
@@ -176,7 +204,7 @@ your application.</para>
<varlistentry>
<term><option>--config-file=FILENAME</option></term>
<listitem>
-<para>Pass --config-file=FILENAME to the bus daemon, instead of passing it
+<para>Pass --config-file=FILENAME to the bus daemon, instead of passing it
the --session argument. See the man page for dbus-daemon</para>
</listitem>
@@ -191,7 +219,7 @@ the --session argument. See the man page for dbus-daemon</para>
<varlistentry>
<term><option>--exit-with-session</option></term>
<listitem>
-<para>If this option is provided, a persistent "babysitter" process will be
+<para>If this option is provided, a persistent "babysitter" process will be
created that watches stdin for HUP and tries to connect to the X
server. If this process gets a HUP on stdin or loses its X connection,
it kills the message bus daemon.</para>
@@ -224,9 +252,30 @@ use it manually. It may change in the future.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--help</option></term>
+ <listitem>
+<para>Print the help info of dbus-launch</para>
+
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
+<refsect1 id='notes'><title>NOTES</title>
+<para>If you run
+<emphasis remap='B'>dbus-launch myapp</emphasis>
+(with any other options), dbus-daemon will
+<emphasis remap='I'>not</emphasis>
+exit when
+<emphasis remap='B'>myapp</emphasis>
+terminates: this is because
+<emphasis remap='B'>myapp</emphasis>
+is assumed to be part of a larger session, rather than a session in its
+own right.</para>
+
+</refsect1>
+
<refsect1 id='author'><title>AUTHOR</title>
<para>See <ulink url='http://www.freedesktop.org/software/dbus/doc/AUTHORS'>http://www.freedesktop.org/software/dbus/doc/AUTHORS</ulink></para>
@@ -237,4 +286,3 @@ use it manually. It may change in the future.</para>
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>
-
diff --git a/doc/dbus-monitor.1 b/doc/dbus-monitor.1
deleted file mode 100644
index 6282b9eb..00000000
--- a/doc/dbus-monitor.1
+++ /dev/null
@@ -1,78 +0,0 @@
-.\"
-.\" dbus\-monitor manual page.
-.\" Copyright (C) 2003 Red Hat, Inc.
-.\"
-.TH dbus\-monitor 1
-.SH NAME
-dbus\-monitor \- debug probe to print message bus messages
-.SH SYNOPSIS
-.PP
-.B dbus\-monitor
-[\-\-system | \-\-session | \-\-address ADDRESS] [\-\-profile | \-\-monitor]
-[watch expressions]
-
-.SH DESCRIPTION
-
-The \fIdbus\-monitor\fP command is used to monitor messages going
-through a D\-Bus message bus. See
-http://www.freedesktop.org/software/dbus/ for more information about
-the big picture.
-
-.PP
-There are two well\-known message buses: the systemwide message bus
-(installed on many systems as the "messagebus" service) and the
-per\-user\-login\-session message bus (started each time a user logs in).
-The \-\-system and \-\-session options direct \fIdbus\-monitor\fP to
-monitor the system or session buses respectively. If neither is
-specified, \fIdbus\-monitor\fP monitors the session bus.
-
-.PP
-\fIdbus\-monitor\fP has two different output modes, the 'classic'\-style
-monitoring mode and profiling mode. The profiling format is a compact
-format with a single line per message and microsecond\-resolution timing
-information. The \-\-profile and \-\-monitor options select the profiling
-and monitoring output format respectively. If neither is specified,
-\fIdbus\-monitor\fP uses the monitoring output format.
-
-.PP
-In order to get \fIdbus\-monitor\fP to see the messages you are interested
-in, you should specify a set of watch expressions as you would expect to
-be passed to the \fIdbus_bus_add_match\fP function.
-
-.PP
-The message bus configuration may keep \fIdbus\-monitor\fP from seeing
-all messages, especially if you run the monitor as a non\-root user.
-
-.SH OPTIONS
-.TP
-.I "\-\-system"
-Monitor the system message bus.
-.TP
-.I "\-\-session"
-Monitor the session message bus. (This is the default.)
-.TP
-.I "\-\-address ADDRESS"
-Monitor an arbitrary message bus given at ADDRESS.
-.TP
-.I "\-\-profile"
-Use the profiling output format.
-.TP
-.I "\-\-monitor"
-Use the monitoring output format. (This is the default.)
-
-.SH EXAMPLE
-Here is an example of using dbus\-monitor to watch for the gnome typing
-monitor to say things
-.nf
-
- dbus\-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
-
-.fi
-
-.SH AUTHOR
-dbus\-monitor was written by Philip Blundell.
-The profiling output mode was added by Olli Salli.
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/cmake/tools/dbus-monitor.xml b/doc/dbus-monitor.1.xml.in
index b41cace2..af05e3aa 100644
--- a/cmake/tools/dbus-monitor.xml
+++ b/doc/dbus-monitor.1.xml.in
@@ -1,24 +1,26 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<!-- lifted from troff+man by doclifter -->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<refentry id='dbusmonitor1'>
-<!-- -->
-<!-- dbus\-monitor manual page. -->
-<!-- Copyright (C) 2003 Red Hat, Inc. -->
+
+<!-- dbus&bsol;-monitor manual page.
+ Copyright (C) 2003 Red Hat, Inc. -->
<refmeta>
<refentrytitle>dbus-monitor</refentrytitle>
<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
</refmeta>
-<refnamediv id='name'>
+<refnamediv>
<refname>dbus-monitor</refname>
<refpurpose>debug probe to print message bus messages</refpurpose>
</refnamediv>
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
- <command>dbus-monitor</command>
+ <command>dbus-monitor</command>
<group choice='opt'><arg choice='plain'>--system </arg><arg choice='plain'>--session </arg><arg choice='plain'>--address <replaceable>ADDRESS</replaceable></arg></group>
<group choice='opt'><arg choice='plain'>--profile </arg><arg choice='plain'>--monitor </arg></group>
<arg choice='opt'><arg choice='plain'><replaceable>watch</replaceable></arg><arg choice='plain'><replaceable>expressions</replaceable></arg></arg>
@@ -118,4 +120,3 @@ The profiling output mode was added by Olli Salli.</para>
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>
-
diff --git a/doc/dbus-run-session.1.xml.in b/doc/dbus-run-session.1.xml.in
new file mode 100644
index 00000000..5181a8b1
--- /dev/null
+++ b/doc/dbus-run-session.1.xml.in
@@ -0,0 +1,151 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<refentry id='dbusrunsession1'>
+<refmeta>
+<refentrytitle>dbus-run-session</refentrytitle>
+<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>dbus-run-session</refname>
+<refpurpose>start a process as a new D-Bus session</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+<refsynopsisdiv id='synopsis'>
+<cmdsynopsis>
+ <command>dbus-run-session</command>
+ <arg choice='opt'><arg choice='plain'>--config-file </arg><arg choice='plain'><replaceable>FILENAME</replaceable></arg></arg>
+ <arg choice='opt'><arg choice='plain'>--dbus-daemon </arg><arg choice='plain'><replaceable>BINARY</replaceable></arg></arg>
+ <arg choice='opt'>-- </arg>
+ <arg choice='plain'><replaceable>PROGRAM</replaceable></arg>
+ <arg choice='opt' rep='repeat'><replaceable>ARGUMENTS</replaceable></arg>
+</cmdsynopsis>
+<cmdsynopsis>
+ <command>dbus-run-session</command> <arg choice='plain'>--help </arg>
+</cmdsynopsis>
+<cmdsynopsis>
+ <command>dbus-run-session</command> <arg choice='plain'>--version </arg>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<refsect1 id='description'><title>DESCRIPTION</title>
+<para><command>dbus-run-session</command>
+is used to start a session bus instance of
+<emphasis remap='B'>dbus-daemon</emphasis>
+from a shell script, and start a specified program in that session. The
+<emphasis remap='B'>dbus-daemon</emphasis>
+will run for as long as the program does, after which it will terminate.</para>
+
+<para>One use is to run a shell with its own
+<emphasis remap='B'>dbus-daemon</emphasis>
+in a text&hyphen;mode or SSH session, and have the
+<emphasis remap='B'>dbus-daemon</emphasis>
+terminate automatically on leaving the sub&hyphen;shell, like this:</para>
+
+<para> dbus-run-session -- bash</para>
+
+<para>or to replace the login shell altogether, by combining <command>dbus-run-session</command>
+with the <emphasis remap='B'>exec</emphasis> builtin:</para>
+
+<para> exec dbus-run-session -- bash</para>
+
+<para>Another use is to run regression tests and similar things in an isolated
+D-Bus session, to avoid either interfering with the "real" D-Bus session
+or relying on there already being a D-Bus session active, for instance:</para>
+
+<para> dbus-run-session -- make check</para>
+
+<para>or (in
+<citerefentry><refentrytitle>automake</refentrytitle><manvolnum>1</manvolnum></citerefentry>):</para>
+
+<literallayout remap='.nf'>
+ TESTS_ENVIRONMENT = MY_DEBUG=all dbus-run-session --
+
+</literallayout></refsect1>
+
+<refsect1 id='options'><title>OPTIONS</title>
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><option>--config-file=</option><replaceable>FILENAME</replaceable>, <option>--config-file</option> <replaceable>FILENAME</replaceable></term>
+ <listitem>
+<para>Pass
+<option>--config-file=</option><replaceable>FILENAME</replaceable>
+to the bus daemon, instead of passing it the
+<option>--session</option>
+argument. See
+<citerefentry><refentrytitle>dbus-daemon</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--dbus-daemon=</option><replaceable>BINARY</replaceable>, <option>--dbus-daemon</option> <replaceable>BINARY</replaceable></term>
+ <listitem>
+<para>Run <emphasis remap='I'>BINARY</emphasis> as <citerefentry><refentrytitle>dbus-daemon</refentrytitle><manvolnum>1</manvolnum></citerefentry>, instead of searching the <envar>PATH</envar>
+in the usual way for an executable called <emphasis remap='B'>dbus-daemon</emphasis>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--help</option></term>
+ <listitem>
+<para>Print usage information and exit.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--version</option></term>
+ <listitem>
+<para>Print the version of dbus-run-session and exit.</para>
+ </listitem>
+ </varlistentry>
+</variablelist>
+</refsect1>
+
+<refsect1 id='exit_status'><title>EXIT STATUS</title>
+<para><command>dbus-run-session</command>
+exits with the exit status of
+<emphasis remap='I'>PROGRAM</emphasis>,
+0 if the
+<option>--help</option> or <option>--version</option>
+options were used, 127 on an error within
+<command>dbus-run-session</command>
+itself, or
+128+<emphasis remap='I'>n</emphasis>
+if the
+<emphasis remap='I'>PROGRAM</emphasis>
+was killed by signal
+<emphasis remap='I'>n</emphasis>.</para>
+</refsect1>
+
+<refsect1 id='environment'><title>ENVIRONMENT</title>
+<para><envar>PATH</envar>
+is searched to find
+<emphasis remap='I'>PROGRAM</emphasis>,
+and (if the --dbus-daemon option is not used or its argument does not
+contain a
+<emphasis remap='B'>/</emphasis> character) to find <emphasis remap='B'>dbus-daemon</emphasis>.</para>
+
+<para>The session bus' address is made available to
+<emphasis remap='I'>PROGRAM</emphasis>
+in the environment variable
+<emphasis remap='B'>DBUS_SESSION_BUS_ADDRESS</emphasis>.</para>
+
+<para>The variables
+ <emphasis remap='B'>DBUS_SESSION_BUS_PID</emphasis>,
+ <emphasis remap='B'>DBUS_SESSION_BUS_WINDOWID</emphasis>,
+ <emphasis remap='B'>DBUS_STARTER_BUS_TYPE</emphasis> and
+ <emphasis remap='B'>DBUS_STARTER_ADDRESS</emphasis>
+ are removed from the environment, if present.</para>
+</refsect1>
+
+<refsect1 id='bugs'><title>BUGS</title>
+<para>Please send bug reports to the D-Bus mailing list or bug tracker,
+see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
+</refsect1>
+
+<refsect1 id='see_also'><title>SEE ALSO</title>
+<para><citerefentry><refentrytitle>dbus-daemon</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+<citerefentry><refentrytitle>dbus-launch</refentrytitle><manvolnum>1</manvolnum></citerefentry></para>
+</refsect1>
+</refentry>
diff --git a/doc/dbus-send.1 b/doc/dbus-send.1
deleted file mode 100644
index 131a60df..00000000
--- a/doc/dbus-send.1
+++ /dev/null
@@ -1,109 +0,0 @@
-.\"
-.\" dbus\-send manual page.
-.\" Copyright (C) 2003 Red Hat, Inc.
-.\"
-.TH dbus\-send 1
-.SH NAME
-dbus\-send \- Send a message to a message bus
-.SH SYNOPSIS
-.PP
-.B dbus\-send
-[\fB\-\-system\fP | \fB\-\-session\fP]
-[\fB\-\-dest=\fINAME\fP]
-[\fB\-\-print\-reply\fP[\fB=literal\fP]]
-[\fB\-\-reply\-timeout=\fIMSEC\fP]
-[\fB\-\-type=\fITYPE\fP]
-\fIOBJECT_PATH\fP \fIINTERFACE\fB.\fIMEMBER\fP [\fICONTENTS\fP ...]
-
-.SH DESCRIPTION
-
-The \fIdbus\-send\fP command is used to send a message to a D\-Bus message
-bus. See http://www.freedesktop.org/software/dbus/ for more
-information about the big picture.
-
-.PP
-There are two well\-known message buses: the systemwide message bus
-(installed on many systems as the "messagebus" service) and the
-per\-user\-login\-session message bus (started each time a user logs in).
-The \fB\-\-system\fP and \fB\-\-session\fP options direct
-\fBdbus\-send\fP to send messages to the system or session buses respectively.
-If neither is specified, \fBdbus\-send\fP sends to the session bus.
-
-.PP
-Nearly all uses of \fBdbus\-send\fP must provide the \fB\-\-dest\fP argument
-which is the name of a connection on the bus to send the message to. If
-\fB\-\-dest\fP is omitted, no destination is set.
-
-.PP
-The object path and the name of the message to send must always be
-specified. Following arguments, if any, are the message contents
-(message arguments). These are given as type\-specified values and
-may include containers (arrays, dicts, and variants) as described below.
-
-.nf
-<contents> ::= <item> | <container> [ <item> | <container>...]
-<item> ::= <type>:<value>
-<container> ::= <array> | <dict> | <variant>
-<array> ::= array:<type>:<value>[,<value>...]
-<dict> ::= dict:<type>:<type>:<key>,<value>[,<key>,<value>...]
-<variant> ::= variant:<type>:<value>
-<type> ::= string | int16 | uint 16 | int32 | uint32 | int64 | uint64 | double | byte | boolean | objpath
-.fi
-
-D\-Bus supports more types than these, but \fBdbus\-send\fP currently
-does not. Also, \fBdbus\-send\fP does not permit empty containers
-or nested containers (e.g. arrays of variants).
-
-.PP
-Here is an example invocation:
-.nf
-
- dbus\-send \-\-dest=org.freedesktop.ExampleName \\
- /org/freedesktop/sample/object/name \\
- org.freedesktop.ExampleInterface.ExampleMethod \\
- int32:47 string:'hello world' double:65.32 \\
- array:string:"1st item","next item","last item" \\
- dict:string:int32:"one",1,"two",2,"three",3 \\
- variant:int32:\-8 \\
- objpath:/org/freedesktop/sample/object/name
-
-.fi
-
-Note that the interface is separated from a method or signal
-name by a dot, though in the actual protocol the interface
-and the interface member are separate fields.
-
-.SH OPTIONS
-The following options are supported:
-.TP
-.BI \-\-dest= NAME
-Specify the name of the connection to receive the message.
-.TP
-.B "\-\-print\-reply"
-Block for a reply to the message sent, and print any reply received
-in a human-readable form.
-.TP
-.B "\-\-print\-reply=literal"
-Block for a reply to the message sent, and print the body of the
-reply. If the reply is an object path or a string, it is printed
-literally, with no punctuation, escape characters etc.
-.TP
-.BI \-\-reply\-timeout= MSEC
-Wait for a reply for up to \fIMSEC\fP milliseconds.
-The default is implementation\(hydefined, typically 25 seconds.
-.TP
-.B "\-\-system"
-Send to the system message bus.
-.TP
-.B "\-\-session"
-Send to the session message bus. (This is the default.)
-.TP
-.BI \-\-type= TYPE
-Specify \fBmethod_call\fP or \fBsignal\fP (defaults to "\fBsignal\fP").
-
-.SH AUTHOR
-dbus\-send was written by Philip Blundell.
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/cmake/tools/dbus-send.xml b/doc/dbus-send.1.xml.in
index 7fefc03e..67b6dfd2 100644
--- a/cmake/tools/dbus-send.xml
+++ b/doc/dbus-send.1.xml.in
@@ -1,34 +1,34 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
- "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
-<!-- lifted from troff+man by doclifter -->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
<refentry id='dbussend1'>
-<!-- -->
-<!-- dbus\-send manual page. -->
-<!-- Copyright (C) 2003 Red Hat, Inc. -->
+
+<!-- dbus&bsol;-send manual page.
+ Copyright (C) 2003 Red Hat, Inc. -->
<refmeta>
<refentrytitle>dbus-send</refentrytitle>
<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
</refmeta>
-<refnamediv id='name'>
+<refnamediv>
<refname>dbus-send</refname>
<refpurpose>Send a message to a message bus</refpurpose>
</refnamediv>
<!-- body begins here -->
<refsynopsisdiv id='synopsis'>
<cmdsynopsis>
- <command>dbus-send</command>
- <group choice='opt'><arg choice='plain'>--system </arg><arg choice='plain'>--session </arg></group>
+ <command>dbus-send</command>
+ <group choice='opt'><arg choice='plain'>--system </arg><arg choice='plain'>--session </arg><arg choice='plain'>--address=<replaceable>ADDRESS</replaceable></arg></group>
<arg choice='opt'>--dest=<replaceable>NAME</replaceable></arg>
- <arg choice='opt'>--print-reply </arg>
+ <arg choice='opt'><arg choice='plain'>--print-reply </arg><arg choice='opt'><replaceable>=literal</replaceable></arg></arg>
+ <arg choice='opt'>--reply-timeout=<replaceable>MSEC</replaceable></arg>
<arg choice='opt'>--type=<replaceable>TYPE</replaceable></arg>
- <arg choice='plain'><replaceable>&lt;destination</replaceable></arg>
- <arg choice='plain'><replaceable>object</replaceable></arg>
- <arg choice='plain'><replaceable>path&gt;</replaceable></arg>
- <arg choice='plain'><replaceable>&lt;message</replaceable></arg>
- <arg choice='plain'><replaceable>name&gt;</replaceable></arg>
- <arg choice='opt' rep='repeat'><replaceable>contents</replaceable></arg>
+ <arg choice='plain'><replaceable>OBJECT_PATH</replaceable></arg>
+ <arg choice='plain'><replaceable>INTERFACE.MEMBER</replaceable></arg>
+ <arg choice='opt' rep='repeat'><replaceable>CONTENTS</replaceable></arg>
<sbr/>
</cmdsynopsis>
</refsynopsisdiv>
@@ -36,33 +36,33 @@
<refsect1 id='description'><title>DESCRIPTION</title>
<para>The <command>dbus-send</command> command is used to send a message to a D-Bus message
-bus. See <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more
+bus. See <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more
information about the big picture.</para>
-<para>There are two well-known message buses: the systemwide message bus
-(installed on many systems as the "messagebus" service) and the
+<para>There are two well-known message buses: the systemwide message bus
+(installed on many systems as the "messagebus" service) and the
per-user-login-session message bus (started each time a user logs in).
-The --system and --session options direct <command>dbus-send</command> to send
-messages to the system or session buses respectively. If neither is
-specified, <command>dbus-send</command> sends to the session bus.</para>
+The <option>--system</option> and <option>--session</option> options direct
+<command>dbus-send</command> to send messages to the system or session buses respectively.
+If neither is specified, <command>dbus-send</command> sends to the session bus.</para>
-<para>Nearly all uses of <command>dbus-send</command> must provide the --dest argument
+<para>Nearly all uses of <command>dbus-send</command> must provide the <option>--dest</option> argument
which is the name of a connection on the bus to send the message to. If
---dest is omitted, no destination is set.</para>
+<option>--dest</option> is omitted, no destination is set.</para>
<para>The object path and the name of the message to send must always be
specified. Following arguments, if any, are the message contents
-(message arguments). These are given as type-specified values and
+(message arguments). These are given as type-specified values and
may include containers (arrays, dicts, and variants) as described below.</para>
<literallayout remap='.nf'>
&lt;contents&gt; ::= &lt;item&gt; | &lt;container&gt; [ &lt;item&gt; | &lt;container&gt;...]
&lt;item&gt; ::= &lt;type&gt;:&lt;value&gt;
&lt;container&gt; ::= &lt;array&gt; | &lt;dict&gt; | &lt;variant&gt;
-&lt;array&gt; ::= array:&lt;type&gt;:&lt;value&gt;[,&lt;value&gt;...]
+&lt;array&gt; ::= array:&lt;type&gt;:&lt;value&gt;[,&lt;value&gt;...]
&lt;dict&gt; ::= dict:&lt;type&gt;:&lt;type&gt;:&lt;key&gt;,&lt;value&gt;[,&lt;key&gt;,&lt;value&gt;...]
&lt;variant&gt; ::= variant:&lt;type&gt;:&lt;value&gt;
&lt;type&gt; ::= string | int16 | uint 16 | int32 | uint32 | int64 | uint64 | double | byte | boolean | objpath
@@ -76,18 +76,18 @@ or nested containers (e.g. arrays of variants).</para>
<para>Here is an example invocation:</para>
<literallayout remap='.nf'>
- dbus-send --dest=org.freedesktop.ExampleName \
- /org/freedesktop/sample/object/name \
- org.freedesktop.ExampleInterface.ExampleMethod \
- int32:47 string:'hello world' double:65.32 \
- array:string:"1st item","next item","last item" \
- dict:string:int32:"one",1,"two",2,"three",3 \
- variant:int32:-8 \
- objpath:/org/freedesktop/sample/object/name
+ dbus-send --dest=org.freedesktop.ExampleName &bsol;
+ /org/freedesktop/sample/object/name &bsol;
+ org.freedesktop.ExampleInterface.ExampleMethod &bsol;
+ int32:47 string:'hello world' double:65.32 &bsol;
+ array:string:"1st item","next item","last item" &bsol;
+ dict:string:int32:"one",1,"two",2,"three",3 &bsol;
+ variant:int32:-8 &bsol;
+ objpath:/org/freedesktop/sample/object/name
</literallayout> <!-- .fi -->
-<para>Note that the interface is separated from a method or signal
+<para>Note that the interface is separated from a method or signal
name by a dot, though in the actual protocol the interface
and the interface member are separate fields.</para>
@@ -97,7 +97,7 @@ and the interface member are separate fields.</para>
<para>The following options are supported:</para>
<variablelist remap='TP'>
<varlistentry>
- <term><option>--dest=NAME</option></term>
+ <term><option>--dest=</option><replaceable>NAME</replaceable></term>
<listitem>
<para>Specify the name of the connection to receive the message.</para>
</listitem>
@@ -105,7 +105,23 @@ and the interface member are separate fields.</para>
<varlistentry>
<term><option>--print-reply</option></term>
<listitem>
-<para>Block for a reply to the message sent, and print any reply received.</para>
+<para>Block for a reply to the message sent, and print any reply received
+in a human-readable form. It also means the message type (<option>--type=</option>) is <emphasis remap='B'>method_call</emphasis>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--print-reply=literal</option></term>
+ <listitem>
+<para>Block for a reply to the message sent, and print the body of the
+reply. If the reply is an object path or a string, it is printed
+literally, with no punctuation, escape characters etc.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--reply-timeout=</option><replaceable>MSEC</replaceable></term>
+ <listitem>
+<para>Wait for a reply for up to <emphasis remap='I'>MSEC</emphasis> milliseconds.
+The default is implementation&hyphen;defined, typically 25 seconds.</para>
</listitem>
</varlistentry>
<varlistentry>
@@ -121,9 +137,15 @@ and the interface member are separate fields.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>--type=TYPE</option></term>
+ <term><option>--address=</option><replaceable>ADDRESS</replaceable></term>
<listitem>
-<para>Specify "method_call" or "signal" (defaults to "signal").</para>
+<para>Send to <replaceable>ADDRESS</replaceable>.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--type=</option><replaceable>TYPE</replaceable></term>
+ <listitem>
+<para>Specify <emphasis remap='B'>method_call</emphasis> or <emphasis remap='B'>signal</emphasis> (defaults to "<emphasis remap='B'>signal</emphasis>").</para>
</listitem>
</varlistentry>
@@ -140,4 +162,3 @@ and the interface member are separate fields.</para>
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>
-
diff --git a/doc/dbus-specification.xml b/doc/dbus-specification.xml
index d806b8ea..8b83495f 100644
--- a/doc/dbus-specification.xml
+++ b/doc/dbus-specification.xml
@@ -1,53 +1,53 @@
<?xml version="1.0" standalone="no" ?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
]>
<article id="index">
<articleinfo>
<title>D-Bus Specification</title>
- <releaseinfo>Version 0.19</releaseinfo>
- <date>2012-02-21</date>
+ <releaseinfo>Version 0.23</releaseinfo>
+ <date>2014-01-06</date>
<authorgroup>
<author>
- <firstname>Havoc</firstname>
- <surname>Pennington</surname>
- <affiliation>
- <orgname>Red Hat, Inc.</orgname>
- <address>
- <email>hp@pobox.com</email>
- </address>
- </affiliation>
+ <firstname>Havoc</firstname>
+ <surname>Pennington</surname>
+ <affiliation>
+ <orgname>Red Hat, Inc.</orgname>
+ <address>
+ <email>hp@pobox.com</email>
+ </address>
+ </affiliation>
</author>
<author>
- <firstname>Anders</firstname>
- <surname>Carlsson</surname>
- <affiliation>
- <orgname>CodeFactory AB</orgname>
- <address>
+ <firstname>Anders</firstname>
+ <surname>Carlsson</surname>
+ <affiliation>
+ <orgname>CodeFactory AB</orgname>
+ <address>
<email>andersca@codefactory.se</email>
</address>
- </affiliation>
+ </affiliation>
</author>
<author>
- <firstname>Alexander</firstname>
- <surname>Larsson</surname>
- <affiliation>
- <orgname>Red Hat, Inc.</orgname>
- <address>
+ <firstname>Alexander</firstname>
+ <surname>Larsson</surname>
+ <affiliation>
+ <orgname>Red Hat, Inc.</orgname>
+ <address>
<email>alexl@redhat.com</email>
</address>
- </affiliation>
+ </affiliation>
</author>
<author>
- <firstname>Sven</firstname>
- <surname>Herzberg</surname>
- <affiliation>
- <orgname>Imendio AB</orgname>
- <address>
+ <firstname>Sven</firstname>
+ <surname>Herzberg</surname>
+ <affiliation>
+ <orgname>Imendio AB</orgname>
+ <address>
<email>sven@imendio.com</email>
</address>
- </affiliation>
+ </affiliation>
</author>
<author>
<firstname>Simon</firstname>
@@ -72,10 +72,37 @@
</authorgroup>
<revhistory>
<revision>
- <revnumber>current</revnumber>
- <date><ulink url='http://cgit.freedesktop.org/dbus/dbus/log/doc/dbus-specification.xml'>commit log</ulink></date>
+ <revnumber>0.23</revnumber>
+ <date>2014-01-06</date>
+ <authorinitials>SMcV, CY</authorinitials>
+ <revremark>
+ method call messages with no INTERFACE may be considered an error;
+ document tcp:bind=... and nonce-tcp:bind=...; define listenable
+ and connectable addresses
+ </revremark>
+ </revision>
+ <revision>
+ <revnumber>0.22</revnumber>
+ <date>2013-10-09</date>
<authorinitials></authorinitials>
- <revremark></revremark>
+ <revremark>add GetConnectionCredentials, document
+ GetAtdAuditSessionData, document GetConnectionSELinuxSecurityContext,
+ document and correct .service file syntax and naming
+ </revremark>
+ </revision>
+ <revision>
+ <revnumber>0.21</revnumber>
+ <date>2013-04-25</date>
+ <authorinitials>smcv</authorinitials>
+ <revremark>allow Unicode noncharacters in UTF-8 (Unicode
+ Corrigendum #9)</revremark>
+ </revision>
+ <revision>
+ <revnumber>0.20</revnumber>
+ <date>22 February 2013</date>
+ <authorinitials>smcv, walters</authorinitials>
+ <revremark>reorganise for clarity, remove false claims about
+ basic types, mention /o/fd/DBus</revremark>
</revision>
<revision>
<revnumber>0.19</revnumber>
@@ -161,23 +188,18 @@
<sect1 id="introduction">
<title>Introduction</title>
<para>
- D-Bus is a system for low-latency, low-overhead, easy to use
+ D-Bus is a system for low-overhead, easy to use
interprocess communication (IPC). In more detail:
<itemizedlist>
<listitem>
<para>
- D-Bus is <emphasis>low-latency</emphasis> because it is designed
- to avoid round trips and allow asynchronous operation, much like
- the X protocol.
- </para>
- </listitem>
- <listitem>
- <para>
D-Bus is <emphasis>low-overhead</emphasis> because it uses a
binary protocol, and does not have to convert to and from a text
format such as XML. Because D-Bus is intended for potentially
high-resolution same-machine IPC, not primarily for Internet IPC,
- this is an interesting optimization.
+ this is an interesting optimization. D-Bus is also designed to
+ avoid round trips and allow asynchronous operation, much like
+ the X protocol.
</para>
</listitem>
<listitem>
@@ -292,17 +314,68 @@
it back from the wire format is <firstterm>unmarshaling</firstterm>.
</para>
- <sect2 id="message-protocol-signatures">
- <title>Type Signatures</title>
+ <para>
+ The D-Bus protocol does not include type tags in the marshaled data; a
+ block of marshaled values must have a known <firstterm>type
+ signature</firstterm>. The type signature is made up of zero or more
+ <firstterm id="term-single-complete-type">single complete
+ types</firstterm>, each made up of one or more
+ <firstterm>type codes</firstterm>.
+ </para>
+
+ <para>
+ A type code is an ASCII character representing the
+ type of a value. Because ASCII characters are used, the type signature
+ will always form a valid ASCII string. A simple string compare
+ determines whether two type signatures are equivalent.
+ </para>
+
+ <para>
+ A single complete type is a sequence of type codes that fully describes
+ one type: either a basic type, or a single fully-described container type.
+ A single complete type is a basic type code, a variant type code,
+ an array with its element type, or a struct with its fields (all of which
+ are defined below). So the following signatures are not single complete
+ types:
+ <programlisting>
+ "aa"
+ </programlisting>
+ <programlisting>
+ "(ii"
+ </programlisting>
+ <programlisting>
+ "ii)"
+ </programlisting>
+ And the following signatures contain multiple complete types:
+ <programlisting>
+ "ii"
+ </programlisting>
+ <programlisting>
+ "aiai"
+ </programlisting>
+ <programlisting>
+ "(ii)(ii)"
+ </programlisting>
+ Note however that a single complete type may <emphasis>contain</emphasis>
+ multiple other single complete types, by containing a struct or dict
+ entry.
+ </para>
+
+ <sect2 id="basic-types">
+ <title>Basic types</title>
+
+ <para>
+ The simplest type codes are the <firstterm id="term-basic-type">basic
+ types</firstterm>, which are the types whose structure is entirely
+ defined by their 1-character type code. Basic types consist of
+ fixed types and string-like types.
+ </para>
<para>
- The D-Bus protocol does not include type tags in the marshaled data; a
- block of marshaled values must have a known <firstterm>type
- signature</firstterm>. The type signature is made up of <firstterm>type
- codes</firstterm>. A type code is an ASCII character representing the
- type of a value. Because ASCII characters are used, the type signature
- will always form a valid ASCII string. A simple string compare
- determines whether two type signatures are equivalent.
+ The <firstterm id="term-fixed-type">fixed types</firstterm>
+ are basic types whose values have a fixed length, namely BYTE,
+ BOOLEAN, DOUBLE, UNIX_FD, and signed or unsigned integers of length
+ 16, 32 or 64 bits.
</para>
<para>
@@ -319,10 +392,267 @@
</para>
<para>
- All <firstterm>basic</firstterm> types work like
- <literal>INT32</literal> in this example. To marshal and unmarshal
- basic types, you simply read one value from the data
- block corresponding to each type code in the signature.
+ The characteristics of the fixed types are listed in this table.
+
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Conventional name</entry>
+ <entry>ASCII type-code</entry>
+ <entry>Encoding</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>BYTE</literal></entry>
+ <entry><literal>y</literal> (121)</entry>
+ <entry>Unsigned 8-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>BOOLEAN</literal></entry>
+ <entry><literal>b</literal> (98)</entry>
+ <entry>Boolean value: 0 is false, 1 is true, any other value
+ allowed by the marshalling format is invalid</entry>
+ </row>
+ <row>
+ <entry><literal>INT16</literal></entry>
+ <entry><literal>n</literal> (110)</entry>
+ <entry>Signed (two's complement) 16-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>UINT16</literal></entry>
+ <entry><literal>q</literal> (113)</entry>
+ <entry>Unsigned 16-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>INT32</literal></entry>
+ <entry><literal>i</literal> (105)</entry>
+ <entry>Signed (two's complement) 32-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>UINT32</literal></entry>
+ <entry><literal>u</literal> (117)</entry>
+ <entry>Unsigned 32-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>INT64</literal></entry>
+ <entry><literal>x</literal> (120)</entry>
+ <entry>Signed (two's complement) 64-bit integer
+ (mnemonic: x and t are the first characters in "sixty" not
+ already used for something more common)</entry>
+ </row>
+ <row>
+ <entry><literal>UINT64</literal></entry>
+ <entry><literal>t</literal> (116)</entry>
+ <entry>Unsigned 64-bit integer</entry>
+ </row>
+ <row>
+ <entry><literal>DOUBLE</literal></entry>
+ <entry><literal>d</literal> (100)</entry>
+ <entry>IEEE 754 double-precision floating point</entry>
+ </row>
+ <row>
+ <entry><literal>UNIX_FD</literal></entry>
+ <entry><literal>h</literal> (104)</entry>
+ <entry>Unsigned 32-bit integer representing an index into an
+ out-of-band array of file descriptors, transferred via some
+ platform-specific mechanism (mnemonic: h for handle)</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+
+ <para>
+ The <firstterm id="term-string-like-type">string-like types</firstterm>
+ are basic types with a variable length. The value of any string-like
+ type is conceptually 0 or more Unicode codepoints encoded in UTF-8,
+ none of which may be U+0000. The UTF-8 text must be validated
+ strictly: in particular, it must not contain overlong sequences
+ or codepoints above U+10FFFF.
+ </para>
+
+ <para>
+ Since D-Bus Specification version 0.21, in accordance with Unicode
+ Corrigendum #9, the "noncharacters" U+FDD0..U+FDEF, U+nFFFE and
+ U+nFFFF are allowed in UTF-8 strings (but note that older versions of
+ D-Bus rejected these noncharacters).
+ </para>
+
+ <para>
+ The marshalling formats for the string-like types all end with a
+ single zero (NUL) byte, but that byte is not considered to be part of
+ the text.
+ </para>
+
+ <para>
+ The characteristics of the string-like types are listed in this table.
+
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Conventional name</entry>
+ <entry>ASCII type-code</entry>
+ <entry>Validity constraints</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>STRING</literal></entry>
+ <entry><literal>s</literal> (115)</entry>
+ <entry>No extra constraints</entry>
+ </row>
+ <row>
+ <entry><literal>OBJECT_PATH</literal></entry>
+ <entry><literal>o</literal> (111)</entry>
+ <entry>Must be
+ <link linkend="message-protocol-marshaling-object-path">a
+ syntactically valid object path</link></entry>
+ </row>
+ <row>
+ <entry><literal>SIGNATURE</literal></entry>
+ <entry><literal>g</literal> (103)</entry>
+ <entry>Zero or more
+ <firstterm linkend="term-single-complete-type">single
+ complete types</firstterm></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+
+ <sect3 id="message-protocol-marshaling-object-path">
+ <title>Valid Object Paths</title>
+
+ <para>
+ An object path is a name used to refer to an object instance.
+ Conceptually, each participant in a D-Bus message exchange may have
+ any number of object instances (think of C++ or Java objects) and each
+ such instance will have a path. Like a filesystem, the object
+ instances in an application form a hierarchical tree.
+ </para>
+
+ <para>
+ Object paths are often namespaced by starting with a reversed
+ domain name and containing an interface version number, in the
+ same way as
+ <link linkend="message-protocol-names-interface">interface
+ names</link> and
+ <link linkend="message-protocol-names-bus">well-known
+ bus names</link>.
+ This makes it possible to implement more than one service, or
+ more than one version of a service, in the same process,
+ even if the services share a connection but cannot otherwise
+ co-operate (for instance, if they are implemented by different
+ plugins).
+ </para>
+
+ <para>
+ For instance, if the owner of <literal>example.com</literal> is
+ developing a D-Bus API for a music player, they might use the
+ hierarchy of object paths that start with
+ <literal>/com/example/MusicPlayer1</literal> for its objects.
+ </para>
+
+ <para>
+ The following rules define a valid object path. Implementations must
+ not send or accept messages with invalid object paths.
+ <itemizedlist>
+ <listitem>
+ <para>
+ The path may be of any length.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The path must begin with an ASCII '/' (integer 47) character,
+ and must consist of elements separated by slash characters.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Each element must only contain the ASCII characters
+ "[A-Z][a-z][0-9]_"
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ No element may be the empty string.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Multiple '/' characters cannot occur in sequence.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ A trailing '/' character is not allowed unless the
+ path is the root path (a single '/' character).
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ </sect3>
+
+ <sect3 id="message-protocol-marshaling-signature">
+ <title>Valid Signatures</title>
+ <para>
+ An implementation must not send or accept invalid signatures.
+ Valid signatures will conform to the following rules:
+ <itemizedlist>
+ <listitem>
+ <para>
+ The signature is a list of single complete types.
+ Arrays must have element types, and structs must
+ have both open and close parentheses.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Only type codes, open and close parentheses, and open and
+ close curly brackets are allowed in the signature. The
+ <literal>STRUCT</literal> type code
+ is not allowed in signatures, because parentheses
+ are used instead. Similarly, the
+ <literal>DICT_ENTRY</literal> type code is not allowed in
+ signatures, because curly brackets are used instead.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The maximum depth of container type nesting is 32 array type
+ codes and 32 open parentheses. This implies that the maximum
+ total depth of recursion is 64, for an "array of array of array
+ of ... struct of struct of struct of ..." where there are 32
+ array and 32 struct.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The maximum length of a signature is 255.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <para>
+ When signatures appear in messages, the marshalling format
+ guarantees that they will be followed by a nul byte (which can
+ be interpreted as either C-style string termination or the INVALID
+ type-code), but this is not conceptually part of the signature.
+ </para>
+ </sect3>
+
+ </sect2>
+
+ <sect2 id="container-types">
+ <title>Container types</title>
+
+ <para>
In addition to basic types, there are four <firstterm>container</firstterm>
types: <literal>STRUCT</literal>, <literal>ARRAY</literal>, <literal>VARIANT</literal>,
and <literal>DICT_ENTRY</literal>.
@@ -378,34 +708,6 @@
</para>
<para>
- The phrase <firstterm>single complete type</firstterm> deserves some
- definition. A single complete type is a basic type code, a variant type code,
- an array with its element type, or a struct with its fields.
- So the following signatures are not single complete types:
- <programlisting>
- "aa"
- </programlisting>
- <programlisting>
- "(ii"
- </programlisting>
- <programlisting>
- "ii)"
- </programlisting>
- And the following signatures contain multiple complete types:
- <programlisting>
- "ii"
- </programlisting>
- <programlisting>
- "aiai"
- </programlisting>
- <programlisting>
- "(ii)(ii)"
- </programlisting>
- Note however that a single complete type may <emphasis>contain</emphasis>
- multiple other single complete types.
- </para>
-
- <para>
<literal>VARIANT</literal> has ASCII character 'v' as its type code. A marshaled value of
type <literal>VARIANT</literal> will have the signature of a single complete type as part
of the <emphasis>value</emphasis>. This signature will be followed by a
@@ -413,6 +715,14 @@
</para>
<para>
+ Unlike a message signature, the variant signature can
+ contain only a single complete type. So "i", "ai"
+ or "(ii)" is OK, but "ii" is not. Use of variants may not
+ cause a total message depth to be larger than 64, including
+ other container types such as structures.
+ </para>
+
+ <para>
A <literal>DICT_ENTRY</literal> works exactly like a struct, but rather
than parentheses it uses curly braces, and it has more restrictions.
The restrictions are: it occurs only as an array element type; it has
@@ -435,6 +745,10 @@
In most languages, an array of dict entry would be represented as a
map, hash table, or dict object.
</para>
+ </sect2>
+
+ <sect2>
+ <title>Summary of types</title>
<para>
The following table summarizes the D-Bus types.
@@ -453,14 +767,14 @@
<entry>0 (ASCII NUL)</entry>
<entry>Not a valid type code, used to terminate signatures</entry>
</row><row>
- <entry><literal>BYTE</literal></entry>
- <entry>121 (ASCII 'y')</entry>
- <entry>8-bit unsigned integer</entry>
+ <entry><literal>BYTE</literal></entry>
+ <entry>121 (ASCII 'y')</entry>
+ <entry>8-bit unsigned integer</entry>
+ </row><row>
+ <entry><literal>BOOLEAN</literal></entry>
+ <entry>98 (ASCII 'b')</entry>
+ <entry>Boolean value, 0 is <literal>FALSE</literal> and 1 is <literal>TRUE</literal>. Everything else is invalid.</entry>
</row><row>
- <entry><literal>BOOLEAN</literal></entry>
- <entry>98 (ASCII 'b')</entry>
- <entry>Boolean value, 0 is <literal>FALSE</literal> and 1 is <literal>TRUE</literal>. Everything else is invalid.</entry>
- </row><row>
<entry><literal>INT16</literal></entry>
<entry>110 (ASCII 'n')</entry>
<entry>16-bit signed integer</entry>
@@ -468,7 +782,7 @@
<entry><literal>UINT16</literal></entry>
<entry>113 (ASCII 'q')</entry>
<entry>16-bit unsigned integer</entry>
- </row><row>
+ </row><row>
<entry><literal>INT32</literal></entry>
<entry>105 (ASCII 'i')</entry>
<entry>32-bit signed integer</entry>
@@ -476,7 +790,7 @@
<entry><literal>UINT32</literal></entry>
<entry>117 (ASCII 'u')</entry>
<entry>32-bit unsigned integer</entry>
- </row><row>
+ </row><row>
<entry><literal>INT64</literal></entry>
<entry>120 (ASCII 'x')</entry>
<entry>64-bit signed integer</entry>
@@ -566,9 +880,21 @@
</para>
</sect2>
+ </sect1>
+
+ <sect1 id="message-protocol-marshaling">
+ <title>Marshaling (Wire Format)</title>
- <sect2 id="message-protocol-marshaling">
- <title>Marshaling (Wire Format)</title>
+ <para>
+ D-Bus defines a marshalling format for its type system, which is
+ used in D-Bus messages. This is not the only possible marshalling
+ format for the type system: for instance, GVariant (part of GLib)
+ re-uses the D-Bus type system but implements an alternative marshalling
+ format.
+ </para>
+
+ <sect2>
+ <title>Byte order and alignment</title>
<para>
Given a type signature, a block of bytes can be converted into typed
@@ -577,11 +903,11 @@
</para>
<para>
- A block of bytes has an associated byte order. The byte order
- has to be discovered in some way; for D-Bus messages, the
- byte order is part of the message header as described in
- <xref linkend="message-protocol-messages"/>. For now, assume
- that the byte order is known to be either little endian or big
+ A block of bytes has an associated byte order. The byte order
+ has to be discovered in some way; for D-Bus messages, the
+ byte order is part of the message header as described in
+ <xref linkend="message-protocol-messages"/>. For now, assume
+ that the byte order is known to be either little endian or big
endian.
</para>
@@ -597,6 +923,95 @@
</para>
<para>
+ As an exception to natural alignment, <literal>STRUCT</literal> and
+ <literal>DICT_ENTRY</literal> values are always aligned to an 8-byte
+ boundary, regardless of the alignments of their contents.
+ </para>
+ </sect2>
+
+ <sect2>
+ <title>Marshalling basic types</title>
+
+ <para>
+ To marshal and unmarshal fixed types, you simply read one value
+ from the data block corresponding to each type code in the signature.
+ All signed integer values are encoded in two's complement, DOUBLE
+ values are IEEE 754 double-precision floating-point, and BOOLEAN
+ values are encoded in 32 bits (of which only the least significant
+ bit is used).
+ </para>
+
+ <para>
+ The string-like types are all marshalled as a
+ fixed-length unsigned integer <varname>n</varname> giving the
+ length of the variable part, followed by <varname>n</varname>
+ nonzero bytes of UTF-8 text, followed by a single zero (nul) byte
+ which is not considered to be part of the text. The alignment
+ of the string-like type is the same as the alignment of
+ <varname>n</varname>.
+ </para>
+
+ <para>
+ For the STRING and OBJECT_PATH types, <varname>n</varname> is
+ encoded in 4 bytes, leading to 4-byte alignment.
+ For the SIGNATURE type, <varname>n</varname> is encoded as a single
+ byte. As a result, alignment padding is never required before a
+ SIGNATURE.
+ </para>
+ </sect2>
+
+ <sect2>
+ <title>Marshalling containers</title>
+
+ <para>
+ Arrays are marshalled as a <literal>UINT32</literal>
+ <varname>n</varname> giving the length of the array data in bytes,
+ followed by alignment padding to the alignment boundary of the array
+ element type, followed by the <varname>n</varname> bytes of the
+ array elements marshalled in sequence. <varname>n</varname> does not
+ include the padding after the length, or any padding after the
+ last element.
+ </para>
+
+ <para>
+ For instance, if the current position in the message is a multiple
+ of 8 bytes and the byte-order is big-endian, an array containing only
+ the 64-bit integer 5 would be marshalled as:
+
+ <screen>
+00 00 00 08 <lineannotation>8 bytes of data</lineannotation>
+00 00 00 00 <lineannotation>padding to 8-byte boundary</lineannotation>
+00 00 00 00 00 00 00 05 <lineannotation>first element = 5</lineannotation>
+ </screen>
+ </para>
+
+ <para>
+ Arrays have a maximum length defined to be 2 to the 26th power or
+ 67108864. Implementations must not send or accept arrays exceeding this
+ length.
+ </para>
+
+ <para>
+ Structs and dict entries are marshalled in the same way as their
+ contents, but their alignment is always to an 8-byte boundary,
+ even if their contents would normally be less strictly aligned.
+ </para>
+
+ <para>
+ Variants are marshalled as the <literal>SIGNATURE</literal> of
+ the contents (which must be a single complete type), followed by a
+ marshalled value with the type given by that signature. The
+ variant has the same 1-byte alignment as the signature, which means
+ that alignment padding before a variant is never needed.
+ Use of variants may not cause a total message depth to be larger
+ than 64, including other container types such as structures.
+ </para>
+ </sect2>
+
+ <sect2>
+ <title>Summary of D-Bus marshalling</title>
+
+ <para>
Given all this, the types are marshaled on the wire as follows:
<informaltable>
<tgroup cols="3">
@@ -661,7 +1076,7 @@
</row><row>
<entry><literal>OBJECT_PATH</literal></entry>
<entry>Exactly the same as <literal>STRING</literal> except the
- content must be a valid object path (see below).
+ content must be a valid object path (see above).
</entry>
<entry>
4 (for the length)
@@ -670,7 +1085,7 @@
<entry><literal>SIGNATURE</literal></entry>
<entry>The same as <literal>STRING</literal> except the length is a single
byte (thus signatures have a maximum length of 255)
- and the content must be a valid signature (see below).
+ and the content must be a valid signature (see above).
</entry>
<entry>
1
@@ -679,14 +1094,8 @@
<entry><literal>ARRAY</literal></entry>
<entry>
A <literal>UINT32</literal> giving the length of the array data in bytes, followed by
- alignment padding to the alignment boundary of the array element type,
- followed by each array element. The array length is from the
- end of the alignment padding to the end of the last element,
- i.e. it does not include the padding after the length,
- or any padding after the last element.
- Arrays have a maximum length defined to be 2 to the 26th power or
- 67108864. Implementations must not send or accept arrays exceeding this
- length.
+ alignment padding to the alignment boundary of the array element type,
+ followed by each array element.
</entry>
<entry>
4 (for the length)
@@ -702,22 +1111,17 @@
<entry>
8
</entry>
- </row><row>
+ </row><row>
<entry><literal>VARIANT</literal></entry>
<entry>
- A variant type has a marshaled
- <literal>SIGNATURE</literal> followed by a marshaled
- value with the type given in the signature. Unlike
- a message signature, the variant signature can
- contain only a single complete type. So "i", "ai"
- or "(ii)" is OK, but "ii" is not. Use of variants may not
- cause a total message depth to be larger than 64, including
- other container types such as structures.
+ The marshaled <literal>SIGNATURE</literal> of a single
+ complete type, followed by a marshaled value with the type
+ given in the signature.
</entry>
<entry>
1 (alignment of the signature)
</entry>
- </row><row>
+ </row><row>
<entry><literal>DICT_ENTRY</literal></entry>
<entry>
Identical to STRUCT.
@@ -734,135 +1138,12 @@
file descriptor in the array of file descriptors that
accompany the message.</entry>
<entry>4</entry>
- </row>
+ </row>
</tbody>
</tgroup>
</informaltable>
</para>
-
- <sect3 id="message-protocol-marshaling-object-path">
- <title>Valid Object Paths</title>
-
- <para>
- An object path is a name used to refer to an object instance.
- Conceptually, each participant in a D-Bus message exchange may have
- any number of object instances (think of C++ or Java objects) and each
- such instance will have a path. Like a filesystem, the object
- instances in an application form a hierarchical tree.
- </para>
-
- <para>
- The following rules define a valid object path. Implementations must
- not send or accept messages with invalid object paths.
- <itemizedlist>
- <listitem>
- <para>
- The path may be of any length.
- </para>
- </listitem>
- <listitem>
- <para>
- The path must begin with an ASCII '/' (integer 47) character,
- and must consist of elements separated by slash characters.
- </para>
- </listitem>
- <listitem>
- <para>
- Each element must only contain the ASCII characters
- "[A-Z][a-z][0-9]_"
- </para>
- </listitem>
- <listitem>
- <para>
- No element may be the empty string.
- </para>
- </listitem>
- <listitem>
- <para>
- Multiple '/' characters cannot occur in sequence.
- </para>
- </listitem>
- <listitem>
- <para>
- A trailing '/' character is not allowed unless the
- path is the root path (a single '/' character).
- </para>
- </listitem>
- </itemizedlist>
- </para>
- <para>
- Object paths are often namespaced by starting with a reversed
- domain name and containing an interface version number, in the
- same way as
- <link linkend="message-protocol-names-interface">interface
- names</link> and
- <link linkend="message-protocol-names-bus">well-known
- bus names</link>.
- This makes it possible to implement more than one service, or
- more than one version of a service, in the same process,
- even if the services share a connection but cannot otherwise
- co-operate (for instance, if they are implemented by different
- plugins).
- </para>
-
- <para>
- For instance, if the owner of <literal>example.com</literal> is
- developing a D-Bus API for a music player, they might use the
- hierarchy of object paths that start with
- <literal>/com/example/MusicPlayer1</literal> for its objects.
- </para>
- </sect3>
-
- <sect3 id="message-protocol-marshaling-signature">
- <title>Valid Signatures</title>
- <para>
- An implementation must not send or accept invalid signatures.
- Valid signatures will conform to the following rules:
- <itemizedlist>
- <listitem>
- <para>
- The signature ends with a nul byte.
- </para>
- </listitem>
- <listitem>
- <para>
- The signature is a list of single complete types.
- Arrays must have element types, and structs must
- have both open and close parentheses.
- </para>
- </listitem>
- <listitem>
- <para>
- Only type codes and open and close parentheses are
- allowed in the signature. The <literal>STRUCT</literal> type code
- is not allowed in signatures, because parentheses
- are used instead.
- </para>
- </listitem>
- <listitem>
- <para>
- The maximum depth of container type nesting is 32 array type
- codes and 32 open parentheses. This implies that the maximum
- total depth of recursion is 64, for an "array of array of array
- of ... struct of struct of struct of ..." where there are 32
- array and 32 struct.
- </para>
- </listitem>
- <listitem>
- <para>
- The maximum length of a signature is 255.
- </para>
- </listitem>
- <listitem>
- <para>
- Signatures must be nul-terminated.
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </sect3>
-
</sect2>
</sect1>
@@ -1249,12 +1530,12 @@
</para>
</listitem>
- <listitem><para>Interface names must contain at least one '.' (period)
+ <listitem><para>Interface names must contain at least one '.' (period)
character (and thus at least two elements).
</para></listitem>
- <listitem><para>Interface names must not begin with a '.' (period) character.</para></listitem>
- <listitem><para>Interface names must not exceed the maximum name length.</para></listitem>
+ <listitem><para>Interface names must not begin with a '.' (period) character.</para></listitem>
+ <listitem><para>Interface names must not exceed the maximum name length.</para></listitem>
</itemizedlist>
</para>
@@ -1313,12 +1594,12 @@
</para>
</listitem>
- <listitem><para>Bus names must contain at least one '.' (period)
+ <listitem><para>Bus names must contain at least one '.' (period)
character (and thus at least two elements).
</para></listitem>
- <listitem><para>Bus names must not begin with a '.' (period) character.</para></listitem>
- <listitem><para>Bus names must not exceed the maximum name length.</para></listitem>
+ <listitem><para>Bus names must not begin with a '.' (period) character.</para></listitem>
+ <listitem><para>Bus names must not exceed the maximum name length.</para></listitem>
</itemizedlist>
</para>
<para>
@@ -1356,12 +1637,12 @@
<para>
Member (i.e. method or signal) names:
<itemizedlist>
- <listitem><para>Must only contain the ASCII characters
+ <listitem><para>Must only contain the ASCII characters
"[A-Z][a-z][0-9]_" and may not begin with a
digit.</para></listitem>
- <listitem><para>Must not contain the '.' (period) character.</para></listitem>
- <listitem><para>Must not exceed the maximum name length.</para></listitem>
- <listitem><para>Must be at least 1 byte in length.</para></listitem>
+ <listitem><para>Must not contain the '.' (period) character.</para></listitem>
+ <listitem><para>Must not exceed the maximum name length.</para></listitem>
+ <listitem><para>Must be at least 1 byte in length.</para></listitem>
</itemizedlist>
</para>
@@ -1409,12 +1690,25 @@
<para>
A method call message is required to have a <literal>MEMBER</literal> header field
indicating the name of the method. Optionally, the message has an
- <literal>INTERFACE</literal> field giving the interface the method is a part of. In the
- absence of an <literal>INTERFACE</literal> field, if two interfaces on the same object have
- a method with the same name, it is undefined which of the two methods
- will be invoked. Implementations may also choose to return an error in
- this ambiguous case. However, if a method name is unique
- implementations must not require an interface field.
+ <literal>INTERFACE</literal> field giving the interface the method is a part of.
+ Including the <literal>INTERFACE</literal> in all method call
+ messages is strongly recommended.
+ </para>
+ <para>
+ In the absence of an <literal>INTERFACE</literal> field, if two
+ or more interfaces on the same object have a method with the same
+ name, it is undefined which of those methods will be invoked.
+ Implementations may choose to either return an error, or deliver the
+ message as though it had an arbitrary one of those interfaces.
+ </para>
+ <para>
+ In some situations (such as the well-known system bus), messages
+ are filtered through an access-control list external to the
+ remote object implementation. If that filter rejects certain
+ messages by matching their interface, or accepts only messages
+ to specific interfaces, it must also reject messages that have no
+ <literal>INTERFACE</literal>: otherwise, malicious
+ applications could use this to bypass the filter.
</para>
<para>
Method call messages also include a <literal>PATH</literal> field
@@ -1692,23 +1986,23 @@
Commands from the client to the server are as follows:
<itemizedlist>
- <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
- <listitem><para>CANCEL</para></listitem>
- <listitem><para>BEGIN</para></listitem>
- <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
- <listitem><para>ERROR [human-readable error explanation]</para></listitem>
- <listitem><para>NEGOTIATE_UNIX_FD</para></listitem>
- </itemizedlist>
+ <listitem><para>AUTH [mechanism] [initial-response]</para></listitem>
+ <listitem><para>CANCEL</para></listitem>
+ <listitem><para>BEGIN</para></listitem>
+ <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
+ <listitem><para>ERROR [human-readable error explanation]</para></listitem>
+ <listitem><para>NEGOTIATE_UNIX_FD</para></listitem>
+ </itemizedlist>
From server to client are as follows:
<itemizedlist>
- <listitem><para>REJECTED &lt;space-separated list of mechanism names&gt;</para></listitem>
- <listitem><para>OK &lt;GUID in hex&gt;</para></listitem>
- <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
- <listitem><para>ERROR</para></listitem>
- <listitem><para>AGREE_UNIX_FD</para></listitem>
- </itemizedlist>
+ <listitem><para>REJECTED &lt;space-separated list of mechanism names&gt;</para></listitem>
+ <listitem><para>OK &lt;GUID in hex&gt;</para></listitem>
+ <listitem><para>DATA &lt;data in hex encoding&gt;</para></listitem>
+ <listitem><para>ERROR</para></listitem>
+ <listitem><para>AGREE_UNIX_FD</para></listitem>
+ </itemizedlist>
</para>
<para>
Unofficial extensions to the command set must begin with the letters
@@ -1938,18 +2232,18 @@
<para>
<figure>
- <title>Example of successful magic cookie authentication</title>
- <programlisting>
+ <title>Example of successful magic cookie authentication</title>
+ <programlisting>
(MAGIC_COOKIE is a made up mechanism)
C: AUTH MAGIC_COOKIE 3138363935333137393635383634
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of finding out mechanisms then picking one</title>
- <programlisting>
+ <title>Example of finding out mechanisms then picking one</title>
+ <programlisting>
C: AUTH
S: REJECTED KERBEROS_V4 SKEY
C: AUTH SKEY 7ab83f32ee
@@ -1958,20 +2252,20 @@
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of client sends unknown command then falls back to regular auth</title>
- <programlisting>
+ <title>Example of client sends unknown command then falls back to regular auth</title>
+ <programlisting>
C: FOOBAR
S: ERROR
C: AUTH MAGIC_COOKIE 3736343435313230333039
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of server doesn't support initial auth mechanism</title>
- <programlisting>
+ <title>Example of server doesn't support initial auth mechanism</title>
+ <programlisting>
C: AUTH MAGIC_COOKIE 3736343435313230333039
S: REJECTED KERBEROS_V4 SKEY
C: AUTH SKEY 7ab83f32ee
@@ -1980,10 +2274,10 @@
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of wrong password or the like followed by successful retry</title>
- <programlisting>
+ <title>Example of wrong password or the like followed by successful retry</title>
+ <programlisting>
C: AUTH MAGIC_COOKIE 3736343435313230333039
S: REJECTED KERBEROS_V4 SKEY
C: AUTH SKEY 7ab83f32ee
@@ -1996,10 +2290,10 @@
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of skey cancelled and restarted</title>
- <programlisting>
+ <title>Example of skey cancelled and restarted</title>
+ <programlisting>
C: AUTH MAGIC_COOKIE 3736343435313230333039
S: REJECTED KERBEROS_V4 SKEY
C: AUTH SKEY 7ab83f32ee
@@ -2012,10 +2306,10 @@
S: OK 1234deadbeef
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of successful magic cookie authentication with successful negotiation of Unix FD passing</title>
- <programlisting>
+ <title>Example of successful magic cookie authentication with successful negotiation of Unix FD passing</title>
+ <programlisting>
(MAGIC_COOKIE is a made up mechanism)
C: AUTH MAGIC_COOKIE 3138363935333137393635383634
@@ -2024,10 +2318,10 @@
S: AGREE_UNIX_FD
C: BEGIN
</programlisting>
- </figure>
+ </figure>
<figure>
- <title>Example of successful magic cookie authentication with unsuccessful negotiation of Unix FD passing</title>
- <programlisting>
+ <title>Example of successful magic cookie authentication with unsuccessful negotiation of Unix FD passing</title>
+ <programlisting>
(MAGIC_COOKIE is a made up mechanism)
C: AUTH MAGIC_COOKIE 3138363935333137393635383634
@@ -2036,7 +2330,7 @@
S: ERROR
C: BEGIN
</programlisting>
- </figure>
+ </figure>
</para>
</sect2>
<sect2 id="auth-states">
@@ -2174,7 +2468,7 @@
</listitem>
<listitem>
<para>
- Receive REJECT [mechs] &rarr; send AUTH [next mech],
+ Receive REJECTED [mechs] &rarr; send AUTH [next mech],
goto <emphasis>WaitingForData</emphasis> or
<emphasis>WaitingForOK</emphasis>
</para>
@@ -2210,7 +2504,7 @@
<itemizedlist>
<listitem>
<para>
- Receive REJECT [mechs] &rarr; send AUTH [next mech],
+ Receive REJECTED [mechs] &rarr; send AUTH [next mech],
goto <emphasis>WaitingForData</emphasis> or
<emphasis>WaitingForOK</emphasis>
</para>
@@ -2252,7 +2546,7 @@
<listitem>
<para>
- REJECT means that the client failed to authenticate or
+ REJECTED means that the client failed to authenticate or
there was an error in RESP.
</para>
</listitem>
@@ -2299,7 +2593,7 @@
</member>
<member>
- MECH(RESP) returns REJECT &rarr; send REJECTED
+ MECH(RESP) returns REJECTED &rarr; send REJECTED
[mechs], goto
<emphasis>WaitingForAuth</emphasis>
</member>
@@ -2353,7 +2647,7 @@
</member>
<member>
- MECH(RESP) returns REJECT &rarr; send REJECTED
+ MECH(RESP) returns REJECTED &rarr; send REJECTED
[mechs], goto
<emphasis>WaitingForAuth</emphasis>
</member>
@@ -2659,6 +2953,35 @@
<programlisting>unix:path=/tmp/dbus-test;unix:path=/tmp/dbus-test2</programlisting>
</para>
+ <para>
+ Some addresses are <firstterm>connectable</firstterm>. A connectable
+ address is one containing enough information for a client to connect
+ to it. For instance, <literal>tcp:host=127.0.0.1,port=4242</literal>
+ is a connectable address. It is not necessarily possible to listen
+ on every connectable address: for instance, it is not possible to
+ listen on a <literal>unixexec:</literal> address.
+ </para>
+
+ <para>
+ Some addresses are <firstterm>listenable</firstterm>. A listenable
+ address is one containing enough information for a server to listen on
+ it, producing a connectable address (which may differ from the
+ original address). Many listenable addresses are not connectable:
+ for instance, <literal>tcp:host=127.0.0.1</literal>
+ is listenable, but not connectable (because it does not specify
+ a port number).
+ </para>
+
+ <para>
+ Listening on an address that is not connectable will result in a
+ connectable address that is not the same as the listenable address.
+ For instance, listening on <literal>tcp:host=127.0.0.1</literal>
+ might result in the connectable address
+ <literal>tcp:host=127.0.0.1,port=30958</literal>,
+ or listening on <literal>unix:tmpdir=/tmp</literal>
+ might result in the connectable address
+ <literal>unix:abstract=/tmp/dbus-U8OSdmf7</literal>.
+ </para>
</sect1>
<sect1 id="transports">
@@ -2676,21 +2999,28 @@
<title>Unix Domain Sockets</title>
<para>
Unix domain sockets can be either paths in the file system or on Linux
- kernels, they can be abstract which are similar to paths but
- do not show up in the file system.
+ kernels, they can be abstract which are similar to paths but
+ do not show up in the file system.
</para>
<para>
When a socket is opened by the D-Bus library it truncates the path
- name right before the first trailing Nul byte. This is true for both
- normal paths and abstract paths. Note that this is a departure from
- previous versions of D-Bus that would create sockets with a fixed
- length path name. Names which were shorter than the fixed length
- would be padded by Nul bytes.
+ name right before the first trailing Nul byte. This is true for both
+ normal paths and abstract paths. Note that this is a departure from
+ previous versions of D-Bus that would create sockets with a fixed
+ length path name. Names which were shorter than the fixed length
+ would be padded by Nul bytes.
</para>
<para>
Unix domain sockets are not available on Windows.
</para>
+ <para>
+ Unix addresses that specify <literal>path</literal> or
+ <literal>abstract</literal> are both listenable and connectable.
+ Unix addresses that specify <literal>tmpdir</literal> are only
+ listenable: the corresponding connectable address will specify
+ either <literal>path</literal> or <literal>abstract</literal>.
+ </para>
<sect3 id="transports-unix-domain-sockets-addresses">
<title>Server Address Format</title>
<para>
@@ -2720,11 +3050,16 @@
<row>
<entry>abstract</entry>
<entry>(string)</entry>
- <entry>unique string (path) in the abstract namespace. If set, the "path" or "tempdir" key must not be set.</entry>
+ <entry>unique string (path) in the abstract namespace. If set, the "path" or "tmpdir" key must not be set. This key is only supported on platforms with "abstract Unix sockets", of which Linux is the only known example.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
+ <para>
+ Exactly one of the keys <literal>path</literal>,
+ <literal>abstract</literal> or
+ <literal>tmpdir</literal> must be provided.
+ </para>
</sect3>
</sect2>
<sect2 id="transports-launchd">
@@ -2748,6 +3083,9 @@
<para>
launchd is not available on Microsoft Windows.
</para>
+ <para>
+ launchd addresses are listenable and connectable.
+ </para>
<sect3 id="transports-launchd-addresses">
<title>Server Address Format</title>
<para>
@@ -2772,6 +3110,9 @@
</tbody>
</tgroup>
</informaltable>
+ <para>
+ The <literal>env</literal> key is required.
+ </para>
</sect3>
</sect2>
<sect2 id="transports-systemd">
@@ -2794,6 +3135,11 @@
<para>
The systemd transport defines no parameter keys.
</para>
+ <para>
+ systemd addresses are listenable, but not connectable. The
+ corresponding connectable address is the <literal>unix</literal>
+ or <literal>tcp</literal> address of the socket.
+ </para>
</sect2>
<sect2 id="transports-tcp-sockets">
<title>TCP Sockets</title>
@@ -2806,9 +3152,16 @@
over a network is unsecure.
</para>
<para>
- Windows notes: Because of the tcp stack on Windows does not provide sending
- credentials over a tcp connection, the EXTERNAL authentification
- mechanismus does not work.
+ On Windows and most Unix platforms, the TCP stack is unable to transfer
+ credentials over a TCP connection, so the EXTERNAL authentication
+ mechanism does not work for this transport.
+ </para>
+ <para>
+ All <literal>tcp</literal> addresses are listenable.
+ <literal>tcp</literal> addresses in which both
+ <literal>host</literal> and <literal>port</literal> are
+ specified, and <literal>port</literal> is non-zero,
+ are also connectable.
</para>
<sect3 id="transports-tcp-sockets-addresses">
<title>Server Address Format</title>
@@ -2829,7 +3182,18 @@
<row>
<entry>host</entry>
<entry>(string)</entry>
- <entry>dns name or ip address</entry>
+ <entry>DNS name or IP address</entry>
+ </row>
+ <row>
+ <entry>bind</entry>
+ <entry>(string)</entry>
+ <entry>Used in a listenable address to configure the interface
+ on which the server will listen: either the IP address of one of
+ the local machine's interfaces (most commonly <literal>127.0.0.1
+ </literal>), or a DNS name that resolves to one of those IP
+ addresses, or '*' to listen on all interfaces simultaneously.
+ If not specified, the default is the same value as "host".
+ </entry>
</row>
<row>
<entry>port</entry>
@@ -2880,6 +3244,12 @@
key-value pair and send it over the socket. After that, the
transport behaves like an unsecured tcp transport.
</para>
+ <para>
+ All nonce-tcp addresses are listenable. nonce-tcp addresses in which
+ <literal>host</literal>, <literal>port</literal> and
+ <literal>noncefile</literal> are all specified,
+ and <literal>port</literal> is nonzero, are also connectable.
+ </para>
<sect3 id="transports-nonce-tcp-sockets-addresses">
<title>Server Address Format</title>
<para>
@@ -2899,7 +3269,13 @@
<row>
<entry>host</entry>
<entry>(string)</entry>
- <entry>dns name or ip address</entry>
+ <entry>DNS name or IP address</entry>
+ </row>
+ <row>
+ <entry>bind</entry>
+ <entry>(string)</entry>
+ <entry>The same as for tcp: addresses
+ </entry>
</row>
<row>
<entry>port</entry>
@@ -2917,7 +3293,10 @@
<row>
<entry>noncefile</entry>
<entry>(path)</entry>
- <entry>file location containing the secret</entry>
+ <entry>File location containing the secret.
+ This is only meaningful in connectable addresses:
+ a listening D-Bus server that offers this transport
+ will always create a new nonce file.</entry>
</row>
</tbody>
</tgroup>
@@ -2940,6 +3319,10 @@
<para>
Executed subprocesses are not available on Windows.
</para>
+ <para>
+ <literal>unixexec</literal> addresses are connectable, but are not
+ listenable.
+ </para>
<sect3 id="transports-exec-addresses">
<title>Server Address Format</title>
<para>
@@ -2998,6 +3381,15 @@
<para>The autolaunch transport provides a way for dbus clients to autodetect
a running dbus session bus and to autolaunch a session bus if not present.
</para>
+ <para>
+ On Unix, <literal>autolaunch</literal> addresses are connectable,
+ but not listenable.
+ </para>
+ <para>
+ On Windows, <literal>autolaunch</literal> addresses are both
+ connectable and listenable.
+ </para>
+
<sect3 id="meta-transports-autolaunch-addresses">
<title>Server Address Format</title>
<para>
@@ -3388,8 +3780,8 @@
<programlisting>
&lt;!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"&gt;
- &lt;node name="/org/freedesktop/sample_object"&gt;
- &lt;interface name="org.freedesktop.SampleInterface"&gt;
+ &lt;node name="/com/example/sample_object"&gt;
+ &lt;interface name="com.example.SampleInterface"&gt;
&lt;method name="Frobate"&gt;
&lt;arg name="foo" type="i" direction="in"/&gt;
&lt;arg name="bar" type="s" direction="out"/&gt;
@@ -3473,38 +3865,38 @@
<para>
Method, interface, property, and signal elements may have
"annotations", which are generic key/value pairs of metadata.
- They are similar conceptually to Java's annotations and C# attributes.
+ They are similar conceptually to Java's annotations and C# attributes.
Well-known annotations:
</para>
<informaltable>
<tgroup cols="3">
- <thead>
- <row>
- <entry>Name</entry>
- <entry>Values (separated by ,)</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>org.freedesktop.DBus.Deprecated</entry>
- <entry>true,false</entry>
- <entry>Whether or not the entity is deprecated; defaults to false</entry>
- </row>
- <row>
- <entry>org.freedesktop.DBus.GLib.CSymbol</entry>
- <entry>(string)</entry>
- <entry>The C symbol; may be used for methods and interfaces</entry>
- </row>
- <row>
- <entry>org.freedesktop.DBus.Method.NoReply</entry>
- <entry>true,false</entry>
- <entry>If set, don't expect a reply to the method call; defaults to false.</entry>
- </row>
- <row>
- <entry>org.freedesktop.DBus.Property.EmitsChangedSignal</entry>
- <entry>true,invalidates,false</entry>
- <entry>
+ <thead>
+ <row>
+ <entry>Name</entry>
+ <entry>Values (separated by ,)</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>org.freedesktop.DBus.Deprecated</entry>
+ <entry>true,false</entry>
+ <entry>Whether or not the entity is deprecated; defaults to false</entry>
+ </row>
+ <row>
+ <entry>org.freedesktop.DBus.GLib.CSymbol</entry>
+ <entry>(string)</entry>
+ <entry>The C symbol; may be used for methods and interfaces</entry>
+ </row>
+ <row>
+ <entry>org.freedesktop.DBus.Method.NoReply</entry>
+ <entry>true,false</entry>
+ <entry>If set, don't expect a reply to the method call; defaults to false.</entry>
+ </row>
+ <row>
+ <entry>org.freedesktop.DBus.Property.EmitsChangedSignal</entry>
+ <entry>true,invalidates,false</entry>
+ <entry>
<para>
If set to <literal>false</literal>, the
<literal>org.freedesktop.DBus.Properties.PropertiesChanged</literal>
@@ -3529,8 +3921,8 @@
interface element.
</para>
</entry>
- </row>
- </tbody>
+ </row>
+ </tbody>
</tgroup>
</informaltable>
</sect1>
@@ -3549,14 +3941,17 @@
unique-for-the-lifetime-of-the-bus name automatically assigned.
Applications may request additional names for a connection. Additional
names are usually "well-known names" such as
- "org.freedesktop.TextEditor". When a name is bound to a connection,
+ "com.example.TextEditor". When a name is bound to a connection,
that connection is said to <firstterm>own</firstterm> the name.
</para>
<para>
- The bus itself owns a special name, <literal>org.freedesktop.DBus</literal>.
- This name routes messages to the bus, allowing applications to make
- administrative requests. For example, applications can ask the bus
- to assign a name to a connection.
+ The bus itself owns a special name,
+ <literal>org.freedesktop.DBus</literal>, with an object
+ located at <literal>/org/freedesktop/DBus</literal> that
+ implements the <literal>org.freedesktop.DBus</literal>
+ interface. This service allows applications to make
+ administrative requests of the bus itself. For example,
+ applications can ask the bus to assign a name to a connection.
</para>
<para>
Each name may have <firstterm>queued owners</firstterm>. When an
@@ -3568,7 +3963,7 @@
<para>
This feature causes the right thing to happen if you start two text
- editors for example; the first one may request "org.freedesktop.TextEditor",
+ editors for example; the first one may request "com.example.TextEditor",
and the second will be queued as a possible owner of that name. When
the first exits, the second will take over.
</para>
@@ -3640,11 +4035,11 @@
<entry>STRING</entry>
<entry>Name to request</entry>
</row>
- <row>
- <entry>1</entry>
- <entry>UINT32</entry>
- <entry>Flags</entry>
- </row>
+ <row>
+ <entry>1</entry>
+ <entry>UINT32</entry>
+ <entry>Flags</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
@@ -3755,10 +4150,10 @@
</row>
</thead>
<tbody>
- <row>
- <entry>DBUS_NAME_FLAG_ALLOW_REPLACEMENT</entry>
- <entry>0x1</entry>
- <entry>
+ <row>
+ <entry>DBUS_NAME_FLAG_ALLOW_REPLACEMENT</entry>
+ <entry>0x1</entry>
+ <entry>
If an application A specifies this flag and succeeds in
becoming the owner of the name, and another application B
@@ -3772,11 +4167,11 @@
application A as the owner.
</entry>
- </row>
- <row>
- <entry>DBUS_NAME_FLAG_REPLACE_EXISTING</entry>
- <entry>0x2</entry>
- <entry>
+ </row>
+ <row>
+ <entry>DBUS_NAME_FLAG_REPLACE_EXISTING</entry>
+ <entry>0x2</entry>
+ <entry>
Try to replace the current owner if there is one. If this
flag is not set the application will only become the owner of
@@ -3785,11 +4180,11 @@
the current owner specified DBUS_NAME_FLAG_ALLOW_REPLACEMENT.
</entry>
- </row>
- <row>
- <entry>DBUS_NAME_FLAG_DO_NOT_QUEUE</entry>
- <entry>0x4</entry>
- <entry>
+ </row>
+ <row>
+ <entry>DBUS_NAME_FLAG_DO_NOT_QUEUE</entry>
+ <entry>0x4</entry>
+ <entry>
Without this flag, if an application requests a name that is
already owned, the application will be placed in a queue to
@@ -3802,10 +4197,10 @@
became the name owner.
</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
The return code can be one of the following values:
@@ -3819,41 +4214,41 @@
</row>
</thead>
<tbody>
- <row>
+ <row>
<entry>DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER</entry>
- <entry>1</entry> <entry>The caller is now the primary owner of
- the name, replacing any previous owner. Either the name had no
- owner before, or the caller specified
- DBUS_NAME_FLAG_REPLACE_EXISTING and the current owner specified
+ <entry>1</entry> <entry>The caller is now the primary owner of
+ the name, replacing any previous owner. Either the name had no
+ owner before, or the caller specified
+ DBUS_NAME_FLAG_REPLACE_EXISTING and the current owner specified
DBUS_NAME_FLAG_ALLOW_REPLACEMENT.</entry>
- </row>
- <row>
- <entry>DBUS_REQUEST_NAME_REPLY_IN_QUEUE</entry>
- <entry>2</entry>
+ </row>
+ <row>
+ <entry>DBUS_REQUEST_NAME_REPLY_IN_QUEUE</entry>
+ <entry>2</entry>
- <entry>The name already had an owner,
+ <entry>The name already had an owner,
DBUS_NAME_FLAG_DO_NOT_QUEUE was not specified, and either
the current owner did not specify
DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the requesting
application did not specify DBUS_NAME_FLAG_REPLACE_EXISTING.
</entry>
- </row>
- <row>
- <entry>DBUS_REQUEST_NAME_REPLY_EXISTS</entry> <entry>3</entry>
- <entry>The name already has an owner,
- DBUS_NAME_FLAG_DO_NOT_QUEUE was specified, and either
- DBUS_NAME_FLAG_ALLOW_REPLACEMENT was not specified by the
- current owner, or DBUS_NAME_FLAG_REPLACE_EXISTING was not
- specified by the requesting application.</entry>
- </row>
- <row>
- <entry>DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER</entry>
- <entry>4</entry>
- <entry>The application trying to request ownership of a name is already the owner of it.</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
+ </row>
+ <row>
+ <entry>DBUS_REQUEST_NAME_REPLY_EXISTS</entry> <entry>3</entry>
+ <entry>The name already has an owner,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE was specified, and either
+ DBUS_NAME_FLAG_ALLOW_REPLACEMENT was not specified by the
+ current owner, or DBUS_NAME_FLAG_REPLACE_EXISTING was not
+ specified by the requesting application.</entry>
+ </row>
+ <row>
+ <entry>DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER</entry>
+ <entry>4</entry>
+ <entry>The application trying to request ownership of a name is already the owner of it.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
</para>
</sect3>
@@ -3926,7 +4321,7 @@
</row>
</thead>
<tbody>
- <row>
+ <row>
<entry>DBUS_RELEASE_NAME_REPLY_RELEASED</entry>
<entry>1</entry> <entry>The caller has released his claim on
the given name. Either the caller was the primary owner of
@@ -3934,21 +4329,21 @@
waiting in the queue for the name, or the caller was waiting
in the queue for the name and has now been removed from the
queue.</entry>
- </row>
- <row>
- <entry>DBUS_RELEASE_NAME_REPLY_NON_EXISTENT</entry>
- <entry>2</entry>
- <entry>The given name does not exist on this bus.</entry>
- </row>
- <row>
- <entry>DBUS_RELEASE_NAME_REPLY_NOT_OWNER</entry>
- <entry>3</entry>
- <entry>The caller was not the primary owner of this name,
+ </row>
+ <row>
+ <entry>DBUS_RELEASE_NAME_REPLY_NON_EXISTENT</entry>
+ <entry>2</entry>
+ <entry>The given name does not exist on this bus.</entry>
+ </row>
+ <row>
+ <entry>DBUS_RELEASE_NAME_REPLY_NOT_OWNER</entry>
+ <entry>3</entry>
+ <entry>The caller was not the primary owner of this name,
and was also not waiting in the queue to own this name.</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
</para>
</sect3>
@@ -4110,7 +4505,7 @@
<sect3 id="message-bus-routing-match-rules">
<title>Match Rules</title>
<para>
- An important part of the message bus routing protocol is match
+ An important part of the message bus routing protocol is match
rules. Match rules describe the messages that should be sent to a
client, based on the contents of the message. Broadcast signals
are only sent to clients which have a suitable match rule: this
@@ -4140,8 +4535,7 @@
</para>
<para>
The following table describes the keys that can be used to create
- a match rule:
- The following table summarizes the D-Bus types.
+ a match rule.
<informaltable>
<tgroup cols="3">
<thead>
@@ -4343,9 +4737,9 @@
<para>
With D-Bus, starting a service is normally done by name. That is,
applications ask the message bus to start some program that will own a
- well-known name, such as <literal>org.freedesktop.TextEditor</literal>.
- This implies a contract documented along with the name
- <literal>org.freedesktop.TextEditor</literal> for which objects
+ well-known name, such as <literal>com.example.TextEditor</literal>.
+ This implies a contract documented along with the name
+ <literal>com.example.TextEditor</literal> for which object
the owner of that name will provide, and what interfaces those
objects will have.
</para>
@@ -4369,6 +4763,19 @@
</para>
<para>
+ On the well-known system bus, the name of a service description file
+ must be its well-known name plus <literal>.service</literal>,
+ for instance
+ <literal>com.example.ConfigurationDatabase.service</literal>.
+ </para>
+
+ <para>
+ On the well-known session bus, services should follow the same
+ service description file naming convention as on the system bus,
+ but for backwards compatibility they are not required to do so.
+ </para>
+
+ <para>
[FIXME the file format should be much better specified than "similar to
.desktop entries" esp. since desktop entries are already
badly-specified. ;-)]
@@ -4379,23 +4786,55 @@
<listitem><para>Comment format</para></listitem>
</itemizedlist>
+ Service description files must contain a
+ <literal>D-BUS Service</literal> group with at least the keys
+ <literal>Name</literal> (the well-known name of the service)
+ and <literal>Exec</literal> (the command to be executed).
+
<figure>
- <title>Example service description file</title>
- <programlisting>
+ <title>Example service description file</title>
+ <programlisting>
# Sample service description file
[D-BUS Service]
- Names=org.freedesktop.ConfigurationDatabase;org.gnome.GConf;
- Exec=/usr/libexec/gconfd-2
+ Name=com.example.ConfigurationDatabase
+ Exec=/usr/bin/sample-configd
</programlisting>
- </figure>
+ </figure>
</para>
+
+ <para>
+ Additionally, service description files for the well-known system
+ bus on Unix must contain a <literal>User</literal> key, whose value
+ is the name of a user account (e.g. <literal>root</literal>).
+ The system service will be run as that user.
+ </para>
+
<para>
When an application asks to start a service by name, the bus daemon tries to
find a service that will own that name. It then tries to spawn the
executable associated with it. If this fails, it will report an
- error. [FIXME what happens if two .service files offer the same service;
- what kind of error is reported, should we have a way for the client to
- choose one?]
+ error.
+ </para>
+
+ <para>
+ On the well-known system bus, it is not possible for two .service files
+ in the same directory to offer the same service, because they are
+ constrained to have names that match the service name.
+ </para>
+
+ <para>
+ On the well-known session bus, if two .service files in the same
+ directory offer the same service name, the result is undefined.
+ Distributors should avoid this situation, for instance by naming
+ session services' .service files according to their service name.
+ </para>
+
+ <para>
+ If two .service files in different directories offer the same
+ service name, the one in the higher-priority directory is used:
+ for instance, on the system bus, .service files in
+ /usr/local/share/dbus-1/system-services take precedence over those
+ in /usr/share/dbus-1/system-services.
</para>
<para>
The executable launched will have the environment variable
@@ -4942,16 +5381,16 @@
<entry>STRING</entry>
<entry>Name with a new owner</entry>
</row>
- <row>
- <entry>1</entry>
- <entry>STRING</entry>
- <entry>Old owner or empty string if none</entry>
- </row>
- <row>
- <entry>2</entry>
- <entry>STRING</entry>
- <entry>New owner or empty string if none</entry>
- </row>
+ <row>
+ <entry>1</entry>
+ <entry>STRING</entry>
+ <entry>Old owner or empty string if none</entry>
+ </row>
+ <row>
+ <entry>2</entry>
+ <entry>STRING</entry>
+ <entry>New owner or empty string if none</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
@@ -5051,11 +5490,11 @@
<entry>STRING</entry>
<entry>Name of the service to start</entry>
</row>
- <row>
- <entry>1</entry>
- <entry>UINT32</entry>
- <entry>Flags (currently not used)</entry>
- </row>
+ <row>
+ <entry>1</entry>
+ <entry>UINT32</entry>
+ <entry>Flags (currently not used)</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
@@ -5093,7 +5532,7 @@
</row>
</thead>
<tbody>
- <row>
+ <row>
<entry>DBUS_START_REPLY_SUCCESS</entry>
<entry>1</entry>
<entry>The service was successfully started.</entry>
@@ -5304,6 +5743,225 @@
</para>
</sect3>
+ <sect3 id="bus-messages-get-connection-credentials">
+ <title><literal>org.freedesktop.DBus.GetConnectionCredentials</literal></title>
+ <para>
+ As a method:
+ <programlisting>
+ DICT&lt;STRING,VARIANT&gt; GetConnectionCredentials (in STRING bus_name)
+ </programlisting>
+ Message arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>STRING</entry>
+ <entry>Unique or well-known bus name of the connection to
+ query, such as <literal>:12.34</literal> or
+ <literal>com.example.tea</literal></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ Reply arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>DICT&lt;STRING,VARIANT&gt;</entry>
+ <entry>Credentials</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+
+ <para>
+ Returns as many credentials as possible for the process connected to
+ the server. If unable to determine certain credentials (for instance,
+ because the process is not on the same machine as the bus daemon,
+ or because this version of the bus daemon does not support a
+ particular security framework), or if the values of those credentials
+ cannot be represented as documented here, then those credentials
+ are omitted.
+ </para>
+
+ <para>
+ Keys in the returned dictionary not containing "." are defined
+ by this specification. Bus daemon implementors supporting
+ credentials frameworks not mentioned in this document should either
+ contribute patches to this specification, or use keys containing
+ "." and starting with a reversed domain name.
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Key</entry>
+ <entry>Value type</entry>
+ <entry>Value</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>UnixUserID</entry>
+ <entry>UINT32</entry>
+ <entry>The numeric Unix user ID, as defined by POSIX</entry>
+ </row>
+ <row>
+ <entry>ProcessID</entry>
+ <entry>UINT32</entry>
+ <entry>The numeric process ID, on platforms that have
+ this concept. On Unix, this is the process ID defined by
+ POSIX.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+
+ <para>
+ This method was added in D-Bus 1.7 to reduce the round-trips
+ required to list a process's credentials. In older versions, calling
+ this method will fail: applications should recover by using the
+ separate methods such as
+ <xref linkend="bus-messages-get-connection-unix-user"/>
+ instead.
+ </para>
+ </sect3>
+
+ <sect3 id="bus-messages-get-adt-audit-session-data">
+ <title><literal>org.freedesktop.DBus.GetAdtAuditSessionData</literal></title>
+ <para>
+ As a method:
+ <programlisting>
+ ARRAY of BYTE GetAdtAuditSessionData (in STRING bus_name)
+ </programlisting>
+ Message arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>STRING</entry>
+ <entry>Unique or well-known bus name of the connection to
+ query, such as <literal>:12.34</literal> or
+ <literal>com.example.tea</literal></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ Reply arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>ARRAY of BYTE</entry>
+ <entry>auditing data as returned by
+ adt_export_session_data()</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ Returns auditing data used by Solaris ADT, in an unspecified
+ binary format. If you know what this means, please contribute
+ documentation via the D-Bus bug tracking system.
+ This method is on the core DBus interface for historical reasons;
+ the same information should be made available via
+ <xref linkend="bus-messages-get-connection-credentials"/>
+ in future.
+ </para>
+ </sect3>
+
+ <sect3 id="bus-messages-get-connection-selinux-security-context">
+ <title><literal>org.freedesktop.DBus.GetConnectionSELinuxSecurityContext</literal></title>
+ <para>
+ As a method:
+ <programlisting>
+ ARRAY of BYTE GetConnectionSELinuxSecurityContext (in STRING bus_name)
+ </programlisting>
+ Message arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>STRING</entry>
+ <entry>Unique or well-known bus name of the connection to
+ query, such as <literal>:12.34</literal> or
+ <literal>com.example.tea</literal></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ Reply arguments:
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>Argument</entry>
+ <entry>Type</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>0</entry>
+ <entry>ARRAY of BYTE</entry>
+ <entry>some sort of string of bytes, not necessarily UTF-8,
+ not including '\0'</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ Returns the security context used by SELinux, in an unspecified
+ format. If you know what this means, please contribute
+ documentation via the D-Bus bug tracking system.
+ This method is on the core DBus interface for historical reasons;
+ the same information should be made available via
+ <xref linkend="bus-messages-get-connection-credentials"/>
+ in future.
+ </para>
+ </sect3>
+
+
<sect3 id="bus-messages-add-match">
<title><literal>org.freedesktop.DBus.AddMatch</literal></title>
<para>
@@ -5331,8 +5989,8 @@
</tgroup>
</informaltable>
Adds a match rule to match messages going through the message bus (see <xref linkend='message-bus-routing-match-rules'/>).
- If the bus does not have enough resources the <literal>org.freedesktop.DBus.Error.OOM</literal>
- error is returned.
+ If the bus does not have enough resources the <literal>org.freedesktop.DBus.Error.OOM</literal>
+ error is returned.
</para>
</sect3>
<sect3 id="bus-messages-remove-match">
@@ -5362,8 +6020,8 @@
</tgroup>
</informaltable>
Removes the first rule that matches (see <xref linkend='message-bus-routing-match-rules'/>).
- If the rule is not found the <literal>org.freedesktop.DBus.Error.MatchRuleNotFound</literal>
- error is returned.
+ If the rule is not found the <literal>org.freedesktop.DBus.Error.MatchRuleNotFound</literal>
+ error is returned.
</para>
</sect3>
@@ -5507,7 +6165,7 @@
<glossentry id="one-to-one"><glossterm>One-to-One</glossterm>
<glossdef>
- <para>
+ <para>
An application talking directly to another application, without going
through a message bus. One-to-one connections may be "peer to peer" or
"client to server." The D-Bus protocol has no concept of client
@@ -5546,9 +6204,9 @@
A service is an executable that can be launched by the bus daemon.
Services normally guarantee some particular features, for example they
may guarantee that they will request a specific name such as
- "org.freedesktop.Screensaver", have a singleton object
- "/org/freedesktop/Application", and that object will implement the
- interface "org.freedesktop.ScreensaverControl".
+ "com.example.Screensaver", have a singleton object
+ "/com/example/Application", and that object will implement the
+ interface "com.example.Screensaver.Control".
</para>
</glossdef>
</glossentry>
diff --git a/doc/dbus-test-plan.xml b/doc/dbus-test-plan.xml
index e6aafb9a..e3efd2cd 100644
--- a/doc/dbus-test-plan.xml
+++ b/doc/dbus-test-plan.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
]>
@@ -48,7 +48,7 @@
<sect1 id="client-library">
<title>Testing the D-Bus client library</title>
<para>
- The tests for the client library consist of the dbus-test
+ The tests for the client library consist of the test-dbus
program which is a unit test for all aspects of the client
library. Whenever a bug in the client library is found and
fixed, a test is added to make sure that the bug won't occur again.
@@ -58,7 +58,7 @@
<para>
The D-Bus client library consists of some data structures that
are used internally; a linked list class, a hashtable class and
- a string class. All aspects of those are tested by dbus-test.
+ a string class. All aspects of those are tested by test-dbus.
</para>
</sect2>
<sect2 id="message-loader">
@@ -104,7 +104,7 @@
the D-Bus Reference Manual.
</para>
<para>
- The message test part of dbus-test is using the message
+ The message test part of test-dbus is using the message
builder to build different kinds of messages, both valid,
invalid, and invalid ones, to make sure that the loader won't
crash or leak memory of any of those, and that the loader
@@ -170,10 +170,10 @@
a socket.
</para>
</sect2>
- <sect2 id="bus-test">
- <title>The bus-test program</title>
+ <sect2 id="test-bus">
+ <title>The test-bus program</title>
<para>
- The bus-test program is a program that is used to test various
+ The test-bus program is a program that is used to test various
parts of the D-Bus bus daemon; robustness and that it conforms
to the specifications.
</para>
@@ -185,7 +185,7 @@
testing easier.
</para>
<para>
- The bus-test program should test all major features of the
+ The test-bus program should test all major features of the
bus, such as service registration, notification when things
occurs and message matching.
</para>
diff --git a/doc/dbus-tutorial.xml b/doc/dbus-tutorial.xml
index 5c385f0e..c7580d15 100644
--- a/doc/dbus-tutorial.xml
+++ b/doc/dbus-tutorial.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" standalone="no"?>
-<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
]>
diff --git a/doc/dbus-uuidgen.1 b/doc/dbus-uuidgen.1
deleted file mode 100644
index 8ed8dd20..00000000
--- a/doc/dbus-uuidgen.1
+++ /dev/null
@@ -1,89 +0,0 @@
-.\"
-.\" dbus\-uuidgen manual page.
-.\" Copyright (C) 2006 Red Hat, Inc.
-.\"
-.TH dbus\-uuidgen 1
-.SH NAME
-dbus\-uuidgen \- Utility to generate UUIDs
-.SH SYNOPSIS
-.PP
-.B dbus\-uuidgen [\-\-version] [\-\-ensure[=FILENAME]] [\-\-get[=FILENAME]]
-
-.SH DESCRIPTION
-
-The \fIdbus\-uuidgen\fP command generates or reads a universally unique ID.
-
-.PP
-Note that the D\-Bus UUID has no relationship to RFC 4122 and does not generate
-UUIDs compatible with that spec. Many systems have a separate command
-for that (often called "uuidgen").
-
-.PP
-See http://www.freedesktop.org/software/dbus/ for more information
-about D\-Bus.
-
-.PP
-The primary usage of \fIdbus\-uuidgen\fP is to run in the post\-install
-script of a D\-Bus package like this:
-.nf
- dbus\-uuidgen \-\-ensure
-.fi
-
-.PP
-This will ensure that /var/lib/dbus/machine\-id exists and has the uuid in it.
-It won't overwrite an existing uuid, since this id should remain fixed
-for a single machine until the next reboot at least.
-
-.PP
-The important properties of the machine UUID are that 1) it remains
-unchanged until the next reboot and 2) it is different for any two
-running instances of the OS kernel. That is, if two processes see the
-same UUID, they should also see the same shared memory, UNIX domain
-sockets, local X displays, localhost.localdomain resolution, process
-IDs, and so forth.
-
-.PP
-If you run \fIdbus\-uuidgen\fP with no options it just prints a new uuid made
-up out of thin air.
-
-.PP
-If you run it with \-\-get, it prints the machine UUID by default, or
-the UUID in the specified file if you specify a file.
-
-.PP
-If you try to change an existing machine\-id on a running system, it will
-probably result in bad things happening. Don't try to change this file. Also,
-don't make it the same on two different systems; it needs to be different
-anytime there are two different kernels running.
-
-.PP
-The UUID should be different on two different virtual machines,
-because there are two different kernels.
-
-.SH OPTIONS
-The following options are supported:
-.TP
-.I "\-\-get[=FILENAME]"
-If a filename is not given, defaults to localstatedir/lib/dbus/machine\-id
-(localstatedir is usually /var). If this file exists and is valid, the
-uuid in the file is printed on stdout. Otherwise, the command exits
-with a nonzero status.
-
-.TP
-.I "\-\-ensure[=FILENAME]"
-If a filename is not given, defaults to localstatedir/lib/dbus/machine\-id
-(localstatedir is usually /var). If this file exists then it will be
-validated, and a failure code returned if it contains the wrong thing.
-If the file does not exist, it will be created with a new uuid in it.
-On success, prints no output.
-
-.TP
-.I "\-\-version"
-Print the version of dbus\-uuidgen
-
-.SH AUTHOR
-See http://www.freedesktop.org/software/dbus/doc/AUTHORS
-
-.SH BUGS
-Please send bug reports to the D\-Bus mailing list or bug tracker,
-see http://www.freedesktop.org/software/dbus/
diff --git a/doc/dbus-uuidgen.1.xml.in b/doc/dbus-uuidgen.1.xml.in
new file mode 100644
index 00000000..fbd26812
--- /dev/null
+++ b/doc/dbus-uuidgen.1.xml.in
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<refentry id='dbusuuidgen1'>
+
+<!-- dbus&bsol;-uuidgen manual page.
+ Copyright (C) 2006 Red Hat, Inc. -->
+
+<refmeta>
+<refentrytitle>dbus-uuidgen</refentrytitle>
+<manvolnum>1</manvolnum>
+<refmiscinfo class="manual">User Commands</refmiscinfo>
+<refmiscinfo class="source">D-Bus</refmiscinfo>
+<refmiscinfo class="version">@DBUS_VERSION@</refmiscinfo>
+</refmeta>
+<refnamediv>
+<refname>dbus-uuidgen</refname>
+<refpurpose>Utility to generate UUIDs</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+<refsynopsisdiv id='synopsis'>
+<cmdsynopsis>
+ <command>dbus-uuidgen</command> <arg choice='opt'>--version </arg>
+ <arg choice='opt'><arg choice='plain'>--ensure </arg><arg choice='opt'><replaceable>=FILENAME</replaceable></arg></arg>
+ <arg choice='opt'><arg choice='plain'>--get </arg><arg choice='opt'><replaceable>=FILENAME</replaceable></arg></arg>
+ <sbr/>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<refsect1 id='description'><title>DESCRIPTION</title>
+<para>The <command>dbus-uuidgen</command> command generates or reads a universally unique ID.</para>
+
+
+<para>Note that the D-Bus UUID has no relationship to RFC 4122 and does not generate
+UUIDs compatible with that spec. Many systems have a separate command
+for that (often called "uuidgen").</para>
+
+
+<para>See <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more information
+about D-Bus.</para>
+
+
+<para>The primary usage of <command>dbus-uuidgen</command> is to run in the post-install
+script of a D-Bus package like this:</para>
+<literallayout remap='.nf'>
+ dbus-uuidgen --ensure
+</literallayout> <!-- .fi -->
+
+
+<para>This will ensure that /var/lib/dbus/machine-id exists and has the uuid in it.
+It won't overwrite an existing uuid, since this id should remain fixed
+for a single machine until the next reboot at least.</para>
+
+
+<para>The important properties of the machine UUID are that 1) it remains
+unchanged until the next reboot and 2) it is different for any two
+running instances of the OS kernel. That is, if two processes see the
+same UUID, they should also see the same shared memory, UNIX domain
+sockets, local X displays, localhost.localdomain resolution, process
+IDs, and so forth.</para>
+
+
+<para>If you run <command>dbus-uuidgen</command> with no options it just prints a new uuid made
+up out of thin air.</para>
+
+
+<para>If you run it with --get, it prints the machine UUID by default, or
+the UUID in the specified file if you specify a file.</para>
+
+
+<para>If you try to change an existing machine-id on a running system, it will
+probably result in bad things happening. Don't try to change this file. Also,
+don't make it the same on two different systems; it needs to be different
+anytime there are two different kernels running.</para>
+
+
+<para>The UUID should be different on two different virtual machines,
+because there are two different kernels.</para>
+
+</refsect1>
+
+<refsect1 id='options'><title>OPTIONS</title>
+<para>The following options are supported:</para>
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><option>--get[=FILENAME]</option></term>
+ <listitem>
+<para>If a filename is not given, defaults to localstatedir/lib/dbus/machine-id
+(localstatedir is usually /var). If this file exists and is valid, the
+uuid in the file is printed on stdout. Otherwise, the command exits
+with a nonzero status.</para>
+
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--ensure[=FILENAME]</option></term>
+ <listitem>
+<para>If a filename is not given, defaults to localstatedir/lib/dbus/machine-id
+(localstatedir is usually /var). If this file exists then it will be
+validated, and a failure code returned if it contains the wrong thing.
+If the file does not exist, it will be created with a new uuid in it.
+On success, prints no output.</para>
+
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--version</option></term>
+ <listitem>
+<para>Print the version of dbus-uuidgen</para>
+
+ </listitem>
+ </varlistentry>
+</variablelist>
+</refsect1>
+
+<refsect1 id='author'><title>AUTHOR</title>
+<para>See <ulink url='http://www.freedesktop.org/software/dbus/doc/AUTHORS'>http://www.freedesktop.org/software/dbus/doc/AUTHORS</ulink></para>
+
+</refsect1>
+
+<refsect1 id='bugs'><title>BUGS</title>
+<para>Please send bug reports to the D-Bus mailing list or bug tracker,
+see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
+</refsect1>
+</refentry>
diff --git a/m4/compiler.m4 b/m4/compiler.m4
index 5aff5d81..5a197ada 100644
--- a/m4/compiler.m4
+++ b/m4/compiler.m4
@@ -63,5 +63,5 @@ AC_DEFUN([COMPILER_COVERAGE],
if test "x$GCC" = "xyes"; then
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
fi
-fi])dnl
+fi],[enable_compiler_coverage=no])dnl
])# COMPILER_COVERAGE
diff --git a/test/.gitignore b/test/.gitignore
index 1337de64..de1dfe14 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -7,21 +7,21 @@ Makefile.in
*.o
echo-server
echo-client
-bus-test
+test-bus
unbase64
*.bb
*.bbg
*.da
*.gcov
break-loader
-spawn-test
+test-spawn
test-corrupt
test-exit
test-segfault
test-service
test-sleep-forever
decode-gcov
-shell-test
+test-shell
test-shell-service
test-names
test-loopback
diff --git a/test/Makefile.am b/test/Makefile.am
index 88a0e8cd..cec5cdab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,8 +4,10 @@
SUBDIRS= . name-test
DIST_SUBDIRS=name-test
+# CPPFLAGS for binaries that are normally dynamic
AM_CPPFLAGS = \
-I$(top_srcdir) \
+ $(DBUS_STATIC_BUILD_CPPFLAGS) \
$(GLIB_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
$(NULL)
@@ -13,28 +15,53 @@ AM_CPPFLAGS = \
# improve backtraces from test stuff
AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
+# CPPFLAGS for binaries that are always static
static_cppflags = \
$(AM_CPPFLAGS) \
-DDBUS_STATIC_BUILD \
+ -DDBUS_COMPILATION \
+ -DDBUS_TEST_USE_INTERNAL \
$(NULL)
-libdbus_testutils_la_CPPFLAGS = \
- $(static_cppflags)
+noinst_LTLIBRARIES = libdbus-testutils-internal.la
+
+# You can link either libdbus-testutils, dbus-glib and libdbus-1,
+# or libdbus-testutils-internal and libdbus-internal - never both in the
+# same binary.
+if DBUS_WITH_DBUS_GLIB
+noinst_LTLIBRARIES += libdbus-testutils.la
libdbus_testutils_la_SOURCES = \
test-utils.c \
test-utils.h \
$(NULL)
libdbus_testutils_la_LIBADD = \
- $(top_builddir)/dbus/libdbus-internal.la \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS) \
+ $(DBUS_GLIB_LIBS) \
$(NULL)
+testutils_shared_if_possible_cppflags = $(AM_CPPFLAGS)
+testutils_shared_if_possible_libs = libdbus-testutils.la
+else
+testutils_shared_if_possible_cppflags = $(static_cppflags)
+testutils_shared_if_possible_libs = libdbus-testutils-internal.la
+endif
-noinst_LTLIBRARIES = libdbus-testutils.la
+libdbus_testutils_internal_la_CPPFLAGS = \
+ $(static_cppflags) \
+ $(NULL)
+libdbus_testutils_internal_la_SOURCES = \
+ test-utils.c \
+ test-utils.h \
+ $(NULL)
+libdbus_testutils_internal_la_LIBADD = \
+ $(top_builddir)/dbus/libdbus-internal.la \
+ $(NULL)
-if DBUS_BUILD_TESTS
+if DBUS_ENABLE_EMBEDDED_TESTS
## break-loader removed for now
## these binaries are used in tests but are not themselves tests
TEST_BINARIES = \
- spawn-test \
+ test-spawn \
test-exit \
test-names \
test-segfault \
@@ -47,44 +74,50 @@ TEST_BINARIES = \
## order, but we don't want to run them til we arrive in this directory,
## since they depend on stuff from this directory
TESTS = \
- ../bus/bus-test$(EXEEXT) \
- ../bus/bus-test-system$(EXEEXT) \
- ../dbus/dbus-test$(EXEEXT) \
+ ../bus/test-bus$(EXEEXT) \
+ ../bus/test-bus-system$(EXEEXT) \
+ ../dbus/test-dbus$(EXEEXT) \
$(NULL)
if DBUS_UNIX
-TESTS += ../bus/bus-test-launch-helper$(EXEEXT)
+TESTS += ../bus/test-bus-launch-helper$(EXEEXT)
endif
-else !DBUS_BUILD_TESTS
+else !DBUS_ENABLE_EMBEDDED_TESTS
TEST_BINARIES=
TESTS=
-endif !DBUS_BUILD_TESTS
+endif !DBUS_ENABLE_EMBEDDED_TESTS
noinst_PROGRAMS= $(TEST_BINARIES)
test_service_CPPFLAGS = $(static_cppflags)
-test_service_LDADD = libdbus-testutils.la
+test_service_LDADD = libdbus-testutils-internal.la
test_names_CPPFLAGS = $(static_cppflags)
-test_names_LDADD = libdbus-testutils.la
+test_names_LDADD = libdbus-testutils-internal.la
## break_loader_CPPFLAGS = $(static_cppflags)
## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_shell_service_CPPFLAGS = $(static_cppflags)
-test_shell_service_LDADD = libdbus-testutils.la
-shell_test_CPPFLAGS = $(static_cppflags)
-shell_test_LDADD = libdbus-testutils.la
-spawn_test_CPPFLAGS = $(static_cppflags)
-spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+test_shell_service_LDADD = libdbus-testutils-internal.la
+test_shell_SOURCES = shell-test.c
+test_shell_CPPFLAGS = $(static_cppflags)
+test_shell_LDADD = libdbus-testutils-internal.la
+test_spawn_SOURCES = spawn-test.c
+test_spawn_CPPFLAGS = $(static_cppflags)
+test_spawn_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+
+test_printf_SOURCES = internals/printf.c
+test_printf_CPPFLAGS = $(static_cppflags)
+test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_refs_SOURCES = internals/refs.c
test_refs_CPPFLAGS = $(static_cppflags)
-test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
+test_refs_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS)
test_syslog_SOURCES = internals/syslog.c
test_syslog_CPPFLAGS = $(static_cppflags)
-test_syslog_LDADD = libdbus-testutils.la $(GLIB_LIBS)
+test_syslog_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS)
EXTRA_DIST = dbus-test-runner
@@ -93,7 +126,10 @@ testexecdir = $(libdir)/dbus-1.0/test
testexec_PROGRAMS =
installable_tests = \
- shell-test \
+ test-shell \
+ test-printf \
+ $(NULL)
+installable_manual_tests = \
$(NULL)
if DBUS_WITH_GLIB
@@ -108,66 +144,88 @@ installable_tests += \
test-syntax \
test-syslog \
$(NULL)
+installable_manual_tests += \
+ manual-authz \
+ $(NULL)
endif DBUS_WITH_GLIB
installcheck_tests =
installcheck_environment = \
+ XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \
DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT) \
DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \
DBUS_TEST_SYSCONFDIR=$(DESTDIR)$(sysconfdir)
TESTS_ENVIRONMENT = \
- DBUS_BLOCK_ON_ABORT=1 \
+ XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \
DBUS_FATAL_WARNINGS=1 \
DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
DBUS_TEST_DATA=@abs_top_builddir@/test/data \
DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \
$(NULL)
+manual_authz_SOURCES = manual-authz.c
+manual_authz_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+manual_authz_LDADD = \
+ $(testutils_shared_if_possible_libs) \
+ $(GLIB_LIBS) \
+ $(NULL)
+
test_corrupt_SOURCES = corrupt.c
-test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_corrupt_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+test_corrupt_LDADD = \
+ $(testutils_shared_if_possible_libs) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_loopback_SOURCES = loopback.c
-test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_loopback_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+test_loopback_LDADD = \
+ $(testutils_shared_if_possible_libs) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_relay_SOURCES = relay.c
-test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_relay_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+test_relay_LDADD = \
+ $(testutils_shared_if_possible_libs) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_dbus_daemon_SOURCES = dbus-daemon.c
-test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_dbus_daemon_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+test_dbus_daemon_LDADD = \
+ $(testutils_shared_if_possible_libs) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c
-test_dbus_daemon_eavesdrop_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_dbus_daemon_eavesdrop_LDFLAGS = @R_DYNAMIC_LDFLAG@
-test_dbus_daemon_eavesdrop_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_dbus_daemon_eavesdrop_CPPFLAGS = $(testutils_shared_if_possible_cppflags)
+test_dbus_daemon_eavesdrop_LDADD = \
+ $(testutils_shared_if_possible_libs) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_marshal_SOURCES = marshal.c
-test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_marshal_LDADD = \
+ $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_syntax_SOURCES = syntax.c
-test_syntax_LDADD = $(top_builddir)/dbus/libdbus-1.la \
- $(GLIB_LIBS)
+test_syntax_LDADD = \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS) \
+ $(NULL)
if DBUS_ENABLE_MODULAR_TESTS
TESTS += $(installable_tests)
installcheck_tests += $(installable_tests)
if DBUS_ENABLE_INSTALLED_TESTS
- testexec_PROGRAMS += $(installable_tests)
+ testexec_PROGRAMS += $(installable_tests) $(installable_manual_tests)
else !DBUS_ENABLE_INSTALLED_TESTS
- noinst_PROGRAMS += $(installable_tests)
+ noinst_PROGRAMS += $(installable_tests) $(installable_manual_tests)
endif !DBUS_ENABLE_INSTALLED_TESTS
endif DBUS_ENABLE_MODULAR_TESTS
@@ -191,6 +249,7 @@ in_data = \
data/valid-config-files-system/debug-allow-all-pass.conf.in \
data/valid-config-files/debug-allow-all-sha1.conf.in \
data/valid-config-files/debug-allow-all.conf.in \
+ data/valid-config-files/incoming-limit.conf.in \
data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service.in \
data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in \
data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in \
@@ -262,7 +321,6 @@ static_data = \
data/valid-config-files/basic.conf \
data/valid-config-files/basic.d/basic.conf \
data/valid-config-files/entities.conf \
- data/valid-config-files/incoming-limit.conf \
data/valid-config-files/many-rules.conf \
data/valid-config-files/system.d/test.conf \
data/valid-messages/array-of-array-of-uint32.message \
@@ -287,14 +345,15 @@ EXTRA_DIST += $(static_data)
## copy tests to builddir so that generated tests and static tests
## are all in one place.
all-local:
- $(AM_V_at)$(INSTALL) -d data/valid-config-files/session.d
+ $(AM_V_at)$(MKDIR_P) data/valid-config-files/session.d
$(AM_V_at)set -e && \
if test $(srcdir) = . || test $(srcdir) -ef .; then \
echo '-- No need to copy test data as srcdir = builddir'; \
else \
for F in $(static_data); do \
- $(INSTALL) -d $${F%/*}; \
- $(INSTALL_DATA) $(srcdir)/$$F $$F; \
+ $(MKDIR_P) $${F%/*}; \
+ rm -f $$F; \
+ cp $(srcdir)/$$F $$F; \
done; \
fi
@@ -312,12 +371,8 @@ imported_data = \
$(NULL)
noinst_DATA = $(imported_data)
-CLEANFILES = $(noinst_DATA)
-
-data/valid-config-files/session.conf: $(top_builddir)/bus/session.conf
- $(AM_V_at)$(INSTALL) -d data/valid-config-files
- $(AM_V_GEN)$(INSTALL_DATA) $< $@
+CLEANFILES = $(noinst_DATA) XDG_RUNTIME_DIR
-data/valid-config-files/system.conf: $(top_builddir)/bus/system.conf
- $(AM_V_at)$(INSTALL) -d data/valid-config-files
- $(AM_V_GEN)$(INSTALL_DATA) $< $@
+$(imported_data): data/valid-config-files/%.conf: $(top_builddir)/bus/%.conf
+ $(AM_V_at)$(MKDIR_P) data/valid-config-files
+ $(AM_V_GEN)cp $< $@
diff --git a/test/break-loader.c b/test/break-loader.c
index e62b8c20..1e406fc3 100644
--- a/test/break-loader.c
+++ b/test/break-loader.c
@@ -33,12 +33,10 @@
#include <sys/wait.h>
#include <string.h>
-#define DBUS_COMPILATION
#include <dbus/dbus-string.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-test.h>
#include <dbus/dbus-marshal-basic.h>
-#undef DBUS_COMPILATION
static DBusString failure_dir;
static int total_attempts;
diff --git a/test/corrupt.c b/test/corrupt.c
index 02495901..1a7d4460 100644
--- a/test/corrupt.c
+++ b/test/corrupt.c
@@ -30,10 +30,12 @@
#include <gio/gio.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+
+#include "test-utils.h"
typedef struct {
DBusError e;
+ TestMainContext *ctx;
DBusServer *server;
DBusConnection *server_conn;
@@ -72,13 +74,14 @@ new_conn_cb (DBusServer *server,
g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn);
- dbus_connection_setup_with_g_main (server_conn, NULL);
+ test_connection_setup (f->ctx, server_conn);
}
static void
setup (Fixture *f,
gconstpointer addr)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->client_messages);
@@ -88,7 +91,7 @@ setup (Fixture *f,
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
@@ -103,12 +106,12 @@ test_connect (Fixture *f,
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
g_assert (f->client_conn != NULL);
- dbus_connection_setup_with_g_main (f->client_conn, NULL);
+ test_connection_setup (f->ctx, f->client_conn);
while (f->server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
have_mem = dbus_connection_add_filter (f->client_conn,
@@ -137,7 +140,7 @@ test_message (Fixture *f,
while (g_queue_is_empty (&f->client_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1);
@@ -229,7 +232,7 @@ test_corrupt (Fixture *f,
while (g_queue_is_empty (&f->client_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
incoming = g_queue_pop_head (&f->client_messages);
@@ -246,6 +249,16 @@ test_corrupt (Fixture *f,
"/org/freedesktop/DBus/Local");
dbus_message_unref (incoming);
+
+ /* Free the DBusConnection before the GSocket, because GSocket is
+ * going to close our fd. GSocket tolerates closing an already-closed
+ * fd, whereas DBusLoop + DBusSocketSetEpoll doesn't. On Unix
+ * we could use dup() but that isn't portable to Windows :-(
+ */
+ dbus_connection_close (f->server_conn);
+ dbus_connection_unref (f->server_conn);
+ f->server_conn = NULL;
+
g_object_unref (socket);
}
@@ -308,7 +321,7 @@ test_byte_order (Fixture *f,
while (g_queue_is_empty (&f->client_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
message = g_queue_pop_head (&f->client_messages);
@@ -325,6 +338,12 @@ test_byte_order (Fixture *f,
"/org/freedesktop/DBus/Local");
dbus_message_unref (message);
+
+ /* Free the DBusConnection before the GSocket, as above. */
+ dbus_connection_close (f->server_conn);
+ dbus_connection_unref (f->server_conn);
+ f->server_conn = NULL;
+
g_object_unref (socket);
}
@@ -352,6 +371,8 @@ teardown (Fixture *f,
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
diff --git a/test/data/valid-config-files/incoming-limit.conf b/test/data/valid-config-files/incoming-limit.conf.in
index abfab3f7..40ff2244 100644
--- a/test/data/valid-config-files/incoming-limit.conf
+++ b/test/data/valid-config-files/incoming-limit.conf.in
@@ -3,7 +3,7 @@
<busconfig>
<!-- Our well-known bus type, don't change this -->
<type>session</type>
- <listen>unix:tmpdir=/tmp</listen>
+ <listen>@TEST_LISTEN@</listen>
<policy context="default">
<!-- Allow everything to be sent -->
diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c
index 0bd923d2..bc5ba121 100644
--- a/test/dbus-daemon-eavesdrop.c
+++ b/test/dbus-daemon-eavesdrop.c
@@ -30,7 +30,6 @@
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
@@ -42,6 +41,8 @@
# include <unistd.h>
#endif
+#include "test-utils.h"
+
#define SENDER_NAME "test.eavesdrop.sender"
#define SENDER_PATH "/test/eavesdrop/sender"
#define SENDER_IFACE SENDER_NAME
@@ -71,6 +72,7 @@ typedef enum {
} SignalDst;
typedef struct {
+ TestMainContext *ctx;
DBusError e;
GError *ge;
@@ -160,7 +162,8 @@ spawn_dbus_daemon (gchar *binary,
}
static DBusConnection *
-connect_to_bus (const gchar *address)
+connect_to_bus (Fixture *f,
+ const gchar *address)
{
DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT;
@@ -175,7 +178,7 @@ connect_to_bus (const gchar *address)
g_assert (ok);
g_assert (dbus_bus_get_unique_name (conn) != NULL);
- dbus_connection_setup_with_g_main (conn, NULL);
+ test_connection_setup (f->ctx, conn);
return conn;
}
@@ -380,6 +383,8 @@ setup (Fixture *f,
gchar *config;
gchar *address;
+ f->ctx = test_main_context_get ();
+
f->ge = NULL;
dbus_error_init (&f->e);
@@ -404,17 +409,24 @@ setup (Fixture *f,
config = g_strdup ("--session");
}
- address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+ if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
+ {
+ address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS"));
+ }
+ else
+ {
+ address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+ }
g_free (dbus_daemon);
g_free (config);
- f->sender = connect_to_bus (address);
+ f->sender = connect_to_bus (f, address);
dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE,
&(f->e));
- f->receiver = connect_to_bus (address);
- f->eavesdropper = connect_to_bus (address);
- f->politelistener = connect_to_bus (address);
+ f->receiver = connect_to_bus (f, address);
+ f->eavesdropper = connect_to_bus (f, address);
+ f->politelistener = connect_to_bus (f, address);
add_receiver_filter (f);
add_politelistener_filter (f);
add_eavesdropper_filter (f);
@@ -432,7 +444,7 @@ test_eavesdrop_broadcast (Fixture *f,
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
/* all the three connection can receive a broadcast */
g_assert_cmpint (f->receiver_dst, ==, BROADCAST);
@@ -452,7 +464,7 @@ test_eavesdrop_unicast_to_sender (Fixture *f,
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
/* not directed to it and not broadcasted, they cannot receive it */
g_assert_cmpint (f->receiver_dst, ==, NONE_YET);
@@ -472,7 +484,7 @@ test_eavesdrop_unicast_to_receiver (Fixture *f,
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
/* direct to him */
g_assert_cmpint (f->receiver_dst, ==, TO_ME);
@@ -534,6 +546,8 @@ teardown (Fixture *f,
#endif
g_spawn_close_pid (f->daemon_pid);
+
+ test_main_context_unref (f->ctx);
}
int
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index cc871530..c883425e 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -29,7 +29,6 @@
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
@@ -39,11 +38,16 @@
#else
# include <signal.h>
# include <unistd.h>
+# include <sys/types.h>
#endif
+#include "test-utils.h"
+
typedef struct {
gboolean skip;
+ TestMainContext *ctx;
+
DBusError e;
GError *ge;
@@ -126,7 +130,8 @@ spawn_dbus_daemon (gchar *binary,
}
static DBusConnection *
-connect_to_bus (const gchar *address)
+connect_to_bus (Fixture *f,
+ const gchar *address)
{
DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT;
@@ -141,7 +146,7 @@ connect_to_bus (const gchar *address)
g_assert (ok);
g_assert (dbus_bus_get_unique_name (conn) != NULL);
- dbus_connection_setup_with_g_main (conn, NULL);
+ test_connection_setup (f->ctx, conn);
return conn;
}
@@ -183,11 +188,20 @@ setup (Fixture *f,
gchar *arg;
gchar *address;
+ f->ctx = test_main_context_get ();
f->ge = NULL;
dbus_error_init (&f->e);
if (config != NULL && config->config_file != NULL)
{
+ if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
+ {
+ g_message ("SKIP: cannot use DBUS_TEST_DAEMON_ADDRESS for "
+ "unusally-configured dbus-daemon");
+ f->skip = TRUE;
+ return;
+ }
+
if (g_getenv ("DBUS_TEST_DATA") == NULL)
{
g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s",
@@ -221,13 +235,20 @@ setup (Fixture *f,
if (dbus_daemon == NULL)
dbus_daemon = g_strdup ("dbus-daemon");
- address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid);
+ if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
+ {
+ address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS"));
+ }
+ else
+ {
+ address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid);
+ }
g_free (dbus_daemon);
g_free (arg);
- f->left_conn = connect_to_bus (address);
- f->right_conn = connect_to_bus (address);
+ f->left_conn = connect_to_bus (f, address);
+ f->right_conn = connect_to_bus (f, address);
g_free (address);
}
@@ -301,7 +322,7 @@ test_echo (Fixture *f,
}
while (received < count)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
elapsed = g_test_timer_elapsed ();
@@ -310,6 +331,131 @@ test_echo (Fixture *f,
}
static void
+pending_call_store_reply (DBusPendingCall *pc,
+ void *data)
+{
+ DBusMessage **message_p = data;
+
+ *message_p = dbus_pending_call_steal_reply (pc);
+ g_assert (*message_p != NULL);
+}
+
+static void
+test_creds (Fixture *f,
+ gconstpointer context)
+{
+ const char *unique = dbus_bus_get_unique_name (f->left_conn);
+ DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetConnectionCredentials");
+ DBusPendingCall *pc;
+ DBusMessageIter args_iter;
+ DBusMessageIter arr_iter;
+ DBusMessageIter pair_iter;
+ DBusMessageIter var_iter;
+ enum {
+ SEEN_UNIX_USER = 1,
+ SEEN_PID = 2,
+ SEEN_WINDOWS_SID = 4
+ } seen = 0;
+
+ if (m == NULL)
+ g_error ("OOM");
+
+ if (!dbus_message_append_args (m,
+ DBUS_TYPE_STRING, &unique,
+ DBUS_TYPE_INVALID))
+ g_error ("OOM");
+
+ if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
+ DBUS_TIMEOUT_USE_DEFAULT) ||
+ pc == NULL)
+ g_error ("OOM");
+
+ dbus_message_unref (m);
+ m = NULL;
+
+ if (dbus_pending_call_get_completed (pc))
+ pending_call_store_reply (pc, &m);
+ else if (!dbus_pending_call_set_notify (pc, pending_call_store_reply,
+ &m, NULL))
+ g_error ("OOM");
+
+ while (m == NULL)
+ test_main_context_iterate (f->ctx, TRUE);
+
+ g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}");
+
+ dbus_message_iter_init (m, &args_iter);
+ g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
+ DBUS_TYPE_ARRAY);
+ g_assert_cmpuint (dbus_message_iter_get_element_type (&args_iter), ==,
+ DBUS_TYPE_DICT_ENTRY);
+ dbus_message_iter_recurse (&args_iter, &arr_iter);
+
+ while (dbus_message_iter_get_arg_type (&arr_iter) != DBUS_TYPE_INVALID)
+ {
+ const char *name;
+
+ dbus_message_iter_recurse (&arr_iter, &pair_iter);
+ g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==,
+ DBUS_TYPE_STRING);
+ dbus_message_iter_get_basic (&pair_iter, &name);
+ dbus_message_iter_next (&pair_iter);
+ g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==,
+ DBUS_TYPE_VARIANT);
+ dbus_message_iter_recurse (&pair_iter, &var_iter);
+
+ if (g_strcmp0 (name, "UnixUserID") == 0)
+ {
+#ifdef G_OS_UNIX
+ guint32 u32;
+
+ g_assert (!(seen & SEEN_UNIX_USER));
+ g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
+ DBUS_TYPE_UINT32);
+ dbus_message_iter_get_basic (&var_iter, &u32);
+ g_message ("%s of this process is %u", name, u32);
+ g_assert_cmpuint (u32, ==, geteuid ());
+ seen |= SEEN_UNIX_USER;
+#else
+ g_assert_not_reached ();
+#endif
+ }
+ else if (g_strcmp0 (name, "ProcessID") == 0)
+ {
+ guint32 u32;
+
+ g_assert (!(seen & SEEN_PID));
+ g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
+ DBUS_TYPE_UINT32);
+ dbus_message_iter_get_basic (&var_iter, &u32);
+ g_message ("%s of this process is %u", name, u32);
+#ifdef G_OS_UNIX
+ g_assert_cmpuint (u32, ==, getpid ());
+#elif defined(G_OS_WIN32)
+ g_assert_cmpuint (u32, ==, GetCurrentProcessId ());
+#else
+ g_assert_not_reached ();
+#endif
+ seen |= SEEN_PID;
+ }
+
+ dbus_message_iter_next (&arr_iter);
+ }
+
+#ifdef G_OS_UNIX
+ g_assert (seen & SEEN_UNIX_USER);
+ g_assert (seen & SEEN_PID);
+#endif
+
+#ifdef G_OS_WIN32
+ /* FIXME: when implemented:
+ g_assert (seen & SEEN_WINDOWS_SID);
+ */
+#endif
+}
+
+static void
teardown (Fixture *f,
gconstpointer context G_GNUC_UNUSED)
{
@@ -347,6 +493,8 @@ teardown (Fixture *f,
g_spawn_close_pid (f->daemon_pid);
f->daemon_pid = 0;
}
+
+ test_main_context_unref (f->ctx);
}
static Config limited_config = {
@@ -363,6 +511,7 @@ main (int argc,
g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown);
g_test_add ("/echo/limited", Fixture, &limited_config,
setup, test_echo, teardown);
+ g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown);
return g_test_run ();
}
diff --git a/test/internals/printf.c b/test/internals/printf.c
new file mode 100644
index 00000000..db151518
--- /dev/null
+++ b/test/internals/printf.c
@@ -0,0 +1,88 @@
+/* Regression test for _dbus_printf_string_upper_bound
+ *
+ * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
+ * Copyright © 2013 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-internals.h>
+#include <dbus/dbus-string.h>
+#include "test-utils.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static void
+do_test (int minimum,
+ const char *format,
+ ...)
+{
+ va_list ap;
+ int result;
+
+ va_start (ap, format);
+ result = _dbus_printf_string_upper_bound (format, ap);
+ va_end (ap);
+
+ if (result < minimum)
+ {
+ fprintf (stderr, "expected at least %d, got %d\n", minimum, result);
+ abort ();
+ }
+}
+
+#define X_TIMES_8 "XXXXXXXX"
+#define X_TIMES_16 X_TIMES_8 X_TIMES_8
+#define X_TIMES_32 X_TIMES_16 X_TIMES_16
+#define X_TIMES_64 X_TIMES_32 X_TIMES_32
+#define X_TIMES_128 X_TIMES_64 X_TIMES_64
+#define X_TIMES_256 X_TIMES_128 X_TIMES_128
+#define X_TIMES_512 X_TIMES_256 X_TIMES_256
+#define X_TIMES_1024 X_TIMES_512 X_TIMES_512
+
+int
+main (int argc,
+ char **argv)
+{
+ char buf[] = X_TIMES_1024 X_TIMES_1024 X_TIMES_1024 X_TIMES_1024;
+ int i;
+
+ do_test (1, "%d", 0);
+ do_test (7, "%d", 1234567);
+ do_test (3, "%f", 3.5);
+
+ do_test (0, "%s", "");
+ do_test (1024, "%s", X_TIMES_1024);
+ do_test (1025, "%s", X_TIMES_1024 "Y");
+
+ for (i = 4096; i > 0; i--)
+ {
+ buf[i] = '\0';
+ do_test (i, "%s", buf);
+ do_test (i + 3, "%s:%d", buf, 42);
+ }
+
+ return 0;
+}
diff --git a/test/internals/refs.c b/test/internals/refs.c
index db43a4da..202dc043 100644
--- a/test/internals/refs.c
+++ b/test/internals/refs.c
@@ -29,7 +29,6 @@
#include <glib.h>
#include <glib-object.h>
-#define DBUS_COMPILATION /* this test uses libdbus-internal */
#include <dbus/dbus.h>
#include <dbus/dbus-connection-internal.h>
#include <dbus/dbus-mainloop.h>
diff --git a/test/internals/syslog.c b/test/internals/syslog.c
index 4f6b7c22..7e0eae79 100644
--- a/test/internals/syslog.c
+++ b/test/internals/syslog.c
@@ -30,7 +30,6 @@
#include <glib.h>
-#define DBUS_COMPILATION /* this test uses libdbus-internal */
#include <dbus/dbus.h>
#include <dbus/dbus-sysdeps.h>
@@ -52,9 +51,10 @@ static void
test_syslog (Fixture *f,
gconstpointer data)
{
+#ifndef G_OS_WIN32
if (g_test_trap_fork (0, 0))
{
- _dbus_init_system_log ();
+ _dbus_init_system_log (FALSE);
_dbus_system_log (DBUS_SYSTEM_LOG_FATAL, MESSAGE "%d", 23);
/* should not be reached: exit 0 so the assertion in the main process
* will fail */
@@ -66,7 +66,7 @@ test_syslog (Fixture *f,
if (g_test_trap_fork (0, 0))
{
- _dbus_init_system_log ();
+ _dbus_init_system_log (FALSE);
_dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
_dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
exit (0);
@@ -74,9 +74,9 @@ test_syslog (Fixture *f,
g_test_trap_assert_passed ();
g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*");
-
+#endif
/* manual test (this is the best we can do on Windows) */
- _dbus_init_system_log ();
+ _dbus_init_system_log (FALSE);
_dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
_dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
}
diff --git a/test/loopback.c b/test/loopback.c
index d0d69c82..7526d8d2 100644
--- a/test/loopback.c
+++ b/test/loopback.c
@@ -1,7 +1,7 @@
/* Simple sanity-check for loopback through TCP and Unix sockets.
*
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
- * Copyright © 2010-2011 Nokia Corporation
+ * Copyright © 2010-2012 Nokia Corporation
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -29,9 +29,13 @@
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+
+#include <string.h>
+
+#include "test-utils.h"
typedef struct {
+ TestMainContext *ctx;
DBusError e;
DBusServer *server;
@@ -72,7 +76,7 @@ new_conn_cb (DBusServer *server,
g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn);
- dbus_connection_setup_with_g_main (server_conn, NULL);
+ test_connection_setup (f->ctx, server_conn);
have_mem = dbus_connection_add_filter (server_conn,
server_message_cb, f, NULL);
@@ -83,6 +87,7 @@ static void
setup (Fixture *f,
gconstpointer addr)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->server_messages);
@@ -92,7 +97,7 @@ setup (Fixture *f,
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
@@ -105,13 +110,73 @@ test_connect (Fixture *f,
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
g_assert (f->client_conn != NULL);
- dbus_connection_setup_with_g_main (f->client_conn, NULL);
+ test_connection_setup (f->ctx, f->client_conn);
while (f->server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
+ }
+}
+
+static void
+test_bad_guid (Fixture *f,
+ gconstpointer addr G_GNUC_UNUSED)
+{
+ DBusMessage *incoming;
+ gchar *address = g_strdup (dbus_server_get_address (f->server));
+ gchar *guid;
+
+ g_test_bug ("39720");
+
+ g_assert (f->server_conn == NULL);
+
+ g_assert (strstr (address, "guid=") != NULL);
+ guid = strstr (address, "guid=");
+ g_assert_cmpuint (strlen (guid), >=, 5 + 32);
+
+ /* Change the first char of the guid to something different */
+ if (guid[5] == '0')
+ guid[5] = 'f';
+ else
+ guid[5] = '0';
+
+ f->client_conn = dbus_connection_open_private (address, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->client_conn != NULL);
+ test_connection_setup (f->ctx, f->client_conn);
+
+ while (f->server_conn == NULL)
+ {
+ g_print (".");
+ test_main_context_iterate (f->ctx, TRUE);
+ }
+
+ /* We get disconnected */
+
+ while (g_queue_is_empty (&f->server_messages))
+ {
+ g_print (".");
+ test_main_context_iterate (f->ctx, TRUE);
}
+
+ g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
+
+ incoming = g_queue_pop_head (&f->server_messages);
+
+ g_assert (!dbus_message_contains_unix_fds (incoming));
+ g_assert_cmpstr (dbus_message_get_destination (incoming), ==, NULL);
+ g_assert_cmpstr (dbus_message_get_error_name (incoming), ==, NULL);
+ g_assert_cmpstr (dbus_message_get_interface (incoming), ==,
+ DBUS_INTERFACE_LOCAL);
+ g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Disconnected");
+ g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
+ g_assert_cmpstr (dbus_message_get_signature (incoming), ==, "");
+ g_assert_cmpstr (dbus_message_get_path (incoming), ==, DBUS_PATH_LOCAL);
+
+ dbus_message_unref (incoming);
+
+ g_free (address);
}
static void
@@ -135,7 +200,7 @@ test_message (Fixture *f,
while (g_queue_is_empty (&f->server_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
@@ -182,6 +247,8 @@ teardown (Fixture *f,
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
@@ -189,6 +256,7 @@ main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
test_connect, teardown);
@@ -207,5 +275,8 @@ main (int argc,
test_message, teardown);
#endif
+ g_test_add ("/message/bad-guid", Fixture, "tcp:host=127.0.0.1", setup,
+ test_bad_guid, teardown);
+
return g_test_run ();
}
diff --git a/test/manual-authz.c b/test/manual-authz.c
new file mode 100644
index 00000000..f9e3688e
--- /dev/null
+++ b/test/manual-authz.c
@@ -0,0 +1,409 @@
+/* Simple sanity-check for authentication and authorization.
+ *
+ * Copyright © 2010-2011 Nokia Corporation
+ * Copyright © 2012 Collabora Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+
+#ifdef G_OS_UNIX
+#include <unistd.h>
+#include <sys/types.h>
+#endif
+
+#include "test-utils.h"
+
+typedef struct {
+ DBusError e;
+ TestMainContext *ctx;
+
+ DBusServer *normal_server;
+ DBusServer *anon_allowed_server;
+ DBusServer *anon_only_server;
+ DBusServer *anon_mech_only_server;
+ DBusServer *anon_disallowed_server;
+ DBusServer *permissive_server;
+ DBusServer *unhappy_server;
+ DBusServer *same_uid_server;
+ DBusServer *same_uid_or_anon_server;
+} Fixture;
+
+static void oom (void) G_GNUC_NORETURN;
+static void
+oom (void)
+{
+ g_error ("out of memory");
+}
+
+static void
+assert_no_error (const DBusError *e)
+{
+ if (G_UNLIKELY (dbus_error_is_set (e)))
+ g_error ("expected success but got error: %s: %s", e->name, e->message);
+}
+
+static DBusHandlerResult
+server_message_cb (DBusConnection *conn,
+ DBusMessage *message,
+ void *data)
+{
+ if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected"))
+ {
+ dbus_connection_unref (conn);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL)
+ {
+ DBusMessage *reply = dbus_message_new_method_return (message);
+ const char *hello = "Hello, world!";
+ unsigned long uid;
+ char *sid;
+
+ if (dbus_connection_get_unix_user (conn, &uid))
+ {
+ g_message ("message from uid %lu", uid);
+ }
+ else if (dbus_connection_get_windows_user (conn, &sid))
+ {
+ if (sid == NULL)
+ oom ();
+
+ g_message ("message from sid \"%s\"", sid);
+ dbus_free (sid);
+ }
+ else if (dbus_connection_get_is_anonymous (conn))
+ {
+ g_message ("message from Anonymous");
+ }
+ else
+ {
+ g_message ("message from ... someone?");
+ }
+
+ if (reply == NULL)
+ oom ();
+
+ if (!dbus_message_append_args (reply,
+ DBUS_TYPE_STRING, &hello,
+ DBUS_TYPE_INVALID))
+ oom ();
+
+ if (!dbus_connection_send (conn, reply, NULL))
+ oom ();
+
+ dbus_message_unref (reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static dbus_bool_t
+permissive_unix_func (DBusConnection *conn,
+ unsigned long uid,
+ void *data)
+{
+ g_message ("accepting Unix user %lu", uid);
+ return TRUE;
+}
+
+static dbus_bool_t
+permissive_win_func (DBusConnection *conn,
+ const char *sid,
+ void *data)
+{
+ g_message ("accepting Windows user \"%s\"", sid);
+ return TRUE;
+}
+
+static dbus_bool_t
+broken_unix_func (DBusConnection *conn,
+ unsigned long uid,
+ void *data)
+{
+ g_error ("libdbus called the Unix user function for an ANONYMOUS-only "
+ "connection");
+ return FALSE;
+}
+
+static dbus_bool_t
+broken_win_func (DBusConnection *conn,
+ const char *sid,
+ void *data)
+{
+ g_error ("libdbus called the Windows user function for an ANONYMOUS-only "
+ "connection");
+ return FALSE;
+}
+
+static dbus_bool_t
+unhappy_unix_func (DBusConnection *conn,
+ unsigned long uid,
+ void *data)
+{
+ g_message ("rejecting Unix user %lu", uid);
+ return FALSE;
+}
+
+static dbus_bool_t
+unhappy_win_func (DBusConnection *conn,
+ const char *sid,
+ void *data)
+{
+ g_message ("rejecting Windows user \"%s\"", sid);
+ return FALSE;
+}
+
+static dbus_bool_t
+same_uid_unix_func (DBusConnection *conn,
+ unsigned long uid,
+ void *data)
+{
+ g_message ("checking whether Unix user %lu owns this process", uid);
+ /* I'd use _dbus_unix_user_is_process_owner(), but it's private... */
+#ifdef G_OS_UNIX
+ return (geteuid () == uid);
+#else
+ return FALSE;
+#endif
+}
+
+static dbus_bool_t
+same_uid_win_func (DBusConnection *conn,
+ const char *sid,
+ void *data)
+{
+ g_message ("checking whether Windows user \"%s\" owns this process", sid);
+ g_message ("Stub implementation consistent with dbus-sysdeps-util-win: "
+ "assume they do");
+ return TRUE;
+}
+
+static void
+new_conn_cb (DBusServer *server,
+ DBusConnection *conn,
+ void *data)
+{
+ Fixture *f = data;
+
+ dbus_connection_ref (conn);
+ test_connection_setup (f->ctx, conn);
+
+ if (!dbus_connection_add_filter (conn, server_message_cb, f, NULL))
+ oom ();
+
+ if (server == f->normal_server)
+ {
+ }
+ else if (server == f->anon_allowed_server)
+ {
+ dbus_connection_set_allow_anonymous (conn, TRUE);
+ }
+ else if (server == f->anon_only_server)
+ {
+ dbus_connection_set_allow_anonymous (conn, TRUE);
+
+ dbus_connection_set_unix_user_function (conn, unhappy_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, unhappy_win_func,
+ f, NULL);
+ }
+ else if (server == f->anon_mech_only_server)
+ {
+ dbus_connection_set_allow_anonymous (conn, TRUE);
+
+ /* should never get called */
+ dbus_connection_set_unix_user_function (conn, broken_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, broken_win_func,
+ f, NULL);
+ }
+ else if (server == f->anon_disallowed_server)
+ {
+ dbus_connection_set_allow_anonymous (conn, FALSE);
+
+ /* should never get called */
+ dbus_connection_set_unix_user_function (conn, broken_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, broken_win_func,
+ f, NULL);
+ }
+ else if (server == f->permissive_server)
+ {
+ dbus_connection_set_unix_user_function (conn, permissive_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, permissive_win_func,
+ f, NULL);
+ }
+ else if (server == f->unhappy_server)
+ {
+ dbus_connection_set_unix_user_function (conn, unhappy_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, unhappy_win_func,
+ f, NULL);
+ }
+ else if (server == f->same_uid_server)
+ {
+ dbus_connection_set_unix_user_function (conn, same_uid_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, same_uid_win_func,
+ f, NULL);
+ }
+ else if (server == f->same_uid_or_anon_server)
+ {
+ dbus_connection_set_allow_anonymous (conn, TRUE);
+
+ dbus_connection_set_unix_user_function (conn, same_uid_unix_func,
+ f, NULL);
+ dbus_connection_set_windows_user_function (conn, same_uid_win_func,
+ f, NULL);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+}
+
+static void
+setup (Fixture *f,
+ const gchar *listen_addr)
+{
+ const char *only_anon[] = { "ANONYMOUS", NULL };
+ char *connect_addr;
+
+ f->normal_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->normal_server != NULL);
+ dbus_server_set_new_connection_function (f->normal_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->normal_server);
+ connect_addr = dbus_server_get_address (f->normal_server);
+ g_message ("Normal server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->anon_allowed_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->anon_allowed_server != NULL);
+ dbus_server_set_new_connection_function (f->anon_allowed_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->anon_allowed_server);
+ connect_addr = dbus_server_get_address (f->anon_allowed_server);
+ g_message ("Anonymous-allowed server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->anon_only_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->anon_only_server != NULL);
+ dbus_server_set_new_connection_function (f->anon_only_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->anon_only_server);
+ connect_addr = dbus_server_get_address (f->anon_only_server);
+ g_message ("Anonymous-only server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->anon_mech_only_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->anon_mech_only_server != NULL);
+ dbus_server_set_auth_mechanisms (f->anon_mech_only_server, only_anon);
+ dbus_server_set_new_connection_function (f->anon_mech_only_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->anon_mech_only_server);
+ connect_addr = dbus_server_get_address (f->anon_mech_only_server);
+ g_message ("Anon mech only server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->anon_disallowed_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->anon_disallowed_server != NULL);
+ dbus_server_set_auth_mechanisms (f->anon_disallowed_server, only_anon);
+ dbus_server_set_new_connection_function (f->anon_disallowed_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->anon_disallowed_server);
+ connect_addr = dbus_server_get_address (f->anon_disallowed_server);
+ g_message ("Anonymous-disallowed server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->permissive_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->permissive_server != NULL);
+ dbus_server_set_new_connection_function (f->permissive_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->permissive_server);
+ connect_addr = dbus_server_get_address (f->permissive_server);
+ g_message ("Permissive server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->unhappy_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->unhappy_server != NULL);
+ dbus_server_set_new_connection_function (f->unhappy_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->unhappy_server);
+ connect_addr = dbus_server_get_address (f->unhappy_server);
+ g_message ("Unhappy server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->same_uid_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->same_uid_server != NULL);
+ dbus_server_set_new_connection_function (f->same_uid_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->same_uid_server);
+ connect_addr = dbus_server_get_address (f->same_uid_server);
+ g_message ("Same-UID server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+
+ f->same_uid_or_anon_server = dbus_server_listen (listen_addr, &f->e);
+ assert_no_error (&f->e);
+ g_assert (f->same_uid_or_anon_server != NULL);
+ dbus_server_set_new_connection_function (f->same_uid_or_anon_server,
+ new_conn_cb, f, NULL);
+ test_server_setup (f->ctx, f->same_uid_or_anon_server);
+ connect_addr = dbus_server_get_address (f->same_uid_or_anon_server);
+ g_message ("Same-UID-or-anon server:\n%s", connect_addr);
+ dbus_free (connect_addr);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ Fixture f = { DBUS_ERROR_INIT, test_main_context_get () };
+
+ if (argc >= 2)
+ setup (&f, argv[1]);
+ else
+ setup (&f, "tcp:host=127.0.0.1");
+
+ for (;;)
+ test_main_context_iterate (f.ctx, TRUE);
+
+ /* never returns */
+}
diff --git a/test/marshal.c b/test/marshal.c
index e9ac7e30..d74e7671 100644
--- a/test/marshal.c
+++ b/test/marshal.c
@@ -27,9 +27,9 @@
#include <config.h>
#include <glib.h>
+#include <string.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
typedef struct {
DBusError e;
@@ -244,14 +244,30 @@ int
main (int argc,
char **argv)
{
+ int ret;
+ char *aligned_le_blob;
+ char *aligned_be_blob;
+
g_test_init (&argc, &argv, NULL);
- g_test_add ("/demarshal/le", Fixture, le_blob, setup, test_endian, teardown);
- g_test_add ("/demarshal/be", Fixture, be_blob, setup, test_endian, teardown);
- g_test_add ("/demarshal/needed/le", Fixture, le_blob, setup, test_needed,
+ /* We have to pass in a buffer that's at least "default aligned",
+ * i.e. on GNU systems to 8 or 16. The linker may have only given
+ * us byte-alignment for the char[] static variables.
+ */
+ aligned_le_blob = g_malloc (sizeof (le_blob));
+ memcpy (aligned_le_blob, le_blob, sizeof (le_blob));
+ aligned_be_blob = g_malloc (sizeof (be_blob));
+ memcpy (aligned_be_blob, be_blob, sizeof (be_blob));
+
+ g_test_add ("/demarshal/le", Fixture, aligned_le_blob, setup, test_endian, teardown);
+ g_test_add ("/demarshal/be", Fixture, aligned_be_blob, setup, test_endian, teardown);
+ g_test_add ("/demarshal/needed/le", Fixture, aligned_le_blob, setup, test_needed,
teardown);
- g_test_add ("/demarshal/needed/be", Fixture, be_blob, setup, test_needed,
+ g_test_add ("/demarshal/needed/be", Fixture, aligned_be_blob, setup, test_needed,
teardown);
- return g_test_run ();
+ ret = g_test_run ();
+ g_free (aligned_le_blob);
+ g_free (aligned_be_blob);
+ return ret;
}
diff --git a/test/name-test/.gitignore b/test/name-test/.gitignore
index 09f7ad36..2bf313a5 100644
--- a/test/name-test/.gitignore
+++ b/test/name-test/.gitignore
@@ -3,7 +3,7 @@
Makefile
Makefile.in
echo-error-output.tmp
-run-with-tmp-session-bus.conf
+tmp-session-bus.*.conf
test-ids
test-names
test-pending-call-dispatch
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index 6aaf1783..8ed1e160 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -3,6 +3,7 @@ AM_CPPFLAGS = \
-I$(top_srcdir) \
-DDBUS_COMPILATION \
-DDBUS_STATIC_BUILD \
+ -DDBUS_TEST_USE_INTERNAL \
$(NULL)
# if assertions are enabled, improve backtraces
@@ -11,8 +12,16 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
## note that TESTS has special meaning (stuff to use in make check)
## so if adding tests not to be run in make check, don't add them to
## TESTS
-if DBUS_BUILD_TESTS
-TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@ PYTHON=@PYTHON@
+if DBUS_ENABLE_EMBEDDED_TESTS
+TESTS_ENVIRONMENT = \
+ DBUS_TOP_BUILDDIR=@abs_top_builddir@ \
+ DBUS_TOP_SRCDIR=@abs_top_srcdir@ \
+ PYTHON=@PYTHON@ \
+ DBUS_TEST_DATA=@abs_top_builddir@/test/data \
+ DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \
+ XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \
+ $(NULL)
+
TESTS=run-test.sh run-test-systemserver.sh
else
TESTS=
@@ -20,7 +29,7 @@ endif
EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py test-activation-forking.py
-if DBUS_BUILD_TESTS
+if DBUS_ENABLE_EMBEDDED_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
## build even when not doing "make check"
@@ -31,9 +40,9 @@ test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la
test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la
test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-test_shutdown_LDADD=../libdbus-testutils.la
-test_privserver_LDADD=../libdbus-testutils.la
-test_privserver_client_LDADD=../libdbus-testutils.la
-test_autolaunch_LDADD=../libdbus-testutils.la
+test_shutdown_LDADD=../libdbus-testutils-internal.la
+test_privserver_LDADD=../libdbus-testutils-internal.la
+test_privserver_client_LDADD=../libdbus-testutils-internal.la
+test_autolaunch_LDADD=../libdbus-testutils-internal.la
endif
diff --git a/test/name-test/run-test-systemserver.sh b/test/name-test/run-test-systemserver.sh
index afd1f045..90c03723 100755
--- a/test/name-test/run-test-systemserver.sh
+++ b/test/name-test/run-test-systemserver.sh
@@ -30,6 +30,11 @@ if test -n "$DBUS_TEST_MONITOR"; then
dbus-monitor --session &
fi
+XDG_RUNTIME_DIR="$DBUS_TOP_BUILDDIR"/test/XDG_RUNTIME_DIR
+test -d "$XDG_RUNTIME_DIR" || mkdir "$XDG_RUNTIME_DIR"
+chmod 0700 "$XDG_RUNTIME_DIR"
+export XDG_RUNTIME_DIR
+
echo "running test-expected-echo-fail"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/tools/dbus-send --print-reply --dest=org.freedesktop.DBus.TestSuiteEchoService /org/freedesktop/TestSuite org.freedesktop.TestSuite.Echo string:hi >echo-error-output.tmp 2>&1
if ! grep -q 'DBus.Error' echo-error-output.tmp; then
diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh
index cad5937e..84379c4a 100755
--- a/test/name-test/run-test.sh
+++ b/test/name-test/run-test.sh
@@ -30,6 +30,11 @@ if test -n "$DBUS_TEST_MONITOR"; then
dbus-monitor --session &
fi
+XDG_RUNTIME_DIR="$DBUS_TOP_BUILDDIR"/test/XDG_RUNTIME_DIR
+test -d "$XDG_RUNTIME_DIR" || mkdir "$XDG_RUNTIME_DIR"
+chmod 0700 "$XDG_RUNTIME_DIR"
+export XDG_RUNTIME_DIR
+
echo "running test-ids"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-ids || die "test-ids failed"
diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c
index 5e519895..8b5206a6 100644
--- a/test/name-test/test-autolaunch.c
+++ b/test/name-test/test-autolaunch.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,21 +16,23 @@ main (int argc, char *argv[])
DBusConnection *conn = NULL;
DBusError error;
- _dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
+ dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL);
dbus_error_init (&error);
conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
#ifdef DBUS_ENABLE_X11_AUTOLAUNCH
- if (dbus_error_is_set (&error))
+ /* If X11 autolaunch was enabled, we expect dbus-launch to have worked. */
+ if (_dbus_getenv ("DISPLAY") != NULL && dbus_error_is_set (&error))
{
fprintf (stderr, "*** Failed to autolaunch session bus: %s\n",
error.message);
dbus_error_free (&error);
return 1;
}
-#else
+#endif
+
/* We don't necessarily expect it to *work* without X (although it might -
* for instance on Mac OS it might have used launchd). Just check that the
* results are consistent. */
@@ -38,7 +42,6 @@ main (int argc, char *argv[])
fprintf (stderr, "*** Autolaunched session bus, but an error was set!\n");
return 1;
}
-#endif
if (!dbus_error_is_set (&error) && conn == NULL)
{
diff --git a/test/name-test/test-threads-init.c b/test/name-test/test-threads-init.c
index 5e22852a..580ffe14 100644
--- a/test/name-test/test-threads-init.c
+++ b/test/name-test/test-threads-init.c
@@ -149,11 +149,15 @@ main (int argc, char *argv[])
&dispatch_cond1,
&io_path_cond1);
- check_mutex_lock (mutex1, mutex2, FALSE);
- check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE);
- check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE);
- check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE);
- check_condvar_lock (io_path_cond1, io_path_cond2, FALSE);
+ /* Since 1.7 it is no longer the case that mutex1 != mutex2, because
+ * initializing global locks automatically initializes locks
+ * in general. However, it is true that the mutex is not the dummy
+ * implementation, which is what we really wanted to check here. */
+ _dbus_assert (mutex1 != (DBusMutex *) 0xABCDEF);
+ _dbus_assert (dispatch_mutex1 != (DBusMutex *) 0xABCDEF);
+ _dbus_assert (dispatch_cond1 != (DBusCondVar *) 0xABCDEF2);
+ _dbus_assert (io_path_mutex1 != (DBusMutex *) 0xABCDEF);
+ _dbus_assert (io_path_cond1 != (DBusCondVar *) 0xABCDEF2);
_run_iteration (conn);
_dbus_connection_test_get_locks (conn, &mutex2,
diff --git a/test/relay.c b/test/relay.c
index f4129d0a..ecfe4c82 100644
--- a/test/relay.c
+++ b/test/relay.c
@@ -29,7 +29,8 @@
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+
+#include "test-utils.h"
/* This is basically a miniature dbus-daemon. We relay messages from the client
* on the left to the client on the right.
@@ -43,6 +44,7 @@
*/
typedef struct {
+ TestMainContext *ctx;
DBusError e;
DBusServer *server;
@@ -113,13 +115,14 @@ new_conn_cb (DBusServer *server,
f->right_server_conn = dbus_connection_ref (server_conn);
}
- dbus_connection_setup_with_g_main (server_conn, NULL);
+ test_connection_setup (f->ctx, server_conn);
}
static void
setup (Fixture *f,
gconstpointer data G_GNUC_UNUSED)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->messages);
@@ -129,7 +132,7 @@ setup (Fixture *f,
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
@@ -148,25 +151,25 @@ test_connect (Fixture *f,
f->left_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->left_client_conn != NULL);
- dbus_connection_setup_with_g_main (f->left_client_conn, NULL);
+ test_connection_setup (f->ctx, f->left_client_conn);
while (f->left_server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
f->right_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->right_client_conn != NULL);
- dbus_connection_setup_with_g_main (f->right_client_conn, NULL);
+ test_connection_setup (f->ctx, f->right_client_conn);
dbus_free (address);
while (f->right_server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
have_mem = dbus_connection_add_filter (f->right_client_conn,
@@ -208,7 +211,7 @@ test_relay (Fixture *f,
while (g_queue_get_length (&f->messages) < 2)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 2);
@@ -237,7 +240,7 @@ test_limit (Fixture *f,
/* This was an attempt to reproduce fd.o #34393. It didn't work. */
g_test_bug ("34393");
dbus_connection_set_max_received_size (f->left_server_conn, 1);
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
for (i = 0; i < MANY; i++)
{
@@ -253,7 +256,7 @@ test_limit (Fixture *f,
{
while (g_queue_is_empty (&f->messages))
{
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
while ((incoming = g_queue_pop_head (&f->messages)) != NULL)
@@ -302,6 +305,8 @@ teardown (Fixture *f,
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
diff --git a/test/shell-test.c b/test/shell-test.c
index b479a9c6..d1dc5b5b 100644
--- a/test/shell-test.c
+++ b/test/shell-test.c
@@ -1,7 +1,7 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
-#define DBUS_COMPILATION
+
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
#include <dbus/dbus-memory.h>
diff --git a/test/spawn-test.c b/test/spawn-test.c
index f1a55051..723a4889 100644
--- a/test/spawn-test.c
+++ b/test/spawn-test.c
@@ -1,10 +1,8 @@
#include <config.h>
#include <dbus/dbus.h>
-#define DBUS_COMPILATION /* cheat and use dbus-sysdeps */
#include <dbus/dbus-sysdeps.h>
#include <dbus/dbus-spawn.h>
-#undef DBUS_COMPILATION
#include <stdio.h>
static void
@@ -32,7 +30,7 @@ main (int argc, char **argv)
argv_copy [i] = argv[i + 1];
argv_copy[argc - 1] = NULL;
- if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy, NULL, setup_func, NULL, &error))
+ if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL, setup_func, NULL, &error))
{
fprintf (stderr, "Could not launch application: \"%s\"\n",
error.message);
diff --git a/test/syntax.c b/test/syntax.c
index 88db9638..e26b3643 100644
--- a/test/syntax.c
+++ b/test/syntax.c
@@ -178,12 +178,14 @@ const char * const invalid_single_signatures[] = {
const char * const valid_strings[] = {
"",
- "\xc2\xa9",
+ "\xc2\xa9", /* UTF-8 (c) symbol */
+ "\xef\xbf\xbe", /* U+FFFE is reserved but Corrigendum 9 says it's OK */
NULL
};
const char * const invalid_strings[] = {
- "\xa9",
+ "\xa9", /* Latin-1 (c) symbol */
+ "\xed\xa0\x80", /* UTF-16 surrogates are not valid in UTF-8 */
NULL
};
diff --git a/test/test-exit.c b/test/test-exit.c
index f3358185..b4f967ae 100644
--- a/test/test-exit.c
+++ b/test/test-exit.c
@@ -1,3 +1,5 @@
+#include "config.h"
+
/* This is a process that just exits with a failure code */
int
main (int argc, char **argv)
diff --git a/test/test-utils.c b/test/test-utils.c
index c3c3ed34..9a4f3584 100644
--- a/test/test-utils.c
+++ b/test/test-utils.c
@@ -1,6 +1,13 @@
#include <config.h>
#include "test-utils.h"
+#ifndef DBUS_TEST_USE_INTERNAL
+# include <dbus/dbus.h>
+# include <dbus/dbus-glib-lowlevel.h>
+#endif
+
+#ifdef DBUS_TEST_USE_INTERNAL
+
typedef struct
{
DBusLoop *loop;
@@ -97,10 +104,14 @@ cdata_new (DBusLoop *loop,
return cd;
}
+#endif /* DBUS_TEST_USE_INTERNAL */
+
dbus_bool_t
-test_connection_setup (DBusLoop *loop,
+test_connection_setup (TestMainContext *ctx,
DBusConnection *connection)
{
+#ifdef DBUS_TEST_USE_INTERNAL
+ DBusLoop *loop = ctx;
CData *cd;
cd = NULL;
@@ -148,10 +159,23 @@ test_connection_setup (DBusLoop *loop,
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
return FALSE;
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+ dbus_connection_setup_with_g_main (connection, ctx);
+ return TRUE;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
+}
+
+static void
+die (const char *message)
+{
+ fprintf (stderr, "*** %s", message);
+ exit (1);
}
void
-test_connection_shutdown (DBusLoop *loop,
+test_connection_shutdown (TestMainContext *ctx,
DBusConnection *connection)
{
if (!dbus_connection_set_watch_functions (connection,
@@ -159,18 +183,20 @@ test_connection_shutdown (DBusLoop *loop,
NULL,
NULL,
NULL, NULL))
- _dbus_assert_not_reached ("setting watch functions to NULL failed");
+ die ("setting watch functions to NULL failed");
if (!dbus_connection_set_timeout_functions (connection,
NULL,
NULL,
NULL,
NULL, NULL))
- _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+ die ("setting timeout functions to NULL failed");
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
}
+#ifdef DBUS_TEST_USE_INTERNAL
+
typedef struct
{
DBusLoop *loop;
@@ -252,10 +278,14 @@ remove_server_timeout (DBusTimeout *timeout,
_dbus_loop_remove_timeout (context->loop, timeout);
}
+#endif /* DBUS_TEST_USE_INTERNAL */
+
dbus_bool_t
-test_server_setup (DBusLoop *loop,
+test_server_setup (TestMainContext *ctx,
DBusServer *server)
{
+#ifdef DBUS_TEST_USE_INTERNAL
+ DBusLoop *loop = ctx;
ServerData *sd;
sd = serverdata_new (loop, server);
@@ -293,10 +323,17 @@ test_server_setup (DBusLoop *loop,
test_server_shutdown (loop, server);
return FALSE;
+
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+ dbus_server_setup_with_g_main (server, ctx);
+ return TRUE;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
}
void
-test_server_shutdown (DBusLoop *loop,
+test_server_shutdown (TestMainContext *ctx,
DBusServer *server)
{
dbus_server_disconnect (server);
@@ -305,11 +342,51 @@ test_server_shutdown (DBusLoop *loop,
NULL, NULL, NULL,
NULL,
NULL))
- _dbus_assert_not_reached ("setting watch functions to NULL failed");
+ die ("setting watch functions to NULL failed");
if (!dbus_server_set_timeout_functions (server,
NULL, NULL, NULL,
NULL,
NULL))
- _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+ die ("setting timeout functions to NULL failed");
+}
+
+TestMainContext *
+test_main_context_get (void)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ return _dbus_loop_new ();
+#else
+ /* I suspect dbus-glib relies the default main context in some places */
+ return g_main_context_ref (g_main_context_default ());
+#endif
+}
+
+TestMainContext *
+test_main_context_ref (TestMainContext *ctx)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ return _dbus_loop_ref (ctx);
+#else
+ return g_main_context_ref (ctx);
+#endif
+}
+
+void test_main_context_unref (TestMainContext *ctx)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ _dbus_loop_unref (ctx);
+#else
+ g_main_context_unref (ctx);
+#endif
+}
+
+void test_main_context_iterate (TestMainContext *ctx,
+ dbus_bool_t may_block)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ _dbus_loop_iterate (ctx, may_block);
+#else
+ g_main_context_iteration (ctx, may_block);
+#endif
}
diff --git a/test/test-utils.h b/test/test-utils.h
index 3e1e55e6..0d3f3690 100644
--- a/test/test-utils.h
+++ b/test/test-utils.h
@@ -1,25 +1,38 @@
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
-#ifndef DBUS_COMPILATION
-#define DBUS_COMPILATION /* Cheat and use private stuff */
-#endif
-#include <dbus/dbus.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <dbus/dbus-mainloop.h>
-#include <dbus/dbus-internals.h>
-#undef DBUS_COMPILATION
-dbus_bool_t test_connection_setup (DBusLoop *loop,
+#include <dbus/dbus.h>
+
+#ifdef DBUS_TEST_USE_INTERNAL
+
+# include <dbus/dbus-mainloop.h>
+# include <dbus/dbus-internals.h>
+ typedef DBusLoop TestMainContext;
+
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+# include <glib.h>
+ typedef GMainContext TestMainContext;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
+
+TestMainContext *test_main_context_get (void);
+TestMainContext *test_main_context_ref (TestMainContext *ctx);
+void test_main_context_unref (TestMainContext *ctx);
+void test_main_context_iterate (TestMainContext *ctx,
+ dbus_bool_t may_block);
+
+dbus_bool_t test_connection_setup (TestMainContext *ctx,
DBusConnection *connection);
-void test_connection_shutdown (DBusLoop *loop,
+void test_connection_shutdown (TestMainContext *ctx,
DBusConnection *connection);
-void test_connection_dispatch_all_messages (DBusConnection *connection);
-dbus_bool_t test_connection_dispatch_one_message (DBusConnection *connection);
-dbus_bool_t test_server_setup (DBusLoop *loop,
+dbus_bool_t test_server_setup (TestMainContext *ctx,
DBusServer *server);
-void test_server_shutdown (DBusLoop *loop,
+void test_server_shutdown (TestMainContext *ctx,
DBusServer *server);
#endif
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 08b90234..73d95fcf 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -2,6 +2,7 @@ configdir=$(sysconfdir)/dbus-1
AM_CPPFLAGS = \
-I$(top_srcdir) \
+ $(DBUS_STATIC_BUILD_CPPFLAGS) \
$(DBUS_X_CFLAGS) \
-DDBUS_COMPILATION \
-DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\" \
@@ -19,6 +20,7 @@ bin_PROGRAMS = \
if DBUS_UNIX
bin_PROGRAMS += \
dbus-cleanup-sockets \
+ dbus-run-session \
dbus-uuidgen \
$(NULL)
endif
@@ -42,6 +44,13 @@ dbus_launch_SOURCES= \
dbus-launch.c \
dbus-launch-x11.c \
dbus-launch.h
+
+dbus_run_session_SOURCES = \
+ dbus-run-session.c
+
+dbus_run_session_LDADD = \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(NULL)
endif
dbus_cleanup_sockets_SOURCES= \
@@ -71,6 +80,9 @@ EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c
CLEANFILES = \
run-with-tmp-session-bus.conf
-#create the /var/lib/data directory for dbus-uuidgen
-localstatelibdir = $(localstatedir)/lib/dbus
-localstatelib_DATA =
+# create the /var/lib/dbus directory for dbus-uuidgen
+install-data-local:
+ $(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/dbus
+
+installcheck-local:
+ test -d $(DESTDIR)$(localstatedir)/lib/dbus
diff --git a/tools/dbus-launch-win.c b/tools/dbus-launch-win.c
index ea4bf0dd..d899010a 100644
--- a/tools/dbus-launch-win.c
+++ b/tools/dbus-launch-win.c
@@ -130,9 +130,10 @@ main (int argc, char **argv)
fprintf (stderr, "%ls %ls\n", dbusDaemonPath, command);
#else
command[0] = L'\0';
- /* Windows CE has a different interpretation of cmdline: Start with argv[1]. */
- wcscpy_s (command, sizeof (command), dbusDaemonPath);
- wcscat_s (command, sizeof (command), L" --session");
+ /* Windows cmdline starts with path, which can contain spaces. */
+ wcscpy_s (command, sizeof (command), L"\"");
+ wcscat_s (command, sizeof (command), dbusDaemonPath);
+ wcscat_s (command, sizeof (command), L"\" --session");
if (verbose)
fprintf (stderr, "%ls\n", command);
#endif
@@ -158,8 +159,8 @@ main (int argc, char **argv)
if (result == 0)
{
if (verbose)
- fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%d\n",
- GetLastError ());
+ fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%u\n",
+ (unsigned)GetLastError ());
return 4;
}
diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c
index bbaac2c3..7ecee63e 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -43,6 +43,47 @@
extern Display *xdisplay;
#endif
+/* PROCESSES
+ *
+ * If you are in a shell and run "dbus-launch myapp", here is what happens:
+ *
+ * shell [*]
+ * \- main() --exec--> myapp[*]
+ * \- "intermediate parent"
+ * \- bus-runner --exec--> dbus-daemon --fork
+ * \- babysitter[*] \- final dbus-daemon[*]
+ *
+ * Processes marked [*] survive the initial flurry of activity.
+ *
+ * If you run "dbus-launch --sh-syntax" then the diagram is the same, except
+ * that main() prints variables and exits 0 instead of exec'ing myapp.
+ *
+ * PIPES
+ *
+ * dbus-daemon --print-pid -> bus_pid_to_launcher_pipe -> main
+ * dbus-daemon --print-address -> bus_address_to_launcher_pipe -> main
+ * main -> bus_pid_to_babysitter_pipe -> babysitter
+ *
+ * The intermediate parent looks pretty useless at first glance. Its purpose
+ * is to avoid the bus-runner becoming a zombie: when the intermediate parent
+ * terminates, the bus-runner and babysitter are reparented to init, which
+ * reaps them if they have finished. We can't rely on main() to reap arbitrary
+ * children because it might exec myapp, after which it can't be relied on to
+ * reap its children. We *can* rely on main() to reap the intermediate parent,
+ * because that happens before it execs myapp.
+ *
+ * It's unclear why dbus-daemon needs to fork, but we explicitly tell it to
+ * for some reason, then wait for it. If we left it undefined, a forking
+ * dbus-daemon would get the parent process reparented to init and reaped
+ * when the intermediate parent terminated, and a non-forking dbus-daemon
+ * would get reparented to init and carry on there.
+ *
+ * myapp is exec'd by the process that initially ran main() so that it's
+ * the shell's child, so the shell knows how to do job control and stuff.
+ * This is desirable for the "dbus-launch an application" use-case, less so
+ * for the "dbus-launch a test suite in an isolated session" use-case.
+ */
+
static char* machine_uuid = NULL;
const char*
@@ -64,6 +105,7 @@ save_machine_uuid (const char *uuid_arg)
machine_uuid = xstrdup (uuid_arg);
}
+#ifdef DBUS_BUILD_X11
#define UUID_MAXLEN 40
/* Read the machine uuid from file if needed. Returns TRUE if machine_uuid is
* set after this function */
@@ -90,7 +132,7 @@ read_machine_uuid_if_needed (void)
goto out;
/* rstrip the read uuid */
- while (len > 31 && isspace(uuid[len - 1]))
+ while (len > 31 && isspace((int) uuid[len - 1]))
len--;
if (len != 32)
@@ -105,12 +147,13 @@ out:
fclose(f);
return ret;
}
-
+#endif /* DBUS_BUILD_X11 */
void
verbose (const char *format,
...)
{
+#ifdef DBUS_ENABLE_VERBOSE_MODE
va_list args;
static int verbose = TRUE;
static int verbose_initted = FALSE;
@@ -135,12 +178,16 @@ verbose (const char *format,
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
}
static void
usage (int ecode)
{
- fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n");
+ fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax]"
+ " [--csh-syntax] [--auto-syntax] [--binary-syntax] [--close-stderr]"
+ " [--exit-with-session] [--autolaunch=MACHINEID]"
+ " [--config-file=FILENAME] [PROGRAM] [ARGS...]\n");
exit (ecode);
}
@@ -175,6 +222,26 @@ xstrdup (const char *str)
return copy;
}
+static char *
+concat2 (const char *a,
+ const char *b)
+{
+ size_t la, lb;
+ char *ret;
+
+ la = strlen (a);
+ lb = strlen (b);
+
+ ret = malloc (la + lb + 1);
+
+ if (ret == NULL)
+ return NULL;
+
+ memcpy (ret, a, la);
+ memcpy (ret + la, b, lb + 1);
+ return ret;
+}
+
typedef enum
{
READ_STATUS_OK, /**< Read succeeded */
@@ -404,9 +471,7 @@ signal_handler (int sig)
{
switch (sig)
{
-#ifdef SIGHUP
case SIGHUP:
-#endif
case SIGINT:
case SIGTERM:
got_sighup = TRUE;
@@ -451,11 +516,20 @@ kill_bus_when_session_ends (void)
else
tty_fd = -1;
- if (tty_fd >= 0)
- verbose ("stdin isatty(), monitoring it\n");
+ if (x_fd >= 0)
+ {
+ verbose ("session lifetime is defined by X, not monitoring stdin\n");
+ tty_fd = -1;
+ }
+ else if (tty_fd >= 0)
+ {
+ verbose ("stdin isatty(), monitoring it\n");
+ }
else
- verbose ("stdin was not a TTY, not monitoring it\n");
-
+ {
+ verbose ("stdin was not a TTY, not monitoring it\n");
+ }
+
if (tty_fd < 0 && x_fd < 0)
{
fprintf (stderr, "No terminal on standard input and no X display; cannot attach message bus to session lifetime\n");
@@ -583,6 +657,7 @@ babysit (int exit_with_session,
s = getenv ("DBUS_DEBUG_OUTPUT");
if (s == NULL || *s == '\0')
dup2 (dev_null_fd, 2);
+ close (dev_null_fd);
}
else
{
@@ -704,31 +779,35 @@ pass_info (const char *runprog, const char *bus_address, pid_t bus_pid,
if (envvar == NULL || args == NULL)
goto oom;
- args[0] = xstrdup (runprog);
+ args[0] = xstrdup (runprog);
if (!args[0])
goto oom;
- for (i = 1; i <= (argc-remaining_args); i++)
- {
- size_t len = strlen (argv[remaining_args+i-1])+1;
- args[i] = malloc (len);
- if (!args[i])
- goto oom;
- strncpy (args[i], argv[remaining_args+i-1], len);
- }
- args[i] = NULL;
+ for (i = 1; i <= (argc-remaining_args); i++)
+ {
+ size_t len = strlen (argv[remaining_args+i-1])+1;
+ args[i] = malloc (len);
+ if (!args[i])
+ {
+ while (i > 1)
+ free (args[--i]);
+ goto oom;
+ }
+ strncpy (args[i], argv[remaining_args+i-1], len);
+ }
+ args[i] = NULL;
- strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
- strcat (envvar, bus_address);
- putenv (envvar);
+ strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
+ strcat (envvar, bus_address);
+ putenv (envvar);
- execvp (runprog, args);
- fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
- exit (1);
+ execvp (runprog, args);
+ fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
+ exit (1);
}
else
{
print_variables (bus_address, bus_pid, bus_wid, c_shell_syntax,
- bourne_shell_syntax, binary_syntax);
+ bourne_shell_syntax, binary_syntax);
}
verbose ("dbus-launch exiting\n");
@@ -1049,24 +1128,41 @@ main (int argc, char **argv)
verbose ("Calling exec()\n");
-#ifdef DBUS_BUILD_TESTS
- /* exec from testdir */
- if (getenv("DBUS_USE_TEST_BINARY") != NULL)
- {
- execl (TEST_BUS_BINARY,
- TEST_BUS_BINARY,
- "--fork",
- "--print-pid", write_pid_fd_as_string,
- "--print-address", write_address_fd_as_string,
- config_file ? "--config-file" : "--session",
- config_file, /* has to be last in this varargs list */
- NULL);
-
- fprintf (stderr,
- "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
- TEST_BUS_BINARY, strerror (errno));
- }
- #endif /* DBUS_BUILD_TESTS */
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+ {
+ const char *test_daemon;
+ /* exec from testdir */
+ if (getenv ("DBUS_USE_TEST_BINARY") != NULL &&
+ (test_daemon = getenv ("DBUS_TEST_DAEMON")) != NULL)
+ {
+ if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL)
+ {
+ config_file = concat2 (getenv ("DBUS_TEST_DATA"),
+ "/valid-config-files/session.conf");
+
+ if (config_file == NULL)
+ {
+ fprintf (stderr, "Out of memory\n");
+ exit (1);
+ }
+ }
+
+ execl (test_daemon,
+ test_daemon,
+ "--fork",
+ "--print-pid", write_pid_fd_as_string,
+ "--print-address", write_address_fd_as_string,
+ config_file ? "--config-file" : "--session",
+ config_file, /* has to be last in this varargs list */
+ NULL);
+
+ fprintf (stderr,
+ "Failed to execute test message bus daemon %s: %s.\n",
+ test_daemon, strerror (errno));
+ exit (1);
+ }
+ }
+ #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
execl (DBUS_DAEMONDIR"/dbus-daemon",
DBUS_DAEMONDIR"/dbus-daemon",
@@ -1111,7 +1207,6 @@ main (int argc, char **argv)
char *end;
long wid = 0;
long val;
- int ret2;
verbose ("=== Parent dbus-launch continues\n");
@@ -1185,6 +1280,8 @@ main (int argc, char **argv)
#ifdef DBUS_ENABLE_X11_AUTOLAUNCH
if (xdisplay != NULL)
{
+ int ret2;
+
verbose("Saving x11 address\n");
ret2 = x11_save_address (bus_address, bus_pid, &wid);
/* Only get an existing dbus session when autolaunching */
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index a4b54782..ff8390d7 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -106,6 +106,9 @@ monitor_filter_func (DBusConnection *connection,
#ifdef __APPLE__
#define PROFILE_TIMED_FORMAT "%s\t%lu\t%d"
+#elif defined(__NetBSD__)
+#include <inttypes.h>
+#define PROFILE_TIMED_FORMAT "%s\t%" PRId64 "\t%d"
#else
#define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu"
#endif
@@ -310,7 +313,7 @@ main (int argc, char *argv[])
filters = (char **) realloc (filters, numFilters * sizeof (char *));
if (filters == NULL)
oom ("adding a new filter slot");
- filters[j] = (char *) malloc (filter_len * sizeof (char *));
+ filters[j] = (char *) malloc (filter_len);
if (filters[j] == NULL)
oom ("adding a new filter");
snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg);
@@ -364,41 +367,45 @@ main (int argc, char *argv[])
if (numFilters)
{
+ size_t offset = 0;
for (i = 0; i < j; i++)
{
- dbus_bus_add_match (connection, filters[i], &error);
- if (dbus_error_is_set (&error))
+ dbus_bus_add_match (connection, filters[i] + offset, &error);
+ if (dbus_error_is_set (&error) && i == 0 && offset == 0)
+ {
+ /* We might be talking to a pre-1.5.6 dbus-daemon
+ * which wouldn't understand eavesdrop=true.
+ * If this works, carry on with offset > 0
+ * on the remaining iterations. */
+ offset = strlen (EAVESDROPPING_RULE) + 1;
+ dbus_error_free (&error);
+ dbus_bus_add_match (connection, filters[i] + offset, &error);
+ }
+
+ if (dbus_error_is_set (&error))
{
fprintf (stderr, "Failed to setup match \"%s\": %s\n",
filters[i], error.message);
dbus_error_free (&error);
exit (1);
}
- free(filters[i]);
+ free(filters[i]);
}
}
else
{
dbus_bus_add_match (connection,
- EAVESDROPPING_RULE ",type='signal'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- EAVESDROPPING_RULE ",type='method_call'",
- &error);
+ EAVESDROPPING_RULE,
+ &error);
if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- EAVESDROPPING_RULE ",type='method_return'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- EAVESDROPPING_RULE ",type='error'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
+ {
+ dbus_error_free (&error);
+ dbus_bus_add_match (connection,
+ "",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ }
}
if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) {
diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c
index 75d00aca..e0dd2da6 100644
--- a/tools/dbus-print-message.c
+++ b/tools/dbus-print-message.c
@@ -346,7 +346,15 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
printf("}\n");
break;
}
-
+
+ case DBUS_TYPE_UNIX_FD:
+ {
+ int fd;
+ dbus_message_iter_get_basic (iter, &fd);
+ printf ("unix fd %d\n", fd);
+ break;
+ }
+
default:
printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
break;
diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c
new file mode 100644
index 00000000..105ab3b4
--- /dev/null
+++ b/tools/dbus-run-session.c
@@ -0,0 +1,464 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-run-session.c - run a child process in its own session
+ *
+ * Copyright © 2003-2006 Red Hat, Inc.
+ * Copyright © 2006 Thiago Macieira <thiago@kde.org>
+ * Copyright © 2011-2012 Nokia Corporation
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <config.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+#include "dbus/dbus.h"
+
+#define MAX_ADDR_LEN 512
+#define PIPE_READ_END 0
+#define PIPE_WRITE_END 1
+
+/* PROCESSES
+ *
+ * If you are in a shell and run "dbus-run-session myapp", here is what
+ * happens (compare and contrast with dbus-launch):
+ *
+ * shell
+ * \- dbus-run-session myapp
+ * \- dbus-daemon --nofork --print-address --session
+ * \- myapp
+ *
+ * All processes are long-running.
+ *
+ * When myapp exits, dbus-run-session kills dbus-daemon and terminates.
+ *
+ * If dbus-daemon exits, dbus-run-session warns and continues to run.
+ *
+ * PIPES
+ *
+ * dbus-daemon --print-address -> bus_address_pipe -> d-r-s
+ */
+
+static const char me[] = "dbus-run-session";
+
+static void
+usage (int ecode)
+{
+ fprintf (stderr,
+ "%s [OPTIONS] [--] PROGRAM [ARGUMENTS]\n"
+ "%s --version\n"
+ "%s --help\n"
+ "\n"
+ "Options:\n"
+ "--dbus-daemon=BINARY run BINARY instead of dbus-daemon\n"
+ "--config-file=FILENAME pass to dbus-daemon instead of --session\n"
+ "\n",
+ me, me, me);
+ exit (ecode);
+}
+
+static void
+version (void)
+{
+ printf ("%s %s\n"
+ "Copyright (C) 2003-2006 Red Hat, Inc.\n"
+ "Copyright (C) 2006 Thiago Macieira\n"
+ "Copyright © 2011-2012 Nokia Corporation\n"
+ "\n"
+ "This is free software; see the source for copying conditions.\n"
+ "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+ me, VERSION);
+ exit (0);
+}
+
+static void
+oom (void)
+{
+ fprintf (stderr, "%s: out of memory\n", me);
+ exit (1);
+}
+
+typedef enum
+{
+ READ_STATUS_OK, /**< Read succeeded */
+ READ_STATUS_ERROR, /**< Some kind of error */
+ READ_STATUS_EOF /**< EOF returned */
+} ReadStatus;
+
+static ReadStatus
+read_line (int fd,
+ char *buf,
+ size_t maxlen)
+{
+ size_t bytes = 0;
+ ReadStatus retval;
+
+ memset (buf, '\0', maxlen);
+ maxlen -= 1; /* ensure nul term */
+
+ retval = READ_STATUS_OK;
+
+ while (1)
+ {
+ ssize_t chunk;
+ size_t to_read;
+
+ again:
+ to_read = maxlen - bytes;
+
+ if (to_read == 0)
+ break;
+
+ chunk = read (fd,
+ buf + bytes,
+ to_read);
+ if (chunk < 0 && errno == EINTR)
+ goto again;
+
+ if (chunk < 0)
+ {
+ retval = READ_STATUS_ERROR;
+ break;
+ }
+ else if (chunk == 0)
+ {
+ retval = READ_STATUS_EOF;
+ break; /* EOF */
+ }
+ else /* chunk > 0 */
+ bytes += chunk;
+ }
+
+ if (retval == READ_STATUS_EOF &&
+ bytes > 0)
+ retval = READ_STATUS_OK;
+
+ /* whack newline */
+ if (retval != READ_STATUS_ERROR &&
+ bytes > 0 &&
+ buf[bytes-1] == '\n')
+ buf[bytes-1] = '\0';
+
+ return retval;
+}
+
+static void
+exec_dbus_daemon (const char *dbus_daemon,
+ int bus_address_pipe[2],
+ const char *config_file)
+{
+ /* Child process, which execs dbus-daemon or dies trying */
+#define MAX_FD_LEN 64
+ char write_address_fd_as_string[MAX_FD_LEN];
+
+ close (bus_address_pipe[PIPE_READ_END]);
+
+ sprintf (write_address_fd_as_string, "%d", bus_address_pipe[PIPE_WRITE_END]);
+
+ execlp (dbus_daemon,
+ dbus_daemon,
+ "--nofork",
+ "--print-address", write_address_fd_as_string,
+ config_file ? "--config-file" : "--session",
+ config_file, /* has to be last in this varargs list */
+ NULL);
+
+ fprintf (stderr, "%s: failed to execute message bus daemon '%s': %s\n",
+ me, dbus_daemon, strerror (errno));
+}
+
+static void
+exec_app (int prog_arg, char **argv)
+{
+ execvp (argv[prog_arg], argv + prog_arg);
+
+ fprintf (stderr, "%s: failed to exec '%s': %s\n", me, argv[prog_arg],
+ strerror (errno));
+ exit (1);
+}
+
+int
+main (int argc, char **argv)
+{
+ int prog_arg = 0;
+ int bus_address_pipe[2] = { 0, 0 };
+ const char *config_file = NULL;
+ const char *dbus_daemon = NULL;
+ char bus_address[MAX_ADDR_LEN] = { 0 };
+ const char *prev_arg = NULL;
+ int i = 1;
+ int requires_arg = 0;
+ pid_t bus_pid;
+ pid_t app_pid;
+
+ while (i < argc)
+ {
+ const char *arg = argv[i];
+
+ if (requires_arg)
+ {
+ const char **arg_dest;
+
+ assert (prev_arg != NULL);
+
+ if (strcmp (prev_arg, "--config-file") == 0)
+ {
+ arg_dest = &config_file;
+ }
+ else if (strcmp (prev_arg, "--dbus-daemon") == 0)
+ {
+ arg_dest = &dbus_daemon;
+ }
+ else
+ {
+ /* shouldn't happen */
+ fprintf (stderr, "%s: internal error: %s not fully implemented\n",
+ me, prev_arg);
+ return 127;
+ }
+
+ if (*arg_dest != NULL)
+ {
+ fprintf (stderr, "%s: %s given twice\n", me, prev_arg);
+ return 127;
+ }
+
+ *arg_dest = arg;
+ requires_arg = 0;
+ prev_arg = arg;
+ ++i;
+ continue;
+ }
+
+ if (strcmp (arg, "--help") == 0 ||
+ strcmp (arg, "-h") == 0 ||
+ strcmp (arg, "-?") == 0)
+ {
+ usage (0);
+ }
+ else if (strcmp (arg, "--version") == 0)
+ {
+ version ();
+ }
+ else if (strstr (arg, "--config-file=") == arg)
+ {
+ const char *file;
+
+ if (config_file != NULL)
+ {
+ fprintf (stderr, "%s: --config-file given twice\n", me);
+ return 127;
+ }
+
+ file = strchr (arg, '=');
+ ++file;
+
+ config_file = file;
+ }
+ else if (strstr (arg, "--dbus-daemon=") == arg)
+ {
+ const char *file;
+
+ if (dbus_daemon != NULL)
+ {
+ fprintf (stderr, "%s: --dbus-daemon given twice\n", me);
+ return 127;
+ }
+
+ file = strchr (arg, '=');
+ ++file;
+
+ dbus_daemon = file;
+ }
+ else if (strcmp (arg, "--config-file") == 0 ||
+ strcmp (arg, "--dbus-daemon") == 0)
+ {
+ requires_arg = 1;
+ }
+ else if (arg[0] == '-')
+ {
+ if (strcmp (arg, "--") != 0)
+ {
+ fprintf (stderr, "%s: option '%s' is unknown\n", me, arg);
+ return 127;
+ }
+ else
+ {
+ prog_arg = i + 1;
+ break;
+ }
+ }
+ else
+ {
+ prog_arg = i;
+ break;
+ }
+
+ prev_arg = arg;
+ ++i;
+ }
+
+ /* "dbus-run-session" and "dbus-run-session ... --" are not allowed:
+ * there must be something to run */
+ if (prog_arg < 1 || prog_arg >= argc)
+ {
+ fprintf (stderr, "%s: a non-option argument is required\n", me);
+ return 127;
+ }
+
+ if (requires_arg)
+ {
+ fprintf (stderr, "%s: option '%s' requires an argument\n", me, prev_arg);
+ return 127;
+ }
+
+ if (dbus_daemon == NULL)
+ dbus_daemon = "dbus-daemon";
+
+ if (pipe (bus_address_pipe) < 0)
+ {
+ fprintf (stderr, "%s: failed to create pipe: %s\n", me, strerror (errno));
+ return 127;
+ }
+
+ bus_pid = fork ();
+
+ if (bus_pid < 0)
+ {
+ fprintf (stderr, "%s: failed to fork: %s\n", me, strerror (errno));
+ return 127;
+ }
+
+ if (bus_pid == 0)
+ {
+ /* child */
+ exec_dbus_daemon (dbus_daemon, bus_address_pipe, config_file);
+ /* not reached */
+ return 127;
+ }
+
+ close (bus_address_pipe[PIPE_WRITE_END]);
+
+ switch (read_line (bus_address_pipe[PIPE_READ_END], bus_address, MAX_ADDR_LEN))
+ {
+ case READ_STATUS_OK:
+ break;
+
+ case READ_STATUS_EOF:
+ fprintf (stderr, "%s: EOF reading address from bus daemon\n", me);
+ return 127;
+ break;
+
+ case READ_STATUS_ERROR:
+ fprintf (stderr, "%s: error reading address from bus daemon: %s\n",
+ me, strerror (errno));
+ return 127;
+ break;
+ }
+
+ close (bus_address_pipe[PIPE_READ_END]);
+
+ if (!dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", bus_address) ||
+ !dbus_setenv ("DBUS_SESSION_BUS_PID", NULL) ||
+ !dbus_setenv ("DBUS_SESSION_BUS_WINDOWID", NULL) ||
+ !dbus_setenv ("DBUS_STARTER_ADDRESS", NULL) ||
+ !dbus_setenv ("DBUS_STARTER_BUS_TYPE", NULL))
+ oom ();
+
+ app_pid = fork ();
+
+ if (app_pid < 0)
+ {
+ fprintf (stderr, "%s: failed to fork: %s\n", me, strerror (errno));
+ return 127;
+ }
+
+ if (app_pid == 0)
+ {
+ /* child */
+ exec_app (prog_arg, argv);
+ /* not reached */
+ return 127;
+ }
+
+ while (1)
+ {
+ int child_status;
+ pid_t child_pid = waitpid (-1, &child_status, 0);
+
+ if (child_pid == (pid_t) -1)
+ {
+ int errsv = errno;
+
+ if (errsv == EINTR)
+ continue;
+
+ /* shouldn't happen: the only other documented errors are ECHILD,
+ * which shouldn't happen because we terminate when all our children
+ * have died, and EINVAL, which would indicate programming error */
+ fprintf (stderr, "%s: waitpid() failed: %s\n", me, strerror (errsv));
+ return 127;
+ }
+ else if (child_pid == bus_pid)
+ {
+ /* no need to kill it, now */
+ bus_pid = 0;
+
+ if (WIFEXITED (child_status))
+ fprintf (stderr, "%s: dbus-daemon exited with code %d\n",
+ me, WEXITSTATUS (child_status));
+ else if (WIFSIGNALED (child_status))
+ fprintf (stderr, "%s: dbus-daemon terminated by signal %d\n",
+ me, WTERMSIG (child_status));
+ else
+ fprintf (stderr, "%s: dbus-daemon died or something\n", me);
+ }
+ else if (child_pid == app_pid)
+ {
+ if (bus_pid != 0)
+ kill (bus_pid, SIGTERM);
+
+ if (WIFEXITED (child_status))
+ return WEXITSTATUS (child_status);
+
+ /* if it died from a signal, behave like sh(1) */
+ if (WIFSIGNALED (child_status))
+ return 128 + WTERMSIG (child_status);
+
+ /* I give up (this should never be reached) */
+ fprintf (stderr, "%s: child process died or something\n", me);
+ return 127;
+ }
+ else
+ {
+ fprintf (stderr, "%s: ignoring unknown child process %ld\n", me,
+ (long) child_pid);
+ }
+ }
+
+ return 0;
+}
diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index e403a587..d3ff2589 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -51,7 +51,7 @@ static const char *appname;
static void
usage (int ecode)
{
- fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname);
+ fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname);
exit (ecode);
}
@@ -241,6 +241,7 @@ main (int argc, char *argv[])
int message_type = DBUS_MESSAGE_TYPE_SIGNAL;
const char *type_str = NULL;
const char *address = NULL;
+ int is_bus = FALSE;
int session_or_system = FALSE;
appname = argv[0];
@@ -266,34 +267,66 @@ main (int argc, char *argv[])
type = DBUS_BUS_SESSION;
session_or_system = TRUE;
}
- else if (strstr (arg, "--address") == arg)
+ else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg))
{
- address = strchr (arg, '=');
-
- if (address == NULL)
+ if (arg[2] == 'b') /* bus */
{
- fprintf (stderr, "\"--address=\" requires an ADDRESS\n");
- usage (1);
+ is_bus = TRUE;
+ }
+ else if (arg[2] == 'p') /* peer */
+ {
+ is_bus = FALSE;
}
- else
+ else /* address; keeping backwards compatibility */
+ {
+ is_bus = FALSE;
+ }
+
+ address = strchr (arg, '=') + 1;
+
+ if (address[0] == '\0')
{
- address = address + 1;
+ fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n");
+ usage (1);
}
}
else if (strncmp (arg, "--print-reply", 13) == 0)
{
print_reply = TRUE;
message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
- if (*(arg + 13) != '\0')
+ if (strcmp (arg + 13, "=literal") == 0)
print_reply_literal = TRUE;
+ else if (*(arg + 13) != '\0')
+ {
+ fprintf (stderr, "invalid value (%s) of \"--print-reply\"\n", arg + 13);
+ usage (1);
+ }
}
else if (strstr (arg, "--reply-timeout=") == arg)
{
+ if (*(strchr (arg, '=') + 1) == '\0')
+ {
+ fprintf (stderr, "\"--reply-timeout=\" requires an MSEC\n");
+ usage (1);
+ }
reply_timeout = strtol (strchr (arg, '=') + 1,
NULL, 10);
+ if (reply_timeout <= 0)
+ {
+ fprintf (stderr, "invalid value (%s) of \"--reply-timeout\"\n",
+ strchr (arg, '=') + 1);
+ usage (1);
+ }
}
else if (strstr (arg, "--dest=") == arg)
- dest = strchr (arg, '=') + 1;
+ {
+ if (*(strchr (arg, '=') + 1) == '\0')
+ {
+ fprintf (stderr, "\"--dest=\" requires an NAME\n");
+ usage (1);
+ }
+ dest = strchr (arg, '=') + 1;
+ }
else if (strstr (arg, "--type=") == arg)
type_str = strchr (arg, '=') + 1;
else if (!strcmp(arg, "--help"))
@@ -312,7 +345,7 @@ main (int argc, char *argv[])
if (session_or_system &&
(address != NULL))
{
- fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n");
+ fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n");
usage (1);
}
@@ -330,6 +363,12 @@ main (int argc, char *argv[])
dbus_error_init (&error);
+ if (dest && !dbus_validate_bus_name (dest, &error))
+ {
+ fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest);
+ usage (1);
+ }
+
if (address != NULL)
{
connection = dbus_connection_open (address, &error);
@@ -348,6 +387,16 @@ main (int argc, char *argv[])
dbus_error_free (&error);
exit (1);
}
+ else if ((address != NULL) && is_bus)
+ {
+ if (!dbus_bus_register (connection, &error))
+ {
+ fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n",
+ address, error.message);
+ dbus_error_free (&error);
+ exit (1);
+ }
+ }
if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
{
diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh
index c39999fb..94ae8fc8 100755
--- a/tools/run-with-tmp-session-bus.sh
+++ b/tools/run-with-tmp-session-bus.sh
@@ -1,16 +1,15 @@
#! /bin/sh
-SCRIPTNAME=$0
-WRAPPED_SCRIPT=$1
+SCRIPTNAME="$0"
+WRAPPED_SCRIPT="$1"
shift
-die()
+CONFIG_FILE=./tmp-session-bus.$$.conf
+
+die ()
{
- if ! test -z "$DBUS_SESSION_BUS_PID" ; then
- echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
- kill -9 $DBUS_SESSION_BUS_PID
- fi
- echo $SCRIPTNAME: $* >&2
+ echo "$SCRIPTNAME: $*" >&2
+ rm -f "$CONFIG_FILE"
exit 1
}
@@ -18,10 +17,6 @@ if test -z "$DBUS_TOP_BUILDDIR" ; then
die "Must set DBUS_TOP_BUILDDIR"
fi
-## convenient to be able to ctrl+C without leaking the message bus process
-trap 'die "Received SIGINT"' INT
-
-CONFIG_FILE=./run-with-tmp-session-bus.conf
SERVICE_DIR="$DBUS_TOP_BUILDDIR/test/data/valid-service-files"
ESCAPED_SERVICE_DIR=`echo $SERVICE_DIR | sed -e 's/\//\\\\\\//g'`
echo "escaped service dir is: $ESCAPED_SERVICE_DIR" >&2
@@ -50,27 +45,18 @@ export LD_LIBRARY_PATH
unset DBUS_SESSION_BUS_ADDRESS
unset DBUS_SESSION_BUS_PID
-echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
-
-DBUS_USE_TEST_BINARY=1
+# this does not actually affect dbus-run-session any more, but could be
+# significant for dbus-launch as used by the autolaunch test
+DBUS_USE_TEST_BINARY=1
export DBUS_USE_TEST_BINARY
-eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
-
-if test -z "$DBUS_SESSION_BUS_PID" ; then
- die "Failed to launch message bus for test script to run"
-fi
-
-echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
-
-# Execute wrapped script
-echo "Running $WRAPPED_SCRIPT $@" >&2
-$WRAPPED_SCRIPT "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
-
-kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
-
-sleep 2
-## be sure it really died
-kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
+$DBUS_TOP_BUILDDIR/tools/dbus-run-session \
+ --config-file="$CONFIG_FILE" \
+ --dbus-daemon="$DBUS_TOP_BUILDDIR/bus/dbus-daemon" \
+ -- \
+ "$WRAPPED_SCRIPT" "$@"
+error=$?
-exit 0
+# clean up
+rm -f "$CONFIG_FILE"
+exit $error
diff --git a/tools/strtoll.c b/tools/strtoll.c
index e4f57701..7360c630 100644
--- a/tools/strtoll.c
+++ b/tools/strtoll.c
@@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
+#include "config.h"
#include <limits.h>
#ifdef HAVE_ERRNO_H
diff --git a/tools/strtoull.c b/tools/strtoull.c
index 459c5091..35595542 100644
--- a/tools/strtoull.c
+++ b/tools/strtoull.c
@@ -27,6 +27,7 @@
* SUCH DAMAGE.
*/
+#include "config.h"
#include <limits.h>
#ifdef HAVE_ERRNO_H