Project import generated by Copybara.
GitOrigin-RevId: 7ee95c3a50c149f0194ffc8c0f85d91760eeeca2
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..35c4c91
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,9 @@
+subdirs = [
+ "bus",
+ "dbus",
+]
+
+cc_library_static {
+ name: "libdbus-headers",
+ export_include_dirs: ["."],
+}
diff --git a/Doxyfile.in b/Doxyfile.in
index f0a37ed..afac639 100644
--- a/Doxyfile.in
+++ b/Doxyfile.in
@@ -147,6 +147,7 @@
"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 2fed9e6..805fd2e 100644
--- a/HACKING
+++ b/HACKING
@@ -11,11 +11,6 @@
Security
===
-If you find a security vulnerability that is not known to the public,
-please report it privately to dbus-security@lists.freedesktop.org
-or by reporting a freedesktop.org bug that is marked as
-restricted to the "D-BUS security group".
-
Most of D-Bus is security sensitive. Guidelines related to that:
- avoid memcpy(), sprintf(), strlen(), snprintf, strlcat(),
@@ -272,7 +267,7 @@
These are the test programs that are built if dbus is compiled using
--enable-tests.
-dbus/test-dbus
+dbus/dbus-test
This is the main unit test program that tests all aspects of the D-Bus
client library.
diff --git a/INSTALL b/INSTALL
index f2f0122..e182f98 100644
--- a/INSTALL
+++ b/INSTALL
@@ -51,11 +51,15 @@
Requisite:
- Gettext
- - expat
+ - expat or libxml-2
+
+ NB, expat is the recommended XML parser because it has more robust
+ handling of OOM conditions.
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 756ab8b..10b9670 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,6 @@
dbus-1.pc
EXTRA_DIST = \
- autogen.sh \
HACKING \
dbus-1.pc.in \
cleanup-man-pages.sh \
@@ -15,7 +14,6 @@
NEWS.pre-1-0 \
ChangeLog.pre-1-2 \
NEWS.pre-1-2 \
- README.valgrind \
README.win \
README.wince \
README.cygwin \
@@ -28,7 +26,6 @@
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/Makefile.cvs b/Makefile.cvs
new file mode 100644
index 0000000..d44e565
--- /dev/null
+++ b/Makefile.cvs
@@ -0,0 +1,8 @@
+## -*- makefile -*-
+
+configure:
+ ./autogen.sh --no-configure
+
+.SILENT:
+
+.PHONY: configure
diff --git a/NEWS b/NEWS
index 56b4ccc..02fa145 100644
--- a/NEWS
+++ b/NEWS
@@ -1,1490 +1,3 @@
-D-Bus 1.10.12 (2016-10-10)
-==
-
-The “not excessively inhospitable” release.
-
-Security fixes:
-
-• Do not treat ActivationFailure message received from root-owned systemd
- name as a format string. In principle this is a security vulnerability,
- but we do not believe it is exploitable in practice, because only
- privileged processes can own the org.freedesktop.systemd1 bus name, and
- systemd does not appear to send activation failures that contain "%".
-
- Please note that this probably *was* exploitable in dbus versions
- older than 1.6.30, 1.8.16 and 1.9.10 due to a missing check which at
- the time was only thought to be a denial of service vulnerability
- (CVE-2015-0245). If you are still running one of those versions,
- patch or upgrade immediately.
-
- (fd.o #98157, Simon McVittie)
-
-Other fixes:
-
-• Harden dbus-daemon against malicious or incorrect ActivationFailure
- messages by rejecting them if they do not come from a privileged
- process, or if systemd activation is not enabled
- (fd.o #98157, Simon McVittie)
-
-• Avoid undefined behaviour when setting reply serial number without going
- via union DBusBasicValue (fd.o #98035, Marc Mutz)
-
-• autogen.sh: fail cleanly if autoconf fails (Simon McVittie)
-
-D-Bus 1.10.10 (2016-08-15)
-==
-
-The “tungsten door” release.
-
-Fixes:
-
-• On Linux, when dbus-daemon is run with reduced susceptibility to the
- OOM killer (typically via systemd), do not let child processes inherit
- that setting (fd.o #32851; Kimmo Hämäläinen, WaLyong Cho)
-
-• Output valid shell syntax in ~/.dbus/session-bus/ if the bus address
- contains a semicolon (fd.o #94746, Thiago Macieira)
-
-• Fix memory leaks and thread safety in subprocess starting on Windows
- (fd.o #95191, Ralf Habacker)
-
-• Do not require systemd to have a service file if using it for activation
- (fd.o #93194; Simon McVittie; backport from 1.11.0)
-
-• Stop test-dbus-daemon incorrectly failing on platforms that cannot
- discover the process ID of clients (fd.o #96653, Руслан Ижбулатов)
-
-• In tests that exercise correct handling of crashing D-Bus services,
- suppress Windows crash handler (fd.o #95155; Yiyang Fei, Ralf Habacker)
-
-• Explicitly check for stdint.h (Ioan-Adrian Ratiu)
-
-• update-activation-environment: produce better diagnostics on error
- (fd.o #96653, Simon McVittie)
-
-• Don't fail the build with an unused const variable warning under gcc 6
- (fd.o #97282; Thomas Zimmermann, Simon McVittie)
-
-• Merge dbus-1.10-ci branch, containing backports from 1.11.0 in build/test
- code to support continuous integration (fd.o #93194, Simon McVittie)
-
- · Avoid -Wunused-label when compiling with libselinux but no libaudit
- · In development builds, allow OOM tests to be disabled as documented
- · Accept and ignore the --tap argument in all "embedded tests", and run
- all automated tests with that argument for better diagnostics
- · Fix the systemd activation test under CMake by installing the required
- files
- · In Automake, fix shell syntax for installcheck-local with no DESTDIR
- · In Automake, don't try to run manual tests in installcheck
- · In CMake, don't run manual-tcp test as an automated test
- · Add travis-ci.org build machinery
-
-D-Bus 1.10.8 (2016-03-07)
-==
-
-The “digestive biscuits” release.
-
-Fixes:
-
-• Enable "large file support" on systems where it exists: dbus-daemon
- is not expected to open large files, but it might need to stat files
- that happen to have large inode numbers (fd.o #93545, Hongxu Jia)
-
-• Eliminate padding inside DBusMessageIter on 64-bit platforms,
- which might result in a pedantic C compiler not copying the entire contents
- of a DBusMessageIter; statically assert that this is not an ABI change
- in practice (fd.o #94136, Simon McVittie)
-
-• Document dbus-test-tool echo --sleep-ms=N instead of incorrect --sleep=N
- (fd.o #94244, Dmitri Iouchtchenko)
-
-• Correctly report test failures in C tests from run-test.sh
- (fd.o #93379; amit tewari, Simon McVittie)
-
-• When tests are enabled, run all the marshal-validate tests, not just
- the even-numbered ones (fd.o #93908, Nick Lewycky)
-
-• Correct the expected error from one marshal-validate test, which was
- previously not run due to the above bug (fd.o #93908, Simon McVittie)
-
-D-Bus 1.10.6 (2015-12-01)
-==
-
-The “marzipan beetles” release.
-
-Fixes:
-
-• On Unix when running tests as root, don't assert that root and
- the dbus-daemon user can still call UpdateActivationEnvironment;
- assert that those privileged users can call BecomeMonitor instead
- (fd.o #93036, Simon McVittie)
-
-• On Windows, fix a memory leak in the autolaunch transport (fd.o #92899,
- Simon McVittie)
-
-• On Windows Autotools builds, don't run tests that rely on
- dbus-run-session and other Unix-specifics (fd.o #92899, Simon McVittie)
-
-D-Bus 1.10.4 (2015-11-17)
-==
-
-The “Frostburn Canyon” release.
-
-Enhancements:
-
-• GetConnectionCredentials, GetConnectionUnixUser and
- GetConnectionUnixProcessID with argument "org.freedesktop.DBus"
- will now return details of the dbus-daemon itself. This is required
- to be able to call SetEnvironment on systemd.
- (fd.o #92857, Jan Alexander Steffens)
-
-Fixes:
-
-• Make UpdateActivationEnvironment always fail with AccessDenied on the
- system bus. Previously, it was possible to configure it so root could
- call it, but the environment variables were not actually used,
- because the launch helper would discard them.
- (fd.o #92857, Jan Alexander Steffens)
-
-• On Unix with --systemd-activation on a user bus, make
- UpdateActivationEnvironment pass on its arguments to systemd's
- SetEnvironment method, solving inconsistency between the environments
- used for traditional activation and systemd user-service activation.
- (fd.o #92857, Jan Alexander Steffens)
-
-• On Windows, don't crash if <syslog/> or --syslog is used
- (fd.o #92538, Ralf Habacker)
-
-• On Windows, fix a memory leak when setting a DBusError from a Windows
- error (fd.o #92721, Ralf Habacker)
-
-• On Windows, don't go into infinite recursion if we abort the process
- with backtraces enabled (fd.o #92721, Ralf Habacker)
-
-• Fix various failing tests, variously on Windows and cross-platform:
- · don't test system.conf features (users, groups) that only make sense
- on the system bus, which is not supported on Windows
- · don't call _dbus_warn() when we skip a test, since it is fatal
- · fix computation of expected <standard_session_servicedirs/>
- · when running TAP tests, translate newlines to Unix format, fixing
- cross-compiled tests under Wine on Linux
- · don't stress-test refcounting under Wine, where it's really slow
- · stop assuming that a message looped-back to the test will be received
- immediately
- · skip some system bus tests on Windows since they make no sense there
- (fd.o #92538, fd.o #92721; Ralf Habacker, Simon McVittie)
-
-D-Bus 1.10.2 (2015-10-26)
-==
-
-The “worst pies in London” release.
-
-Fixes:
-
-• Correct error handling for activation: if there are multiple attempts
- to activate the same service and it fails immediately, the first attempt
- would get the correct reply, but the rest would time out. We now send
- the same error reply to each attempt. (fd.o #92200, Simon McVittie)
-
-• If BecomeMonitor is called with a syntactically invalid match rule,
- don't crash with an assertion failure, fixing a regression in 1.9.10.
- This was not exploitable as a denial of service, because the check
- for a privileged user is done first. (fd.o #92298, Simon McVittie)
-
-• On Linux with --enable-user-session, add the bus address to the
- environment of systemd services for better backwards compatibility
- (fd.o #92612, Jan Alexander Steffens)
-
-• On Windows, fix the logic for replacing the installation prefix
- in service files' Exec lines (fd.o #83539; Milan Crha, Simon McVittie)
-
-• On Windows, if installed in the conventional layout with ${prefix}/etc
- and ${prefix}/share, use relative paths between bus configuration files
- to allow the tree to be relocated (fd.o #92028, Simon McVittie)
-
-• Make more of the regression tests pass in Windows builds (fd.o #92538,
- Simon McVittie)
-
-D-Bus 1.10.0 (2015-08-25)
-==
-
-The “0x20” release.
-
-This is a new stable branch, recommended for use in OS distributions.
-
-Fixes since 1.9.20:
-
-• distribute test/tap-test.sh.in, even if the tarball was built without
- tests enabled (fd.o #91684, Simon McVittie)
-• work around a fd leak in libcap-ng < 0.7.7 (fd.o #91684, Simon McVittie)
-
-Summary of major changes since 1.8.0:
-
-• The basic setup for the well-known system and session buses is
- now done in read-only files in ${datadir} (normally /usr/share).
- See the NEWS entry for 1.9.18 for details.
-
-• AppArmor integration has been merged, with features similar to the
- pre-existing SELinux integration. It is mostly compatible with the
- patches previously shipped by Ubuntu, with one significant change:
- Ubuntu's GetConnectionAppArmorSecurityContext method has been superseded
- by GetConnectionCredentials and was not included.
-
-• The --enable-user-session configure option can be enabled
- by OS integrators intending to use systemd to provide a session bus
- per user (in effect, treating all concurrent graphical and non-graphical
- login sessions as one large session).
-
-• The new listenable address mode "unix:runtime=yes" listens on
- $XDG_RUNTIME_DIR/bus, the same AF_UNIX socket used by the systemd
- user session. libdbus and "dbus-launch --autolaunch" will connect to
- this address by default. GLib ≥ 2.45.3 and sd-bus ≥ 209 have a
- matching default.
-
-• All executables are now dynamically linked to libdbus-1.
- Previously, some executables, most notably dbus-daemon, were statically
- linked to a specially-compiled variant of libdbus. This results in
- various private functions in the _dbus namespace being exposed by the
- shared library. These are not API, and must not be used outside
- the dbus source tree.
-
-• On platforms with ELF symbol versioning, all public symbols
- are versioned LIBDBUS_1_3.
-
-New bus APIs:
-
-• org.freedesktop.DBus.GetConnectionCredentials returns
- LinuxSecurityLabel where supported
-• org.freedesktop.DBus.Monitoring interface (privileged)
- · BecomeMonitor method supersedes match rules with eavesdrop=true,
- which are now deprecated
-• org.freedesktop.DBus.Stats interface (semi-privileged)
- · now enabled by default
- · new GetAllMatchRules method
-• org.freedesktop.DBus.Verbose interface (not normally compiled)
- · toggles the effect of DBUS_VERBOSE
-
-New executables:
-
-• dbus-test-tool
-• dbus-update-activation-environment
-
-New optional dependencies:
-
-• The systemd: pseudo-transport requires libsystemd or libsd-daemon
-• Complete documentation requires Ducktype and yelp-tools
-• Full test coverage requires GLib 2.36 and PyGI
-• AppArmor integration requires libapparmor and optionally libaudit
-
-Dependencies removed:
-
-• dbus-glib
-
-D-Bus 1.9.20 (2015-08-06)
-==
-
-The “Remember Tomorrow” release.
-
-This is a release-candidate for D-Bus 1.10.0. OS distribution vendors
-should test it.
-
-Fixes:
-
-• Don't second-guess what the ABI of poll() is, allowing it to be used
- on Integrity RTOS and other unusual platforms (fd.o #90314;
- Rolland Dudemaine, Simon McVittie)
-
-• Don't duplicate audit subsystem integration if AppArmor and SELinux are
- both enabled (fd.o #89225, Simon McVittie)
-
-• Log audit events for AppArmor/SELinux policy violations whenever
- we have CAP_AUDIT_WRITE, even if not the system bus
- (fd.o #83856, Laurent Bigonville)
-
-D-Bus 1.9.18 (2015-07-21)
-==
-
-The “Pirate Elite” release.
-
-Configuration changes:
-
-• The basic setup for the well-known system and session buses is now done
- in read-only files in ${datadir}, moving a step closer to systems
- that can operate with an empty /etc directory. In increasing order
- of precedence:
-
- · ${datadir}/dbus-1/s*.conf now perform the basic setup such as setting
- the default message policies.
- · ${sysconfdir}/dbus-1/s*.conf are now optional. By default
- dbus still installs a trivial version of each, for documentation
- purposes; putting configuration directives in these files is deprecated.
- · ${datadir}/dbus-1/s*.d/ are now available for third-party software
- to install "drop-in" configuration snippets (any packages
- using those directories should explicitly depend on at least this
- version of dbus).
- · ${sysconfdir}/dbus-1/s*.d/ are also still available for sysadmins
- or third-party software to install "drop-in" configuration snippets
- · ${sysconfdir}/dbus-1/s*-local.conf are still available for sysadmins'
- overrides
-
- ${datadir} is normally /usr/share, ${sysconfdir} is normally /etc,
- and "s*" refers to either system or session as appropriate.
-
- (fd.o #89280, Dimitri John Ledkov)
-
-Fixes:
-
-• Fix a memory leak when GetConnectionCredentials() succeeds
- (fd.o #91008, Jacek Bukarewicz)
-
-• Ensure that dbus-monitor does not reply to messages intended for others,
- resulting in its own disconnection (fd.o #90952, Simon McVittie)
-
-D-Bus 1.9.16 (2015-05-14)
-==
-
-The “titanium barns” release.
-
-Dependencies:
-
-• Automake 1.13 is now required when compiling from git or modifying
- the build system.
-
-Security hardening:
-
-• On Unix platforms, change the default configuration for the session bus
- to only allow EXTERNAL authentication (secure kernel-mediated
- credentials-passing), as was already done for the system bus.
-
- This avoids falling back to DBUS_COOKIE_SHA1, which relies on strongly
- unpredictable pseudo-random numbers.
-
- If you are using D-Bus over the (unencrypted!) tcp: or nonce-tcp: transport,
- in conjunction with DBUS_COOKIE_SHA1 and a shared home directory using
- NFS or similar, you will need to reconfigure the session bus to accept
- DBUS_COOKIE_SHA1 by commenting out the <auth> element. This configuration
- is not recommended.
-
- (fd.o #90414, Simon McVittie)
-
-• When asked for random numbers for DBUS_COOKIE_SHA1, the nonce-tcp:
- transport, UUIDs or any other reason, fail if we cannot obtain entropy
- (from /dev/urandom or CryptGenRandom()) or an out-of-memory condition
- occurs, instead of silently falling back to low-entropy pseudorandom
- numbers from rand(). (fd.o #90414; Simon McVittie, Ralf Habacker)
-
-Enhancements:
-
-• Add dbus_message_iter_get_element_count()
- (fd.o #30350; Christian Dywan, Simon McVittie)
-
-• Introduce new internal DBusSocket and DBusPollable types so we can
- stop treating the Windows SOCKET type as if it was int. DBusSocket
- is specifically a socket, cross-platform. DBusPollable is whatever
- _dbus_poll() can act on, i.e. a fd on Unix or a SOCKET on Windows.
- (fd.o #89444; Ralf Habacker, Simon McVittie)
-
-• All regression tests now output TAP <https://testanything.org/>
- (fd.o #89846, Simon McVittie)
-
-• Internal APIs consistently use signed values for timestamps
- (fd.o #18494, Peter McCurdy)
-
-• Improve diagnostics when UpdateActivationEnvironment calls are rejected
- (fd.o #88812, Simon McVittie)
-
-• Clean up a lot of compiler warnings
- (fd.o #17289, fd.o #89284; Ralf Habacker, Simon McVittie)
-
-Fixes:
-
-• Add locking to DBusCounter's reference count and notify function
- (fd.o #89297, Adrian Szyndela)
-
-• Ensure that DBusTransport's reference count is protected by the
- corresponding DBusConnection's lock (fd.o #90312, Adrian Szyndela)
-
-• Correctly release DBusServer mutex before early-return if we run out
- of memory while copying authentication mechanisms (fd.o #90021,
- Ralf Habacker)
-
-• Make dbus-test-tool and dbus-update-activation-environment portable
- to Windows (fd.o #90089, Ralf Habacker)
-
-• Correctly initialize all fields of DBusTypeReader (fd.o #90021;
- Ralf Habacker, Simon McVittie)
-
-• Fix some missing \n in verbose (debug log) messages (fd.o #90004,
- Ralf Habacker)
-
-• Clean up some memory and fd leaks in test code and tools
- (fd.o #90021, Ralf Habacker)
-
-• Fix a NULL dereference if the dbus-daemon cannot read a configuration
- directory for a reason that is not ENOENT (fd.o #90021, Ralf Habacker)
-
-• CMake generates a versioned shared library even if the revision is 0,
- as it usually is on the development branch. (fd.o #89450, Ralf Habacker)
-
-D-Bus 1.9.14 (2015-03-02)
-==
-
-The “don't stand in the poison cloud” release.
-
-Dependencies:
-
-• dbus-daemon and dbus-daemon-launch-helper now require libdbus. They
- were previously linked to a static version of libdbus.
-
-• The tests no longer require dbus-glib in order to exercise the libdbus
- shared library; they are always linked to libdbus now.
-
-Build-time configuration:
-
-• The new --enable-user-session option, off by default, can be enabled
- by OS integrators intending to use systemd to provide a session bus
- per user (in effect, treating all concurrent graphical and non-graphical
- login sessions as one large session)
-
-Enhancements:
-
-• All executables are now linked dynamically to libdbus.
- (fd.o #83115; Bertrand SIMONNET, Simon McVittie, Ralf Habacker)
-
-• On platforms that support them (GNU libc and possibly others),
- libdbus now has versioned symbols for its public API.
- All public symbols (visible in the header files) are currently
- versioned as LIBDBUS_1_3; private symbols starting with _dbus or
- dbus_internal have a version that changes with each release, and
- must not be used by applications. (also fd.o #83115)
-
-• New listenable address mode "unix:runtime=yes" which listens on
- a real filesystem (non-abstract) socket $XDG_RUNTIME_DIR/bus
- (fd.o #61303; Colin Walters, Alexander Larsson, Simon McVittie)
-
-• Add optional systemd units for a per-user bus listening on
- $XDG_RUNTIME_DIR/bus (fd.o #61301; Simon McVittie, Colin Walters)
-
-• On Unix platforms, both libdbus and "dbus-launch --autolaunch"
- default to connecting to $XDG_RUNTIME_DIR/bus if it is a socket
- (also fd.o #61301)
-
-• New dbus-update-activation-environment tool uploads environment
- variables to "dbus-daemon --session" and optionally "systemd --user",
- primarily as a way to keep the per-user bus compatible with
- distributions' existing X11 login scripts (also fd.o #61301)
-
-• <includedir/> elements in dbus-daemon configuration are now silently
- ignored if the directory does not exist. (fd.o #89280, Dimitri John Ledkov)
-
-• Add microsecond-resolution timestamps to the default output of
- dbus-monitor and dbus-send (fd.o #88896; Ralf Habacker, Simon McVittie)
-
-Fixes:
-
-• Fix a race condition in the 'monitor' test introduced in 1.9.10
- (fd.o #89222, Simon McVittie)
-
-D-Bus 1.9.12 (2015-02-19)
-==
-
-The “monster lasagna” release.
-
-Dependencies:
-
-• Ducktype and yelp-tools are now required to build complete documentation
- (they are optional for normal builds).
-
-Enhancements:
-
-• D-Bus Specification version 0.26
- · GetConnectionCredentials can return LinuxSecurityLabel or WindowsSID
- · document the BecomeMonitor method
-
-• On Linux, add LinuxSecurityLabel to GetConnectionCredentials
- (fd.o #89041; Tyler Hicks, Simon McVittie)
-
-• On Linux, add support for AppArmor mediation of message sending and
- receiving and name ownership (paralleling existing SELinux mediation
- support), and eavesdropping (a new check, currently AppArmor-specific)
- (fd.o #75113; John Johansen, Tyler Hicks, Simon McVittie)
-
-• In dbus-send and dbus-monitor, pretty-print \0-terminated bytestrings
- that have printable ASCII contents; we previously only did this for
- unterminated bytestrings (fd.o #89109, Simon McVittie)
-
-• Add a guide to designing good D-Bus APIs (fd.o #88994, Philip Withnall)
-
-• On Windows, add WindowsSID to GetConnectionCredentials
- (fd.o #54445, Ralf Habacker)
-
-• Improve clarity of dbus-monitor --profile output and add more columns
- (fd.o #89165, Ralf Habacker)
-
-• Add a man page for dbus-test-tool, and build it under CMake as well
- as Autotools (fd.o#89086, Simon McVittie)
-
-• If dbus-daemon was compiled with --enable-verbose, add a D-Bus API
- to control it at runtime, overriding the DBUS_VERBOSE environment variable
- (fd.o #88896, Ralf Habacker)
-
-Fixes:
-
-• Reduce the number of file descriptors used in the fd-passing test,
- avoiding failure under the default Linux fd limit, and automatically
- skip it if the rlimit is too small (fd.o #88998, Simon McVittie)
-
-D-Bus 1.9.10 (2015-02-09)
-==
-
-The “sad cyborgs” release.
-
-Security fixes merged from 1.8.16:
-
-• Do not allow non-uid-0 processes to send forged ActivationFailure
- messages. On Linux systems with systemd activation, this would
- allow a local denial of service: unprivileged processes could
- flood the bus with these forged messages, winning the race with
- the actual service activation and causing an error reply
- to be sent back when service auto-activation was requested.
- This does not prevent the real service from being started,
- so the attack only works while the real service is not running.
- (CVE-2015-0245, fd.o #88811; Simon McVittie)
-
-Enhancements:
-
-• The new Monitoring interface in the dbus-daemon lets dbus-monitor and
- similar tools receive messages without altering the security properties
- of the system bus, by calling the new BecomeMonitor method on a
- private connection. This bypasses the normal <allow> and <deny> rules
- entirely, so to preserve normal message-privacy assumptions, only root
- is allowed to do this on the system bus. Restricted environments,
- such as Linux with LSMs, should lock down access to the Monitoring
- interface. (fd.o #46787, Simon McVittie)
-
-• dbus-monitor uses BecomeMonitor to capture more traffic, if the
- dbus-daemon supports it and access permissions allow it.
- It still supports the previous approach ("eavesdropping" match rules)
- for compatibility with older bus daemons. (fd.o #46787, Simon)
-
-• dbus-monitor can now log the message stream as binary data for later
- analysis, with either no extra framing beyond the normal D-Bus headers,
- or libpcap-compatible framing treating each D-Bus message
- as a captured packet. (fd.o #46787, Simon)
-
-Other fixes:
-
-• Fix some CMake build regressions (fd.o #88964, Ralf Habacker)
-
-• On Unix, forcibly terminate regression tests after 60 seconds to
- prevent them from blocking continuous integration frameworks
- (fd.o #46787, Simon)
-
-D-Bus 1.9.8 (2015-02-03)
-==
-
-The “all the types of precipitation” release.
-
-Dependencies:
-
-• full test coverage now requires GLib 2.36
-• full test coverage now requires PyGI (PyGObject 3,
- "import gi.repository.GObject") instead of the
- obsolete PyGObject 2 ("import gobject")
-
-Enhancements:
-
-• add GLib-style "installed tests" (fd.o #88810, Simon McVittie)
-
-• better regression test coverage, including systemd activation
- (fd.o #57952, #88810; Simon McVittie)
-
-Fixes:
-
-• fatal errors correctly make the dbus-daemon exit even if <syslog/> is
- turned off (fd.o #88808, Simon McVittie)
-
-• TCP sockets on Windows no longer fail to listen approximately 1 time
- in 256, caused by a logic error that should have always made it fail but
- was mitigated by incorrect endianness for the port number
- (fd.o #87999, Ralf Habacker)
-
-• fix some Windows build failures (fd.o #88009, #88010; Ralf Habacker)
-
-• on Windows, allow up to 8K connections to the dbus-daemon instead of the
- previous 64, completing a previous fix which only worked under
- Autotools (fd.o #71297, Ralf Habacker)
-
-• on Windows, if the IP family is unspecified only use IPv4,
- to mitigate IPv6 not working correctly (fd.o #87999, Ralf Habacker)
-
-• fix some unlikely memory leaks on OOM (fd.o #88087, Simon McVittie)
-
-• lcov code coverage analysis works again (fd.o #88808, Simon McVittie)
-
-• fix an unused function error with --disable-embedded-tests (fd.o #87837,
- Thiago Macieira)
-
-D-Bus 1.9.6 (2015-01-05)
-==
-
-The “I do have a bread knife” release.
-
-Security hardening:
-
-• Do not allow calls to UpdateActivationEnvironment from uids other than
- the uid of the dbus-daemon. If a system service installs unsafe
- security policy rules that allow arbitrary method calls
- (such as CVE-2014-8148) then this prevents memory consumption and
- possible privilege escalation via UpdateActivationEnvironment.
-
- We believe that in practice, privilege escalation here is avoided
- by dbus-daemon-launch-helper sanitizing its environment; but
- it seems better to be safe.
-
-• Do not allow calls to UpdateActivationEnvironment or the Stats interface
- on object paths other than /org/freedesktop/DBus. Some system services
- install unsafe security policy rules that allow arbitrary method calls
- to any destination, method and interface with a specified object path;
- while less bad than allowing arbitrary method calls, these security
- policies are still harmful, since dbus-daemon normally offers the
- same API on all object paths and other system services might behave
- similarly.
-
-Other fixes:
-
-• Add missing initialization so GetExtendedTcpTable doesn't crash on
- Windows Vista SP0 (fd.o #77008, Илья А. Ткаченко)
-
-D-Bus 1.9.4 (2014-11-24)
-==
-
-The “extra-sturdy caramel” release.
-
-Fixes:
-
-• Partially revert the CVE-2014-3639 patch by increasing the default
- authentication timeout on the system bus from 5 seconds back to 30
- seconds, since this has been reported to cause boot regressions for
- some users, mostly with parallel boot (systemd) on slower hardware.
-
- On fast systems where local users are considered particularly hostile,
- administrators can return to the 5 second timeout (or any other value
- in milliseconds) by saving this as /etc/dbus-1/system-local.conf:
-
- <busconfig>
- <limit name="auth_timeout">5000</limit>
- </busconfig>
-
- (fd.o #86431, Simon McVittie)
-
-• Add a message in syslog/the Journal when the auth_timeout is exceeded
- (fd.o #86431, Simon McVittie)
-
-• Send back an AccessDenied error if the addressed recipient is not allowed
- to receive a message (and in builds with assertions enabled, don't
- assert under the same conditions). (fd.o #86194, Jacek Bukarewicz)
-
-D-Bus 1.9.2 (2014-11-10)
-==
-
-The “structurally unsound flapjack” release.
-
-Security fixes:
-
-• Increase dbus-daemon's RLIMIT_NOFILE rlimit to 65536
- so that CVE-2014-3636 part A cannot exhaust the system bus'
- file descriptors, completing the incomplete fix in 1.8.8.
- (CVE-2014-7824, fd.o #85105; Simon McVittie, Alban Crequy)
-
-Enhancements:
-
-• D-Bus Specification version 0.25
- · new value 'const' for EmitsChangedSignal annotation
- (fd.o #72958, Lennart Poettering)
- · new ALLOW_INTERACTIVE_AUTHORIZATION flag, for PolicyKit and similar
- (fd.o #83449; Lennart Poettering, Simon McVittie)
- · annotate table of types with reserved/basic/container, and for
- basic types, fixed/string-like
- · clarify arbitrary limits by quoting them in mebibytes
-
-• New API: add accessors for the ALLOW_INTERACTIVE_AUTHORIZATION flag
- (fd.o #83449, Simon McVittie)
-
-• Add dbus-test-tool, a D-Bus swiss army knife with multiple subcommands,
- useful for debugging and performance testing:
- · dbus-test-tool spam: send repeated messages
- · dbus-test-tool echo: send an empty reply for all method calls
- · dbus-test-tool black-hole: do not reply to method calls
- (fd.o #34140; Alban Crequy, Simon McVittie, Will Thompson)
-
-• Add support for process ID in credentials-passing on NetBSD
- (fd.o #69702, Patrick Welche)
-
-• Add an example script to find potentially undesired match rules
- (fd.o #84598, Alban Crequy)
-
-• Document the central assumption that makes our use of credentials-passing
- secure (fd.o #83499, Simon McVittie)
-
-• Replace the dbus-glib section of the tutorial with a GDBus recommendation,
- and add some links to GDBus and QtDBus documentation (fd.o #25140,
- Simon McVittie)
-
-Fixes:
-
-• Use a less confusing NoReply message when disconnected with a reply pending
- (fd.o #76112, Simon McVittie)
-
-• Make the .pc file relocatable by letting pkg-config do all variable
- expansion itself (fd.o #75858, Руслан Ижбулатов)
-
-• Fix a build failure on platforms with kqueue, which regressed in 1.9.0
- (fd.o #85563, Patrick Welche)
-
-• Consistently save errno after socket calls (fd.o #83625, Simon McVittie)
-
-• In dbus-spawn, when the grandchild process exits due to a failed exec(),
- do not lose the exec() errno (fd.o #24821, Simon McVittie)
-
-• Do not fail the tests if a parent process has leaked non-close-on-exec
- file descriptors to us (fd.o #73689, fd.o #83899; Simon McVittie)
-
-• Do not fail the tests on Unix platforms with incomplete
- credentials-passing support, but do fail if we can't pass credentials
- on a platform where it is known to work: Linux, FreeBSD, OpenBSD, NetBSD
- (fd.o #69702, Simon McVittie)
-
-• Detect accept4, dirfd, inotify_init1, pipe2, and Unix fd passing
- when building with cmake, and expand test coverage there
- (fd.o #73689; Ralf Habacker, Simon McVittie)
-
-D-Bus 1.9.0 (2014-10-01)
-==
-
-The “tiered cheeses” release.
-
-Requirements:
-
-• Support for the systemd: (LISTEN_FDS) pseudo-transport on Linux now
- requires either the libsystemd or libsd-daemon shared library, dropping the
- embedded convenience copy of sd-daemon (fd.o #71818, Simon)
-
-Build-time configuration changes:
-
-• The Stats interface is now enabled by default, and locked-down to
- root-only on the system bus. Configure with --disable-stats
- to disable it altogether on memory- or disk-constrained systems,
- or see ${docdir}/examples/ to open it up to non-root users on the
- system bus or restrict access on the session bus.
- (fd.o #80759; Simon McVittie, Alban Crequy)
-
-• The CMake build system now builds the same shared library name as Autotools
- on at least Linux and Windows:
- - on Linux (and perhaps other Unix platforms), it previously built
- libdbus-1.so, but now builds libdbus-1.so.3.* with development
- symlink libdbus-1.so and SONAME/symlink libdbus-1.so.3
- - on Windows, it previously built either libdbus-1.dll (release) or
- libdbus-1d.dll (debug), but now builds libdbus-1-3.dll, copied to
- libdbus-1.dll for compatibility with older applications.
- (fd.o #74117, Ralf Habacker)
-
-Enhancements:
-
-• D-Bus Specification version 0.24
- · document how to quote match rules (fd.o #24307, Simon McVittie)
- · explicitly say that most message types never expect a reply
- regardles of whether they have NO_REPLY_EXPECTED
- (fd.o #75749, Simon McVittie)
-
-• on Unix platforms, disable Nagle's algorithm on TCP connections to improve
- initial latency (fd.o #75544, Matt Hoosier)
-
-• use backtrace() if it is in -lexecinfo instead of libc, as on NetBSD
- (fd.o #69702, Patrick Welche)
-
-• in dbus-monitor, print more information about file descriptors
- (fd.o #80603, Alban Crequy)
-
-• do not install system bus configuration if built for Windows
- (fd.o #83583; Ralf Habacker, Simon McVittie)
-
-• Add GetAllMatchRules to the Stats interface (fd.o #24307, Alban Crequy)
-
-• Add a regression test for file descriptor passing (fd.o #83622,
- Simon McVittie)
-
-Fixes:
-
-• fix an incorrect error message if a Unix socket path is too long
- (fd.o #73887, Antoine Jacoutot)
-
-• in an MSYS/Cygwin environment, pass Unix-style filenames to xmlto,
- fixing documentation generation (fd.o #75860, Руслан Ижбулатов)
-
-• in Unix with X11, avoid giving dbus-launch a misleading argv[0]
- in ps(1) (fd.o #69716, Chengwei Yang)
-
-• avoid calling poll() with timeout < -1, which is considered invalid
- on FreeBSD and NetBSD (fd.o #78480, Jaap Boender)
-
-• be portable to BSD-derived platforms where O_CLOEXEC is unavailable in libc
- (like Mac OS X 10.6), or available in libc but unsupported by the kernel
- (fd.o #77032; rmvsxop, OBATA Akio, Patrick Welche)
-
-• Fix include path for test/internal/*.c with cmake (Ralf Habacker)
-
-• Documentation improvements
- (fd.o #80795, #84313; Thomas Haller, Sebastian Rasmussen)
-
-• in dbus-monitor, do not leak file descriptors that we have monitored
- (fd.o #80603, Alban Crequy)
-
-• Set the close-on-exec flag for the inotify file descriptor, even
- if built with CMake or older libc (fd.o #73689, Simon McVittie)
-
-• Remove some LGPL code from the Windows dbus-daemon
- (fd.o #57272, Ralf Habacker)
-
-D-Bus 1.8.8 (2014-09-16)
-==
-
-The "smashy smashy egg man" release.
-
-Security fixes:
-
-• Do not accept an extra fd in the padding of a cmsg message, which
- could lead to a 4-byte heap buffer overrun.
- (CVE-2014-3635, fd.o #83622; Simon McVittie)
-
-• Reduce default for maximum Unix file descriptors passed per message
- from 1024 to 16, preventing a uid with the default maximum number of
- connections from exhausting the system bus' file descriptors under
- Linux's default rlimit. Distributors or system administrators with a
- more restrictive fd limit may wish to reduce these limits further.
-
- Additionally, on Linux this prevents a second denial of service
- in which the dbus-daemon can be made to exceed the maximum number
- of fds per sendmsg() and disconnect the process that would have
- received them.
- (CVE-2014-3636, fd.o #82820; Alban Crequy)
-
-• Disconnect connections that still have a fd pending unmarshalling after
- a new configurable limit, pending_fd_timeout (defaulting to 150 seconds),
- removing the possibility of creating an abusive connection that cannot be
- disconnected by setting up a circular reference to a connection's
- file descriptor.
- (CVE-2014-3637, fd.o #80559; Alban Crequy)
-
-• Reduce default for maximum pending replies per connection from 8192 to 128,
- mitigating an algorithmic complexity denial-of-service attack
- (CVE-2014-3638, fd.o #81053; Alban Crequy)
-
-• Reduce default for authentication timeout on the system bus from
- 30 seconds to 5 seconds, avoiding denial of service by using up
- all unauthenticated connection slots; and when all unauthenticated
- connection slots are used up, make new connection attempts block
- instead of disconnecting them.
- (CVE-2014-3639, fd.o #80919; Alban Crequy)
-
-Other fixes:
-
-• Check for libsystemd from systemd >= 209, falling back to
- the older separate libraries if not found (Umut Tezduyar Lindskog,
- Simon McVittie)
-
-• On Linux, use prctl() to disable core dumps from a test executable
- that deliberately raises SIGSEGV to test dbus-daemon's handling
- of that condition (fd.o #83772, Simon McVittie)
-
-• Fix compilation with --enable-stats (fd.o #81043, Gentoo #507232;
- Alban Crequy)
-
-• Improve documentation for running tests on Windows (fd.o #41252,
- Ralf Habacker)
-
-D-Bus 1.8.6 (2014-06-02)
-==
-
-Security fixes:
-
-• On Linux ≥ 2.6.37-rc4, if sendmsg() fails with ETOOMANYREFS, silently drop
- the message. This prevents an attack in which a malicious client can
- make dbus-daemon disconnect a system service, which is a local
- denial of service.
- (fd.o #80163, CVE-2014-3532; Alban Crequy)
-
-• Track remaining Unix file descriptors correctly when more than one
- message in quick succession contains fds. This prevents another attack
- in which a malicious client can make dbus-daemon disconnect a system
- service.
- (fd.o #79694, fd.o #80469, CVE-2014-3533; Alejandro Martínez Suárez,
- Simon McVittie, Alban Crequy)
-
-Other fixes:
-
-• When dbus-launch --exit-with-session starts a dbus-daemon but then cannot
- attach to a session, kill the dbus-daemon as intended
- (fd.o #74698, Роман Донченко)
-
-D-Bus 1.8.4 (2014-06-10)
-==
-
-Security fix:
-
-• Alban Crequy at Collabora Ltd. discovered and fixed a denial-of-service
- flaw in dbus-daemon, part of the reference implementation of D-Bus.
- Additionally, in highly unusual environments the same flaw could lead to
- a side channel between processes that should not be able to communicate.
- (CVE-2014-3477, fd.o #78979)
-
-D-Bus 1.8.2 (2014-04-30)
-==
-
-The “nobody wants red” release.
-
-Enhancements:
-
-• in the CMake build system, add some hints for Linux users cross-compiling
- Windows D-Bus binaries to be able to run tests under Wine
- (fd.o #41252, Ralf Habacker)
-
-• add Documentation key to dbus.service (fd.o #77447, Cameron Norman)
-
-Fixes:
-
-• in "dbus-uuidgen --ensure", try to copy systemd's /etc/machine-id
- to /var/lib/dbus/machine-id instead of generating an entirely new ID
- (fd.o #77941, Simon McVittie)
-
-• if dbus-launch receives an X error very quickly, do not kill
- unrelated processes (fd.o #74698, Роман Донченко)
-
-• on Windows, allow up to 8K connections to the dbus-daemon, instead of the
- previous 64 (fd.o #71297; Cristian Onet, Ralf Habacker)
-
-• cope with \r\n newlines in regression tests, since on Windows,
- dbus-daemon.exe uses text mode (fd.o #75863, Руслан Ижбулатов)
-
-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)
==
diff --git a/README b/README
index 0257e69..fd832ca 100644
--- a/README
+++ b/README
@@ -29,25 +29,6 @@
only by accident; so you should evaluate carefully whether D-Bus makes
sense for your project.
-Security
-==
-
-If you find a security vulnerability that is not known to the public,
-please report it privately to dbus-security@lists.freedesktop.org
-or by reporting a freedesktop.org bug that is marked as
-restricted to the "D-BUS security group" (you might need to "Show
-Advanced Fields" to have that option).
-
-On Unix systems, the system bus (dbus-daemon --system) is designed
-to be a security boundary between users with different privileges.
-
-On Unix systems, the session bus (dbus-daemon --session) is designed
-to be used by a single user, and only accessible by that user.
-
-We do not currently consider D-Bus on Windows to be security-supported,
-and we do not recommend allowing untrusted users to access Windows
-D-Bus via TCP.
-
Note: low-level API vs. high-level binding APIs
===
@@ -85,9 +66,7 @@
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. dbus requires GNU Make
-(on BSD systems, this is typically called gmake) or a "make" implementation
-with compatible extensions.
+with or without additional configuration flags.
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
new file mode 100644
index 0000000..5feaf55
--- /dev/null
+++ b/README.cmake
@@ -0,0 +1,171 @@
+This file describes how to compile dbus using the cmake build system
+
+Requirements
+------------
+- cmake version >= 2.4.4 see http://www.cmake.org
+- installed libexpat see http://sourceforge.net/projects/expat/
+ unsupported RelWithDebInfo builds could be fetched
+ from http://sourceforge.net/projects/kde-windows/files/expat/
+
+Building
+--------
+
+Win32 MinGW-w64|32
+1. install mingw-w64 from http://sourceforge.net/projects/mingw-w64/
+2. install cmake and libexpat
+3. get dbus sources
+4. unpack dbus sources into a sub directory (referred as <dbus-src-root> later)
+5. mkdir dbus-build
+6. cd dbus-build
+7. run
+ cmake -G "MinGW Makefiles" [<options, see below>] <dbus-src-root>/cmake
+ mingw32-make
+ mingw32-make install
+
+Win32 Microsoft nmake
+1. install MSVC 2010 Express Version from http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
+2. install cmake and libexpat
+3. get dbus sources
+4. unpack dbus sources into a sub directory (referred as <dbus-src-root> later)
+5. mkdir dbus-build
+6. cd dbus-build
+7. run
+ cmake -G "NMake Makefiles" [<options, see below>] <dbus-src-root>/cmake
+ nmake
+ nmake install
+
+Win32 Visual Studio 2010 Express IDE
+1. install MSVC 2010 Express Version from http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
+2. install cmake and libexpat
+3. get dbus sources
+4. unpack dbus sources into a sub directory (referred as <dbus-src-root> later)
+5. mkdir dbus-build
+6. cd dbus-build
+7. run
+ cmake -G "Visual Studio 10" [<options, see below>] <dbus-src-root>/cmake
+8a. open IDE with
+ vcexpress dbus.sln
+8b. for immediate build run
+ vcexpress dbus.sln /build
+
+Win32 Visual Studio 2010 Professional IDE
+1. install MSVC 2010 Professional Version
+2. install cmake and libexpat
+3. get dbus sources
+4. unpack dbus sources into a sub directory (referred as <dbus-src-root> later)
+5. mkdir dbus-build
+6. cd dbus-build
+7. run
+ cmake -G "Visual Studio 10" [<options, see below>] <dbus-src-root>/cmake
+8a. open IDE with
+ devenv dbus.sln
+8b. for immediate build run
+ devenv dbus.sln /build
+
+Linux
+1. install cmake and libexpat
+2. get dbus sources
+3. unpack dbus sources into a sub directory (referred as <dbus-src-root> later)
+4. mkdir dbus-build
+5. cd dbus-build
+6. run
+ cmake -G "<for available targets, see cmake --help for a list>" [<options, see below>] <dbus-src-root>/cmake
+ make
+ make install
+
+For other compilers see cmake --help in the Generators section
+
+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.
+
+// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
+// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
+CMAKE_BUILD_TYPE:STRING=Debug
+
+// Include path for 3rdparty packages
+CMAKE_INCLUDE_PATH:PATH=
+
+// Library path for 3rdparty packages
+CMAKE_LIBRARY_PATH:PATH=
+
+// Install path prefix, prepended onto install directories.
+CMAKE_INSTALL_PREFIX:PATH=C:/Program Files/dbus
+
+
+// enable unit test code
+DBUS_BUILD_TESTS:BOOL=ON
+
+// The name of the dbus daemon executable
+DBUS_DAEMON_NAME:STRING=dbus-daemon
+
+// Disable assertion checking
+DBUS_DISABLE_ASSERTS:BOOL=OFF
+
+// Disable public API sanity checking
+DBUS_DISABLE_CHECKS:BOOL=OFF
+
+// enable -ansi -pedantic gcc flags
+DBUS_ENABLE_ANSI:BOOL=OFF
+
+// build DOXYGEN documentation (requires Doxygen)
+DBUS_ENABLE_DOXYGEN_DOCS:BOOL=OFF
+
+// enable bus daemon usage statistics
+DBUS_ENABLE_STATS:BOOL=OFF
+
+// support verbose debug mode
+DBUS_ENABLE_VERBOSE_MODE:BOOL=ON
+
+// build XML documentation (requires xmlto or meinproc4)
+DBUS_ENABLE_XML_DOCS:BOOL=ON
+
+// Some atomic integer implementation present
+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:
+
+// system bus default address
+DBUS_SYSTEM_BUS_DEFAULT_ADDRESS:STRING=nonce-tcp:
+
+// 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
+
+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
+
+// Directory to check for console ownership
+DBUS_CONSOLE_OWNER_FILE:STRING=/dev/console
+
+x11 only:
+// Build with X11 auto launch support
+DBUS_BUILD_X11:BOOL=ON
+
+
+Note: The above mentioned options could be extracted after
+configuring from the output of running "<maketool> help-options"
+in the build directory. The related entries start with
+CMAKE_ or DBUS_.
diff --git a/README.valgrind b/README.valgrind
deleted file mode 100644
index c13f530..0000000
--- a/README.valgrind
+++ /dev/null
@@ -1,24 +0,0 @@
-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 8a5b3c0..d18f23d 100644
--- a/README.win
+++ b/README.win
@@ -13,13 +13,15 @@
Supported compilers
-------------------
-On windows Microsoft Visual Studio 2010 (Express and professional variants)
+On windows Microsoft Visual Studio 2010 (Express and professional variants)
and mingw-w64|32 are known to work.
Building
--------
DBus can be built on windows using automake or cmake. See the
-file INSTALL for more information.
+file README for more information.
+Special cmake build instructions can be found in cmake/readme-cmake.txt
+
windbus and dbus4win Ports
--------------------------
@@ -30,19 +32,14 @@
Tests
-----
- - run complete test suite
- make check
- or
- ctest [-V]
-
- dbus library check
- ctest [-V] -R test-dbus
+ bin\dbus-test.exe <build-root>\test\data
- bus daemon check
- ctest [-V] -R test-bus
+ bin\bus-test.exe <build-root>\test\data
- check available names
- ctest [-V] -R test-names
+ bin\test_names.exe
- check if dbus-daemon is accessable
bin\dbus-send.exe --session --type=method_call --print-reply --dest=org.freedesktop.DBus / org.freedesktop.DBus.ListNames method return sender=org.freedesktop.DBus -> dest=:1.4 array [ string "org.freedesktop.DBus"string ":1.4"]
@@ -91,13 +88,13 @@
The OpenWengo dbus-c++ binding has been ported to windows see in WinDBus svn
(http://sf.net/projects/windbus)
- The related test applications are running well.
+ The related test applicationa are running well.
TODO
----
-October 2010:
+Oktober 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 6de735f..1558112 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -15,8 +15,8 @@
if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
echo "Activating pre-commit hook."
- cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
- chmod +x .git/hooks/pre-commit
+ cp -av .git/hooks/pre-commit.sample .git/hooks/pre-commit
+ chmod -c +x .git/hooks/pre-commit
fi
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
@@ -48,7 +48,7 @@
}
LIBTOOLIZE=`which libtoolize`
-if ! test -f "$LIBTOOLIZE"; then
+if ! test -f $LIBTOOLIZE; then
LIBTOOLIZE=`which glibtoolize`
fi
@@ -81,10 +81,7 @@
(autoheader --version) < /dev/null > /dev/null 2>&1 && autoheader
$AUTOMAKE -a $am_opt
-if ! autoconf; then
- echo "autoconf failed - version 2.5x is probably required" >&2
- exit 1
-fi
+autoconf || echo "autoconf failed - version 2.5x is probably required"
cd $ORIGDIR
@@ -105,4 +102,10 @@
if $run_configure; then
$srcdir/configure --enable-developer --config-cache "$@"
+ echo
+ echo "Now type 'make' to compile $PROJECT."
+else
+ echo
+ echo "Now run 'configure' and 'make' to compile $PROJECT."
fi
+
diff --git a/build-aux/tap-driver.sh b/build-aux/tap-driver.sh
deleted file mode 100755
index 4254e2b..0000000
--- a/build-aux/tap-driver.sh
+++ /dev/null
@@ -1,651 +0,0 @@
-#! /bin/sh
-# Copyright (C) 2011-2014 Free Software Foundation, Inc.
-#
-# 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, 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, see <http://www.gnu.org/licenses/>.
-
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# This file is maintained in Automake, please report
-# bugs to <bug-automake@gnu.org> or send patches to
-# <automake-patches@gnu.org>.
-
-scriptversion=2013-12-23.17; # UTC
-
-# Make unconditional expansion of undefined variables an error. This
-# helps a lot in preventing typo-related bugs.
-set -u
-
-me=tap-driver.sh
-
-fatal ()
-{
- echo "$me: fatal: $*" >&2
- exit 1
-}
-
-usage_error ()
-{
- echo "$me: $*" >&2
- print_usage >&2
- exit 2
-}
-
-print_usage ()
-{
- cat <<END
-Usage:
- tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
- [--expect-failure={yes|no}] [--color-tests={yes|no}]
- [--enable-hard-errors={yes|no}] [--ignore-exit]
- [--diagnostic-string=STRING] [--merge|--no-merge]
- [--comments|--no-comments] [--] TEST-COMMAND
-The '--test-name', '-log-file' and '--trs-file' options are mandatory.
-END
-}
-
-# TODO: better error handling in option parsing (in particular, ensure
-# TODO: $log_file, $trs_file and $test_name are defined).
-test_name= # Used for reporting.
-log_file= # Where to save the result and output of the test script.
-trs_file= # Where to save the metadata of the test run.
-expect_failure=0
-color_tests=0
-merge=0
-ignore_exit=0
-comments=0
-diag_string='#'
-while test $# -gt 0; do
- case $1 in
- --help) print_usage; exit $?;;
- --version) echo "$me $scriptversion"; exit $?;;
- --test-name) test_name=$2; shift;;
- --log-file) log_file=$2; shift;;
- --trs-file) trs_file=$2; shift;;
- --color-tests) color_tests=$2; shift;;
- --expect-failure) expect_failure=$2; shift;;
- --enable-hard-errors) shift;; # No-op.
- --merge) merge=1;;
- --no-merge) merge=0;;
- --ignore-exit) ignore_exit=1;;
- --comments) comments=1;;
- --no-comments) comments=0;;
- --diagnostic-string) diag_string=$2; shift;;
- --) shift; break;;
- -*) usage_error "invalid option: '$1'";;
- esac
- shift
-done
-
-test $# -gt 0 || usage_error "missing test command"
-
-case $expect_failure in
- yes) expect_failure=1;;
- *) expect_failure=0;;
-esac
-
-if test $color_tests = yes; then
- init_colors='
- color_map["red"]="[0;31m" # Red.
- color_map["grn"]="[0;32m" # Green.
- color_map["lgn"]="[1;32m" # Light green.
- color_map["blu"]="[1;34m" # Blue.
- color_map["mgn"]="[0;35m" # Magenta.
- color_map["std"]="[m" # No color.
- color_for_result["ERROR"] = "mgn"
- color_for_result["PASS"] = "grn"
- color_for_result["XPASS"] = "red"
- color_for_result["FAIL"] = "red"
- color_for_result["XFAIL"] = "lgn"
- color_for_result["SKIP"] = "blu"'
-else
- init_colors=''
-fi
-
-# :; is there to work around a bug in bash 3.2 (and earlier) which
-# does not always set '$?' properly on redirection failure.
-# See the Autoconf manual for more details.
-:;{
- (
- # Ignore common signals (in this subshell only!), to avoid potential
- # problems with Korn shells. Some Korn shells are known to propagate
- # to themselves signals that have killed a child process they were
- # waiting for; this is done at least for SIGINT (and usually only for
- # it, in truth). Without the `trap' below, such a behaviour could
- # cause a premature exit in the current subshell, e.g., in case the
- # test command it runs gets terminated by a SIGINT. Thus, the awk
- # script we are piping into would never seen the exit status it
- # expects on its last input line (which is displayed below by the
- # last `echo $?' statement), and would thus die reporting an internal
- # error.
- # For more information, see the Autoconf manual and the threads:
- # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
- # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
- trap : 1 3 2 13 15
- if test $merge -gt 0; then
- exec 2>&1
- else
- exec 2>&3
- fi
- "$@"
- echo $?
- ) | LC_ALL=C ${AM_TAP_AWK-awk} \
- -v me="$me" \
- -v test_script_name="$test_name" \
- -v log_file="$log_file" \
- -v trs_file="$trs_file" \
- -v expect_failure="$expect_failure" \
- -v merge="$merge" \
- -v ignore_exit="$ignore_exit" \
- -v comments="$comments" \
- -v diag_string="$diag_string" \
-'
-# TODO: the usages of "cat >&3" below could be optimized when using
-# GNU awk, and/on on systems that supports /dev/fd/.
-
-# Implementation note: in what follows, `result_obj` will be an
-# associative array that (partly) simulates a TAP result object
-# from the `TAP::Parser` perl module.
-
-## ----------- ##
-## FUNCTIONS ##
-## ----------- ##
-
-function fatal(msg)
-{
- print me ": " msg | "cat >&2"
- exit 1
-}
-
-function abort(where)
-{
- fatal("internal error " where)
-}
-
-# Convert a boolean to a "yes"/"no" string.
-function yn(bool)
-{
- return bool ? "yes" : "no";
-}
-
-function add_test_result(result)
-{
- if (!test_results_index)
- test_results_index = 0
- test_results_list[test_results_index] = result
- test_results_index += 1
- test_results_seen[result] = 1;
-}
-
-# Whether the test script should be re-run by "make recheck".
-function must_recheck()
-{
- for (k in test_results_seen)
- if (k != "XFAIL" && k != "PASS" && k != "SKIP")
- return 1
- return 0
-}
-
-# Whether the content of the log file associated to this test should
-# be copied into the "global" test-suite.log.
-function copy_in_global_log()
-{
- for (k in test_results_seen)
- if (k != "PASS")
- return 1
- return 0
-}
-
-function get_global_test_result()
-{
- if ("ERROR" in test_results_seen)
- return "ERROR"
- if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
- return "FAIL"
- all_skipped = 1
- for (k in test_results_seen)
- if (k != "SKIP")
- all_skipped = 0
- if (all_skipped)
- return "SKIP"
- return "PASS";
-}
-
-function stringify_result_obj(result_obj)
-{
- if (result_obj["is_unplanned"] || result_obj["number"] != testno)
- return "ERROR"
-
- if (plan_seen == LATE_PLAN)
- return "ERROR"
-
- if (result_obj["directive"] == "TODO")
- return result_obj["is_ok"] ? "XPASS" : "XFAIL"
-
- if (result_obj["directive"] == "SKIP")
- return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
-
- if (length(result_obj["directive"]))
- abort("in function stringify_result_obj()")
-
- return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
-}
-
-function decorate_result(result)
-{
- color_name = color_for_result[result]
- if (color_name)
- return color_map[color_name] "" result "" color_map["std"]
- # If we are not using colorized output, or if we do not know how
- # to colorize the given result, we should return it unchanged.
- return result
-}
-
-function report(result, details)
-{
- if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
- {
- msg = ": " test_script_name
- add_test_result(result)
- }
- else if (result == "#")
- {
- msg = " " test_script_name ":"
- }
- else
- {
- abort("in function report()")
- }
- if (length(details))
- msg = msg " " details
- # Output on console might be colorized.
- print decorate_result(result) msg
- # Log the result in the log file too, to help debugging (this is
- # especially true when said result is a TAP error or "Bail out!").
- print result msg | "cat >&3";
-}
-
-function testsuite_error(error_message)
-{
- report("ERROR", "- " error_message)
-}
-
-function handle_tap_result()
-{
- details = result_obj["number"];
- if (length(result_obj["description"]))
- details = details " " result_obj["description"]
-
- if (plan_seen == LATE_PLAN)
- {
- details = details " # AFTER LATE PLAN";
- }
- else if (result_obj["is_unplanned"])
- {
- details = details " # UNPLANNED";
- }
- else if (result_obj["number"] != testno)
- {
- details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
- details, testno);
- }
- else if (result_obj["directive"])
- {
- details = details " # " result_obj["directive"];
- if (length(result_obj["explanation"]))
- details = details " " result_obj["explanation"]
- }
-
- report(stringify_result_obj(result_obj), details)
-}
-
-# `skip_reason` should be empty whenever planned > 0.
-function handle_tap_plan(planned, skip_reason)
-{
- planned += 0 # Avoid getting confused if, say, `planned` is "00"
- if (length(skip_reason) && planned > 0)
- abort("in function handle_tap_plan()")
- if (plan_seen)
- {
- # Error, only one plan per stream is acceptable.
- testsuite_error("multiple test plans")
- return;
- }
- planned_tests = planned
- # The TAP plan can come before or after *all* the TAP results; we speak
- # respectively of an "early" or a "late" plan. If we see the plan line
- # after at least one TAP result has been seen, assume we have a late
- # plan; in this case, any further test result seen after the plan will
- # be flagged as an error.
- plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
- # If testno > 0, we have an error ("too many tests run") that will be
- # automatically dealt with later, so do not worry about it here. If
- # $plan_seen is true, we have an error due to a repeated plan, and that
- # has already been dealt with above. Otherwise, we have a valid "plan
- # with SKIP" specification, and should report it as a particular kind
- # of SKIP result.
- if (planned == 0 && testno == 0)
- {
- if (length(skip_reason))
- skip_reason = "- " skip_reason;
- report("SKIP", skip_reason);
- }
-}
-
-function extract_tap_comment(line)
-{
- if (index(line, diag_string) == 1)
- {
- # Strip leading `diag_string` from `line`.
- line = substr(line, length(diag_string) + 1)
- # And strip any leading and trailing whitespace left.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
- # Return what is left (if any).
- return line;
- }
- return "";
-}
-
-# When this function is called, we know that line is a TAP result line,
-# so that it matches the (perl) RE "^(not )?ok\b".
-function setup_result_obj(line)
-{
- # Get the result, and remove it from the line.
- result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
- sub("^(not )?ok[ \t]*", "", line)
-
- # If the result has an explicit number, get it and strip it; otherwise,
- # automatically assing the next progresive number to it.
- if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
- {
- match(line, "^[0-9]+")
- # The final `+ 0` is to normalize numbers with leading zeros.
- result_obj["number"] = substr(line, 1, RLENGTH) + 0
- line = substr(line, RLENGTH + 1)
- }
- else
- {
- result_obj["number"] = testno
- }
-
- if (plan_seen == LATE_PLAN)
- # No further test results are acceptable after a "late" TAP plan
- # has been seen.
- result_obj["is_unplanned"] = 1
- else if (plan_seen && testno > planned_tests)
- result_obj["is_unplanned"] = 1
- else
- result_obj["is_unplanned"] = 0
-
- # Strip trailing and leading whitespace.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
-
- # This will have to be corrected if we have a "TODO"/"SKIP" directive.
- result_obj["description"] = line
- result_obj["directive"] = ""
- result_obj["explanation"] = ""
-
- if (index(line, "#") == 0)
- return # No possible directive, nothing more to do.
-
- # Directives are case-insensitive.
- rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
-
- # See whether we have the directive, and if yes, where.
- pos = match(line, rx "$")
- if (!pos)
- pos = match(line, rx "[^a-zA-Z0-9_]")
-
- # If there was no TAP directive, we have nothing more to do.
- if (!pos)
- return
-
- # Let`s now see if the TAP directive has been escaped. For example:
- # escaped: ok \# SKIP
- # not escaped: ok \\# SKIP
- # escaped: ok \\\\\# SKIP
- # not escaped: ok \ # SKIP
- if (substr(line, pos, 1) == "#")
- {
- bslash_count = 0
- for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
- bslash_count += 1
- if (bslash_count % 2)
- return # Directive was escaped.
- }
-
- # Strip the directive and its explanation (if any) from the test
- # description.
- result_obj["description"] = substr(line, 1, pos - 1)
- # Now remove the test description from the line, that has been dealt
- # with already.
- line = substr(line, pos)
- # Strip the directive, and save its value (normalized to upper case).
- sub("^[ \t]*#[ \t]*", "", line)
- result_obj["directive"] = toupper(substr(line, 1, 4))
- line = substr(line, 5)
- # Now get the explanation for the directive (if any), with leading
- # and trailing whitespace removed.
- sub("^[ \t]*", "", line)
- sub("[ \t]*$", "", line)
- result_obj["explanation"] = line
-}
-
-function get_test_exit_message(status)
-{
- if (status == 0)
- return ""
- if (status !~ /^[1-9][0-9]*$/)
- abort("getting exit status")
- if (status < 127)
- exit_details = ""
- else if (status == 127)
- exit_details = " (command not found?)"
- else if (status >= 128 && status <= 255)
- exit_details = sprintf(" (terminated by signal %d?)", status - 128)
- else if (status > 256 && status <= 384)
- # We used to report an "abnormal termination" here, but some Korn
- # shells, when a child process die due to signal number n, can leave
- # in $? an exit status of 256+n instead of the more standard 128+n.
- # Apparently, both behaviours are allowed by POSIX (2008), so be
- # prepared to handle them both. See also Austing Group report ID
- # 0000051 <http://www.austingroupbugs.net/view.php?id=51>
- exit_details = sprintf(" (terminated by signal %d?)", status - 256)
- else
- # Never seen in practice.
- exit_details = " (abnormal termination)"
- return sprintf("exited with status %d%s", status, exit_details)
-}
-
-function write_test_results()
-{
- print ":global-test-result: " get_global_test_result() > trs_file
- print ":recheck: " yn(must_recheck()) > trs_file
- print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
- for (i = 0; i < test_results_index; i += 1)
- print ":test-result: " test_results_list[i] > trs_file
- close(trs_file);
-}
-
-BEGIN {
-
-## ------- ##
-## SETUP ##
-## ------- ##
-
-'"$init_colors"'
-
-# Properly initialized once the TAP plan is seen.
-planned_tests = 0
-
-COOKED_PASS = expect_failure ? "XPASS": "PASS";
-COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
-
-# Enumeration-like constants to remember which kind of plan (if any)
-# has been seen. It is important that NO_PLAN evaluates "false" as
-# a boolean.
-NO_PLAN = 0
-EARLY_PLAN = 1
-LATE_PLAN = 2
-
-testno = 0 # Number of test results seen so far.
-bailed_out = 0 # Whether a "Bail out!" directive has been seen.
-
-# Whether the TAP plan has been seen or not, and if yes, which kind
-# it is ("early" is seen before any test result, "late" otherwise).
-plan_seen = NO_PLAN
-
-## --------- ##
-## PARSING ##
-## --------- ##
-
-is_first_read = 1
-
-while (1)
- {
- # Involutions required so that we are able to read the exit status
- # from the last input line.
- st = getline
- if (st < 0) # I/O error.
- fatal("I/O error while reading from input stream")
- else if (st == 0) # End-of-input
- {
- if (is_first_read)
- abort("in input loop: only one input line")
- break
- }
- if (is_first_read)
- {
- is_first_read = 0
- nextline = $0
- continue
- }
- else
- {
- curline = nextline
- nextline = $0
- $0 = curline
- }
- # Copy any input line verbatim into the log file.
- print | "cat >&3"
- # Parsing of TAP input should stop after a "Bail out!" directive.
- if (bailed_out)
- continue
-
- # TAP test result.
- if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
- {
- testno += 1
- setup_result_obj($0)
- handle_tap_result()
- }
- # TAP plan (normal or "SKIP" without explanation).
- else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
- {
- # The next two lines will put the number of planned tests in $0.
- sub("^1\\.\\.", "")
- sub("[^0-9]*$", "")
- handle_tap_plan($0, "")
- continue
- }
- # TAP "SKIP" plan, with an explanation.
- else if ($0 ~ /^1\.\.0+[ \t]*#/)
- {
- # The next lines will put the skip explanation in $0, stripping
- # any leading and trailing whitespace. This is a little more
- # tricky in truth, since we want to also strip a potential leading
- # "SKIP" string from the message.
- sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
- sub("[ \t]*$", "");
- handle_tap_plan(0, $0)
- }
- # "Bail out!" magic.
- # Older versions of prove and TAP::Harness (e.g., 3.17) did not
- # recognize a "Bail out!" directive when preceded by leading
- # whitespace, but more modern versions (e.g., 3.23) do. So we
- # emulate the latter, "more modern" behaviour.
- else if ($0 ~ /^[ \t]*Bail out!/)
- {
- bailed_out = 1
- # Get the bailout message (if any), with leading and trailing
- # whitespace stripped. The message remains stored in `$0`.
- sub("^[ \t]*Bail out![ \t]*", "");
- sub("[ \t]*$", "");
- # Format the error message for the
- bailout_message = "Bail out!"
- if (length($0))
- bailout_message = bailout_message " " $0
- testsuite_error(bailout_message)
- }
- # Maybe we have too look for dianogtic comments too.
- else if (comments != 0)
- {
- comment = extract_tap_comment($0);
- if (length(comment))
- report("#", comment);
- }
- }
-
-## -------- ##
-## FINISH ##
-## -------- ##
-
-# A "Bail out!" directive should cause us to ignore any following TAP
-# error, as well as a non-zero exit status from the TAP producer.
-if (!bailed_out)
- {
- if (!plan_seen)
- {
- testsuite_error("missing test plan")
- }
- else if (planned_tests != testno)
- {
- bad_amount = testno > planned_tests ? "many" : "few"
- testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
- bad_amount, planned_tests, testno))
- }
- if (!ignore_exit)
- {
- # Fetch exit status from the last line.
- exit_message = get_test_exit_message(nextline)
- if (exit_message)
- testsuite_error(exit_message)
- }
- }
-
-write_test_results()
-
-exit 0
-
-} # End of "BEGIN" block.
-'
-
-# TODO: document that we consume the file descriptor 3 :-(
-} 3>"$log_file"
-
-test $? -eq 0 || fatal "I/O or internal error"
-
-# Local Variables:
-# mode: shell-script
-# sh-indentation: 2
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-time-zone: "UTC"
-# time-stamp-end: "; # UTC"
-# End:
diff --git a/bus/Android.bp b/bus/Android.bp
new file mode 100644
index 0000000..7ab773b
--- /dev/null
+++ b/bus/Android.bp
@@ -0,0 +1,41 @@
+cc_binary {
+ name: "dbus-daemon",
+
+ cflags: [
+ "-O3",
+ "-DDBUS_COMPILATION",
+ "-DDBUS_DAEMON_NAME=\\\"dbus-daemon\\\"",
+ "-DDBUS_SYSTEM_CONFIG_FILE=\\\"/system/etc/dbus.conf\\\"",
+ "-DDBUS_SESSION_CONFIG_FILE=\\\"/system/etc/session.conf\\\"",
+ "-Wno-address",
+ "-Wno-empty-body",
+ "-Wno-pointer-sign",
+ "-Wno-sign-compare",
+ "-Wno-unused-parameter",
+ ],
+
+ srcs: [
+ "activation.c",
+ "bus.c",
+ "config-loader-expat.c",
+ "config-parser.c",
+ "config-parser-common.c",
+ "connection.c",
+ "desktop-file.c",
+ "dir-watch-default.c",
+ "dispatch.c",
+ "driver.c",
+ "expirelist.c",
+ "main.c",
+ "policy.c",
+ "selinux.c",
+ "services.c",
+ "signals.c",
+ "utils.c",
+ ],
+
+ shared_libs: [
+ "libexpat",
+ "libdbus",
+ ],
+}
diff --git a/bus/Android.mk b/bus/Android.mk
deleted file mode 100644
index 248746a..0000000
--- a/bus/Android.mk
+++ /dev/null
@@ -1,55 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_C_INCLUDES:= $(LOCAL_PATH)/..
-
-LOCAL_CFLAGS:= \
- -O3 \
- -DDBUS_ANDROID_LOG \
- -DDBUS_COMPILATION \
- -DDBUS_DAEMON_NAME=\"dbus-daemon\" \
- -DDBUS_SYSTEM_CONFIG_FILE=\"/etc/dbus-1/system.conf\" \
- -DDBUS_SESSION_CONFIG_FILE=\"/etc/dbus-1/session.conf\" \
- -Wno-address \
- -Wno-empty-body \
- -Wno-pointer-sign \
- -Wno-sign-compare \
- -Wno-unused-parameter
-
-LOCAL_SRC_FILES:= \
- activation.c \
- activation-helper.c \
- apparmor.c \
- audit.c \
- bus.c \
- config-loader-expat.c \
- config-parser.c \
- config-parser-common.c \
- connection.c \
- desktop-file.c \
- dir-watch-inotify.c \
- dispatch.c \
- driver.c \
- expirelist.c \
- main.c \
- policy.c \
- selinux.c \
- services.c \
- signals.c \
- stats.c \
- utils.c
-
-ifeq ($(BUILD_EUREKA),true)
-LOCAL_C_INCLUDES += external/expat/lib
-LOCAL_STATIC_LIBRARIES := libexpat_static
-LOCAL_SHARED_LIBRARIES := \
- libdbus
-else
-LOCAL_SHARED_LIBRARIES := \
- libexpat \
- libdbus
-endif
-
-LOCAL_MODULE:=dbus-daemon
-
-include $(BUILD_EXECUTABLE)
diff --git a/bus/Makefile.am b/bus/Makefile.am
index 33af09b..6cbc09a 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -1,11 +1,9 @@
-dbusdatadir=$(datadir)/dbus-1
-legacydbusdatadir=$(sysconfdir)/dbus-1
+configdir=$(sysconfdir)/dbus-1
dbus_daemon_execdir = $(DBUS_DAEMONDIR)
DBUS_BUS_LIBS = \
$(XML_LIBS) \
$(SELINUX_LIBS) \
- $(APPARMOR_LIBS) \
$(THREAD_LIBS) \
$(ADT_LIBS) \
$(NETWORK_libs) \
@@ -19,11 +17,10 @@
AM_CPPFLAGS = \
-I$(top_srcdir) \
- $(DBUS_STATIC_BUILD_CPPFLAGS) \
$(XML_CFLAGS) \
- $(APPARMOR_CFLAGS) \
- -DDBUS_SYSTEM_CONFIG_FILE=\""$(dbusdatadir)/system.conf"\" \
+ -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\" \
-DDBUS_COMPILATION \
+ -DDBUS_STATIC_BUILD \
$(NULL)
# if assertions are enabled, improve backtraces
@@ -34,33 +31,23 @@
CONFIG_IN_FILES= \
session.conf.in \
system.conf.in \
- legacy-config/session.conf.in \
- legacy-config/system.conf.in \
- org.freedesktop.dbus-session.plist.in \
- example-system-enable-stats.conf.in \
- example-session-disable-stats.conf.in \
- $(NULL)
+ org.freedesktop.dbus-session.plist.in
-dbusdata_DATA = session.conf
-legacydbusdata_DATA = legacy-config/session.conf
-
-if DBUS_UNIX
-dbusdata_DATA += system.conf
-legacydbusdata_DATA += legacy-config/system.conf
-endif
-
-examplesdir = ${docdir}/examples
-examples_DATA = \
- example-system-enable-stats.conf \
- example-session-disable-stats.conf \
- $(NULL)
+config_DATA= \
+ session.conf \
+ system.conf
if DBUS_ENABLE_LAUNCHD
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
@@ -68,18 +55,18 @@
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 \
activation.h \
activation-exit-codes.h \
- apparmor.c \
- apparmor.h \
- audit.c \
- audit.h \
bus.c \
bus.h \
config-parser.c \
@@ -119,7 +106,6 @@
main.c
dbus_daemon_LDADD= \
- $(top_builddir)/dbus/libdbus-1.la \
$(top_builddir)/dbus/libdbus-internal.la \
$(EFENCE) \
$(DBUS_BUS_LIBS)
@@ -144,8 +130,7 @@
$(LAUNCH_HELPER_SOURCES)
dbus_daemon_launch_helper_LDADD= \
- $(top_builddir)/dbus/libdbus-1.la \
- $(top_builddir)/dbus/libdbus-internal.la \
+ $(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
## we build another binary so we can do the launch testing without root privs.
@@ -155,7 +140,6 @@
$(LAUNCH_HELPER_SOURCES)
dbus_daemon_launch_helper_test_LDADD= \
- $(top_builddir)/dbus/libdbus-1.la \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
@@ -165,17 +149,15 @@
## we build yet another binary so we can do the OOM tests
## DO NOT INSTALL THIS FILE
-test_bus_launch_helper_SOURCES= \
+bus_test_launch_helper_SOURCES= \
test-launch-helper.c \
$(LAUNCH_HELPER_SOURCES)
-test_bus_launch_helper_LDADD= \
- $(top_builddir)/dbus/libdbus-1.la \
+bus_test_launch_helper_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
- $(NULL)
-test_bus_launch_helper_CPPFLAGS = \
+bus_test_launch_helper_CPPFLAGS = \
$(AM_CPPFLAGS) \
-DACTIVATION_LAUNCHER_TEST \
-DACTIVATION_LAUNCHER_DO_OOM
@@ -191,23 +173,23 @@
## compiled, so we don't put them in TESTS here; we run them in test/
## instead.
-if DBUS_ENABLE_EMBEDDED_TESTS
+if DBUS_BUILD_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 += test-bus
+noinst_PROGRAMS += bus-test bus-test-system
if DBUS_UNIX
# run as a test by test/Makefile.am
-noinst_PROGRAMS += test-bus-launch-helper test-bus-system
+noinst_PROGRAMS += bus-test-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_ENABLE_EMBEDDED_TESTS
+endif DBUS_BUILD_TESTS
-test_bus_system_SOURCES= \
+bus_test_system_SOURCES= \
$(XML_SOURCES) \
config-parser-common.c \
config-parser-common.h \
@@ -217,34 +199,24 @@
utils.h \
test-system.c
-test_bus_system_LDADD = \
- $(top_builddir)/dbus/libdbus-1.la \
- $(top_builddir)/dbus/libdbus-internal.la \
- $(DBUS_BUS_LIBS) \
- $(NULL)
+bus_test_system_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
-test_bus_SOURCES= \
+bus_test_SOURCES= \
$(BUS_SOURCES) \
test-main.c
-test_bus_LDADD = \
- $(top_builddir)/dbus/libdbus-1.la \
- $(top_builddir)/dbus/libdbus-internal.la \
- $(DBUS_BUS_LIBS) \
- $(NULL)
+bus_test_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
## mop up the gcov files
clean-local:
/bin/rm *.bb *.bbg *.da *.gcov || true
install-data-hook:
- $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/session.d
- $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/services
-if DBUS_UNIX
$(mkinstalldirs) $(DESTDIR)$(localstatedir)/run/dbus
- $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system.d
- $(mkinstalldirs) $(DESTDIR)$(dbusdatadir)/system-services
-endif
+ $(mkinstalldirs) $(DESTDIR)$(configdir)/system.d
+ $(mkinstalldirs) $(DESTDIR)$(configdir)/session.d
+ $(mkinstalldirs) $(DESTDIR)$(datadir)/dbus-1/services
+ $(mkinstalldirs) $(DESTDIR)$(datadir)/dbus-1/system-services
if HAVE_SYSTEMD
# Install dbus.socket as default implementation of a D-Bus stack.
# Deliberately not using $(LN_S) here: ln -fs is not universally portable,
@@ -257,10 +229,6 @@
$(mkinstalldirs) $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants
ln -fs ../dbus.service $(DESTDIR)$(systemdsystemunitdir)/multi-user.target.wants/dbus.service
endif
-if DBUS_ENABLE_USER_SESSION
- $(mkinstalldirs) $(DESTDIR)$(systemduserunitdir)/sockets.target.wants
- ln -fs ../dbus.socket $(DESTDIR)$(systemduserunitdir)/sockets.target.wants/dbus.socket
-endif
if DBUS_UNIX
install-exec-hook:
@@ -312,23 +280,13 @@
if HAVE_SYSTEMD
SCRIPT_IN_FILES += \
dbus.service.in \
- dbus.socket.in \
- systemd-user/dbus.service.in \
- systemd-user/dbus.socket.in \
- $(NULL)
+ dbus.socket.in
systemdsystemunit_DATA = \
dbus.service \
dbus.socket
endif
-if DBUS_ENABLE_USER_SESSION
-systemduserunit_DATA = \
- systemd-user/dbus.service \
- systemd-user/dbus.socket \
- $(NULL)
-endif
-
#### Extra dist
EXTRA_DIST=$(CONFIG_IN_FILES) $(SCRIPT_IN_FILES)
diff --git a/bus/activation-helper-bin.c b/bus/activation-helper-bin.c
index f5f16d2..a360acc 100644
--- a/bus/activation-helper-bin.c
+++ b/bus/activation-helper-bin.c
@@ -45,9 +45,6 @@
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))
@@ -68,7 +65,7 @@
/* should we assert? */
fprintf(stderr, "%s: %s\n", error->name, error->message);
- return BUS_SPAWN_EXIT_CODE_GENERIC_FAILURE;
+ return BUS_SPAWN_EXIT_CODE_SETUP_FAILED;
}
int
diff --git a/bus/activation-helper.c b/bus/activation-helper.c
index 394f393..cbc00d2 100644
--- a/bus/activation-helper.c
+++ b/bus/activation-helper.c
@@ -40,7 +40,6 @@
#include <pwd.h>
#include <grp.h>
-#include <dbus/dbus-misc.h>
#include <dbus/dbus-shell.h>
#include <dbus/dbus-marshal-validate.h>
@@ -155,11 +154,11 @@
"could not clear environment\n");
return FALSE;
}
+#endif
/* 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
+ _dbus_setenv ("DBUS_STARTER_ADDRESS", DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
+ _dbus_setenv ("DBUS_STARTER_BUS_TYPE", "system");
return TRUE;
}
@@ -372,7 +371,7 @@
_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_INVALID,
+ dbus_set_error (error, DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND,
"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 1211329..3dfba78 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -80,14 +80,7 @@
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;
@@ -637,7 +630,7 @@
if (!_dbus_string_ends_with_c_str (&filename, ".service"))
{
- _dbus_verbose ("Skipping non-.service file '%s'\n",
+ _dbus_verbose ("Skipping non-.service file %s\n",
_dbus_string_get_const_data (&filename));
continue;
}
@@ -1044,7 +1037,7 @@
}
static void
-free_restore_pending_data (void *data)
+free_pending_restore_data (void *data)
{
RestorePendingData *d = data;
@@ -1074,9 +1067,9 @@
if (d->hash_entry == NULL ||
!bus_transaction_add_cancel_hook (transaction, restore_pending, d,
- free_restore_pending_data))
+ free_pending_restore_data))
{
- free_restore_pending_data (d);
+ free_pending_restore_data (d);
return FALSE;
}
@@ -1113,8 +1106,7 @@
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- /* entry->connection is NULL for activating systemd */
- if (entry->connection && dbus_connection_get_is_connected (entry->connection))
+ if (dbus_connection_get_is_connected (entry->connection))
{
/* Only send activation replies to regular activation requests. */
if (!entry->auto_activation)
@@ -1162,11 +1154,14 @@
dbus_bool_t
bus_activation_send_pending_auto_activation_messages (BusActivation *activation,
BusService *service,
- BusTransaction *transaction)
+ BusTransaction *transaction,
+ DBusError *error)
{
BusPendingActivation *pending_activation;
DBusList *link;
+ _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
/* Check if it's a pending activation */
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations,
bus_service_get_name (service));
@@ -1180,12 +1175,9 @@
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- if (entry->auto_activation && (entry->connection == NULL || dbus_connection_get_is_connected (entry->connection)))
+ if (entry->auto_activation && dbus_connection_get_is_connected (entry->connection))
{
DBusConnection *addressed_recipient;
- DBusError error;
-
- dbus_error_init (&error);
addressed_recipient = bus_service_get_primary_owners_connection (service);
@@ -1193,22 +1185,8 @@
if (!bus_dispatch_matches (transaction,
entry->connection,
addressed_recipient,
- entry->activation_message, &error))
- {
- /* If permission is denied, we just want to return the error
- * to the original method invoker; in particular, we don't
- * want to make the RequestName call fail with that error
- * (see fd.o #78979, CVE-2014-3477). */
- if (!bus_transaction_send_error_reply (transaction, entry->connection,
- &error, entry->activation_message))
- {
- bus_connection_send_oom_error (entry->connection,
- entry->activation_message);
- }
-
- link = next;
- continue;
- }
+ entry->activation_message, error))
+ goto error;
}
link = next;
@@ -1217,6 +1195,7 @@
if (!add_restore_pending_to_transaction (transaction, pending_activation))
{
_dbus_verbose ("Could not add cancel hook to transaction to revert removing pending activation\n");
+ BUS_SET_OOM (error);
goto error;
}
@@ -1254,7 +1233,7 @@
BusPendingActivationEntry *entry = link->data;
DBusList *next = _dbus_list_get_next_link (&pending_activation->entries, link);
- if (entry->connection && dbus_connection_get_is_connected (entry->connection))
+ if (dbus_connection_get_is_connected (entry->connection))
{
if (!bus_transaction_send_error_reply (transaction,
entry->connection,
@@ -1302,10 +1281,6 @@
{
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)");
@@ -1342,7 +1317,6 @@
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);
@@ -1418,8 +1392,7 @@
{
BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
- if (p != pending_activation && p->exec != NULL &&
- strcmp (p->exec, pending_activation->exec) == 0)
+ if (p != pending_activation && strcmp (p->exec, pending_activation->exec) == 0)
pending_activation_failed (p, &error);
}
@@ -1479,8 +1452,11 @@
dbus_error_init (&error);
- bus_context_log_and_set_error (pending_activation->activation->context,
- DBUS_SYSTEM_LOG_INFO, &error, DBUS_ERROR_TIMED_OUT,
+ dbus_set_error (&error, DBUS_ERROR_TIMED_OUT,
+ "Activation of %s timed out",
+ pending_activation->service_name);
+ bus_context_log (pending_activation->activation->context,
+ DBUS_SYSTEM_LOG_INFO,
"Failed to activate service '%s': timed out",
pending_activation->service_name);
@@ -1686,31 +1662,6 @@
return retval;
}
-static void
-child_setup (void *user_data)
-{
-#ifdef DBUS_UNIX
- BusActivation *activation = user_data;
- DBusRLimit *initial_fd_limit;
- DBusError error;
-
- dbus_error_init (&error);
- initial_fd_limit = bus_context_get_initial_fd_limit (activation->context);
-
- if (initial_fd_limit != NULL &&
- !_dbus_rlimit_restore_fd_limit (initial_fd_limit, &error))
- {
- /* unfortunately we don't actually know the service name here */
- bus_context_log (activation->context,
- DBUS_SYSTEM_LOG_WARNING,
- "Failed to reset fd limit before activating "
- "service: %s: %s",
- error.name, error.message);
- }
-#endif
-}
-
-
dbus_bool_t
bus_activation_activate_service (BusActivation *activation,
DBusConnection *connection,
@@ -1745,19 +1696,9 @@
return FALSE;
}
- if (bus_context_get_systemd_activation (activation->context) &&
- strcmp (service_name, "org.freedesktop.systemd1") == 0)
- {
- /* if we're doing systemd activation, we assume systemd will connect
- * eventually, and it does not need a .service file */
- entry = NULL;
- }
- else
- {
- entry = activation_find_entry (activation, service_name, error);
- if (!entry)
- return FALSE;
- }
+ entry = activation_find_entry (activation, service_name, error);
+ if (!entry)
+ return FALSE;
/* Bypass the registry lookup if we're auto-activating, bus_dispatch would not
* call us if the service is already active.
@@ -1818,8 +1759,7 @@
pending_activation_entry->activation_message = activation_message;
dbus_message_ref (activation_message);
pending_activation_entry->connection = connection;
- if (connection)
- dbus_connection_ref (connection);
+ dbus_connection_ref (connection);
/* Check if the service is being activated */
pending_activation = _dbus_hash_table_lookup_string (activation->pending_activations, service_name);
@@ -1864,20 +1804,17 @@
return FALSE;
}
- if (entry != NULL)
+ pending_activation->exec = _dbus_strdup (entry->exec);
+ if (!pending_activation->exec)
{
- pending_activation->exec = _dbus_strdup (entry->exec);
- if (!pending_activation->exec)
- {
- _dbus_verbose ("Failed to copy service exec for pending activation\n");
- BUS_SET_OOM (error);
- bus_pending_activation_unref (pending_activation);
- bus_pending_activation_entry_free (pending_activation_entry);
- return FALSE;
- }
+ _dbus_verbose ("Failed to copy service exec for pending activation\n");
+ BUS_SET_OOM (error);
+ bus_pending_activation_unref (pending_activation);
+ bus_pending_activation_entry_free (pending_activation_entry);
+ return FALSE;
}
- if (entry != NULL && entry->systemd_service != NULL)
+ if (entry->systemd_service)
{
pending_activation->systemd_service = _dbus_strdup (entry->systemd_service);
if (!pending_activation->systemd_service)
@@ -1947,7 +1884,10 @@
{
_dbus_verbose ("Failed to add pending activation cancel hook to transaction\n");
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ _dbus_hash_table_remove_string (activation->pending_activations,
+ pending_activation->service_name);
+
+ return FALSE;
}
if (was_pending_activation)
@@ -1985,7 +1925,7 @@
{
_dbus_verbose ("No memory to create activation message\n");
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS) ||
@@ -1997,7 +1937,7 @@
_dbus_verbose ("No memory to set args of activation message\n");
dbus_message_unref (message);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
/* Create our transaction */
@@ -2007,7 +1947,7 @@
_dbus_verbose ("No memory to create activation transaction\n");
dbus_message_unref (message);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
/* Check whether systemd is already connected */
@@ -2015,17 +1955,6 @@
_dbus_string_init_const (&service_string, "org.freedesktop.systemd1");
service = bus_registry_lookup (registry, &service_string);
- /* Following the general principle of "log early and often",
- * we capture that we *want* to send the activation message, even if
- * systemd is not actually there to receive it yet */
- if (!bus_transaction_capture (activation_transaction,
- NULL, message))
- {
- dbus_message_unref (message);
- BUS_SET_OOM (error);
- goto cancel_pending_activation;
- }
-
if (service != NULL)
{
bus_context_log (activation->context,
@@ -2043,7 +1972,7 @@
service_name,
entry->systemd_service);
/* systemd is not around, let's "activate" it. */
- retval = bus_activation_activate_service (activation, NULL, activation_transaction, TRUE,
+ retval = bus_activation_activate_service (activation, connection, activation_transaction, TRUE,
message, "org.freedesktop.systemd1", error);
}
@@ -2058,7 +1987,7 @@
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_verbose ("failed to send activation message: %s\n", error->name);
bus_transaction_cancel_and_free (activation_transaction);
- goto cancel_pending_activation;
+ return FALSE;
}
bus_transaction_execute_and_free (activation_transaction);
@@ -2069,16 +1998,11 @@
proceed with traditional activation. */
}
- /* If entry was NULL, it would be because we were doing systemd activation
- * and activating systemd itself; but we already handled that case with
- * an early-return */
- _dbus_assert (entry != NULL);
-
/* use command as system and session different */
if (!_dbus_string_init (&command))
{
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
/* does the bus use a helper? */
@@ -2090,7 +2014,7 @@
_dbus_string_free (&command);
dbus_set_error (error, DBUS_ERROR_SPAWN_FILE_INVALID,
"Cannot do system-bus activation with no user\n");
- goto cancel_pending_activation;
+ return FALSE;
}
/* join the helper path and the service name */
@@ -2098,19 +2022,19 @@
{
_dbus_string_free (&command);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
if (!_dbus_string_append (&command, " "))
{
_dbus_string_free (&command);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
if (!_dbus_string_append (&command, service_name))
{
_dbus_string_free (&command);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
}
else
@@ -2120,7 +2044,7 @@
{
_dbus_string_free (&command);
BUS_SET_OOM (error);
- goto cancel_pending_activation;
+ return FALSE;
}
}
@@ -2129,8 +2053,12 @@
{
_dbus_verbose ("Failed to parse command line: %s\n", entry->exec);
_DBUS_ASSERT_ERROR_IS_SET (error);
+
+ _dbus_hash_table_remove_string (activation->pending_activations,
+ pending_activation->service_name);
+
_dbus_string_free (&command);
- goto cancel_pending_activation;
+ return FALSE;
}
_dbus_string_free (&command);
@@ -2138,7 +2066,7 @@
{
_DBUS_ASSERT_ERROR_IS_SET (error);
dbus_free_string_array (argv);
- goto cancel_pending_activation;
+ return FALSE;
}
envp = bus_activation_get_environment (activation);
@@ -2147,7 +2075,7 @@
{
BUS_SET_OOM (error);
dbus_free_string_array (argv);
- goto cancel_pending_activation;
+ return FALSE;
}
_dbus_verbose ("Spawning %s ...\n", argv[0]);
@@ -2162,12 +2090,9 @@
dbus_error_init (&tmp_error);
- if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter,
- service_name,
- argv,
+ if (!_dbus_spawn_async_with_babysitter (&pending_activation->babysitter, argv,
envp,
- child_setup,
- activation,
+ NULL, activation,
&tmp_error))
{
_dbus_verbose ("Failed to spawn child\n");
@@ -2179,7 +2104,8 @@
dbus_move_error (&tmp_error, error);
dbus_free_string_array (argv);
dbus_free_string_array (envp);
- goto cancel_pending_activation;
+
+ return FALSE;
}
dbus_free_string_array (argv);
@@ -2200,16 +2126,10 @@
{
BUS_SET_OOM (error);
_dbus_verbose ("Failed to set babysitter watch functions\n");
- goto cancel_pending_activation;
+ return FALSE;
}
return TRUE;
-
-cancel_pending_activation:
- _DBUS_ASSERT_ERROR_IS_SET (error);
- _dbus_hash_table_remove_string (activation->pending_activations,
- pending_activation->service_name);
- return FALSE;
}
dbus_bool_t
@@ -2250,7 +2170,7 @@
error:
for (j = 0; j < i; j++)
- dbus_free (retval[j]);
+ dbus_free (retval[i]);
dbus_free (retval);
return FALSE;
@@ -2274,7 +2194,7 @@
DBUS_TYPE_STRING, &code,
DBUS_TYPE_STRING, &str,
DBUS_TYPE_INVALID))
- dbus_set_error (&error, code, "%s", str);
+ dbus_set_error(&error, code, str);
if (unit)
@@ -2303,7 +2223,7 @@
return TRUE;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
@@ -2414,7 +2334,6 @@
if (!test_remove_service_file (dir, _dbus_string_get_const_data (&filename)))
{
ret_val = FALSE;
- _dbus_directory_close (iter);
goto out;
}
}
@@ -2611,23 +2530,18 @@
bus_activation_service_reload_test (const DBusString *test_data_dir)
{
DBusString directory;
- const char *tmp;
- dbus_bool_t ret = FALSE;
if (!_dbus_string_init (&directory))
return FALSE;
- tmp = _dbus_get_tmpdir ();
-
- if (tmp == NULL)
- goto out;
-
- if (!_dbus_string_append (&directory, tmp))
- goto out;
+ if (!_dbus_string_append (&directory, _dbus_get_tmpdir()))
+ return FALSE;
if (!_dbus_string_append (&directory, "/dbus-reload-test-") ||
- !_dbus_generate_random_ascii (&directory, 6, NULL))
- goto out;
+ !_dbus_generate_random_ascii (&directory, 6))
+ {
+ return FALSE;
+ }
/* Do normal tests */
if (!init_service_reload_test (&directory))
@@ -2649,13 +2563,11 @@
/* Cleanup test directory */
if (!cleanup_service_reload_test (&directory))
- goto out;
+ return FALSE;
- ret = TRUE;
-
-out:
_dbus_string_free (&directory);
- return ret;
+
+ return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/activation.h b/bus/activation.h
index fc5d426..97f25b1 100644
--- a/bus/activation.h
+++ b/bus/activation.h
@@ -62,7 +62,8 @@
dbus_bool_t bus_activation_send_pending_auto_activation_messages (BusActivation *activation,
BusService *service,
- BusTransaction *transaction);
+ BusTransaction *transaction,
+ DBusError *error);
#endif /* BUS_ACTIVATION_H */
diff --git a/bus/apparmor.c b/bus/apparmor.c
deleted file mode 100644
index 3ba84d8..0000000
--- a/bus/apparmor.c
+++ /dev/null
@@ -1,1101 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- * apparmor.c AppArmor security checks for D-Bus
- *
- * Based on selinux.c
- *
- * Copyright © 2014-2015 Canonical, 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 "apparmor.h"
-
-#ifdef HAVE_APPARMOR
-
-#include <dbus/dbus-internals.h>
-#include <dbus/dbus-string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/apparmor.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#ifdef HAVE_LIBAUDIT
-#include <libaudit.h>
-#endif /* HAVE_LIBAUDIT */
-
-#include "audit.h"
-#include "connection.h"
-#include "utils.h"
-
-/* Store the value telling us if AppArmor D-Bus mediation is enabled. */
-static dbus_bool_t apparmor_enabled = FALSE;
-
-typedef enum {
- APPARMOR_DISABLED,
- APPARMOR_ENABLED,
- APPARMOR_REQUIRED
-} AppArmorConfigMode;
-
-/* Store the value of the AppArmor mediation mode in the bus configuration */
-static AppArmorConfigMode apparmor_config_mode = APPARMOR_ENABLED;
-
-/* The AppArmor context, consisting of a label and a mode. */
-struct BusAppArmorConfinement
-{
- int refcount; /* Reference count */
-
- char *label; /* AppArmor confinement label */
- const char *mode; /* AppArmor confinement mode (freed by freeing *label) */
-};
-
-static BusAppArmorConfinement *bus_con = NULL;
-
-/**
- * Callers of this function give up ownership of the *label and *mode
- * pointers.
- *
- * Additionally, the responsibility of freeing *label and *mode becomes the
- * responsibility of the bus_apparmor_confinement_unref() function. However, it
- * does not free *mode because libapparmor's aa_getcon(), and libapparmor's
- * other related functions, allocate a single buffer for *label and *mode and
- * then separate the two char arrays with a NUL char. See the aa_getcon(2) man
- * page for more details.
- */
-static BusAppArmorConfinement*
-bus_apparmor_confinement_new (char *label,
- const char *mode)
-{
- BusAppArmorConfinement *confinement;
-
- confinement = dbus_new0 (BusAppArmorConfinement, 1);
- if (confinement != NULL)
- {
- confinement->refcount = 1;
- confinement->label = label;
- confinement->mode = mode;
- }
-
- return confinement;
-}
-
-/*
- * Return TRUE on successful check, FALSE on OOM.
- * Set *is_supported to whether AA has D-Bus features.
- */
-static dbus_bool_t
-_bus_apparmor_detect_aa_dbus_support (dbus_bool_t *is_supported)
-{
- int mask_file;
- DBusString aa_dbus;
- char *aa_securityfs = NULL;
- dbus_bool_t retval = FALSE;
-
- *is_supported = FALSE;
-
- if (!_dbus_string_init (&aa_dbus))
- return FALSE;
-
- if (aa_find_mountpoint (&aa_securityfs) != 0)
- goto out;
-
- /*
- * John Johansen has confirmed that the mainline kernel will not have
- * the apparmorfs/features/dbus/mask file until the mainline kernel
- * has AppArmor getpeersec support.
- */
- if (!_dbus_string_append (&aa_dbus, aa_securityfs) ||
- !_dbus_string_append (&aa_dbus, "/features/dbus/mask"))
- goto out;
-
- /* We need to open() the flag file, not just stat() it, because AppArmor
- * does not mediate stat() in the apparmorfs. If you have a
- * dbus-daemon inside an LXC container, with insufficiently broad
- * AppArmor privileges to do its own AppArmor mediation, the desired
- * result is that it behaves as if AppArmor was not present; but a stat()
- * here would succeed, and result in it trying and failing to do full
- * mediation. https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/1238267 */
- mask_file = open (_dbus_string_get_const_data (&aa_dbus),
- O_RDONLY | O_CLOEXEC);
- if (mask_file != -1)
- {
- *is_supported = TRUE;
- close (mask_file);
- }
-
- retval = TRUE;
-
-out:
- free (aa_securityfs);
- _dbus_string_free (&aa_dbus);
-
- return retval;
-}
-
-static dbus_bool_t
-modestr_is_complain (const char *mode)
-{
- if (mode && strcmp (mode, "complain") == 0)
- return TRUE;
- return FALSE;
-}
-
-static void
-log_message (dbus_bool_t allow, const char *op, DBusString *data)
-{
- const char *mstr;
-#ifdef HAVE_LIBAUDIT
- int audit_fd;
-#endif
-
- if (allow)
- mstr = "ALLOWED";
- else
- mstr = "DENIED";
-
-#ifdef HAVE_LIBAUDIT
- audit_fd = bus_audit_get_fd ();
-
- if (audit_fd >= 0)
- {
- DBusString avc;
-
- if (!_dbus_string_init (&avc))
- goto syslog;
-
- if (!_dbus_string_append_printf (&avc,
- "apparmor=\"%s\" operation=\"dbus_%s\" %s\n",
- mstr, op, _dbus_string_get_const_data (data)))
- {
- _dbus_string_free (&avc);
- goto syslog;
- }
-
- /* FIXME: need to change this to show real user */
- audit_log_user_avc_message (audit_fd, AUDIT_USER_AVC,
- _dbus_string_get_const_data (&avc),
- NULL, NULL, NULL, getuid ());
- _dbus_string_free (&avc);
- return;
- }
-
-syslog:
-#endif /* HAVE_LIBAUDIT */
-
- syslog (LOG_USER | LOG_NOTICE, "apparmor=\"%s\" operation=\"dbus_%s\" %s\n",
- mstr, op, _dbus_string_get_const_data (data));
-}
-
-static dbus_bool_t
-_dbus_append_pair_uint (DBusString *auxdata, const char *name,
- unsigned long value)
-{
- return _dbus_string_append (auxdata, " ") &&
- _dbus_string_append (auxdata, name) &&
- _dbus_string_append (auxdata, "=") &&
- _dbus_string_append_uint (auxdata, value);
-}
-
-static dbus_bool_t
-_dbus_append_pair_str (DBusString *auxdata, const char *name, const char *value)
-{
- return _dbus_string_append (auxdata, " ") &&
- _dbus_string_append (auxdata, name) &&
- _dbus_string_append (auxdata, "=\"") &&
- _dbus_string_append (auxdata, value) &&
- _dbus_string_append (auxdata, "\"");
-}
-
-static dbus_bool_t
-_dbus_append_mask (DBusString *auxdata, uint32_t mask)
-{
- const char *mask_str;
-
- /* Only one permission bit can be set */
- if (mask == AA_DBUS_SEND)
- mask_str = "send";
- else if (mask == AA_DBUS_RECEIVE)
- mask_str = "receive";
- else if (mask == AA_DBUS_BIND)
- mask_str = "bind";
- else
- return FALSE;
-
- return _dbus_append_pair_str (auxdata, "mask", mask_str);
-}
-
-static dbus_bool_t
-is_unconfined (const char *con, const char *mode)
-{
- /* treat con == NULL as confined as it is going to result in a denial */
- if ((!mode && con && strcmp (con, "unconfined") == 0) ||
- strcmp (mode, "unconfined") == 0)
- {
- return TRUE;
- }
-
- return FALSE;
-}
-
-static dbus_bool_t
-query_append (DBusString *query, const char *buffer)
-{
- if (!_dbus_string_append_byte (query, '\0'))
- return FALSE;
-
- if (buffer && !_dbus_string_append (query, buffer))
- return FALSE;
-
- return TRUE;
-}
-
-static dbus_bool_t
-build_common_query (DBusString *query, const char *con, const char *bustype)
-{
- /**
- * libapparmor's aa_query_label() function scribbles over the first
- * AA_QUERY_CMD_LABEL_SIZE bytes of the query string with a private value.
- */
- return _dbus_string_insert_bytes (query, 0, AA_QUERY_CMD_LABEL_SIZE, 0) &&
- _dbus_string_append (query, con) &&
- _dbus_string_append_byte (query, '\0') &&
- _dbus_string_append_byte (query, AA_CLASS_DBUS) &&
- _dbus_string_append (query, bustype ? bustype : "");
-}
-
-static dbus_bool_t
-build_service_query (DBusString *query,
- const char *con,
- const char *bustype,
- const char *name)
-{
- return build_common_query (query, con, bustype) &&
- query_append (query, name);
-}
-
-static dbus_bool_t
-build_message_query (DBusString *query,
- const char *src_con,
- const char *bustype,
- const char *name,
- const char *dst_con,
- const char *path,
- const char *interface,
- const char *member)
-{
- return build_common_query (query, src_con, bustype) &&
- query_append (query, name) &&
- query_append (query, dst_con) &&
- query_append (query, path) &&
- query_append (query, interface) &&
- query_append (query, member);
-}
-
-static dbus_bool_t
-build_eavesdrop_query (DBusString *query, const char *con, const char *bustype)
-{
- return build_common_query (query, con, bustype);
-}
-
-static void
-set_error_from_query_errno (DBusError *error, int error_number)
-{
- dbus_set_error (error, _dbus_error_from_errno (error_number),
- "Failed to query AppArmor policy: %s",
- _dbus_strerror (error_number));
-}
-
-static void
-set_error_from_denied_message (DBusError *error,
- DBusConnection *sender,
- DBusConnection *proposed_recipient,
- dbus_bool_t requested_reply,
- const char *msgtype,
- const char *path,
- const char *interface,
- const char *member,
- const char *error_name,
- const char *destination)
-{
- const char *proposed_recipient_loginfo;
- const char *unset = "(unset)";
-
- proposed_recipient_loginfo = proposed_recipient ?
- bus_connection_get_loginfo (proposed_recipient) :
- "bus";
-
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "An AppArmor policy prevents this sender from sending this "
- "message to this recipient; type=\"%s\", "
- "sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" "
- "error name=\"%s\" requested_reply=\"%d\" "
- "destination=\"%s\" (%s)",
- msgtype,
- bus_connection_get_name (sender),
- bus_connection_get_loginfo (sender),
- interface ? interface : unset,
- member ? member : unset,
- error_name ? error_name : unset,
- requested_reply,
- destination,
- proposed_recipient_loginfo);
-}
-#endif /* HAVE_APPARMOR */
-
-/**
- * Do early initialization; determine whether AppArmor is enabled.
- * Return TRUE on successful check (whether AppArmor is actually
- * enabled or not) or FALSE on OOM.
- */
-dbus_bool_t
-bus_apparmor_pre_init (void)
-{
-#ifdef HAVE_APPARMOR
- apparmor_enabled = FALSE;
-
- if (!aa_is_enabled ())
- return TRUE;
-
- if (!_bus_apparmor_detect_aa_dbus_support (&apparmor_enabled))
- return FALSE;
-#endif
-
- return TRUE;
-}
-
-dbus_bool_t
-bus_apparmor_set_mode_from_config (const char *mode, DBusError *error)
-{
-#ifdef HAVE_APPARMOR
- if (mode != NULL)
- {
- if (strcmp (mode, "disabled") == 0)
- apparmor_config_mode = APPARMOR_DISABLED;
- else if (strcmp (mode, "enabled") == 0)
- apparmor_config_mode = APPARMOR_ENABLED;
- else if (strcmp (mode, "required") == 0)
- apparmor_config_mode = APPARMOR_REQUIRED;
- else
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Mode attribute on <apparmor> must have value "
- "\"required\", \"enabled\" or \"disabled\", "
- "not \"%s\"", mode);
- return FALSE;
- }
- }
-
- return TRUE;
-#else
- if (mode == NULL || strcmp (mode, "disabled") == 0 ||
- strcmp (mode, "enabled") == 0)
- return TRUE;
-
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Mode attribute on <apparmor> must have value \"enabled\" or "
- "\"disabled\" but cannot be \"%s\" when D-Bus is built "
- "without AppArmor support", mode);
- return FALSE;
-#endif
-}
-
-/**
- * Verify that the config mode is compatible with the kernel's AppArmor
- * support. If AppArmor mediation will be enabled, determine the bus
- * confinement label.
- */
-dbus_bool_t
-bus_apparmor_full_init (DBusError *error)
-{
-#ifdef HAVE_APPARMOR
- char *label, *mode;
-
- if (apparmor_enabled)
- {
- if (apparmor_config_mode == APPARMOR_DISABLED)
- {
- apparmor_enabled = FALSE;
- return TRUE;
- }
-
- if (bus_con == NULL)
- {
- if (aa_getcon (&label, &mode) == -1)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Error getting AppArmor context of bus: %s",
- _dbus_strerror (errno));
- return FALSE;
- }
-
- bus_con = bus_apparmor_confinement_new (label, mode);
- if (bus_con == NULL)
- {
- BUS_SET_OOM (error);
- free (label);
- return FALSE;
- }
- }
- }
- else
- {
- if (apparmor_config_mode == APPARMOR_REQUIRED)
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "AppArmor mediation required but not present");
- return FALSE;
- }
- else if (apparmor_config_mode == APPARMOR_ENABLED)
- {
- return TRUE;
- }
- }
-#endif
-
- return TRUE;
-}
-
-void
-bus_apparmor_shutdown (void)
-{
-#ifdef HAVE_APPARMOR
- if (!apparmor_enabled)
- return;
-
- _dbus_verbose ("AppArmor shutdown\n");
-
- bus_apparmor_confinement_unref (bus_con);
- bus_con = NULL;
-#endif /* HAVE_APPARMOR */
-}
-
-dbus_bool_t
-bus_apparmor_enabled (void)
-{
-#ifdef HAVE_APPARMOR
- return apparmor_enabled;
-#else
- return FALSE;
-#endif
-}
-
-void
-bus_apparmor_confinement_unref (BusAppArmorConfinement *confinement)
-{
-#ifdef HAVE_APPARMOR
- if (!apparmor_enabled)
- return;
-
- _dbus_assert (confinement != NULL);
- _dbus_assert (confinement->refcount > 0);
-
- confinement->refcount -= 1;
-
- if (confinement->refcount == 0)
- {
- /**
- * Do not free confinement->mode, as libapparmor does a single malloc for
- * both confinement->label and confinement->mode.
- */
- free (confinement->label);
- dbus_free (confinement);
- }
-#endif
-}
-
-void
-bus_apparmor_confinement_ref (BusAppArmorConfinement *confinement)
-{
-#ifdef HAVE_APPARMOR
- if (!apparmor_enabled)
- return;
-
- _dbus_assert (confinement != NULL);
- _dbus_assert (confinement->refcount > 0);
-
- confinement->refcount += 1;
-#endif /* HAVE_APPARMOR */
-}
-
-BusAppArmorConfinement*
-bus_apparmor_init_connection_confinement (DBusConnection *connection,
- DBusError *error)
-{
-#ifdef HAVE_APPARMOR
- BusAppArmorConfinement *confinement;
- char *label, *mode;
- int fd;
-
- if (!apparmor_enabled)
- return NULL;
-
- _dbus_assert (connection != NULL);
-
- if (!dbus_connection_get_socket (connection, &fd))
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Failed to get socket file descriptor of connection");
- return NULL;
- }
-
- if (aa_getpeercon (fd, &label, &mode) == -1)
- {
- if (errno == ENOMEM)
- BUS_SET_OOM (error);
- else
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to get AppArmor confinement information of socket peer: %s",
- _dbus_strerror (errno));
- return NULL;
- }
-
- confinement = bus_apparmor_confinement_new (label, mode);
- if (confinement == NULL)
- {
- BUS_SET_OOM (error);
- free (label);
- return NULL;
- }
-
- return confinement;
-#else
- return NULL;
-#endif /* HAVE_APPARMOR */
-}
-
-/**
- * Returns true if the given connection can acquire a service,
- * using the tasks security context
- *
- * @param connection connection that wants to own the service
- * @param bustype name of the bus
- * @param service_name the name of the service to acquire
- * @param error the reason for failure when FALSE is returned
- * @returns TRUE if acquire is permitted
- */
-dbus_bool_t
-bus_apparmor_allows_acquire_service (DBusConnection *connection,
- const char *bustype,
- const char *service_name,
- DBusError *error)
-{
-
-#ifdef HAVE_APPARMOR
- BusAppArmorConfinement *con = NULL;
- DBusString qstr, auxdata;
- dbus_bool_t free_auxdata = FALSE;
- dbus_bool_t allow = FALSE, audit = TRUE;
- unsigned long pid;
- int res, serrno = 0;
-
- if (!apparmor_enabled)
- return TRUE;
-
- _dbus_assert (connection != NULL);
-
- con = bus_connection_dup_apparmor_confinement (connection);
-
- if (is_unconfined (con->label, con->mode))
- {
- allow = TRUE;
- audit = FALSE;
- goto out;
- }
-
- if (!_dbus_string_init (&qstr))
- goto oom;
-
- if (!build_service_query (&qstr, con->label, bustype, service_name))
- {
- _dbus_string_free (&qstr);
- goto oom;
- }
-
- res = aa_query_label (AA_DBUS_BIND,
- _dbus_string_get_data (&qstr),
- _dbus_string_get_length (&qstr),
- &allow, &audit);
- _dbus_string_free (&qstr);
- if (res == -1)
- {
- serrno = errno;
- set_error_from_query_errno (error, serrno);
- goto audit;
- }
-
- /* Don't fail operations on profiles in complain mode */
- if (modestr_is_complain (con->mode))
- allow = TRUE;
-
- if (!allow)
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "Connection \"%s\" is not allowed to own the service "
- "\"%s\" due to AppArmor policy",
- bus_connection_is_active (connection) ?
- bus_connection_get_name (connection) : "(inactive)",
- service_name);
-
- if (!audit)
- goto out;
-
- audit:
- if (!_dbus_string_init (&auxdata))
- goto oom;
- free_auxdata = TRUE;
-
- if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown"))
- goto oom;
-
- if (!_dbus_append_pair_str (&auxdata, "name", service_name))
- goto oom;
-
- if (serrno && !_dbus_append_pair_str (&auxdata, "info", strerror (serrno)))
- goto oom;
-
- if (!_dbus_append_mask (&auxdata, AA_DBUS_BIND))
- goto oom;
-
- if (connection && dbus_connection_get_unix_process_id (connection, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "pid", pid))
- goto oom;
-
- if (con->label && !_dbus_append_pair_str (&auxdata, "label", con->label))
- goto oom;
-
- log_message (allow, "bind", &auxdata);
-
- out:
- if (con != NULL)
- bus_apparmor_confinement_unref (con);
- if (free_auxdata)
- _dbus_string_free (&auxdata);
- return allow;
-
- oom:
- if (error != NULL && !dbus_error_is_set (error))
- BUS_SET_OOM (error);
- allow = FALSE;
- goto out;
-
-#else
- return TRUE;
-#endif /* HAVE_APPARMOR */
-}
-
-/**
- * Check if Apparmor security controls allow the message to be sent to a
- * particular connection based on the security context of the sender and
- * that of the receiver. The destination connection need not be the
- * addressed recipient, it could be an "eavesdropper"
- *
- * @param sender the sender of the message.
- * @param proposed_recipient the connection the message is to be sent to.
- * @param requested_reply TRUE if the message is a reply requested by
- * proposed_recipient
- * @param bustype name of the bus
- * @param msgtype message type (DBUS_MESSAGE_TYPE_METHOD_CALL, etc.)
- * @param path object path the message should be sent to
- * @param interface the type of the object instance
- * @param member the member of the object
- * @param error_name the name of the error if the message type is error
- * @param destination name that the message should be sent to
- * @param source name that the message should be sent from
- * @param error the reason for failure when FALSE is returned
- * @returns TRUE if the message is permitted
- */
-dbus_bool_t
-bus_apparmor_allows_send (DBusConnection *sender,
- DBusConnection *proposed_recipient,
- dbus_bool_t requested_reply,
- const char *bustype,
- int msgtype,
- const char *path,
- const char *interface,
- const char *member,
- const char *error_name,
- const char *destination,
- const char *source,
- DBusError *error)
-{
-#ifdef HAVE_APPARMOR
- BusAppArmorConfinement *src_con = NULL, *dst_con = NULL;
- DBusString qstr, auxdata;
- dbus_bool_t src_allow = FALSE, dst_allow = FALSE;
- dbus_bool_t src_audit = TRUE, dst_audit = TRUE;
- dbus_bool_t free_auxdata = FALSE;
- unsigned long pid;
- int len, res, src_errno = 0, dst_errno = 0;
- uint32_t src_perm = AA_DBUS_SEND, dst_perm = AA_DBUS_RECEIVE;
- const char *msgtypestr = dbus_message_type_to_string(msgtype);
-
- if (!apparmor_enabled)
- return TRUE;
-
- _dbus_assert (sender != NULL);
-
- src_con = bus_connection_dup_apparmor_confinement (sender);
-
- if (proposed_recipient)
- {
- dst_con = bus_connection_dup_apparmor_confinement (proposed_recipient);
- }
- else
- {
- dst_con = bus_con;
- bus_apparmor_confinement_ref (dst_con);
- }
-
- /* map reply messages to initial send and receive permission. That is
- * permission to receive a message from X grants permission to reply to X.
- * And permission to send a message to Y grants permission to receive a reply
- * from Y. Note that this only applies to requested replies. Unrequested
- * replies still require a policy query.
- */
- if (requested_reply)
- {
- /* ignore requested reply messages and let dbus reply mapping handle them
- * as the send was already allowed
- */
- src_allow = TRUE;
- dst_allow = TRUE;
- goto out;
- }
-
- if (is_unconfined (src_con->label, src_con->mode))
- {
- src_allow = TRUE;
- src_audit = FALSE;
- }
- else
- {
- if (!_dbus_string_init (&qstr))
- goto oom;
-
- if (!build_message_query (&qstr, src_con->label, bustype, destination,
- dst_con->label, path, interface, member))
- {
- _dbus_string_free (&qstr);
- goto oom;
- }
-
- res = aa_query_label (src_perm,
- _dbus_string_get_data (&qstr),
- _dbus_string_get_length (&qstr),
- &src_allow, &src_audit);
- _dbus_string_free (&qstr);
- if (res == -1)
- {
- src_errno = errno;
- set_error_from_query_errno (error, src_errno);
- goto audit;
- }
- }
-
- if (is_unconfined (dst_con->label, dst_con->mode))
- {
- dst_allow = TRUE;
- dst_audit = FALSE;
- }
- else
- {
- if (!_dbus_string_init (&qstr))
- goto oom;
-
- if (!build_message_query (&qstr, dst_con->label, bustype, source,
- src_con->label, path, interface, member))
- {
- _dbus_string_free (&qstr);
- goto oom;
- }
-
- res = aa_query_label (dst_perm,
- _dbus_string_get_data (&qstr),
- _dbus_string_get_length (&qstr),
- &dst_allow, &dst_audit);
- _dbus_string_free (&qstr);
- if (res == -1)
- {
- dst_errno = errno;
- set_error_from_query_errno (error, dst_errno);
- goto audit;
- }
- }
-
- /* Don't fail operations on profiles in complain mode */
- if (modestr_is_complain (src_con->mode))
- src_allow = TRUE;
- if (modestr_is_complain (dst_con->mode))
- dst_allow = TRUE;
-
- if (!src_allow || !dst_allow)
- set_error_from_denied_message (error,
- sender,
- proposed_recipient,
- requested_reply,
- msgtypestr,
- path,
- interface,
- member,
- error_name,
- destination);
-
- /* Don't audit the message if one of the following conditions is true:
- * 1) The AppArmor query indicates that auditing should not happen.
- * 2) The message is a reply type. Reply message are not audited because
- * the AppArmor policy language does not have the notion of a reply
- * message. Unrequested replies will be silently discarded if the sender
- * does not have permission to send to the receiver or if the receiver
- * does not have permission to receive from the sender.
- */
- if ((!src_audit && !dst_audit) ||
- (msgtype == DBUS_MESSAGE_TYPE_METHOD_RETURN ||
- msgtype == DBUS_MESSAGE_TYPE_ERROR))
- goto out;
-
- audit:
- if (!_dbus_string_init (&auxdata))
- goto oom;
- free_auxdata = TRUE;
-
- if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown"))
- goto oom;
-
- if (path && !_dbus_append_pair_str (&auxdata, "path", path))
- goto oom;
-
- if (interface && !_dbus_append_pair_str (&auxdata, "interface", interface))
- goto oom;
-
- if (member && !_dbus_append_pair_str (&auxdata, "member", member))
- goto oom;
-
- if (error_name && !_dbus_append_pair_str (&auxdata, "error_name", error_name))
- goto oom;
-
- len = _dbus_string_get_length (&auxdata);
-
- if (src_audit)
- {
- if (!_dbus_append_mask (&auxdata, src_perm))
- goto oom;
-
- if (destination && !_dbus_append_pair_str (&auxdata, "name", destination))
- goto oom;
-
- if (sender && dbus_connection_get_unix_process_id (sender, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "pid", pid))
- goto oom;
-
- if (src_con->label &&
- !_dbus_append_pair_str (&auxdata, "label", src_con->label))
- goto oom;
-
- if (proposed_recipient &&
- dbus_connection_get_unix_process_id (proposed_recipient, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "peer_pid", pid))
- goto oom;
-
- if (dst_con->label &&
- !_dbus_append_pair_str (&auxdata, "peer_label", dst_con->label))
- goto oom;
-
- if (src_errno && !_dbus_append_pair_str (&auxdata, "info", strerror (src_errno)))
- goto oom;
-
- if (dst_errno &&
- !_dbus_append_pair_str (&auxdata, "peer_info", strerror (dst_errno)))
- goto oom;
-
- log_message (src_allow, msgtypestr, &auxdata);
- }
- if (dst_audit)
- {
- _dbus_string_set_length (&auxdata, len);
-
- if (source && !_dbus_append_pair_str (&auxdata, "name", source))
- goto oom;
-
- if (!_dbus_append_mask (&auxdata, dst_perm))
- goto oom;
-
- if (proposed_recipient &&
- dbus_connection_get_unix_process_id (proposed_recipient, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "pid", pid))
- goto oom;
-
- if (dst_con->label &&
- !_dbus_append_pair_str (&auxdata, "label", dst_con->label))
- goto oom;
-
- if (sender && dbus_connection_get_unix_process_id (sender, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "peer_pid", pid))
- goto oom;
-
- if (src_con->label &&
- !_dbus_append_pair_str (&auxdata, "peer_label", src_con->label))
- goto oom;
-
- if (dst_errno && !_dbus_append_pair_str (&auxdata, "info", strerror (dst_errno)))
- goto oom;
-
- if (src_errno &&
- !_dbus_append_pair_str (&auxdata, "peer_info", strerror (src_errno)))
- goto oom;
-
- log_message (dst_allow, msgtypestr, &auxdata);
- }
-
- out:
- if (src_con != NULL)
- bus_apparmor_confinement_unref (src_con);
- if (dst_con != NULL)
- bus_apparmor_confinement_unref (dst_con);
- if (free_auxdata)
- _dbus_string_free (&auxdata);
-
- return src_allow && dst_allow;
-
- oom:
- if (error != NULL && !dbus_error_is_set (error))
- BUS_SET_OOM (error);
- src_allow = FALSE;
- dst_allow = FALSE;
- goto out;
-
-#else
- return TRUE;
-#endif /* HAVE_APPARMOR */
-}
-
-/**
- * Check if Apparmor security controls allow the connection to eavesdrop on
- * other connections.
- *
- * @param connection the connection attempting to eavesdrop.
- * @param bustype name of the bus
- * @param error the reason for failure when FALSE is returned
- * @returns TRUE if eavesdropping is permitted
- */
-dbus_bool_t
-bus_apparmor_allows_eavesdropping (DBusConnection *connection,
- const char *bustype,
- DBusError *error)
-{
-#ifdef HAVE_APPARMOR
- BusAppArmorConfinement *con = NULL;
- DBusString qstr, auxdata;
- dbus_bool_t allow = FALSE, audit = TRUE;
- dbus_bool_t free_auxdata = FALSE;
- unsigned long pid;
- int res, serrno = 0;
-
- if (!apparmor_enabled)
- return TRUE;
-
- con = bus_connection_dup_apparmor_confinement (connection);
-
- if (is_unconfined (con->label, con->mode))
- {
- allow = TRUE;
- audit = FALSE;
- goto out;
- }
-
- if (!_dbus_string_init (&qstr))
- goto oom;
-
- if (!build_eavesdrop_query (&qstr, con->label, bustype))
- {
- _dbus_string_free (&qstr);
- goto oom;
- }
-
- res = aa_query_label (AA_DBUS_EAVESDROP,
- _dbus_string_get_data (&qstr),
- _dbus_string_get_length (&qstr),
- &allow, &audit);
- _dbus_string_free (&qstr);
- if (res == -1)
- {
- serrno = errno;
- set_error_from_query_errno (error, serrno);
- goto audit;
- }
-
- /* Don't fail operations on profiles in complain mode */
- if (modestr_is_complain (con->mode))
- allow = TRUE;
-
- if (!allow)
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "Connection \"%s\" is not allowed to eavesdrop due to "
- "AppArmor policy",
- bus_connection_is_active (connection) ?
- bus_connection_get_name (connection) : "(inactive)");
-
- if (!audit)
- goto out;
-
- audit:
- if (!_dbus_string_init (&auxdata))
- goto oom;
- free_auxdata = TRUE;
-
- if (!_dbus_append_pair_str (&auxdata, "bus", bustype ? bustype : "unknown"))
- goto oom;
-
- if (serrno && !_dbus_append_pair_str (&auxdata, "info", strerror (serrno)))
- goto oom;
-
- if (!_dbus_append_pair_str (&auxdata, "mask", "eavesdrop"))
- goto oom;
-
- if (connection && dbus_connection_get_unix_process_id (connection, &pid) &&
- !_dbus_append_pair_uint (&auxdata, "pid", pid))
- goto oom;
-
- if (con->label && !_dbus_append_pair_str (&auxdata, "label", con->label))
- goto oom;
-
- log_message (allow, "eavesdrop", &auxdata);
-
- out:
- if (con != NULL)
- bus_apparmor_confinement_unref (con);
- if (free_auxdata)
- _dbus_string_free (&auxdata);
-
- return allow;
-
- oom:
- if (error != NULL && !dbus_error_is_set (error))
- BUS_SET_OOM (error);
- allow = FALSE;
- goto out;
-
-#else
- return TRUE;
-#endif /* HAVE_APPARMOR */
-}
diff --git a/bus/apparmor.h b/bus/apparmor.h
deleted file mode 100644
index 18f3ee7..0000000
--- a/bus/apparmor.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- * apparmor.c AppArmor security checks for D-Bus
- *
- * Authors: John Johansen <john.johansen@canonical.com>
- * Tyler Hicks <tyhicks@canonical.com>
- * Based on: selinux.h by Matthew Rickard
- *
- * 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 BUS_APPARMOR_H
-#define BUS_APPARMOR_H
-
-#include <dbus/dbus.h>
-#include "bus.h"
-
-dbus_bool_t bus_apparmor_pre_init (void);
-dbus_bool_t bus_apparmor_set_mode_from_config (const char *mode,
- DBusError *error);
-dbus_bool_t bus_apparmor_full_init (DBusError *error);
-void bus_apparmor_shutdown (void);
-dbus_bool_t bus_apparmor_enabled (void);
-
-void bus_apparmor_confinement_unref (BusAppArmorConfinement *confinement);
-void bus_apparmor_confinement_ref (BusAppArmorConfinement *confinement);
-BusAppArmorConfinement* bus_apparmor_init_connection_confinement (DBusConnection *connection,
- DBusError *error);
-
-dbus_bool_t bus_apparmor_allows_acquire_service (DBusConnection *connection,
- const char *bustype,
- const char *service_name,
- DBusError *error);
-dbus_bool_t bus_apparmor_allows_send (DBusConnection *sender,
- DBusConnection *proposed_recipient,
- dbus_bool_t requested_reply,
- const char *bustype,
- int msgtype,
- const char *path,
- const char *interface,
- const char *member,
- const char *error_name,
- const char *destination,
- const char *source,
- DBusError *error);
-
-dbus_bool_t bus_apparmor_allows_eavesdropping (DBusConnection *connection,
- const char *bustype,
- DBusError *error);
-
-#endif /* BUS_APPARMOR_H */
diff --git a/bus/audit.c b/bus/audit.c
deleted file mode 100644
index 7705e42..0000000
--- a/bus/audit.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- * audit.c - libaudit integration for SELinux and AppArmor
- *
- * Based on apparmor.c, selinux.c
- *
- * Copyright © 2014-2015 Canonical, Ltd.
- * Copyright © 2015 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 "audit.h"
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-
-#ifdef HAVE_LIBAUDIT
-#include <cap-ng.h>
-#include <libaudit.h>
-#endif
-
-#include <dbus/dbus-internals.h>
-#ifdef DBUS_UNIX
-#include <dbus/dbus-userdb.h>
-#endif
-
-#ifdef HAVE_LIBAUDIT
-static int audit_fd = -1;
-#endif
-
-/**
- * Open the libaudit fd if appropriate.
- */
-void
-bus_audit_init (BusContext *context)
-{
-#ifdef HAVE_LIBAUDIT
- int i;
-
- capng_get_caps_process ();
-
- /* Work around a bug in libcap-ng < 0.7.7: it leaks a fd, which isn't
- * close-on-exec. Assume it will be one of the first few fds. */
- for (i = 3; i < 42; i++)
- _dbus_fd_set_close_on_exec (i);
-
- if (!capng_have_capability (CAPNG_EFFECTIVE, CAP_AUDIT_WRITE))
- return;
-
- audit_fd = audit_open ();
-
- if (audit_fd < 0)
- {
- int e = errno;
-
- /* If kernel doesn't support audit, bail out */
- if (e == EINVAL || e == EPROTONOSUPPORT || e == EAFNOSUPPORT)
- return;
-
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "Failed to open connection to the audit subsystem: %s",
- _dbus_strerror (e));
- }
-#endif /* HAVE_LIBAUDIT */
-}
-
-/**
- * If libaudit is in use and it would be appropriate to write audit records,
- * return the libaudit fd. Otherwise return -1.
- */
-int
-bus_audit_get_fd (void)
-{
-#ifdef HAVE_LIBAUDIT
- if (audit_fd >= 0)
- {
- return audit_fd;
- }
-#endif
-
- return -1;
-}
-
-/**
- * Close the libaudit fd.
- */
-void
-bus_audit_shutdown (void)
-{
-#ifdef HAVE_LIBAUDIT
- audit_close (audit_fd);
-#endif /* HAVE_LIBAUDIT */
-}
-
-/* The !HAVE_LIBAUDIT case lives in dbus-sysdeps-util-unix.c */
-#ifdef HAVE_LIBAUDIT
-/**
- * Changes the user and group the bus is running as.
- *
- * @param user the user to become
- * @param error return location for errors
- * @returns #FALSE on failure
- */
-dbus_bool_t
-_dbus_change_to_daemon_user (const char *user,
- DBusError *error)
-{
- dbus_uid_t uid;
- dbus_gid_t gid;
- DBusString u;
-
- _dbus_string_init_const (&u, user);
-
- if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
- {
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "User '%s' does not appear to exist?",
- user);
- return FALSE;
- }
-
- /* If we were root */
- 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);
- /* 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)
- {
- switch (rc) {
- default:
- dbus_set_error (error, DBUS_ERROR_FAILED,
- "Failed to drop capabilities: %s\n",
- _dbus_strerror (errno));
- break;
- case -4:
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to set GID to %lu: %s", gid,
- _dbus_strerror (errno));
- break;
- case -5:
- _dbus_warn ("Failed to drop supplementary groups: %s\n",
- _dbus_strerror (errno));
- break;
- case -6:
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to set UID to %lu: %s", uid,
- _dbus_strerror (errno));
- break;
- case -7:
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to unset keep-capabilities: %s\n",
- _dbus_strerror (errno));
- break;
- }
- return FALSE;
- }
- }
-
- return TRUE;
-}
-#endif
diff --git a/bus/audit.h b/bus/audit.h
deleted file mode 100644
index e17016f..0000000
--- a/bus/audit.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
- * audit.h - libaudit integration for SELinux and AppArmor
- *
- * 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 BUS_AUDIT_H
-#define BUS_AUDIT_H
-
-#include <dbus/dbus.h>
-
-#include "bus.h"
-
-void bus_audit_init (BusContext *context);
-int bus_audit_get_fd (void);
-void bus_audit_shutdown (void);
-
-#endif
diff --git a/bus/bus.c b/bus/bus.c
index 128ae3c..bc27f46 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -34,14 +34,11 @@
#include "config-parser.h"
#include "signals.h"
#include "selinux.h"
-#include "apparmor.h"
-#include "audit.h"
#include "dir-watch.h"
#include <dbus/dbus-list.h>
#include <dbus/dbus-hash.h>
#include <dbus/dbus-credentials.h>
#include <dbus/dbus-internals.h>
-#include <dbus/dbus-server-protected.h>
#ifdef DBUS_CYGWIN
#include <signal.h>
@@ -55,7 +52,9 @@
char *type;
char *servicehelper;
char *address;
+#ifdef WANT_PIDFILE
char *pidfile;
+#endif
char *user;
char *log_prefix;
DBusLoop *loop;
@@ -66,13 +65,11 @@
BusPolicy *policy;
BusMatchmaker *matchmaker;
BusLimits limits;
- DBusRLimit *initial_fd_limit;
unsigned int fork : 1;
unsigned int syslog : 1;
unsigned int keep_umask : 1;
unsigned int allow_anonymous : 1;
unsigned int systemd_activation : 1;
- dbus_bool_t watches_enabled;
};
static dbus_int32_t server_data_slot = -1;
@@ -292,13 +289,14 @@
auth_mechanisms = NULL;
pidfile = NULL;
- _dbus_init_system_log (TRUE);
+ _dbus_init_system_log ();
if (flags & BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION)
context->systemd_activation = TRUE;
else
context->systemd_activation = FALSE;
+#ifdef WANT_PIDFILE
/* Check for an existing pid file. Of course this is a race;
* we'd have to use fcntl() locks on the pid file to
* avoid that. But we want to check for the pid file
@@ -345,6 +343,7 @@
/* keep around the pid filename so we can delete it later */
context->pidfile = _dbus_strdup (pidfile);
+#endif
/* note that type may be NULL */
context->type = _dbus_strdup (bus_config_parser_get_type (parser));
@@ -531,18 +530,6 @@
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
*/
@@ -662,38 +649,19 @@
static void
raise_file_descriptor_limit (BusContext *context)
{
-#ifdef DBUS_UNIX
- DBusError error = DBUS_ERROR_INIT;
- /* we only do this once */
- if (context->initial_fd_limit != NULL)
- return;
-
- context->initial_fd_limit = _dbus_rlimit_save_fd_limit (&error);
-
- if (context->initial_fd_limit == NULL)
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "%s: %s", error.name, error.message);
- dbus_error_free (&error);
- return;
- }
-
- /* We used to compute a suitable rlimit based on the configured number
- * of connections, but that breaks down as soon as we allow fd-passing,
- * because each connection is allowed to pass 64 fds to us, and if
- * they all did, we'd hit kernel limits. We now hard-code 64k as a
- * good limit, like systemd does: that's enough to avoid DoS from
- * anything short of multiple uids conspiring against us.
+ /* I just picked this out of thin air; we need some extra
+ * descriptors for things like any internal pipes we create,
+ * inotify, connections to SELinux, etc.
*/
- if (!_dbus_rlimit_raise_fd_limit_if_privileged (65536, &error))
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "%s: %s", error.name, error.message);
- dbus_error_free (&error);
- return;
- }
-#endif
+ unsigned int arbitrary_extra_fds = 32;
+ unsigned int limit;
+
+ limit = context->limits.max_completed_connections +
+ context->limits.max_incomplete_connections
+ + arbitrary_extra_fds;
+
+ _dbus_request_file_descriptor_limit (limit);
}
static dbus_bool_t
@@ -767,8 +735,7 @@
}
context->refcount = 1;
- if (!_dbus_generate_uuid (&context->uuid, error))
- goto failed;
+ _dbus_generate_uuid (&context->uuid);
if (!_dbus_string_copy_data (config_file, &context->config_file))
{
@@ -783,8 +750,6 @@
goto failed;
}
- context->watches_enabled = TRUE;
-
context->registry = bus_registry_new (context);
if (context->registry == NULL)
{
@@ -889,6 +854,7 @@
/* Now become a daemon if appropriate and write out pid file in any case */
{
+#ifdef WANT_PIDFILE
DBusString u;
if (context->pidfile)
@@ -903,6 +869,7 @@
print_pid_pipe,
error,
context->keep_umask))
+
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
@@ -925,6 +892,20 @@
goto failed;
}
}
+#else
+ if (((flags & BUS_CONTEXT_FLAG_FORK_NEVER) == 0 && context->fork) ||
+ (flags & BUS_CONTEXT_FLAG_FORK_ALWAYS))
+ {
+ if (!_dbus_become_daemon (NULL,
+ 0,
+ error,
+ context->keep_umask))
+ {
+ _DBUS_ASSERT_ERROR_IS_SET (error);
+ goto failed;
+ }
+ }
+#endif
}
if (print_pid_pipe && _dbus_pipe_is_valid (print_pid_pipe) &&
@@ -933,21 +914,7 @@
if (!bus_selinux_full_init ())
{
- bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but D-Bus initialization failed; check system log\n");
- }
-
- if (!bus_apparmor_full_init (error))
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- goto failed;
- }
-
- if (bus_apparmor_enabled ())
- {
- /* Only print AppArmor mediation message when syslog support is enabled */
- if (context->syslog)
- bus_context_log (context, DBUS_SYSTEM_LOG_INFO,
- "AppArmor D-Bus mediation is enabled\n");
+ bus_context_log (context, DBUS_SYSTEM_LOG_FATAL, "SELinux enabled but AVC initialization failed; check system log\n");
}
if (!process_config_postinit (context, parser, error))
@@ -972,9 +939,12 @@
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
}
- }
- bus_audit_init (context);
+#ifdef HAVE_SELINUX
+ /* FIXME - why not just put this in full_init() below? */
+ bus_selinux_audit_init ();
+#endif
+ }
dbus_server_free_data_slot (&server_data_slot);
@@ -1152,6 +1122,7 @@
dbus_free (context->user);
dbus_free (context->servicehelper);
+#ifdef WANT_PIDFILE
if (context->pidfile)
{
DBusString u;
@@ -1164,9 +1135,7 @@
dbus_free (context->pidfile);
}
-
- if (context->initial_fd_limit)
- _dbus_rlimit_free (context->initial_fd_limit);
+#endif
dbus_free (context);
@@ -1279,12 +1248,6 @@
}
int
-bus_context_get_pending_fd_timeout (BusContext *context)
-{
- return context->limits.pending_fd_timeout;
-}
-
-int
bus_context_get_max_completed_connections (BusContext *context)
{
return context->limits.max_completed_connections;
@@ -1332,11 +1295,8 @@
return context->limits.reply_timeout;
}
-DBusRLimit *
-bus_context_get_initial_fd_limit (BusContext *context)
-{
- return context->initial_fd_limit;
-}
+void
+bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4);
void
bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
@@ -1350,10 +1310,6 @@
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
va_end (args);
-
- if (severity == DBUS_SYSTEM_LOG_FATAL)
- _dbus_exit (1);
-
return;
}
@@ -1388,49 +1344,6 @@
return (maybe_null ? maybe_null : if_null);
}
-void
-bus_context_log_literal (BusContext *context,
- DBusSystemLogSeverity severity,
- const char *msg)
-{
- if (!context->syslog)
- {
- fputs (msg, stderr);
- fputc ('\n', stderr);
-
- if (severity == DBUS_SYSTEM_LOG_FATAL)
- _dbus_exit (1);
- }
- else
- {
- _dbus_system_log (severity, "%s%s", nonnull (context->log_prefix, ""),
- msg);
- }
-}
-
-void
-bus_context_log_and_set_error (BusContext *context,
- DBusSystemLogSeverity severity,
- DBusError *error,
- const char *name,
- const char *msg,
- ...)
-{
- DBusError stack_error = DBUS_ERROR_INIT;
- va_list args;
-
- va_start (args, msg);
- _dbus_set_error_valist (&stack_error, name, msg, args);
- va_end (args);
-
- /* If we hit OOM while setting the error, this will syslog "out of memory"
- * which is itself an indication that something is seriously wrong */
- bus_context_log_literal (context, DBUS_SYSTEM_LOG_SECURITY,
- stack_error.message);
-
- dbus_move_error (&stack_error, error);
-}
-
/*
* Log something about a message, usually that it was rejected.
*/
@@ -1489,7 +1402,7 @@
/* If we hit OOM while setting the error, this will syslog "out of memory"
* which is itself an indication that something is seriously wrong */
if (log)
- bus_context_log_literal (context, DBUS_SYSTEM_LOG_SECURITY,
+ bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, "%s",
stack_error.message);
dbus_move_error (&stack_error, error);
@@ -1517,7 +1430,7 @@
DBusMessage *message,
DBusError *error)
{
- const char *src, *dest;
+ const char *dest;
BusClientPolicy *sender_policy;
BusClientPolicy *recipient_policy;
dbus_int32_t toggles;
@@ -1526,7 +1439,6 @@
dbus_bool_t requested_reply;
type = dbus_message_get_type (message);
- src = dbus_message_get_sender (message);
dest = dbus_message_get_destination (message);
/* dispatch.c was supposed to ensure these invariants */
@@ -1559,6 +1471,30 @@
if (sender != NULL)
{
+ /* First verify the SELinux access controls. If allowed then
+ * go on with the standard checks.
+ */
+ if (!bus_selinux_allows_send (sender, proposed_recipient,
+ dbus_message_type_to_string (dbus_message_get_type (message)),
+ dbus_message_get_interface (message),
+ dbus_message_get_member (message),
+ dbus_message_get_error_name (message),
+ dest ? dest : DBUS_SERVICE_DBUS, error))
+ {
+ if (error != NULL && !dbus_error_is_set (error))
+ {
+ /* don't syslog this, just set the error: avc_has_perm should
+ * have already written to either the audit log or syslog */
+ complain_about_message (context, DBUS_ERROR_ACCESS_DENIED,
+ "An SELinux policy prevents this sender from sending this "
+ "message to this recipient",
+ 0, message, sender, proposed_recipient, FALSE, FALSE, error);
+ _dbus_verbose ("SELinux security check denying send to service\n");
+ }
+
+ return FALSE;
+ }
+
if (bus_connection_is_active (sender))
{
sender_policy = bus_connection_get_policy (sender);
@@ -1589,51 +1525,6 @@
}
else
{
- sender_policy = NULL;
- }
-
- /* First verify the SELinux access controls. If allowed then
- * go on with the standard checks.
- */
- if (!bus_selinux_allows_send (sender, proposed_recipient,
- dbus_message_type_to_string (dbus_message_get_type (message)),
- dbus_message_get_interface (message),
- dbus_message_get_member (message),
- dbus_message_get_error_name (message),
- dest ? dest : DBUS_SERVICE_DBUS, error))
- {
- if (error != NULL && !dbus_error_is_set (error))
- {
- /* don't syslog this, just set the error: avc_has_perm should
- * have already written to either the audit log or syslog */
- complain_about_message (context, DBUS_ERROR_ACCESS_DENIED,
- "An SELinux policy prevents this sender from sending this "
- "message to this recipient",
- 0, message, sender, proposed_recipient, FALSE, FALSE, error);
- _dbus_verbose ("SELinux security check denying send to service\n");
- }
-
- return FALSE;
- }
-
- /* next verify AppArmor access controls. If allowed then
- * go on with the standard checks.
- */
- if (!bus_apparmor_allows_send (sender, proposed_recipient,
- requested_reply,
- bus_context_get_type (context),
- dbus_message_get_type (message),
- dbus_message_get_path (message),
- dbus_message_get_interface (message),
- dbus_message_get_member (message),
- dbus_message_get_error_name (message),
- dest ? dest : DBUS_SERVICE_DBUS,
- src ? src : DBUS_SERVICE_DBUS,
- error))
- return FALSE;
-
- if (!bus_connection_is_active (sender))
- {
/* Policy for inactive connections is that they can only send
* the hello message to the bus driver
*/
@@ -1740,7 +1631,7 @@
complain_about_message (context, DBUS_ERROR_ACCESS_DENIED,
"Rejected receive message", toggles,
message, sender, proposed_recipient, requested_reply,
- (addressed_recipient == proposed_recipient), error);
+ (addressed_recipient == proposed_recipient), NULL);
_dbus_verbose ("security policy disallowing message due to recipient policy\n");
return FALSE;
}
@@ -1778,36 +1669,3 @@
_dbus_verbose ("security policy allowing message\n");
return TRUE;
}
-
-void
-bus_context_check_all_watches (BusContext *context)
-{
- DBusList *link;
- dbus_bool_t enabled = TRUE;
-
- if (bus_connections_get_n_incomplete (context->connections) >=
- bus_context_get_max_incomplete_connections (context))
- {
- enabled = FALSE;
- }
-
- if (context->watches_enabled == enabled)
- return;
-
- context->watches_enabled = enabled;
-
- for (link = _dbus_list_get_first_link (&context->servers);
- link != NULL;
- link = _dbus_list_get_next_link (&context->servers, link))
- {
- /* A BusContext might contains several DBusServer (if there are
- * several <listen> configuration items) and a DBusServer might
- * contain several DBusWatch in its DBusWatchList (if getaddrinfo
- * returns several addresses on a dual IPv4-IPv6 stack or if
- * systemd passes several fds).
- * We want to enable/disable them all.
- */
- DBusServer *server = link->data;
- _dbus_server_toggle_all_watches (server, enabled);
- }
-}
diff --git a/bus/bus.h b/bus/bus.h
index 3fab59f..3597884 100644
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -38,7 +38,6 @@
typedef struct BusPolicyRule BusPolicyRule;
typedef struct BusRegistry BusRegistry;
typedef struct BusSELinuxID BusSELinuxID;
-typedef struct BusAppArmorConfinement BusAppArmorConfinement;
typedef struct BusService BusService;
typedef struct BusOwner BusOwner;
typedef struct BusTransaction BusTransaction;
@@ -55,7 +54,6 @@
long max_message_unix_fds; /**< Max number of unix fds of a single message*/
int activation_timeout; /**< How long to wait for an activation to time out */
int auth_timeout; /**< How long to wait for an authentication to time out */
- int pending_fd_timeout; /**< How long to wait for a D-Bus message with a fd to time out */
int max_completed_connections; /**< Max number of authorized connections */
int max_incomplete_connections; /**< Max number of incomplete connections */
int max_connections_per_user; /**< Max number of connections auth'd as same user */
@@ -108,7 +106,6 @@
DBusError *error);
int bus_context_get_activation_timeout (BusContext *context);
int bus_context_get_auth_timeout (BusContext *context);
-int bus_context_get_pending_fd_timeout (BusContext *context);
int bus_context_get_max_completed_connections (BusContext *context);
int bus_context_get_max_incomplete_connections (BusContext *context);
int bus_context_get_max_connections_per_user (BusContext *context);
@@ -117,20 +114,10 @@
int bus_context_get_max_match_rules_per_connection (BusContext *context);
int bus_context_get_max_replies_per_connection (BusContext *context);
int bus_context_get_reply_timeout (BusContext *context);
-DBusRLimit * bus_context_get_initial_fd_limit (BusContext *context);
void bus_context_log (BusContext *context,
DBusSystemLogSeverity severity,
const char *msg,
- ...) _DBUS_GNUC_PRINTF (3, 4);
-void bus_context_log_literal (BusContext *context,
- DBusSystemLogSeverity severity,
- const char *msg);
-void bus_context_log_and_set_error (BusContext *context,
- DBusSystemLogSeverity severity,
- DBusError *error,
- const char *name,
- const char *msg,
- ...) _DBUS_GNUC_PRINTF (5, 6);
+ ...);
dbus_bool_t bus_context_check_security_policy (BusContext *context,
BusTransaction *transaction,
DBusConnection *sender,
@@ -138,6 +125,5 @@
DBusConnection *proposed_recipient,
DBusMessage *message,
DBusError *error);
-void bus_context_check_all_watches (BusContext *context);
#endif /* BUS_BUS_H */
diff --git a/bus/config-loader-libxml.c b/bus/config-loader-libxml.c
new file mode 100644
index 0000000..c73a181
--- /dev/null
+++ b/bus/config-loader-libxml.c
@@ -0,0 +1,324 @@
+/* -*- 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-common.c b/bus/config-parser-common.c
index 5db6b28..c522ff4 100644
--- a/bus/config-parser-common.c
+++ b/bus/config-parser-common.c
@@ -127,10 +127,6 @@
{
return ELEMENT_ALLOW_ANONYMOUS;
}
- else if (strcmp (name, "apparmor") == 0)
- {
- return ELEMENT_APPARMOR;
- }
return ELEMENT_NONE;
}
@@ -185,8 +181,6 @@
return "keep_umask";
case ELEMENT_ALLOW_ANONYMOUS:
return "allow_anonymous";
- case ELEMENT_APPARMOR:
- return "apparmor";
}
_dbus_assert_not_reached ("bad element type");
diff --git a/bus/config-parser-common.h b/bus/config-parser-common.h
index 382a014..186bf4c 100644
--- a/bus/config-parser-common.h
+++ b/bus/config-parser-common.h
@@ -49,8 +49,7 @@
ELEMENT_STANDARD_SYSTEM_SERVICEDIRS,
ELEMENT_KEEP_UMASK,
ELEMENT_SYSLOG,
- ELEMENT_ALLOW_ANONYMOUS,
- ELEMENT_APPARMOR
+ ELEMENT_ALLOW_ANONYMOUS
} ElementType;
ElementType bus_config_parser_element_name_to_type (const char *element_name);
diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c
index 03ad838..6ef50f8 100644
--- a/bus/config-parser-trivial.c
+++ b/bus/config-parser-trivial.c
@@ -330,7 +330,7 @@
return &parser->service_dirs;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
#include "test.h"
@@ -684,13 +684,6 @@
if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
goto finish;
-#ifndef DBUS_WIN
- /* We already test default_session_servicedirs and default_system_servicedirs
- * in bus_config_parser_test() */
- if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID))
- goto finish;
-#endif
-
/* we don't process all the invalid files, as the trivial parser can't hope
* to validate them all for all different syntaxes. We just check one broken
* file to see if junk is received */
@@ -700,16 +693,14 @@
goto finish;
_dbus_string_free (&full_path);
-#ifndef DBUS_WIN
/* just test if the check_file_valid works okay and we got sane values */
- if (!make_full_path (test_data_dir, "valid-config-files-system", "system.conf", &full_path))
+ if (!make_full_path (test_data_dir, "valid-config-files", "system.conf", &full_path))
goto finish;
if (!check_file_valid (&full_path, VALID))
goto finish;
/* check to see if we got the correct values from the parser */
if (!check_return_values (&full_path))
goto finish;
-#endif
/* woot! */
retval = TRUE;
@@ -721,5 +712,5 @@
return retval;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/config-parser.c b/bus/config-parser.c
index d9f6042..07e8fbb 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -28,10 +28,8 @@
#include "utils.h"
#include "policy.h"
#include "selinux.h"
-#include "apparmor.h"
#include <dbus/dbus-list.h>
#include <dbus/dbus-internals.h>
-#include <dbus/dbus-misc.h>
#include <dbus/dbus-sysdeps.h>
#include <string.h>
@@ -319,23 +317,13 @@
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);
@@ -425,9 +413,9 @@
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 = 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;
+ parser->limits.max_incoming_unix_fds = 1024*4;
+ parser->limits.max_outgoing_unix_fds = 1024*4;
+ parser->limits.max_message_unix_fds = 1024;
/* Making this long means the user has to wait longer for an error
* message if something screws up, but making it too short means
@@ -440,11 +428,6 @@
* password) is allowed, then potentially it has to be quite long.
*/
parser->limits.auth_timeout = 30000; /* 30 seconds */
-
- /* Do not allow a fd to stay forever in dbus-daemon
- * https://bugs.freedesktop.org/show_bug.cgi?id=80559
- */
- parser->limits.pending_fd_timeout = 150000; /* 2.5 minutes */
parser->limits.max_incomplete_connections = 64;
parser->limits.max_connections_per_user = 256;
@@ -473,7 +456,7 @@
/* this is effectively a limit on message queue size for messages
* that require a reply
*/
- parser->limits.max_replies_per_connection = 128;
+ parser->limits.max_replies_per_connection = 1024*8;
}
parser->refcount = 1;
@@ -1137,27 +1120,6 @@
return TRUE;
}
- else if (element_type == ELEMENT_APPARMOR)
- {
- Element *e;
- const char *mode;
-
- if ((e = push_element (parser, ELEMENT_APPARMOR)) == NULL)
- {
- BUS_SET_OOM (error);
- return FALSE;
- }
-
- if (!locate_attributes (parser, "apparmor",
- attribute_names,
- attribute_values,
- error,
- "mode", &mode,
- NULL))
- return FALSE;
-
- return bus_apparmor_set_mode_from_config (mode, error);
- }
else
{
dbus_set_error (error, DBUS_ERROR_FAILED,
@@ -1929,12 +1891,6 @@
must_be_int = TRUE;
parser->limits.auth_timeout = value;
}
- else if (strcmp (name, "pending_fd_timeout") == 0)
- {
- must_be_positive = TRUE;
- must_be_int = TRUE;
- parser->limits.pending_fd_timeout = value;
- }
else if (strcmp (name, "reply_timeout") == 0)
{
must_be_positive = TRUE;
@@ -2096,7 +2052,6 @@
case ELEMENT_STANDARD_SESSION_SERVICEDIRS:
case ELEMENT_STANDARD_SYSTEM_SERVICEDIRS:
case ELEMENT_ALLOW_ANONYMOUS:
- case ELEMENT_APPARMOR:
break;
}
@@ -2265,15 +2220,7 @@
dir = _dbus_directory_open (dirname, error);
if (dir == NULL)
- {
- if (dbus_error_has_name (error, DBUS_ERROR_FILE_NOT_FOUND))
- {
- dbus_error_free (error);
- goto success;
- }
- else
- goto failed;
- }
+ goto failed;
dbus_error_init (&tmp_error);
while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
@@ -2343,7 +2290,6 @@
goto failed;
}
- success:
retval = TRUE;
failed:
@@ -2405,7 +2351,6 @@
case ELEMENT_ALLOW_ANONYMOUS:
case ELEMENT_SELINUX:
case ELEMENT_ASSOCIATE:
- case ELEMENT_APPARMOR:
if (all_whitespace (content))
return TRUE;
else
@@ -2790,7 +2735,7 @@
return table;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
typedef enum
@@ -3152,7 +3097,6 @@
|| a->max_message_unix_fds == b->max_message_unix_fds
|| a->activation_timeout == b->activation_timeout
|| a->auth_timeout == b->auth_timeout
- || a->pending_fd_timeout == b->pending_fd_timeout
|| a->max_completed_connections == b->max_completed_connections
|| a->max_incomplete_connections == b->max_incomplete_connections
|| a->max_connections_per_user == b->max_connections_per_user
@@ -3401,46 +3345,41 @@
DBusList *dirs;
DBusList *link;
DBusString progs;
- DBusString install_root_based;
int i;
- dbus_bool_t ret = FALSE;
+
#ifdef DBUS_WIN
- const char *tmp;
const char *common_progs;
+ char buffer[1024];
+
+ if (_dbus_get_install_root(buffer, sizeof(buffer)))
+ {
+ strcat(buffer,DBUS_DATADIR);
+ strcat(buffer,"/dbus-1/services");
+ test_session_service_dir_matches[0] = buffer;
+ }
#endif
- /* On Unix we don't actually use these, but it's easier to handle the
- * deallocation if we always allocate them, whether needed or not */
- if (!_dbus_string_init (&progs) ||
- !_dbus_string_init (&install_root_based))
- _dbus_assert_not_reached ("OOM allocating strings");
+ /* On Unix we don't actually use this variable, but it's easier to handle the
+ * deallocation if we always allocate it, whether needed or not */
+ if (!_dbus_string_init (&progs))
+ _dbus_assert_not_reached ("OOM allocating progs");
-#ifdef DBUS_WIN
- if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) ||
- !_dbus_string_append (&install_root_based, "/dbus-1/services"))
- goto out;
-
- tmp = _dbus_replace_install_prefix (
- _dbus_string_get_const_data (&install_root_based));
-
- if (tmp == NULL ||
- !_dbus_string_set_length (&install_root_based, 0) ||
- !_dbus_string_append (&install_root_based, tmp))
- goto out;
-
- test_session_service_dir_matches[0] = _dbus_string_get_const_data (
- &install_root_based);
-
+#ifndef DBUS_UNIX
common_progs = _dbus_getenv ("CommonProgramFiles");
if (common_progs)
{
if (!_dbus_string_append (&progs, common_progs))
- goto out;
+ {
+ _dbus_string_free (&progs);
+ return FALSE;
+ }
if (!_dbus_string_append (&progs, "/dbus-1/services"))
- goto out;
-
+ {
+ _dbus_string_free (&progs);
+ return FALSE;
+ }
test_session_service_dir_matches[1] = _dbus_string_get_const_data(&progs);
}
#endif
@@ -3462,7 +3401,8 @@
printf ("error with default session service directories\n");
dbus_free (link->data);
_dbus_list_free_link (link);
- goto out;
+ _dbus_string_free (&progs);
+ return FALSE;
}
dbus_free (link->data);
@@ -3470,10 +3410,10 @@
}
#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))
@@ -3489,7 +3429,8 @@
printf ("more directories parsed than in match set\n");
dbus_free (link->data);
_dbus_list_free_link (link);
- goto out;
+ _dbus_string_free (&progs);
+ return FALSE;
}
if (strcmp (test_session_service_dir_matches[i],
@@ -3500,7 +3441,8 @@
test_session_service_dir_matches[i]);
dbus_free (link->data);
_dbus_list_free_link (link);
- goto out;
+ _dbus_string_free (&progs);
+ return FALSE;
}
++i;
@@ -3513,15 +3455,13 @@
{
printf ("extra data %s in the match set was not matched\n",
test_session_service_dir_matches[i]);
- goto out;
+
+ _dbus_string_free (&progs);
+ return FALSE;
}
-
- ret = TRUE;
-
-out:
- _dbus_string_free (&install_root_based);
+
_dbus_string_free (&progs);
- return ret;
+ return TRUE;
}
static const char *test_system_service_dir_matches[] =
@@ -3603,10 +3543,10 @@
}
#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))
@@ -3680,11 +3620,6 @@
if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
return FALSE;
-#ifndef DBUS_WIN
- if (!process_test_valid_subdir (test_data_dir, "valid-config-files-system", VALID))
- return FALSE;
-#endif
-
if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
return FALSE;
@@ -3694,5 +3629,5 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/connection.c b/bus/connection.c
index 95e20a6..d69758c 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -30,12 +30,9 @@
#include "signals.h"
#include "expirelist.h"
#include "selinux.h"
-#include "apparmor.h"
#include <dbus/dbus-list.h>
#include <dbus/dbus-hash.h>
#include <dbus/dbus-timeout.h>
-#include <dbus/dbus-connection-internal.h>
-#include <dbus/dbus-internals.h>
/* Trim executed commands to this length; we want to keep logs readable */
#define MAX_LOG_COMMAND_LEN 50
@@ -66,11 +63,6 @@
int stamp; /**< Incrementing number */
BusExpireList *pending_replies; /**< List of pending replies */
- /** List of all monitoring connections, a subset of completed.
- * Each member is a #DBusConnection. */
- DBusList *monitors;
- BusMatchmaker *monitor_matchmaker;
-
#ifdef DBUS_ENABLE_STATS
int total_match_rules;
int peak_match_rules;
@@ -101,7 +93,6 @@
char *cached_loginfo_string;
BusSELinuxID *selinux_id;
- BusAppArmorConfinement *apparmor_confinement;
long connection_tv_sec; /**< Time when we connected (seconds component) */
long connection_tv_usec; /**< Time when we connected (microsec component) */
@@ -111,11 +102,6 @@
int peak_match_rules;
int peak_bus_names;
#endif
- int n_pending_unix_fds;
- DBusTimeout *pending_unix_fds_timeout;
-
- /** non-NULL if and only if this is a monitor */
- DBusList *link_in_monitors;
} BusConnectionData;
static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
@@ -135,7 +121,6 @@
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
return bus_context_get_loop (d->connections->context);
}
@@ -283,29 +268,9 @@
dbus_connection_set_dispatch_status_function (connection,
NULL, NULL, NULL);
-
- if (d->pending_unix_fds_timeout)
- {
- _dbus_loop_remove_timeout (bus_context_get_loop (d->connections->context),
- d->pending_unix_fds_timeout);
- _dbus_timeout_unref (d->pending_unix_fds_timeout);
- }
- d->pending_unix_fds_timeout = NULL;
- _dbus_connection_set_pending_fds_function (connection, NULL, NULL);
bus_connection_remove_transactions (connection);
- if (d->link_in_monitors != NULL)
- {
- BusMatchmaker *mm = d->connections->monitor_matchmaker;
-
- if (mm != NULL)
- bus_matchmaker_disconnected (mm, connection);
-
- _dbus_list_remove_link (&d->connections->monitors, d->link_in_monitors);
- d->link_in_monitors = NULL;
- }
-
if (d->link_in_connection_list != NULL)
{
if (d->name != NULL)
@@ -328,10 +293,6 @@
_dbus_list_remove_link (&d->connections->incomplete, d->link_in_connection_list);
d->link_in_connection_list = NULL;
d->connections->n_incomplete -= 1;
-
- /* If we have dropped below the max. number of incomplete
- * connections, start accept()ing again */
- bus_context_check_all_watches (d->connections->context);
}
_dbus_assert (d->connections->n_incomplete >= 0);
@@ -443,9 +404,6 @@
if (d->selinux_id)
bus_selinux_id_unref (d->selinux_id);
-
- if (d->apparmor_confinement)
- bus_apparmor_confinement_unref (d->apparmor_confinement);
dbus_free (d->cached_loginfo_string);
@@ -539,10 +497,7 @@
}
_dbus_assert (connections->n_incomplete == 0);
-
- /* drop all monitors */
- _dbus_list_clear (&connections->monitors);
-
+
/* drop all real connections */
while (connections->completed != NULL)
{
@@ -566,10 +521,7 @@
_dbus_timeout_unref (connections->expire_timeout);
_dbus_hash_table_unref (connections->completed_by_user);
-
- if (connections->monitor_matchmaker != NULL)
- bus_matchmaker_unref (connections->monitor_matchmaker);
-
+
dbus_free (connections);
dbus_connection_free_data_slot (&connection_data_slot);
@@ -636,45 +588,6 @@
return FALSE;
}
-static void
-check_pending_fds_cb (DBusConnection *connection)
-{
- BusConnectionData *d = BUS_CONNECTION_DATA (connection);
- int n_pending_unix_fds_old;
- int n_pending_unix_fds_new;
-
- _dbus_assert(d != NULL);
-
- n_pending_unix_fds_old = d->n_pending_unix_fds;
- n_pending_unix_fds_new = _dbus_connection_get_pending_fds_count (connection);
-
- _dbus_verbose ("Pending fds count changed on connection %p: %d -> %d\n",
- connection, n_pending_unix_fds_old, n_pending_unix_fds_new);
-
- if (n_pending_unix_fds_old == 0 && n_pending_unix_fds_new > 0)
- {
- _dbus_timeout_set_interval (d->pending_unix_fds_timeout,
- bus_context_get_pending_fd_timeout (d->connections->context));
- _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, TRUE);
- }
-
- if (n_pending_unix_fds_old > 0 && n_pending_unix_fds_new == 0)
- {
- _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, FALSE);
- }
-
-
- d->n_pending_unix_fds = n_pending_unix_fds_new;
-}
-
-static dbus_bool_t
-pending_unix_fds_timeout_cb (void *data)
-{
- DBusConnection *connection = data;
- dbus_connection_close (connection);
- return TRUE;
-}
-
dbus_bool_t
bus_connections_setup_connection (BusConnections *connections,
DBusConnection *connection)
@@ -724,19 +637,6 @@
goto out;
}
- d->apparmor_confinement = bus_apparmor_init_connection_confinement (connection,
- &error);
- if (dbus_error_is_set (&error))
- {
- /* This is a bit bogus because we pretend all errors
- * are OOM; this is done because we know that in bus.c
- * an OOM error disconnects the connection, which is
- * the same thing we want on any other error.
- */
- dbus_error_free (&error);
- goto out;
- }
-
if (!dbus_connection_set_watch_functions (connection,
add_connection_watch,
remove_connection_watch,
@@ -783,38 +683,36 @@
}
}
- /* Setup pending fds timeout (see #80559) */
- d->pending_unix_fds_timeout = _dbus_timeout_new (100, /* irrelevant */
- pending_unix_fds_timeout_cb,
- connection, NULL);
- if (d->pending_unix_fds_timeout == NULL)
- goto out;
-
- _dbus_timeout_set_enabled (d->pending_unix_fds_timeout, FALSE);
- if (!_dbus_loop_add_timeout (bus_context_get_loop (connections->context),
- d->pending_unix_fds_timeout))
- goto out;
-
- _dbus_connection_set_pending_fds_function (connection,
- (DBusPendingFdsChangeFunction) check_pending_fds_cb,
- connection);
-
_dbus_list_append_link (&connections->incomplete, d->link_in_connection_list);
connections->n_incomplete += 1;
dbus_connection_ref (connection);
+ /* Note that we might disconnect ourselves here, but it only takes
+ * effect on return to the main loop. We call this to free up
+ * expired connections if possible, and to queue the timeout for our
+ * own expiration.
+ */
bus_connections_expire_incomplete (connections);
- /* The listening socket is removed from the main loop,
- * i.e. does not accept(), while n_incomplete is at its
- * maximum value; so we shouldn't get here in that case */
- _dbus_assert (connections->n_incomplete <=
- bus_context_get_max_incomplete_connections (connections->context));
-
- /* If we have the maximum number of incomplete connections,
- * stop accept()ing any more, to avert a DoS. See fd.o #80919 */
- bus_context_check_all_watches (d->connections->context);
+ /* And we might also disconnect ourselves here, but again it
+ * only takes effect on return to main loop.
+ */
+ if (connections->n_incomplete >
+ bus_context_get_max_incomplete_connections (connections->context))
+ {
+ _dbus_verbose ("Number of incomplete connections exceeds max, dropping oldest one\n");
+
+ _dbus_assert (connections->incomplete != NULL);
+ /* Disconnect the oldest unauthenticated connection. FIXME
+ * would it be more secure to drop a *random* connection? This
+ * algorithm seems to mean that if someone can create new
+ * connections quickly enough, they can keep anyone else from
+ * completing authentication. But random may or may not really
+ * help with that, a more elaborate solution might be required.
+ */
+ dbus_connection_close (connections->incomplete->data);
+ }
retval = TRUE;
@@ -824,10 +722,6 @@
if (d->selinux_id)
bus_selinux_id_unref (d->selinux_id);
d->selinux_id = NULL;
-
- if (d->apparmor_confinement)
- bus_apparmor_confinement_unref (d->apparmor_confinement);
- d->apparmor_confinement = NULL;
if (!dbus_connection_set_watch_functions (connection,
NULL, NULL, NULL,
@@ -850,13 +744,6 @@
dbus_connection_set_dispatch_status_function (connection,
NULL, NULL, NULL);
- if (d->pending_unix_fds_timeout)
- _dbus_timeout_unref (d->pending_unix_fds_timeout);
-
- d->pending_unix_fds_timeout = NULL;
-
- _dbus_connection_set_pending_fds_function (connection, NULL, NULL);
-
if (d->link_in_connection_list != NULL)
{
_dbus_assert (d->link_in_connection_list->next == NULL);
@@ -912,14 +799,6 @@
if (elapsed >= (double) auth_timeout)
{
- /* Unfortunately, we can't identify the connection: it doesn't
- * have a unique name yet, we don't know its uid/pid yet,
- * and so on. */
- bus_context_log (connections->context, DBUS_SYSTEM_LOG_WARNING,
- "Connection has not authenticated soon enough, closing it "
- "(auth_timeout=%dms, elapsed: %.0fms)",
- auth_timeout, elapsed);
-
_dbus_verbose ("Timing out authentication for connection %p\n", connection);
dbus_connection_close (connection);
}
@@ -1017,7 +896,6 @@
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
if (!bus_connection_is_active (connection))
return "inactive";
@@ -1229,19 +1107,6 @@
return d->selinux_id;
}
-BusAppArmorConfinement*
-bus_connection_dup_apparmor_confinement (DBusConnection *connection)
-{
- BusConnectionData *d;
-
- d = BUS_CONNECTION_DATA (connection);
-
- _dbus_assert (d != NULL);
-
- bus_apparmor_confinement_ref (d->apparmor_confinement);
- return d->apparmor_confinement;
-}
-
/**
* Checks whether the connection is registered with the message bus.
*
@@ -1254,9 +1119,8 @@
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
- return d->name != NULL;
+ return d != NULL && d->name != NULL;
}
dbus_bool_t
@@ -1323,10 +1187,6 @@
_dbus_assert (d != NULL);
_dbus_assert (d->oom_message != NULL);
- bus_context_log (d->connections->context, DBUS_SYSTEM_LOG_WARNING,
- "dbus-daemon transaction failed (OOM), sending error to "
- "sender %s", bus_connection_get_loginfo (connection));
-
/* should always succeed since we set it to a placeholder earlier */
if (!dbus_message_set_reply_serial (d->oom_message,
dbus_message_get_serial (in_reply_to)))
@@ -1559,10 +1419,6 @@
_dbus_assert (d->connections->n_incomplete >= 0);
_dbus_assert (d->connections->n_completed > 0);
- /* If we have dropped below the max. number of incomplete
- * connections, start accept()ing again */
- bus_context_check_all_watches (d->connections->context);
-
/* See if we can remove the timeout */
bus_connections_expire_incomplete (d->connections);
@@ -1579,42 +1435,6 @@
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)
{
@@ -1698,12 +1518,7 @@
DBUS_ERROR_NO_REPLY))
goto out;
- /* If you change these messages, adjust test/dbus-daemon.c to match */
- if (pending->will_send_reply == NULL)
- errmsg = "Message recipient disconnected from message bus without replying";
- else
- errmsg = "Message did not receive a reply (timeout by message bus)";
-
+ errmsg = "Message did not receive a reply (timeout by message bus)";
dbus_message_iter_init_append (message, &iter);
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &errmsg))
goto out;
@@ -2175,86 +1990,10 @@
return transaction->context;
}
-/**
- * Reserve enough memory to capture the given message if the
- * transaction goes through.
- */
-dbus_bool_t
-bus_transaction_capture (BusTransaction *transaction,
- DBusConnection *sender,
- DBusMessage *message)
+BusConnections*
+bus_transaction_get_connections (BusTransaction *transaction)
{
- BusConnections *connections;
- BusMatchmaker *mm;
- DBusList *link;
- DBusList *recipients = NULL;
- dbus_bool_t ret = FALSE;
-
- connections = bus_context_get_connections (transaction->context);
-
- /* shortcut: don't compose the message unless someone wants it */
- if (connections->monitors == NULL)
- return TRUE;
-
- mm = connections->monitor_matchmaker;
- /* This is non-null if there has ever been a monitor - we don't GC it.
- * There's little point, since there is up to 1 per process. */
- _dbus_assert (mm != NULL);
-
- if (!bus_matchmaker_get_recipients (mm, connections, sender, NULL, message,
- &recipients))
- goto out;
-
- for (link = _dbus_list_get_first_link (&recipients);
- link != NULL;
- link = _dbus_list_get_next_link (&recipients, link))
- {
- DBusConnection *recipient = link->data;
-
- if (!bus_transaction_send (transaction, recipient, message))
- goto out;
- }
-
- ret = TRUE;
-
-out:
- _dbus_list_clear (&recipients);
- return ret;
-}
-
-dbus_bool_t
-bus_transaction_capture_error_reply (BusTransaction *transaction,
- const DBusError *error,
- DBusMessage *in_reply_to)
-{
- BusConnections *connections;
- DBusMessage *reply;
- dbus_bool_t ret = FALSE;
-
- _dbus_assert (error != NULL);
- _DBUS_ASSERT_ERROR_IS_SET (error);
-
- connections = bus_context_get_connections (transaction->context);
-
- /* shortcut: don't compose the message unless someone wants it */
- if (connections->monitors == NULL)
- return TRUE;
-
- reply = dbus_message_new_error (in_reply_to,
- error->name,
- error->message);
-
- if (reply == NULL)
- return FALSE;
-
- if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS))
- goto out;
-
- ret = bus_transaction_capture (transaction, NULL, reply);
-
-out:
- dbus_message_unref (reply);
- return ret;
+ return bus_context_get_connections (transaction->context);
}
dbus_bool_t
@@ -2262,8 +2001,6 @@
DBusConnection *connection,
DBusMessage *message)
{
- DBusError error = DBUS_ERROR_INIT;
-
/* We have to set the sender to the driver, and have
* to check security policy since it was not done in
* dispatch.c
@@ -2288,34 +2025,14 @@
/* bus driver never wants a reply */
dbus_message_set_no_reply (message, TRUE);
-
- /* Capture it for monitors, even if the real recipient's receive policy
- * does not allow it to receive this message from us (which would be odd).
- */
- if (!bus_transaction_capture (transaction, NULL, message))
- return FALSE;
-
- /* If security policy doesn't allow the message, we would silently
- * eat it; the driver doesn't care about getting a reply. However,
- * if we're actively capturing messages, it's nice to log that we
- * tried to send it and did not allow ourselves to do so.
+
+ /* If security policy doesn't allow the message, we silently
+ * eat it; the driver doesn't care about getting a reply.
*/
if (!bus_context_check_security_policy (bus_transaction_get_context (transaction),
transaction,
- NULL, connection, connection, message, &error))
- {
- if (!bus_transaction_capture_error_reply (transaction, &error, message))
- {
- bus_context_log (transaction->context, DBUS_SYSTEM_LOG_WARNING,
- "message from dbus-daemon rejected but not enough "
- "memory to capture it");
- }
-
- /* This is not fatal to the transaction so silently eat the disallowed
- * message (see reasoning above) */
- dbus_error_free (&error);
- return TRUE;
- }
+ NULL, connection, connection, message, NULL))
+ return TRUE;
return bus_transaction_send (transaction, connection, message);
}
@@ -2409,16 +2126,6 @@
}
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)
{
@@ -2456,10 +2163,14 @@
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);
- transaction_free (transaction);
+ free_cancel_hooks (transaction);
+
+ dbus_free (transaction);
}
static void
@@ -2513,7 +2224,11 @@
while ((connection = _dbus_list_pop_first (&transaction->connections)))
connection_execute_transaction (connection, transaction);
- transaction_free (transaction);
+ _dbus_assert (transaction->connections == NULL);
+
+ free_cancel_hooks (transaction);
+
+ dbus_free (transaction);
}
static void
@@ -2601,6 +2316,7 @@
return TRUE;
}
+#ifdef DBUS_ENABLE_STATS
int
bus_connections_get_n_active (BusConnections *connections)
{
@@ -2613,7 +2329,6 @@
return connections->n_incomplete;
}
-#ifdef DBUS_ENABLE_STATS
int
bus_connections_get_total_match_rules (BusConnections *connections)
{
@@ -2656,8 +2371,6 @@
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
-
return d->peak_match_rules;
}
@@ -2667,145 +2380,6 @@
BusConnectionData *d;
d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
-
return d->peak_bus_names;
}
#endif /* DBUS_ENABLE_STATS */
-
-dbus_bool_t
-bus_connection_is_monitor (DBusConnection *connection)
-{
- BusConnectionData *d;
-
- d = BUS_CONNECTION_DATA (connection);
- _dbus_assert(d != NULL);
-
- return d->link_in_monitors != NULL;
-}
-
-static dbus_bool_t
-bcd_add_monitor_rules (BusConnectionData *d,
- DBusConnection *connection,
- DBusList **rules)
-{
- BusMatchmaker *mm = d->connections->monitor_matchmaker;
- DBusList *iter;
-
- if (mm == NULL)
- {
- mm = bus_matchmaker_new ();
-
- if (mm == NULL)
- return FALSE;
-
- d->connections->monitor_matchmaker = mm;
- }
-
- for (iter = _dbus_list_get_first_link (rules);
- iter != NULL;
- iter = _dbus_list_get_next_link (rules, iter))
- {
- if (!bus_matchmaker_add_rule (mm, iter->data))
- {
- bus_matchmaker_disconnected (mm, connection);
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static void
-bcd_drop_monitor_rules (BusConnectionData *d,
- DBusConnection *connection)
-{
- BusMatchmaker *mm = d->connections->monitor_matchmaker;
-
- if (mm != NULL)
- bus_matchmaker_disconnected (mm, connection);
-}
-
-dbus_bool_t
-bus_connection_be_monitor (DBusConnection *connection,
- BusTransaction *transaction,
- DBusList **rules,
- DBusError *error)
-{
- BusConnectionData *d;
- DBusList *link;
- DBusList *tmp;
- DBusList *iter;
-
- d = BUS_CONNECTION_DATA (connection);
- _dbus_assert (d != NULL);
-
- link = _dbus_list_alloc_link (connection);
-
- if (link == NULL)
- {
- BUS_SET_OOM (error);
- return FALSE;
- }
-
- if (!bcd_add_monitor_rules (d, connection, rules))
- {
- _dbus_list_free_link (link);
- BUS_SET_OOM (error);
- return FALSE;
- }
-
- /* release all its names */
- if (!_dbus_list_copy (&d->services_owned, &tmp))
- {
- bcd_drop_monitor_rules (d, connection);
- _dbus_list_free_link (link);
- BUS_SET_OOM (error);
- return FALSE;
- }
-
- for (iter = _dbus_list_get_first_link (&tmp);
- iter != NULL;
- iter = _dbus_list_get_next_link (&tmp, iter))
- {
- BusService *service = iter->data;
-
- /* This call is transactional: if there isn't enough memory to
- * do everything, then the service gets all its names back when
- * the transaction is cancelled due to OOM. */
- if (!bus_service_remove_owner (service, connection, transaction, error))
- {
- bcd_drop_monitor_rules (d, connection);
- _dbus_list_free_link (link);
- _dbus_list_clear (&tmp);
- return FALSE;
- }
- }
-
- /* We have now done everything that can fail, so there is no problem
- * with doing the irrevocable stuff. */
-
- _dbus_list_clear (&tmp);
-
- bus_context_log (transaction->context, DBUS_SYSTEM_LOG_INFO,
- "Connection %s (%s) became a monitor.", d->name,
- d->cached_loginfo_string);
-
- if (d->n_match_rules > 0)
- {
- BusMatchmaker *mm;
-
- mm = bus_context_get_matchmaker (d->connections->context);
- bus_matchmaker_disconnected (mm, connection);
- }
-
- /* flag it as a monitor */
- d->link_in_monitors = link;
- _dbus_list_append_link (&d->connections->monitors, link);
-
- /* it isn't allowed to reply, and it is no longer relevant whether it
- * receives replies */
- bus_connection_drop_pending_replies (d->connections, connection);
-
- return TRUE;
-}
diff --git a/bus/connection.h b/bus/connection.h
index 8c68d0a..c936021 100644
--- a/bus/connection.h
+++ b/bus/connection.h
@@ -45,8 +45,6 @@
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);
@@ -54,7 +52,6 @@
BusMatchmaker* bus_connection_get_matchmaker (DBusConnection *connection);
const char * bus_connection_get_loginfo (DBusConnection *connection);
BusSELinuxID* bus_connection_get_selinux_id (DBusConnection *connection);
-BusAppArmorConfinement* bus_connection_dup_apparmor_confinement (DBusConnection *connection);
dbus_bool_t bus_connections_check_limits (BusConnections *connections,
DBusConnection *requesting_completion,
DBusError *error);
@@ -117,27 +114,16 @@
DBusError *error);
BusClientPolicy* bus_connection_get_policy (DBusConnection *connection);
-dbus_bool_t bus_connection_is_monitor (DBusConnection *connection);
-dbus_bool_t bus_connection_be_monitor (DBusConnection *connection,
- BusTransaction *transaction,
- DBusList **rules,
- DBusError *error);
-
/* transaction API so we can send or not send a block of messages as a whole */
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);
-dbus_bool_t bus_transaction_capture (BusTransaction *transaction,
- DBusConnection *connection,
- DBusMessage *message);
-dbus_bool_t bus_transaction_capture_error_reply (BusTransaction *transaction,
- const DBusError *error,
- DBusMessage *in_reply_to);
dbus_bool_t bus_transaction_send_from_driver (BusTransaction *transaction,
DBusConnection *connection,
DBusMessage *message);
@@ -152,10 +138,9 @@
void *data,
DBusFreeFunction free_data_function);
+/* called by stats.c, only present if DBUS_ENABLE_STATS */
int bus_connections_get_n_active (BusConnections *connections);
int bus_connections_get_n_incomplete (BusConnections *connections);
-
-/* called by stats.c, only present if DBUS_ENABLE_STATS */
int bus_connections_get_total_match_rules (BusConnections *connections);
int bus_connections_get_peak_match_rules (BusConnections *connections);
int bus_connections_get_peak_match_rules_per_conn (BusConnections *connections);
diff --git a/bus/dbus.service.in b/bus/dbus.service.in
index 3bc4726..160947c 100644
--- a/bus/dbus.service.in
+++ b/bus/dbus.service.in
@@ -1,7 +1,7 @@
[Unit]
Description=D-Bus System Message Bus
-Documentation=man:dbus-daemon(1)
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 bfeb72e..ae441c5 100644
--- a/bus/desktop-file.c
+++ b/bus/desktop-file.c
@@ -688,12 +688,6 @@
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 e405625..58e78e8 100644
--- a/bus/desktop-file.h
+++ b/bus/desktop-file.h
@@ -34,6 +34,7 @@
#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
new file mode 100644
index 0000000..b38d7d1
--- /dev/null
+++ b/bus/dir-watch-dnotify.c
@@ -0,0 +1,93 @@
+/* -*- 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 ce19fdc..2e9be98 100644
--- a/bus/dir-watch-inotify.c
+++ b/bus/dir-watch-inotify.c
@@ -22,15 +22,11 @@
*
*/
-/* 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>
@@ -38,7 +34,6 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
-#include <dbus/dbus-sysdeps-unix.h>
#include <dbus/dbus-watch.h>
#include "dir-watch.h"
@@ -60,30 +55,32 @@
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);
return TRUE;
}
@@ -237,11 +234,6 @@
_dbus_warn ("Cannot initialize inotify\n");
goto out;
}
-
- /* In the inotify_init1 case this is unnecessary but harmless,
- * in the other cases it's necessary */
- _dbus_fd_set_close_on_exec (inotify_fd);
-
loop = bus_context_get_loop (context);
_dbus_loop_ref (loop);
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c
index c1e8324..ac6290c 100644
--- a/bus/dir-watch-kqueue.c
+++ b/bus/dir-watch-kqueue.c
@@ -38,7 +38,6 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-list.h>
-#include <dbus/dbus-sysdeps-unix.h>
#include "dir-watch.h"
#define MAX_DIRS_TO_WATCH 128
@@ -74,12 +73,12 @@
{
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);
@@ -88,49 +87,11 @@
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)
{
@@ -138,61 +99,38 @@
if (kq < 0)
{
_dbus_warn ("Cannot create kqueue; error '%s'\n", _dbus_strerror (errno));
- goto out;
- }
+ goto out;
+ }
- loop = bus_context_get_loop (context);
- _dbus_loop_ref (loop);
+ loop = bus_context_get_loop (context);
- watch = _dbus_watch_new (kq, DBUS_WATCH_READABLE, TRUE,
- _handle_kqueue_watch, NULL, NULL);
+ 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 (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");
- goto out2;
- }
-
- if (!_dbus_register_shutdown_func (_shutdown_kqueue, NULL))
- {
- _dbus_warn ("Unable to register shutdown function");
- goto out3;
- }
+ 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;
+ }
}
- return 1;
-
-out3:
- _dbus_loop_remove_watch (loop, watch);
-
-out2:
- if (watch)
- {
- _dbus_watch_invalidate (watch);
- _dbus_watch_unref (watch);
- watch = NULL;
- }
-
-out1:
- if (kq >= 0)
- {
- close (kq);
- kq = -1;
- }
- if (loop)
- {
- _dbus_loop_unref (loop);
- loop = NULL;
- }
+ ret = 1;
out:
- return 0;
+ return ret;
}
void
@@ -201,11 +139,8 @@
int new_fds[MAX_DIRS_TO_WATCH];
char *new_dirs[MAX_DIRS_TO_WATCH];
DBusList *link;
- int i, j, fd;
+ int i, j, f, fd;
struct kevent ev;
-#ifdef O_CLOEXEC
- dbus_bool_t cloexec_done = 0;
-#endif
if (!_init_kqueue (context))
goto out;
@@ -234,12 +169,12 @@
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
@@ -250,10 +185,10 @@
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++)
@@ -261,17 +196,9 @@
if (new_fds[i] == -1)
{
/* FIXME - less lame error handling for failing to add a watch;
- * we may need to sleep.
- */
-#ifdef O_CLOEXEC
- fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC);
- cloexec_done = (fd >= 0);
-
- if (fd < 0 && errno == EINVAL)
-#endif
- {
- fd = open (new_dirs[i], O_RDONLY);
- }
+ * we may need to sleep.
+ */
+ fd = open (new_dirs[i], O_RDONLY);
if (fd < 0)
{
if (errno != ENOENT)
@@ -286,12 +213,6 @@
continue;
}
}
-#ifdef O_CLOEXEC
- if (!cloexec_done)
-#endif
- {
- _dbus_fd_set_close_on_exec (fd);
- }
EV_SET (&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
NOTE_DELETE | NOTE_EXTEND | NOTE_WRITE | NOTE_RENAME, 0, 0);
@@ -302,18 +223,18 @@
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 edfa1b4..7a96f9d 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -34,7 +34,6 @@
#include "signals.h"
#include "test.h"
#include <dbus/dbus-internals.h>
-#include <dbus/dbus-misc.h>
#include <string.h>
#ifdef HAVE_UNIX_FD_PASSING
@@ -47,13 +46,6 @@
* dbus_connection_open_private() does not block. */
#define TEST_DEBUG_PIPE "debug-pipe:name=test-server"
-static inline const char *
-nonnull (const char *maybe_null,
- const char *if_null)
-{
- return (maybe_null ? maybe_null : if_null);
-}
-
static dbus_bool_t
send_one_message (DBusConnection *connection,
BusContext *context,
@@ -63,47 +55,17 @@
BusTransaction *transaction,
DBusError *error)
{
- DBusError stack_error = DBUS_ERROR_INIT;
-
if (!bus_context_check_security_policy (context, transaction,
sender,
addressed_recipient,
connection,
message,
- &stack_error))
- {
- if (!bus_transaction_capture_error_reply (transaction, &stack_error,
- message))
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "broadcast rejected, but not enough "
- "memory to tell monitors");
- }
-
- dbus_error_free (&stack_error);
- return TRUE; /* don't send it but don't return an error either */
- }
+ NULL))
+ return TRUE; /* silently don't send it */
if (dbus_message_contains_unix_fds(message) &&
!dbus_connection_can_send_type(connection, DBUS_TYPE_UNIX_FD))
- {
- dbus_set_error (&stack_error, DBUS_ERROR_NOT_SUPPORTED,
- "broadcast cannot be delivered to %s (%s) because "
- "it does not support receiving Unix fds",
- bus_connection_get_name (connection),
- bus_connection_get_loginfo (connection));
-
- if (!bus_transaction_capture_error_reply (transaction, &stack_error,
- message))
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "broadcast with Unix fd not delivered, but not "
- "enough memory to tell monitors");
- }
-
- dbus_error_free (&stack_error);
- return TRUE; /* don't send it but don't return an error either */
- }
+ return TRUE; /* silently don't send it */
if (!bus_transaction_send (transaction,
connection,
@@ -170,7 +132,7 @@
}
/* Now dispatch to others who look interested in this message */
- connections = bus_context_get_connections (context);
+ connections = bus_transaction_get_connections (transaction);
dbus_error_init (&tmp_error);
matchmaker = bus_context_get_matchmaker (context);
@@ -237,54 +199,6 @@
/* Ref connection in case we disconnect it at some point in here */
dbus_connection_ref (connection);
- /* Monitors aren't meant to send messages to us. */
- if (bus_connection_is_monitor (connection))
- {
- sender = bus_connection_get_name (connection);
-
- /* should never happen */
- if (sender == NULL)
- sender = "(unknown)";
-
- if (dbus_message_is_signal (message,
- DBUS_INTERFACE_LOCAL,
- "Disconnected"))
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_INFO,
- "Monitoring connection %s closed.", sender);
- bus_connection_disconnected (connection);
- goto out;
- }
- else
- {
- /* Monitors are not allowed to send messages, because that
- * probably indicates that the monitor is incorrectly replying
- * to its eavesdropped messages, and we want the authors of
- * such monitors to fix them.
- */
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "Monitoring connection %s (%s) is not allowed "
- "to send messages; closing it. Please fix the "
- "monitor to not do that. "
- "(message type=\"%s\" interface=\"%s\" "
- "member=\"%s\" error name=\"%s\" "
- "destination=\"%s\")",
- sender, bus_connection_get_loginfo (connection),
- dbus_message_type_to_string (
- dbus_message_get_type (message)),
- nonnull (dbus_message_get_interface (message),
- "(unset)"),
- nonnull (dbus_message_get_member (message),
- "(unset)"),
- nonnull (dbus_message_get_error_name (message),
- "(unset)"),
- nonnull (dbus_message_get_destination (message),
- DBUS_SERVICE_DBUS));
- dbus_connection_close (connection);
- goto out;
- }
- }
-
service_name = dbus_message_get_destination (message);
#ifdef DBUS_ENABLE_VERBOSE_MODE
@@ -321,10 +235,6 @@
{
/* DBusConnection also handles some of these automatically, we leave
* it to do so.
- *
- * FIXME: this means monitors won't get the opportunity to see
- * non-signals with NULL destination, or their replies (which in
- * practice are UnknownMethod errors)
*/
result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
goto out;
@@ -350,30 +260,13 @@
BUS_SET_OOM (&error);
goto out;
}
- }
- else
- {
- /* For monitors' benefit: we don't want the sender to be able to
- * trick the monitor by supplying a forged sender, and we also
- * don't want the message to have no sender at all. */
- if (!dbus_message_set_sender (message, ":not.active.yet"))
- {
- BUS_SET_OOM (&error);
- goto out;
- }
- }
- /* We need to refetch the service name here, because
- * dbus_message_set_sender can cause the header to be
- * reallocated, and thus the service_name pointer will become
- * invalid.
- */
- service_name = dbus_message_get_destination (message);
-
- if (!bus_transaction_capture (transaction, connection, message))
- {
- BUS_SET_OOM (&error);
- goto out;
+ /* We need to refetch the service name here, because
+ * dbus_message_set_sender can cause the header to be
+ * reallocated, and thus the service_name pointer will become
+ * invalid.
+ */
+ service_name = dbus_message_get_destination (message);
}
if (service_name &&
@@ -453,10 +346,14 @@
out:
if (dbus_error_is_set (&error))
{
- /* Even if we disconnected it, pretend to send it any pending error
- * messages so that monitors can observe them.
- */
- if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
+ if (!dbus_connection_get_is_connected (connection))
+ {
+ /* If we disconnected it, we won't bother to send it any error
+ * messages.
+ */
+ _dbus_verbose ("Not sending error to connection we disconnected\n");
+ }
+ else if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
{
bus_connection_send_oom_error (connection, message);
@@ -531,12 +428,10 @@
NULL);
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
-#include "stats.h"
-
/* This is used to know whether we need to block in order to finish
* sending a message, or whether the initial dbus_connection_send()
* already flushed the queue.
@@ -653,7 +548,6 @@
const char *expected_service_name;
dbus_bool_t failed;
DBusConnection *skip_connection;
- BusContext *context;
} CheckServiceOwnerChangedData;
static dbus_bool_t
@@ -675,14 +569,9 @@
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
- block_connection_until_message_from_bus (d->context, connection, "NameOwnerChanged");
- message = pop_message_waiting_for_memory (connection);
- if (message == NULL)
- {
- _dbus_warn ("Did not receive a message on %p, expecting %s\n",
- connection, "NameOwnerChanged");
- goto out;
- }
+ _dbus_warn ("Did not receive a message on %p, expecting %s\n",
+ connection, "NameOwnerChanged");
+ goto out;
}
else if (!dbus_message_is_signal (message,
DBUS_INTERFACE_DBUS,
@@ -795,7 +684,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -948,6 +836,8 @@
return TRUE;
}
+ dbus_connection_unref (connection);
+
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
@@ -1024,8 +914,6 @@
socd.expected_service_name = name;
socd.failed = FALSE;
socd.skip_connection = connection; /* we haven't done AddMatch so won't get it ourselves */
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -1038,14 +926,9 @@
message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
- block_connection_until_message_from_bus (context, connection, "signal NameAcquired");
- message = pop_message_waiting_for_memory (connection);
- if (message == NULL)
- {
- _dbus_warn ("Expecting %s, got nothing\n",
+ _dbus_warn ("Expecting %s, got nothing\n",
"NameAcquired");
- goto out;
- }
+ goto out;
}
if (! dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
"NameAcquired"))
@@ -1102,8 +985,6 @@
if (name_message)
dbus_message_unref (name_message);
- dbus_connection_unref (connection);
-
return retval;
}
@@ -1277,12 +1158,6 @@
{
; /* good, this is a valid response */
}
-#ifdef DBUS_WIN
- else if (dbus_message_is_error (message, DBUS_ERROR_FAILED))
- {
- /* this is OK, Unix uids aren't meaningful on Windows */
- }
-#endif
else
{
warn_unexpected (connection, message, "not this error");
@@ -1352,9 +1227,7 @@
dbus_bool_t retval;
DBusError error;
const char *base_service_name;
-#ifdef DBUS_UNIX
dbus_uint32_t pid;
-#endif
retval = FALSE;
dbus_error_init (&error);
@@ -1433,20 +1306,9 @@
#endif
else
{
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
- defined(__linux__) || \
- defined(__OpenBSD__)
- /* In principle NetBSD should also be in that list, but
- * its implementation of PID-passing doesn't work
- * over a socketpair() as used in the debug-pipe transport.
- * We test this functionality in a more realistic situation
- * in test/dbus-daemon.c. */
warn_unexpected (connection, message, "not this error");
goto out;
-#else
- _dbus_verbose ("does not support GetConnectionUnixProcessID but perhaps that's OK?\n");
-#endif
}
}
else
@@ -1524,21 +1386,20 @@
* but the correct thing may include OOM errors.
*/
static dbus_bool_t
-check_add_match (BusContext *context,
- DBusConnection *connection,
- const char *rule)
+check_add_match_all (BusContext *context,
+ DBusConnection *connection)
{
DBusMessage *message;
dbus_bool_t retval;
dbus_uint32_t serial;
DBusError error;
+ const char *empty = "";
retval = FALSE;
dbus_error_init (&error);
message = NULL;
- _dbus_verbose ("check_add_match for connection %p, rule %s\n",
- connection, rule);
+ _dbus_verbose ("check_add_match_all for %p\n", connection);
message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
@@ -1548,7 +1409,8 @@
if (message == NULL)
return TRUE;
- if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &rule,
+ /* empty string match rule matches everything */
+ if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &empty,
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
@@ -1652,132 +1514,6 @@
return retval;
}
-#ifdef DBUS_ENABLE_STATS
-/* returns TRUE if the correct thing happens,
- * but the correct thing may include OOM errors.
- */
-static dbus_bool_t
-check_get_all_match_rules (BusContext *context,
- DBusConnection *connection)
-{
- DBusMessage *message;
- dbus_bool_t retval;
- dbus_uint32_t serial;
- DBusError error;
-
- retval = FALSE;
- dbus_error_init (&error);
- message = NULL;
-
- _dbus_verbose ("check_get_all_match_rules for connection %p\n",
- connection);
-
- message = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- BUS_INTERFACE_STATS,
- "GetAllMatchRules");
-
- if (message == NULL)
- return TRUE;
-
- if (!dbus_connection_send (connection, message, &serial))
- {
- dbus_message_unref (message);
- return TRUE;
- }
-
- dbus_message_unref (message);
- message = NULL;
-
- dbus_connection_ref (connection); /* because we may get disconnected */
-
- /* send our message */
- bus_test_run_clients_loop (SEND_PENDING (connection));
-
- if (!dbus_connection_get_is_connected (connection))
- {
- _dbus_verbose ("connection was disconnected\n");
-
- dbus_connection_unref (connection);
-
- return TRUE;
- }
-
- block_connection_until_message_from_bus (context, connection, "reply to AddMatch");
-
- if (!dbus_connection_get_is_connected (connection))
- {
- _dbus_verbose ("connection was disconnected\n");
-
- dbus_connection_unref (connection);
-
- return TRUE;
- }
-
- dbus_connection_unref (connection);
-
- message = pop_message_waiting_for_memory (connection);
- if (message == NULL)
- {
- _dbus_warn ("Did not receive a reply to %s %d on %p\n",
- "AddMatch", serial, connection);
- goto out;
- }
-
- verbose_message_received (connection, message);
-
- if (!dbus_message_has_sender (message, DBUS_SERVICE_DBUS))
- {
- _dbus_warn ("Message has wrong sender %s\n",
- dbus_message_get_sender (message) ?
- dbus_message_get_sender (message) : "(none)");
- goto out;
- }
-
- if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
- {
- if (dbus_message_is_error (message,
- DBUS_ERROR_NO_MEMORY))
- {
- ; /* good, this is a valid response */
- }
- else
- {
- warn_unexpected (connection, message, "not this error");
-
- goto out;
- }
- }
- else
- {
- if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN)
- {
- ; /* good, expected */
- _dbus_assert (dbus_message_get_reply_serial (message) == serial);
- }
- else
- {
- warn_unexpected (connection, message, "method return for AddMatch");
-
- goto out;
- }
- }
-
- if (!check_no_leftovers (context))
- goto out;
-
- retval = TRUE;
-
- out:
- dbus_error_free (&error);
-
- if (message)
- dbus_message_unref (message);
-
- return retval;
-}
-#endif
-
/* returns TRUE if the correct thing happens,
* but the correct thing may include OOM errors.
*/
@@ -1818,7 +1554,7 @@
}
else
{
- if (!check_add_match (context, connection, ""))
+ if (!check_add_match_all (context, connection))
return FALSE;
kill_client_connection (context, connection);
@@ -2106,8 +1842,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = connection;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2212,8 +1946,6 @@
socd.skip_connection = connection;
socd.failed = FALSE;
socd.expected_service_name = service_name;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2351,8 +2083,6 @@
socd.expected_service_name = service_name;
socd.failed = FALSE;
socd.skip_connection = connection;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2402,8 +2132,6 @@
socd.expected_service_name = activated_name;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2414,8 +2142,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2863,7 +2589,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -2932,6 +2657,7 @@
return retval;
}
+#ifndef DBUS_WIN_FIXME
/* returns TRUE if the correct thing happens,
* but the correct thing may include OOM errors.
*/
@@ -3020,19 +2746,11 @@
/* make sure this only happens with the launch helper */
_dbus_assert (servicehelper != NULL);
}
-#ifdef DBUS_WIN
- else if (dbus_message_is_error (message,
- DBUS_ERROR_SPAWN_CHILD_EXITED))
- {
- /* unhandled exceptions are normal exit codes */
- }
-#else
else if (dbus_message_is_error (message,
DBUS_ERROR_SPAWN_CHILD_SIGNALED))
{
; /* good, this is expected also */
}
-#endif
else
{
warn_unexpected (connection, message, "not this error");
@@ -3121,19 +2839,11 @@
{
; /* good, this is a valid response */
}
-#ifdef DBUS_WIN
- else if (dbus_message_is_error (message,
- DBUS_ERROR_SPAWN_CHILD_EXITED))
- {
- /* unhandled exceptions are normal exit codes */
- }
-#else
else if (dbus_message_is_error (message,
DBUS_ERROR_SPAWN_CHILD_SIGNALED))
{
; /* good, this is expected also */
}
-#endif
else
{
warn_unexpected (connection, message, "not this error");
@@ -3155,6 +2865,7 @@
return retval;
}
+#endif
#define TEST_ECHO_MESSAGE "Test echo message"
#define TEST_RUN_HELLO_FROM_SELF_MESSAGE "Test sending message to self"
@@ -3498,8 +3209,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -4188,8 +3897,6 @@
socd.expected_service_name = base_service;
socd.failed = FALSE;
socd.skip_connection = NULL;
- socd.context = context;
-
bus_test_clients_foreach (check_service_owner_changed_foreach,
&socd);
@@ -4759,7 +4466,7 @@
_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);
@@ -4802,7 +4509,7 @@
if (!check_double_hello_message (context, foo))
_dbus_assert_not_reached ("double hello message failed");
- if (!check_add_match (context, foo, ""))
+ if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("AddMatch message failed");
bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
@@ -4817,7 +4524,7 @@
if (!check_hello_message (context, bar))
_dbus_assert_not_reached ("hello message failed");
- if (!check_add_match (context, bar, ""))
+ if (!check_add_match_all (context, bar))
_dbus_assert_not_reached ("AddMatch message failed");
baz = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
@@ -4832,23 +4539,16 @@
if (!check_hello_message (context, baz))
_dbus_assert_not_reached ("hello message failed");
- if (!check_add_match (context, baz, ""))
+ if (!check_add_match_all (context, baz))
_dbus_assert_not_reached ("AddMatch message failed");
- if (!check_add_match (context, baz, "interface='com.example'"))
- _dbus_assert_not_reached ("AddMatch message failed");
-
-#ifdef DBUS_ENABLE_STATS
- if (!check_get_all_match_rules (context, baz))
- _dbus_assert_not_reached ("GetAllMatchRules message failed");
-#endif
-
+#ifdef DBUS_WIN_FIXME
+ _dbus_warn("TODO: testing of GetConnectionUnixUser message skipped for now\n");
+ _dbus_warn("TODO: testing of GetConnectionUnixProcessID message skipped for now\n");
+#else
if (!check_get_connection_unix_user (context, baz))
_dbus_assert_not_reached ("GetConnectionUnixUser message failed");
-#ifdef DBUS_WIN_FIXME
- _dbus_verbose("TODO: testing of GetConnectionUnixProcessID message skipped for now\n");
-#else
if (!check_get_connection_unix_process_id (context, baz))
_dbus_assert_not_reached ("GetConnectionUnixProcessID message failed");
#endif
@@ -4868,8 +4568,12 @@
check2_try_iterations (context, foo, "nonexistent_service_no_auto_start",
check_nonexistent_service_no_auto_start);
+#ifdef DBUS_WIN_FIXME
+ _dbus_warn("TODO: dispatch.c segfault_service_no_auto_start test\n");
+#else
check2_try_iterations (context, foo, "segfault_service_no_auto_start",
check_segfault_service_no_auto_start);
+#endif
check2_try_iterations (context, foo, "existent_service_no_auto_start",
check_existent_service_no_auto_start);
@@ -4877,9 +4581,14 @@
check2_try_iterations (context, foo, "nonexistent_service_auto_start",
check_nonexistent_service_auto_start);
+
+#ifdef DBUS_WIN_FIXME
+ _dbus_warn("TODO: dispatch.c segfault_service_auto_start test\n");
+#else
/* only do the segfault test if we are not using the launcher */
check2_try_iterations (context, foo, "segfault_service_auto_start",
check_segfault_service_auto_start);
+#endif
/* only do the shell fail test if we are not using the launcher */
check2_try_iterations (context, foo, "shell_fail_service_auto_start",
@@ -4949,7 +4658,7 @@
if (!check_double_hello_message (context, foo))
_dbus_assert_not_reached ("double hello message failed");
- if (!check_add_match (context, foo, ""))
+ if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("AddMatch message failed");
/* this only tests the activation.c user check */
@@ -4982,7 +4691,9 @@
"valid-config-files/debug-allow-all.conf", FALSE))
return FALSE;
-#ifndef DBUS_WIN
+#ifdef DBUS_WIN
+ _dbus_warn("Info: Launch helper activation tests skipped because launch-helper is not supported yet\n");
+#else
/* run launch-helper activation tests */
_dbus_verbose ("Launch helper activation tests\n");
if (!bus_dispatch_test_conf (test_data_dir,
@@ -5027,7 +4738,7 @@
if (!check_hello_message (context, foo))
_dbus_assert_not_reached ("hello message failed");
- if (!check_add_match (context, foo, ""))
+ if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("addmatch message failed");
if (!check_no_leftovers (context))
@@ -5055,8 +4766,7 @@
DBusConnection *foo, *bar;
DBusError error;
DBusMessage *m;
- DBusSocket one[2], two[2];
- int x, y, z;
+ int one[2], two[2], x, y, z;
char r;
dbus_error_init (&error);
@@ -5077,7 +4787,7 @@
if (!check_hello_message (context, foo))
_dbus_assert_not_reached ("hello message failed");
- if (!check_add_match (context, foo, ""))
+ if (!check_add_match_all (context, foo))
_dbus_assert_not_reached ("AddMatch message failed");
bar = dbus_connection_open_private (TEST_DEBUG_PIPE, &error);
@@ -5092,16 +4802,16 @@
if (!check_hello_message (context, bar))
_dbus_assert_not_reached ("hello message failed");
- if (!check_add_match (context, bar, ""))
+ if (!check_add_match_all (context, bar))
_dbus_assert_not_reached ("AddMatch message failed");
if (!(m = dbus_message_new_signal("/", "a.b.c", "d")))
_dbus_assert_not_reached ("could not alloc message");
- if (!(_dbus_socketpair (one, one+1, TRUE, &error)))
+ if (!(_dbus_full_duplex_pipe(one, one+1, TRUE, &error)))
_dbus_assert_not_reached("Failed to allocate pipe #1");
- if (!(_dbus_socketpair (two, two+1, TRUE, &error)))
+ if (!(_dbus_full_duplex_pipe(two, two+1, TRUE, &error)))
_dbus_assert_not_reached("Failed to allocate pipe #2");
if (!dbus_message_append_args(m,
@@ -5111,9 +4821,9 @@
DBUS_TYPE_INVALID))
_dbus_assert_not_reached("Failed to attach fds.");
- if (!_dbus_close_socket (one[0], &error))
+ if (!_dbus_close(one[0], &error))
_dbus_assert_not_reached("Failed to close pipe #1 ");
- if (!_dbus_close_socket (two[0], &error))
+ if (!_dbus_close(two[0], &error))
_dbus_assert_not_reached("Failed to close pipe #2 ");
if (!(dbus_connection_can_send_type(foo, DBUS_TYPE_UNIX_FD)))
@@ -5173,16 +4883,16 @@
if (!_dbus_close(z, &error))
_dbus_assert_not_reached("Failed to close pipe #2/other size 2nd fd ");
- if (read(one[1].fd, &r, 1) != 1 || r != 'X')
+ if (read(one[1], &r, 1) != 1 || r != 'X')
_dbus_assert_not_reached("Failed to read value from pipe.");
- if (read(two[1].fd, &r, 1) != 1 || r != 'Y')
+ if (read(two[1], &r, 1) != 1 || r != 'Y')
_dbus_assert_not_reached("Failed to read value from pipe.");
- if (read(two[1].fd, &r, 1) != 1 || r != 'Z')
+ if (read(two[1], &r, 1) != 1 || r != 'Z')
_dbus_assert_not_reached("Failed to read value from pipe.");
- if (!_dbus_close_socket (one[1], &error))
+ if (!_dbus_close(one[1], &error))
_dbus_assert_not_reached("Failed to close pipe #1 ");
- if (!_dbus_close_socket (two[1], &error))
+ if (!_dbus_close(two[1], &error))
_dbus_assert_not_reached("Failed to close pipe #2 ");
_dbus_verbose ("Disconnecting foo\n");
@@ -5197,4 +4907,4 @@
}
#endif
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/driver.c b/bus/driver.c
index b7e1a0a..574e0f3 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -24,7 +24,6 @@
#include <config.h>
#include "activation.h"
-#include "apparmor.h"
#include "connection.h"
#include "driver.h"
#include "dispatch.h"
@@ -33,184 +32,12 @@
#include "signals.h"
#include "stats.h"
#include "utils.h"
-
-#include <dbus/dbus-asv-util.h>
-#include <dbus/dbus-connection-internal.h>
#include <dbus/dbus-string.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-marshal-recursive.h>
-#include <dbus/dbus-marshal-validate.h>
#include <string.h>
-typedef enum
-{
- BUS_DRIVER_FOUND_SELF,
- BUS_DRIVER_FOUND_PEER,
- BUS_DRIVER_FOUND_ERROR,
-} BusDriverFound;
-
-static inline const char *
-nonnull (const char *maybe_null,
- const char *if_null)
-{
- return (maybe_null ? maybe_null : if_null);
-}
-
-static DBusConnection *
-bus_driver_get_owner_of_name (DBusConnection *connection,
- const char *name)
-{
- BusRegistry *registry;
- BusService *serv;
- DBusString str;
-
- registry = bus_connection_get_registry (connection);
- _dbus_string_init_const (&str, name);
- serv = bus_registry_lookup (registry, &str);
-
- if (serv == NULL)
- return NULL;
-
- return bus_service_get_primary_owners_connection (serv);
-}
-
-static BusDriverFound
-bus_driver_get_conn_helper (DBusConnection *connection,
- DBusMessage *message,
- const char *what_we_want,
- const char **name_p,
- DBusConnection **peer_conn_p,
- DBusError *error)
-{
- DBusConnection *conn;
- const char *name;
-
- if (!dbus_message_get_args (message, error,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID))
- return BUS_DRIVER_FOUND_ERROR;
-
- _dbus_assert (name != NULL);
- _dbus_verbose ("asked for %s of connection %s\n", what_we_want, name);
-
- if (name_p != NULL)
- *name_p = name;
-
- if (strcmp (name, DBUS_SERVICE_DBUS) == 0)
- return BUS_DRIVER_FOUND_SELF;
-
- conn = bus_driver_get_owner_of_name (connection, name);
-
- if (conn == 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 BUS_DRIVER_FOUND_ERROR;
- }
-
- if (peer_conn_p != NULL)
- *peer_conn_p = conn;
-
- return BUS_DRIVER_FOUND_PEER;
-}
-
-/*
- * Log a security warning and set error unless the uid of the connection
- * is either the uid of this process, or on Unix, uid 0 (root).
- *
- * This is intended to be a second line of defence after <deny> rules,
- * to mitigate incorrect system bus security policy configuration files
- * like the ones in CVE-2014-8148 and CVE-2014-8156, and (if present)
- * LSM rules; so it doesn't need to be perfect, but as long as we have
- * potentially dangerous functionality in the system bus, it does need
- * to exist.
- */
-static dbus_bool_t
-bus_driver_check_caller_is_privileged (DBusConnection *connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
-#ifdef DBUS_UNIX
- unsigned long uid;
-
- if (!dbus_connection_get_unix_user (connection, &uid))
- {
- const char *method = dbus_message_get_member (message);
-
- bus_context_log_and_set_error (bus_transaction_get_context (transaction),
- DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED,
- "rejected attempt to call %s by connection %s (%s) with "
- "unknown uid", method,
- nonnull (bus_connection_get_name (connection), "(inactive)"),
- bus_connection_get_loginfo (connection));
- return FALSE;
- }
-
- /* I'm writing it in this slightly strange form so that it's more
- * obvious that this security-sensitive code is correct.
- */
- if (_dbus_unix_user_is_process_owner (uid))
- {
- /* OK */
- }
- else if (uid == 0)
- {
- /* OK */
- }
- else
- {
- const char *method = dbus_message_get_member (message);
-
- bus_context_log_and_set_error (bus_transaction_get_context (transaction),
- DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED,
- "rejected attempt to call %s by connection %s (%s) with "
- "uid %lu", method,
- nonnull (bus_connection_get_name (connection), "(inactive)"),
- bus_connection_get_loginfo (connection), uid);
- return FALSE;
- }
-
- return TRUE;
-#elif defined(DBUS_WIN)
- char *windows_sid = NULL;
- dbus_bool_t ret = FALSE;
-
- if (!dbus_connection_get_windows_user (connection, &windows_sid))
- {
- const char *method = dbus_message_get_member (message);
-
- bus_context_log_and_set_error (bus_transaction_get_context (transaction),
- DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED,
- "rejected attempt to call %s by unknown uid", method);
- goto out;
- }
-
- if (!_dbus_windows_user_is_process_owner (windows_sid))
- {
- const char *method = dbus_message_get_member (message);
-
- bus_context_log_and_set_error (bus_transaction_get_context (transaction),
- DBUS_SYSTEM_LOG_SECURITY, error, DBUS_ERROR_ACCESS_DENIED,
- "rejected attempt to call %s by uid %s", method, windows_sid);
- goto out;
- }
-
- ret = TRUE;
-out:
- dbus_free (windows_sid);
- return ret;
-#else
- /* make sure we fail closed in the hypothetical case that we are neither
- * Unix nor Windows */
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "please teach bus/driver.c how uids work on this platform");
- return FALSE;
-#endif
-}
-
static dbus_bool_t bus_driver_send_welcome_message (DBusConnection *connection,
DBusMessage *hello_message,
BusTransaction *transaction,
@@ -257,9 +84,6 @@
_dbus_assert (dbus_message_has_signature (message, "sss"));
- if (!bus_transaction_capture (transaction, NULL, message))
- goto oom;
-
retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
dbus_message_unref (message);
@@ -992,72 +816,6 @@
return TRUE;
}
-/*
- * Send a message from the driver, activating the destination if necessary.
- * The message must already have a destination set.
- */
-static dbus_bool_t
-bus_driver_send_or_activate (BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
- BusContext *context;
- BusService *service;
- const char *service_name;
- DBusString service_string;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- service_name = dbus_message_get_destination (message);
-
- _dbus_assert (service_name != NULL);
-
- _dbus_string_init_const (&service_string, service_name);
-
- context = bus_transaction_get_context (transaction);
-
- service = bus_registry_lookup (bus_context_get_registry (context),
- &service_string);
-
- if (service == NULL)
- {
- /* destination isn't connected yet; pass the message to activation */
- BusActivation *activation;
-
- activation = bus_context_get_activation (context);
-
- if (!bus_transaction_capture (transaction, NULL, message))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory for bus_transaction_capture()");
- return FALSE;
- }
-
- if (!bus_activation_activate_service (activation, NULL, transaction, TRUE,
- message, service_name, error))
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- _dbus_verbose ("bus_activation_activate_service() failed");
- return FALSE;
- }
- }
- else
- {
- DBusConnection *service_conn;
-
- service_conn = bus_service_get_primary_owners_connection (service);
-
- if (!bus_transaction_send_from_driver (transaction, service_conn, message))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory for bus_transaction_send_from_driver()");
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
static dbus_bool_t
bus_driver_handle_update_activation_environment (DBusConnection *connection,
BusTransaction *transaction,
@@ -1066,7 +824,6 @@
{
dbus_bool_t retval;
BusActivation *activation;
- BusContext *context;
DBusMessageIter iter;
DBusMessageIter dict_iter;
DBusMessageIter dict_entry_iter;
@@ -1074,36 +831,9 @@
int key_type;
DBusList *keys, *key_link;
DBusList *values, *value_link;
- DBusMessage *systemd_message;
- DBusMessageIter systemd_iter;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!bus_driver_check_message_is_for_us (message, error))
- return FALSE;
-
-#ifdef DBUS_UNIX
- {
- /* UpdateActivationEnvironment is basically a recipe for privilege
- * escalation so let's be extra-careful: do not allow the sysadmin
- * to shoot themselves in the foot.
- */
- if (!bus_driver_check_caller_is_privileged (connection, transaction,
- message, error))
- return FALSE;
- }
-#endif
-
- context = bus_connection_get_context (connection);
-
- if (bus_context_get_servicehelper (context) != NULL)
- {
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "Cannot change activation environment "
- "on a system bus.");
- return FALSE;
- }
-
activation = bus_connection_get_activation (connection);
dbus_message_iter_init (message, &iter);
@@ -1111,12 +841,17 @@
/* The message signature has already been checked for us,
* so let's just assert it's right.
*/
- _dbus_assert (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY);
+#ifndef DBUS_DISABLE_ASSERT
+ {
+ int msg_type = dbus_message_iter_get_arg_type (&iter);
+
+ _dbus_assert (msg_type == DBUS_TYPE_ARRAY);
+ }
+#endif
dbus_message_iter_recurse (&iter, &dict_iter);
retval = FALSE;
- systemd_message = NULL;
/* Then loop through the sent dictionary, add the location of
* the environment keys and values to lists. The result will
@@ -1171,33 +906,6 @@
_dbus_assert (_dbus_list_get_length (&keys) == _dbus_list_get_length (&values));
- if (bus_context_get_systemd_activation (bus_connection_get_context (connection)))
- {
- /* Prepare a call to forward environment updates to systemd */
- systemd_message = dbus_message_new_method_call ("org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "SetEnvironment");
- if (systemd_message == NULL ||
- !dbus_message_set_sender (systemd_message, DBUS_SERVICE_DBUS))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory to create systemd message\n");
- goto out;
- }
-
- dbus_message_set_no_reply (systemd_message, TRUE);
- dbus_message_iter_init_append (systemd_message, &iter);
-
- if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s",
- &systemd_iter))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory to open systemd message container\n");
- goto out;
- }
- }
-
key_link = keys;
value_link = values;
while (key_link != NULL)
@@ -1210,41 +918,11 @@
if (!bus_activation_set_environment_variable (activation,
key, value, error))
- {
+ {
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_verbose ("bus_activation_set_environment_variable() failed\n");
break;
- }
-
- if (systemd_message != NULL)
- {
- DBusString envline;
- const char *s;
-
- /* SetEnvironment wants an array of KEY=VALUE strings */
- if (!_dbus_string_init (&envline) ||
- !_dbus_string_append_printf (&envline, "%s=%s", key, value))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory to format systemd environment line\n");
- _dbus_string_free (&envline);
- break;
- }
-
- s = _dbus_string_get_data (&envline);
-
- if (!dbus_message_iter_append_basic (&systemd_iter,
- DBUS_TYPE_STRING, &s))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory to append systemd environment line\n");
- _dbus_string_free (&envline);
- break;
- }
-
- _dbus_string_free (&envline);
- }
-
+ }
key_link = _dbus_list_get_next_link (&keys, key_link);
value_link = _dbus_list_get_next_link (&values, value_link);
}
@@ -1254,28 +932,7 @@
* matter, so we're punting for now.
*/
if (key_link != NULL)
- {
- if (systemd_message != NULL)
- dbus_message_iter_abandon_container (&iter, &systemd_iter);
- goto out;
- }
-
- if (systemd_message != NULL)
- {
- if (!dbus_message_iter_close_container (&iter, &systemd_iter))
- {
- BUS_SET_OOM (error);
- _dbus_verbose ("No memory to close systemd message container\n");
- goto out;
- }
-
- if (!bus_driver_send_or_activate (transaction, systemd_message, error))
- {
- _DBUS_ASSERT_ERROR_IS_SET (error);
- _dbus_verbose ("bus_driver_send_or_activate() failed\n");
- goto out;
- }
- }
+ goto out;
if (!send_ack_reply (connection, transaction,
message, error))
@@ -1284,8 +941,6 @@
retval = TRUE;
out:
- if (systemd_message != NULL)
- dbus_message_unref (systemd_message);
_dbus_list_clear (&keys);
_dbus_list_clear (&values);
return retval;
@@ -1298,10 +953,9 @@
DBusError *error)
{
BusMatchRule *rule;
- const char *text, *bustype;
+ const char *text;
DBusString str;
BusMatchmaker *matchmaker;
- BusContext *context;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1334,12 +988,6 @@
if (rule == NULL)
goto failed;
- context = bus_transaction_get_context (transaction);
- bustype = context ? bus_context_get_type (context) : NULL;
- if (bus_match_rule_get_client_is_eavesdropping (rule) &&
- !bus_apparmor_allows_eavesdropping (connection, bustype, error))
- goto failed;
-
matchmaker = bus_connection_get_matchmaker (connection);
if (!bus_matchmaker_add_rule (matchmaker, rule))
@@ -1614,33 +1262,46 @@
DBusMessage *message,
DBusError *error)
{
+ const char *service;
+ DBusString str;
+ BusRegistry *registry;
+ BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
- dbus_uid_t uid;
+ unsigned long uid;
dbus_uint32_t uid32;
- const char *service;
- BusDriverFound found;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ registry = bus_connection_get_registry (connection);
+
+ service = NULL;
reply = NULL;
- found = bus_driver_get_conn_helper (connection, message, "UID", &service,
- &conn, error);
- switch (found)
+ 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);
+
+ _dbus_string_init_const (&str, service);
+ serv = bus_registry_lookup (registry, &str);
+ if (serv == NULL)
{
- case BUS_DRIVER_FOUND_SELF:
- uid = _dbus_getuid ();
- break;
- case BUS_DRIVER_FOUND_PEER:
- if (!dbus_connection_get_unix_user (conn, &uid))
- uid = DBUS_UID_UNSET;
- break;
- case BUS_DRIVER_FOUND_ERROR:
- goto failed;
+ dbus_set_error (error,
+ DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Could not get UID of name '%s': no such name", service);
+ goto failed;
}
- if (uid == DBUS_UID_UNSET)
+ conn = bus_service_get_primary_owners_connection (serv);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto oom;
+
+ if (!dbus_connection_get_unix_user (conn, &uid))
{
dbus_set_error (error,
DBUS_ERROR_FAILED,
@@ -1648,10 +1309,6 @@
goto failed;
}
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- goto oom;
-
uid32 = uid;
if (! dbus_message_append_args (reply,
DBUS_TYPE_UINT32, &uid32,
@@ -1681,33 +1338,46 @@
DBusMessage *message,
DBusError *error)
{
+ const char *service;
+ DBusString str;
+ BusRegistry *registry;
+ BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
- dbus_pid_t pid;
+ unsigned long pid;
dbus_uint32_t pid32;
- const char *service;
- BusDriverFound found;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ registry = bus_connection_get_registry (connection);
+
+ service = NULL;
reply = NULL;
- found = bus_driver_get_conn_helper (connection, message, "PID", &service,
- &conn, error);
- switch (found)
+ 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);
+
+ _dbus_string_init_const (&str, service);
+ serv = bus_registry_lookup (registry, &str);
+ if (serv == NULL)
{
- case BUS_DRIVER_FOUND_SELF:
- pid = _dbus_getpid ();
- break;
- case BUS_DRIVER_FOUND_PEER:
- if (!dbus_connection_get_unix_process_id (conn, &pid))
- pid = DBUS_PID_UNSET;
- break;
- case BUS_DRIVER_FOUND_ERROR:
- goto failed;
+ dbus_set_error (error,
+ DBUS_ERROR_NAME_HAS_NO_OWNER,
+ "Could not get PID of name '%s': no such name", service);
+ goto failed;
}
- if (pid == DBUS_PID_UNSET)
+ conn = bus_service_get_primary_owners_connection (serv);
+
+ reply = dbus_message_new_method_return (message);
+ if (reply == NULL)
+ goto oom;
+
+ if (!dbus_connection_get_unix_process_id (conn, &pid))
{
dbus_set_error (error,
DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN,
@@ -1715,10 +1385,6 @@
goto failed;
}
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- goto oom;
-
pid32 = pid;
if (! dbus_message_append_args (reply,
DBUS_TYPE_UINT32, &pid32,
@@ -1748,34 +1414,46 @@
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;
- BusDriverFound found;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ registry = bus_connection_get_registry (connection);
+
+ service = NULL;
reply = NULL;
- found = bus_driver_get_conn_helper (connection, message, "audit session data",
- &service, &conn, error);
+ if (! dbus_message_get_args (message, error,
+ DBUS_TYPE_STRING, &service,
+ DBUS_TYPE_INVALID))
+ goto failed;
- if (found == BUS_DRIVER_FOUND_ERROR)
- goto failed;
+ _dbus_verbose ("asked for audit session data for connection %s\n", service);
+
+ _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);
reply = dbus_message_new_method_return (message);
if (reply == NULL)
goto oom;
- /* We don't know how to find "ADT audit session data" for the bus daemon
- * itself. Is that even meaningful?
- * FIXME: Implement this or briefly note it makes no sense.
- */
- if (found != BUS_DRIVER_FOUND_PEER ||
- !dbus_connection_get_adt_audit_session_data (conn, &data, &data_size) ||
- data == NULL)
+ if (!dbus_connection_get_adt_audit_session_data (conn, &data, &data_size) || data == NULL)
{
dbus_set_error (error,
DBUS_ERROR_ADT_AUDIT_DATA_UNKNOWN,
@@ -1811,32 +1489,45 @@
DBusMessage *message,
DBusError *error)
{
+ const char *service;
+ DBusString str;
+ BusRegistry *registry;
+ BusService *serv;
DBusConnection *conn;
DBusMessage *reply;
BusSELinuxID *context;
- const char *service;
- BusDriverFound found;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ registry = bus_connection_get_registry (connection);
+
+ service = NULL;
reply = NULL;
- found = bus_driver_get_conn_helper (connection, message, "security context",
- &service, &conn, error);
+ if (! dbus_message_get_args (message, error,
+ DBUS_TYPE_STRING, &service,
+ DBUS_TYPE_INVALID))
+ goto failed;
- if (found == BUS_DRIVER_FOUND_ERROR)
- goto failed;
+ _dbus_verbose ("asked for security context of connection %s\n", service);
+
+ _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);
reply = dbus_message_new_method_return (message);
if (reply == NULL)
goto oom;
- /* FIXME: Obtain the SELinux security context for the bus daemon itself */
- if (found == BUS_DRIVER_FOUND_PEER)
- context = bus_connection_get_selinux_id (conn);
- else
- context = NULL;
-
+ context = bus_connection_get_selinux_id (conn);
if (!context)
{
dbus_set_error (error,
@@ -1866,135 +1557,6 @@
}
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_uid, ulong_pid;
- char *s;
- const char *service;
- BusDriverFound found;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- reply = NULL;
-
- found = bus_driver_get_conn_helper (connection, message, "credentials",
- &service, &conn, error);
-
- switch (found)
- {
- case BUS_DRIVER_FOUND_SELF:
- ulong_pid = _dbus_getpid ();
- ulong_uid = _dbus_getuid ();
- break;
-
- case BUS_DRIVER_FOUND_PEER:
- if (!dbus_connection_get_unix_process_id (conn, &ulong_pid))
- ulong_pid = DBUS_PID_UNSET;
- if (!dbus_connection_get_unix_user (conn, &ulong_uid))
- ulong_uid = DBUS_UID_UNSET;
- break;
- case BUS_DRIVER_FOUND_ERROR:
- 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 (ulong_pid <= _DBUS_UINT32_MAX && ulong_pid != DBUS_PID_UNSET &&
- !_dbus_asv_add_uint32 (&array_iter, "ProcessID", ulong_pid))
- goto oom;
-
- /* we can't represent > 32-bit uids; if your system needs them, please
- * add UnixUserID64 to the spec or something */
- if (ulong_uid <= _DBUS_UINT32_MAX && ulong_uid != DBUS_UID_UNSET &&
- !_dbus_asv_add_uint32 (&array_iter, "UnixUserID", ulong_uid))
- goto oom;
-
- /* FIXME: Obtain the Windows user of the bus daemon itself */
- if (found == BUS_DRIVER_FOUND_PEER &&
- dbus_connection_get_windows_user (conn, &s))
- {
- DBusString str;
- dbus_bool_t result;
-
- if (s == NULL)
- goto oom;
-
- _dbus_string_init_const (&str, s);
- result = _dbus_validate_utf8 (&str, 0, _dbus_string_get_length (&str));
- _dbus_string_free (&str);
- if (result)
- {
- if (!_dbus_asv_add_string (&array_iter, "WindowsSID", s))
- {
- dbus_free (s);
- goto oom;
- }
- }
- dbus_free (s);
- }
-
- /* FIXME: Obtain the security label for the bus daemon itself */
- if (found == BUS_DRIVER_FOUND_PEER &&
- _dbus_connection_get_linux_security_label (conn, &s))
- {
- if (s == NULL)
- goto oom;
-
- /* use the GVariant bytestring convention for strings of unknown
- * encoding: include the \0 in the payload, for zero-copy reading */
- if (!_dbus_asv_add_byte_array (&array_iter, "LinuxSecurityLabel",
- s, strlen (s) + 1))
- {
- dbus_free (s);
- goto oom;
- }
-
- dbus_free (s);
- }
-
- 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;
- }
-
- dbus_message_unref (reply);
-
- 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,
@@ -2031,72 +1593,6 @@
return FALSE;
}
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-static dbus_bool_t
-bus_driver_handle_enable_verbose (DBusConnection *connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
- DBusMessage *reply = NULL;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- goto oom;
-
- if (! bus_transaction_send_from_driver (transaction, connection, reply))
- goto oom;
-
- _dbus_set_verbose(TRUE);
-
- dbus_message_unref (reply);
- return TRUE;
-
- oom:
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- BUS_SET_OOM (error);
-
- if (reply)
- dbus_message_unref (reply);
- return FALSE;
-}
-
-static dbus_bool_t
-bus_driver_handle_disable_verbose (DBusConnection *connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
- DBusMessage *reply = NULL;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- goto oom;
-
- if (! bus_transaction_send_from_driver (transaction, connection, reply))
- goto oom;
-
- _dbus_set_verbose(FALSE);
-
- dbus_message_unref (reply);
- return TRUE;
-
- oom:
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- BUS_SET_OOM (error);
-
- if (reply)
- dbus_message_unref (reply);
- return FALSE;
-}
-#endif
-
static dbus_bool_t
bus_driver_handle_get_id (DBusConnection *connection,
BusTransaction *transaction,
@@ -2152,121 +1648,6 @@
return FALSE;
}
-static dbus_bool_t
-bus_driver_handle_become_monitor (DBusConnection *connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
- char **match_rules = NULL;
- const char *bustype;
- BusContext *context;
- BusMatchRule *rule;
- DBusList *rules = NULL;
- DBusList *iter;
- DBusString str;
- int i;
- int n_match_rules;
- dbus_uint32_t flags;
- dbus_bool_t ret = FALSE;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- if (!bus_driver_check_message_is_for_us (message, error))
- goto out;
-
- context = bus_transaction_get_context (transaction);
- bustype = context ? bus_context_get_type (context) : NULL;
- if (!bus_apparmor_allows_eavesdropping (connection, bustype, error))
- goto out;
-
- if (!bus_driver_check_caller_is_privileged (connection, transaction,
- message, error))
- goto out;
-
- if (!dbus_message_get_args (message, error,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &match_rules, &n_match_rules,
- DBUS_TYPE_UINT32, &flags,
- DBUS_TYPE_INVALID))
- goto out;
-
- if (flags != 0)
- {
- dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
- "BecomeMonitor does not support any flags yet");
- goto out;
- }
-
- /* Special case: a zero-length array becomes [""] */
- if (n_match_rules == 0)
- {
- match_rules = dbus_malloc (2 * sizeof (char *));
-
- if (match_rules == NULL)
- {
- BUS_SET_OOM (error);
- goto out;
- }
-
- match_rules[0] = _dbus_strdup ("");
-
- if (match_rules[0] == NULL)
- {
- BUS_SET_OOM (error);
- goto out;
- }
-
- match_rules[1] = NULL;
- n_match_rules = 1;
- }
-
- for (i = 0; i < n_match_rules; i++)
- {
- _dbus_string_init_const (&str, match_rules[i]);
- rule = bus_match_rule_parse (connection, &str, error);
-
- if (rule == NULL)
- goto out;
-
- /* monitors always eavesdrop */
- bus_match_rule_set_client_is_eavesdropping (rule, TRUE);
-
- if (!_dbus_list_append (&rules, rule))
- {
- BUS_SET_OOM (error);
- bus_match_rule_unref (rule);
- goto out;
- }
- }
-
- /* Send the ack before we remove the rule, since the ack is undone
- * on transaction cancel, but becoming a monitor isn't.
- */
- if (!send_ack_reply (connection, transaction, message, error))
- goto out;
-
- if (!bus_connection_be_monitor (connection, transaction, &rules, error))
- goto out;
-
- ret = TRUE;
-
-out:
- if (ret)
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
- else
- _DBUS_ASSERT_ERROR_IS_SET (error);
-
- for (iter = _dbus_list_get_first_link (&rules);
- iter != NULL;
- iter = _dbus_list_get_next_link (&rules, iter))
- bus_match_rule_unref (iter->data);
-
- _dbus_list_clear (&rules);
-
- dbus_free_string_array (match_rules);
- return ret;
-}
-
typedef struct
{
const char *name;
@@ -2355,8 +1736,6 @@
"",
DBUS_TYPE_STRING_AS_STRING,
bus_driver_handle_get_id },
- { "GetConnectionCredentials", "s", "a{sv}",
- bus_driver_handle_get_connection_credentials },
{ NULL, NULL, NULL, NULL }
};
@@ -2368,24 +1747,10 @@
{ NULL, NULL, NULL, NULL }
};
-static const MessageHandler monitoring_message_handlers[] = {
- { "BecomeMonitor", "asu", "", bus_driver_handle_become_monitor },
- { NULL, NULL, NULL, NULL }
-};
-
-#ifdef DBUS_ENABLE_VERBOSE_MODE
-static const MessageHandler verbose_message_handlers[] = {
- { "EnableVerbose", "", "", bus_driver_handle_enable_verbose},
- { "DisableVerbose", "", "", bus_driver_handle_disable_verbose},
- { NULL, NULL, NULL, NULL }
-};
-#endif
-
#ifdef DBUS_ENABLE_STATS
static const MessageHandler stats_message_handlers[] = {
{ "GetStats", "", "a{sv}", bus_stats_handle_get_stats },
{ "GetConnectionStats", "s", "a{sv}", bus_stats_handle_get_connection_stats },
- { "GetAllMatchRules", "", "a{sas}", bus_stats_handle_get_all_match_rules },
{ NULL, NULL, NULL, NULL }
};
#endif
@@ -2412,10 +1777,6 @@
" <arg type=\"s\"/>\n"
" </signal>\n" },
{ DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL },
- { DBUS_INTERFACE_MONITORING, monitoring_message_handlers, NULL },
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- { DBUS_INTERFACE_VERBOSE, verbose_message_handlers, NULL },
-#endif
#ifdef DBUS_ENABLE_STATS
{ BUS_INTERFACE_STATS, stats_message_handlers, NULL },
#endif
@@ -2566,38 +1927,6 @@
return FALSE;
}
-/*
- * Set @error and return FALSE if the message is not directed to the
- * dbus-daemon by its canonical object path. This is hardening against
- * system services with poorly-written security policy files, which
- * might allow sending dangerously broad equivalence classes of messages
- * such as "anything with this assumed-to-be-safe object path".
- *
- * dbus-daemon is unusual in that it normally ignores the object path
- * of incoming messages; we need to keep that behaviour for the "read"
- * read-only method calls like GetConnectionUnixUser for backwards
- * compatibility, but it seems safer to be more restrictive for things
- * intended to be root-only or privileged-developers-only.
- *
- * It is possible that there are other system services with the same
- * quirk as dbus-daemon.
- */
-dbus_bool_t
-bus_driver_check_message_is_for_us (DBusMessage *message,
- DBusError *error)
-{
- if (!dbus_message_has_path (message, DBUS_PATH_DBUS))
- {
- dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED,
- "Method '%s' is only available at the canonical object path '%s'",
- dbus_message_get_member (message), DBUS_PATH_DBUS);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
dbus_bool_t
bus_driver_handle_message (DBusConnection *connection,
BusTransaction *transaction,
@@ -2614,43 +1943,8 @@
if (dbus_message_is_signal (message, "org.freedesktop.systemd1.Activator", "ActivationFailure"))
{
BusContext *context;
- DBusConnection *systemd;
-
- /* This is a directed signal, not a method call, so the log message
- * is a little weird (it talks about "calling" ActivationFailure),
- * but it's close enough */
- if (!bus_driver_check_caller_is_privileged (connection,
- transaction,
- message,
- error))
- return FALSE;
context = bus_connection_get_context (connection);
- systemd = bus_driver_get_owner_of_name (connection,
- "org.freedesktop.systemd1");
-
- if (systemd != connection)
- {
- const char *attacker;
-
- attacker = bus_connection_get_name (connection);
- bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY,
- "Ignoring forged ActivationFailure message from "
- "connection %s (%s)",
- attacker ? attacker : "(unauthenticated)",
- bus_connection_get_loginfo (connection));
- /* ignore it */
- return TRUE;
- }
-
- if (!bus_context_get_systemd_activation (context))
- {
- bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
- "Ignoring unexpected ActivationFailure message "
- "while not using systemd activation");
- return FALSE;
- }
-
return dbus_activation_systemd_failure(bus_context_get_activation(context), message);
}
@@ -2670,8 +1964,13 @@
_dbus_verbose ("Driver got a method call: %s\n", name);
/* security checks should have kept this from getting here */
- _dbus_assert (dbus_message_get_sender (message) != NULL ||
- strcmp (name, "Hello") == 0);
+#ifndef DBUS_DISABLE_ASSERT
+ {
+ const char *sender = dbus_message_get_sender (message);
+
+ _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
+ }
+#endif
for (ih = interface_handlers; ih->name != NULL; ih++)
{
diff --git a/bus/driver.h b/bus/driver.h
index 201709c..713b276 100644
--- a/bus/driver.h
+++ b/bus/driver.h
@@ -46,7 +46,7 @@
BusTransaction *transaction,
DBusError *error);
dbus_bool_t bus_driver_generate_introspect_string (DBusString *xml);
-dbus_bool_t bus_driver_check_message_is_for_us (DBusMessage *message,
- DBusError *error);
+
+
#endif /* BUS_DRIVER_H */
diff --git a/bus/example-session-disable-stats.conf.in b/bus/example-session-disable-stats.conf.in
deleted file mode 100644
index 2863ef0..0000000
--- a/bus/example-session-disable-stats.conf.in
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-
- <!-- If the Stats interface was enabled at compile-time, users can use it on
- the session bus by default. Systems providing isolation of processes
- with LSMs might want to restrict this. This can be achieved by copying
- this file in @EXPANDED_SYSCONFDIR@/dbus-1/session.d/ -->
-
- <policy context="default">
- <deny send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Debug.Stats"/>
- </policy>
-
-</busconfig>
diff --git a/bus/example-system-enable-stats.conf.in b/bus/example-system-enable-stats.conf.in
deleted file mode 100644
index a85aa83..0000000
--- a/bus/example-system-enable-stats.conf.in
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
-
- <!-- If the Stats interface was enabled at compile-time, only root may use it.
- Replace USERNAME and copy this file in @EXPANDED_SYSCONFDIR@/dbus-1/system.d/
- if you want to enable other privileged users to view statistics and
- debug info -->
-
- <policy user="USERNAME">
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Debug.Stats"/>
- </policy>
-
-</busconfig>
diff --git a/bus/expirelist.c b/bus/expirelist.c
index 9a3886e..1a12ea4 100644
--- a/bus/expirelist.c
+++ b/bus/expirelist.c
@@ -281,7 +281,7 @@
return _dbus_list_find_last (&list->items, item) != NULL;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
typedef struct
{
@@ -399,4 +399,4 @@
return result;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/legacy-config/session.conf.in b/bus/legacy-config/session.conf.in
deleted file mode 100644
index b35024e..0000000
--- a/bus/legacy-config/session.conf.in
+++ /dev/null
@@ -1,19 +0,0 @@
-<!--
-This configuration file is no longer required and may be removed.
-
-In older versions of dbus, this file defined the behaviour of the well-known
-session bus. That behaviour is now determined by
-@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/session.conf, which should not be edited.
-
-For local configuration changes, create a file
-session-local.conf or files matching session.d/*.conf in the same directory
-as this one, with a <busconfig> element containing configuration directives.
-These directives can override D-Bus or OS defaults.
-
-For upstream or distribution-wide defaults that can be overridden
-by a local sysadmin, create files matching
-@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/session.d/*.conf instead.
--->
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig></busconfig>
diff --git a/bus/legacy-config/system.conf.in b/bus/legacy-config/system.conf.in
deleted file mode 100644
index 17aba08..0000000
--- a/bus/legacy-config/system.conf.in
+++ /dev/null
@@ -1,19 +0,0 @@
-<!--
-This configuration file is no longer required and may be removed.
-
-In older versions of dbus, this file defined the behaviour of the well-known
-system bus. That behaviour is now determined by
-@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/system.conf, which should not be edited.
-
-For local configuration changes, create a file
-system-local.conf or files matching system.d/*.conf in the same directory
-as this one, with a <busconfig> element containing configuration directives.
-These directives can override D-Bus or OS defaults.
-
-For upstream or distribution-wide defaults that can be overridden
-by a local sysadmin, create files matching
-@DATADIR_FROM_PKGSYSCONFDIR@/dbus-1/system.d/*.conf instead.
--->
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig></busconfig>
diff --git a/bus/main.c b/bus/main.c
index c38f252..ca0be3c 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -39,20 +39,12 @@
#include <unistd.h> /* for write() and STDERR_FILENO */
#endif
#include "selinux.h"
-#include "apparmor.h"
-#include "audit.h"
-
-#ifdef DBUS_UNIX
-#include <dbus/dbus-sysdeps-unix.h>
-#endif
static BusContext *context;
#ifdef DBUS_UNIX
-/* Despite its name and its unidirectional nature, this is actually
- * a socket pair. */
-static DBusSocket reload_pipe[2];
+static int reload_pipe[2];
#define RELOAD_READ_END 0
#define RELOAD_WRITE_END 1
@@ -69,13 +61,18 @@
{
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;
char action[2] = { ACTION_RELOAD, '\0' };
_dbus_string_init_const (&str, action);
- if ((reload_pipe[RELOAD_WRITE_END].fd > 0) &&
+ if ((reload_pipe[RELOAD_WRITE_END] > 0) &&
!_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
{
/* If we receive SIGHUP often enough to fill the pipe buffer (4096
@@ -94,21 +91,18 @@
static const char message[] =
"Unable to write to reload pipe - buffer full?\n";
- if (write (STDERR_FILENO, message, strlen (message)) !=
- (ssize_t) strlen (message))
- {
- /* ignore failure to write out a warning */
- }
+ write (STDERR_FILENO, message, strlen (message));
}
}
break;
+#endif
case SIGTERM:
{
DBusString str;
char action[2] = { ACTION_QUIT, '\0' };
_dbus_string_init_const (&str, action);
- if ((reload_pipe[RELOAD_WRITE_END].fd < 0) ||
+ if ((reload_pipe[RELOAD_WRITE_END] < 0) ||
!_dbus_write_socket (reload_pipe[RELOAD_WRITE_END], &str, 0, 1))
{
/* If we can't write to the socket, dying seems a more
@@ -119,11 +113,7 @@
"Unable to write termination signal to pipe - buffer full?\n"
"Will exit instead.\n";
- if (write (STDERR_FILENO, message, strlen (message)) !=
- (ssize_t) strlen (message))
- {
- /* ignore failure to write out a warning */
- }
+ write (STDERR_FILENO, message, strlen (message));
_exit (1);
}
}
@@ -135,23 +125,7 @@
static void
usage (void)
{
- 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");
+ 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");
exit (1);
}
@@ -253,7 +227,7 @@
while (!_dbus_string_init (&str))
_dbus_wait_for_memory ();
- if ((reload_pipe[RELOAD_READ_END].fd > 0) &&
+ if ((reload_pipe[RELOAD_READ_END] > 0) &&
_dbus_read_socket (reload_pipe[RELOAD_READ_END], &str, 1) != 1)
{
_dbus_warn ("Couldn't read from reload pipe.\n");
@@ -320,8 +294,8 @@
dbus_error_init (&error);
- if (!_dbus_socketpair (&reload_pipe[0], &reload_pipe[1],
- TRUE, &error))
+ if (!_dbus_full_duplex_pipe (&reload_pipe[0], &reload_pipe[1],
+ TRUE, &error))
{
_dbus_warn ("Unable to create reload pipe: %s\n",
error.message);
@@ -329,9 +303,9 @@
exit (1);
}
- watch = _dbus_watch_new (_dbus_socket_get_pollable (reload_pipe[RELOAD_READ_END]),
- DBUS_WATCH_READABLE, TRUE,
- handle_reload_watch, NULL, NULL);
+ watch = _dbus_watch_new (reload_pipe[RELOAD_READ_END],
+ DBUS_WATCH_READABLE, TRUE,
+ handle_reload_watch, NULL, NULL);
if (watch == NULL)
{
@@ -360,10 +334,10 @@
*watch = NULL;
_dbus_close_socket (reload_pipe[RELOAD_READ_END], NULL);
- _dbus_socket_invalidate (&reload_pipe[RELOAD_READ_END]);
+ reload_pipe[RELOAD_READ_END] = -1;
_dbus_close_socket (reload_pipe[RELOAD_WRITE_END], NULL);
- _dbus_socket_invalidate (&reload_pipe[RELOAD_WRITE_END]);
+ reload_pipe[RELOAD_WRITE_END] = -1;
}
#endif /* DBUS_UNIX */
@@ -382,27 +356,6 @@
dbus_bool_t print_address;
dbus_bool_t print_pid;
BusContextFlags flags;
-#ifdef DBUS_UNIX
- const char *error_str;
-
- /* Redirect stdin from /dev/null since we will never need it, and
- * redirect stdout and stderr to /dev/null if not already open.
- *
- * We should do this as the very first thing, to ensure that when we
- * create other file descriptors (for example for epoll, inotify or
- * a socket), they never get assigned as fd 0, 1 or 2. If they were,
- * which could happen if our caller had (incorrectly) closed those
- * standard fds, they'd get closed when we daemonize - for example,
- * closing our listening socket would stop us listening, and closing
- * a Linux epoll socket would cause the main loop to fail. */
- if (!_dbus_ensure_standard_fds (DBUS_FORCE_STDIN_NULL, &error_str))
- {
- fprintf (stderr,
- "dbus-daemon: fatal error setting up standard fds: %s: %s\n",
- error_str, _dbus_strerror (errno));
- return 1;
- }
-#endif
if (!_dbus_string_init (&config_file))
return 1;
@@ -446,21 +399,19 @@
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, "--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, "--systemd-activation") == 0)
+ {
+ flags |= BUS_CONTEXT_FLAG_SYSTEMD_ACTIVATION;
+ }
else if (strcmp (arg, "--system") == 0)
{
check_two_config_files (&config_file, "system");
@@ -645,12 +596,6 @@
exit (1);
}
- if (!bus_apparmor_pre_init ())
- {
- _dbus_warn ("AppArmor pre-initialization failed: out of memory\n");
- exit (1);
- }
-
dbus_error_init (&error);
context = bus_context_new (&config_file, flags,
&print_addr_pipe, &print_pid_pipe,
@@ -677,7 +622,12 @@
* 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");
@@ -686,8 +636,6 @@
bus_context_shutdown (context);
bus_context_unref (context);
bus_selinux_shutdown ();
- bus_apparmor_shutdown ();
- bus_audit_shutdown ();
return 0;
}
diff --git a/bus/policy.c b/bus/policy.c
index 082f385..379cea9 100644
--- a/bus/policy.c
+++ b/bus/policy.c
@@ -1302,12 +1302,12 @@
return bus_rules_check_can_own (policy->rules, service_name);
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/policy.h b/bus/policy.h
index d1d3e72..3ff6f48 100644
--- a/bus/policy.h
+++ b/bus/policy.h
@@ -161,7 +161,7 @@
BusPolicyRule *rule);
void bus_client_policy_optimize (BusClientPolicy *policy);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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 ca884ef..36287e9 100644
--- a/bus/selinux.c
+++ b/bus/selinux.c
@@ -28,7 +28,6 @@
#include <dbus/dbus-userdb.h>
#endif
#include "selinux.h"
-#include "audit.h"
#include "services.h"
#include "policy.h"
#include "utils.h"
@@ -45,12 +44,15 @@
#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>
#include <grp.h>
#endif /* HAVE_SELINUX */
#ifdef HAVE_LIBAUDIT
+#include <cap-ng.h>
#include <libaudit.h>
#endif /* HAVE_LIBAUDIT */
@@ -115,40 +117,54 @@
*/
#ifdef HAVE_SELINUX
+#ifdef HAVE_LIBAUDIT
+static int audit_fd = -1;
+#endif
+
+void
+bus_selinux_audit_init(void)
+{
+#ifdef HAVE_LIBAUDIT
+ audit_fd = audit_open ();
+
+ if (audit_fd < 0)
+ {
+ /* If kernel doesn't support audit, bail out */
+ if (errno == EINVAL || errno == EPROTONOSUPPORT || errno == EAFNOSUPPORT)
+ return;
+ /* If user bus, bail out */
+ if (errno == EPERM && getuid() != 0)
+ return;
+ _dbus_warn ("Failed opening connection to the audit subsystem");
+ }
+#endif /* HAVE_LIBAUDIT */
+}
+
static void
log_callback (const char *fmt, ...)
{
va_list ap;
-#ifdef HAVE_LIBAUDIT
- int audit_fd;
-#endif
va_start(ap, fmt);
#ifdef HAVE_LIBAUDIT
- audit_fd = bus_audit_get_fd ();
-
if (audit_fd >= 0)
{
- /* This should really be a DBusString, but DBusString allocates
- * memory dynamically; before switching it, we need to check with
- * SELinux people that it would be OK for this to fall back to
- * syslog if OOM, like the equivalent AppArmor code does. */
- char buf[PATH_MAX*2];
-
- /* FIXME: need to change this to show real user */
- vsnprintf(buf, sizeof(buf), fmt, ap);
- audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL,
- NULL, getuid());
- goto out;
+ capng_get_caps_process();
+ if (capng_have_capability(CAPNG_EFFECTIVE, CAP_AUDIT_WRITE))
+ {
+ char buf[PATH_MAX*2];
+
+ /* FIXME: need to change this to show real user */
+ vsnprintf(buf, sizeof(buf), fmt, ap);
+ audit_log_user_avc_message(audit_fd, AUDIT_USER_AVC, buf, NULL, NULL,
+ NULL, getuid());
+ return;
+ }
}
#endif /* HAVE_LIBAUDIT */
-
+
vsyslog (LOG_USER | LOG_INFO, fmt, ap);
-
-#ifdef HAVE_LIBAUDIT
-out:
-#endif
va_end(ap);
}
@@ -298,27 +314,8 @@
#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 */
-
/**
- * Establish dynamic object class and permission mapping and
- * initialize the user space access vector cache (AVC) for D-Bus and set up
+ * Initialize the user space access vector cache (AVC) for D-Bus and set up
* logging callbacks.
*/
dbus_bool_t
@@ -337,13 +334,6 @@
_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)
{
@@ -946,7 +936,8 @@
void
bus_selinux_id_table_print (DBusHashTable *service_table)
{
-#if defined (DBUS_ENABLE_VERBOSE_MODE) && defined (HAVE_SELINUX)
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+#ifdef HAVE_SELINUX
DBusHashIter iter;
if (!selinux_enabled)
@@ -962,18 +953,19 @@
_dbus_verbose ("The context is %s\n", sid->ctx);
_dbus_verbose ("The refcount is %d\n", sid->refcnt);
}
-#endif /* DBUS_ENABLE_VERBOSE_MODE && HAVE_SELINUX */
+#endif /* HAVE_SELINUX */
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
}
+#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)
@@ -991,9 +983,10 @@
_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.
@@ -1012,9 +1005,89 @@
sidput (bus_sid);
bus_sid = SECSID_WILD;
- bus_avc_print_stats ();
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+
+ if (_dbus_is_verbose())
+ bus_avc_print_stats ();
+
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
avc_destroy ();
+#ifdef HAVE_LIBAUDIT
+ audit_close (audit_fd);
+#endif /* HAVE_LIBAUDIT */
}
#endif /* HAVE_SELINUX */
}
+
+/* The !HAVE_LIBAUDIT case lives in dbus-sysdeps-util-unix.c */
+#ifdef HAVE_LIBAUDIT
+/**
+ * Changes the user and group the bus is running as.
+ *
+ * @param user the user to become
+ * @param error return location for errors
+ * @returns #FALSE on failure
+ */
+dbus_bool_t
+_dbus_change_to_daemon_user (const char *user,
+ DBusError *error)
+{
+ dbus_uid_t uid;
+ dbus_gid_t gid;
+ DBusString u;
+
+ _dbus_string_init_const (&u, user);
+
+ if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
+ {
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "User '%s' does not appear to exist?",
+ user);
+ return FALSE;
+ }
+
+ /* If we were root */
+ if (_dbus_geteuid () == 0)
+ {
+ int rc;
+
+ capng_clear (CAPNG_SELECT_BOTH);
+ capng_update (CAPNG_ADD, CAPNG_EFFECTIVE | CAPNG_PERMITTED,
+ CAP_AUDIT_WRITE);
+ rc = capng_change_id (uid, gid, CAPNG_DROP_SUPP_GRP);
+ if (rc)
+ {
+ switch (rc) {
+ default:
+ dbus_set_error (error, DBUS_ERROR_FAILED,
+ "Failed to drop capabilities: %s\n",
+ _dbus_strerror (errno));
+ break;
+ case -4:
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Failed to set GID to %lu: %s", gid,
+ _dbus_strerror (errno));
+ break;
+ case -5:
+ _dbus_warn ("Failed to drop supplementary groups: %s\n",
+ _dbus_strerror (errno));
+ break;
+ case -6:
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Failed to set UID to %lu: %s", uid,
+ _dbus_strerror (errno));
+ break;
+ case -7:
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Failed to unset keep-capabilities: %s\n",
+ _dbus_strerror (errno));
+ break;
+ }
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+#endif
diff --git a/bus/selinux.h b/bus/selinux.h
index e44c97e..3bab36d 100644
--- a/bus/selinux.h
+++ b/bus/selinux.h
@@ -66,4 +66,7 @@
BusSELinuxID* bus_selinux_init_connection_id (DBusConnection *connection,
DBusError *error);
+
+void bus_selinux_audit_init(void);
+
#endif /* BUS_SELINUX_H */
diff --git a/bus/services.c b/bus/services.c
index 6a4c884..6f380fa 100644
--- a/bus/services.c
+++ b/bus/services.c
@@ -36,7 +36,6 @@
#include "policy.h"
#include "bus.h"
#include "selinux.h"
-#include "apparmor.h"
struct BusService
{
@@ -76,7 +75,6 @@
{
BusRegistry *registry;
- _dbus_assert (context);
registry = dbus_new0 (BusRegistry, 1);
if (registry == NULL)
return NULL;
@@ -370,7 +368,7 @@
error:
for (j = 0; j < i; j++)
- dbus_free (retval[j]);
+ dbus_free (retval[i]);
dbus_free (retval);
return FALSE;
@@ -460,11 +458,6 @@
_dbus_string_get_const_data (service_name));
goto out;
}
-
- if (!bus_apparmor_allows_acquire_service (connection,
- bus_context_get_type (registry->context),
- _dbus_string_get_const_data (service_name), error))
- goto out;
if (!bus_client_policy_check_can_own (policy, service_name))
{
@@ -595,9 +588,8 @@
activation = bus_context_get_activation (registry->context);
retval = bus_activation_send_pending_auto_activation_messages (activation,
service,
- transaction);
- if (!retval)
- BUS_SET_OOM (error);
+ transaction,
+ error);
out:
return retval;
diff --git a/bus/session.conf.in b/bus/session.conf.in
index affa7f1..e121ff9 100644
--- a/bus/session.conf.in
+++ b/bus/session.conf.in
@@ -12,17 +12,7 @@
the behavior of child processes. -->
<keep_umask/>
- <listen>@DBUS_SESSION_BUS_LISTEN_ADDRESS@</listen>
-
- <!-- On Unix systems, the most secure authentication mechanism is
- EXTERNAL, which uses credential-passing over Unix sockets.
-
- This authentication mechanism is not available on Windows,
- is not suitable for use with the tcp: or nonce-tcp: transports,
- and will not work on obscure flavours of Unix that do not have
- a supported credentials-passing mechanism. On those platforms/transports,
- comment out the <auth> element to allow fallback to DBUS_COOKIE_SHA1. -->
- @DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL@
+ <listen>@DBUS_SESSION_BUS_DEFAULT_ADDRESS@</listen>
<standard_session_servicedirs />
@@ -35,18 +25,13 @@
<allow own="*"/>
</policy>
- <!-- Include legacy configuration location -->
- <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session.conf</include>
-
<!-- Config files are placed here that among other things,
further restrict the above policy for specific services. -->
<includedir>session.d</includedir>
- <includedir>@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session.d</includedir>
-
<!-- This is included last so local configuration can override what's
in this standard file -->
- <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/session-local.conf</include>
+ <include ignore_missing="yes">session-local.conf</include>
<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
@@ -64,11 +49,9 @@
<limit name="max_outgoing_bytes">1000000000</limit>
<limit name="max_outgoing_unix_fds">250000000</limit>
<limit name="max_message_size">1000000000</limit>
- <!-- We do not override max_message_unix_fds here since the in-kernel
- limit is also relatively low -->
+ <limit name="max_message_unix_fds">4096</limit>
<limit name="service_start_timeout">120000</limit>
<limit name="auth_timeout">240000</limit>
- <limit name="pending_fd_timeout">150000</limit>
<limit name="max_completed_connections">100000</limit>
<limit name="max_incomplete_connections">10000</limit>
<limit name="max_connections_per_user">100000</limit>
diff --git a/bus/signals.c b/bus/signals.c
index e8def9f..28506d3 100644
--- a/bus/signals.c
+++ b/bus/signals.c
@@ -22,9 +22,6 @@
*/
#include <config.h>
-
-#include <string.h>
-
#include "signals.h"
#include "services.h"
#include "utils.h"
@@ -67,7 +64,7 @@
rule->refcount = 1;
rule->matches_go_to = matches_go_to;
-#ifndef DBUS_ENABLE_EMBEDDED_TESTS
+#ifndef DBUS_BUILD_TESTS
_dbus_assert (rule->matches_go_to != NULL);
#endif
@@ -121,46 +118,10 @@
}
}
-#if defined(DBUS_ENABLE_VERBOSE_MODE) || defined(DBUS_ENABLE_STATS)
-static dbus_bool_t
-append_key_and_escaped_value (DBusString *str, const char *token, const char *value)
-{
- const char *p = value;
-
- if (!_dbus_string_append_printf (str, "%s='", token))
- return FALSE;
-
- while (*p != '\0')
- {
- const char *next = strchr (p, '\'');
-
- if (next)
- {
- if (!_dbus_string_append_printf (str, "%.*s", (int) (next - p), p))
- return FALSE;
- /* Horrible escape sequence: single quote cannot be escaped inside
- * a single quoted string. So we close the single quote, escape the
- * single quote, and reopen a single quote.
- */
- if (!_dbus_string_append_printf (str, "'\\''"))
- return FALSE;
- p = next + 1;
- }
- else
- {
- if (!_dbus_string_append_printf (str, "%s", p))
- return FALSE;
- break;
- }
- }
-
- if (!_dbus_string_append_byte (str, '\''))
- return FALSE;
-
- return TRUE;
-}
-
-/* returns NULL if no memory */
+#ifdef DBUS_ENABLE_VERBOSE_MODE
+/* Note this function does not do escaping, so it's only
+ * good for debug spew at the moment
+ */
static char*
match_rule_to_string (BusMatchRule *rule)
{
@@ -169,12 +130,15 @@
if (!_dbus_string_init (&str))
{
- return NULL;
+ char *s;
+ while ((s = _dbus_strdup ("nomem")) == NULL)
+ ; /* only OK for debug spew... */
+ return s;
}
if (rule->flags & BUS_MATCH_MESSAGE_TYPE)
{
- if (!append_key_and_escaped_value (&str, "type",
+ if (!_dbus_string_append_printf (&str, "type='%s'",
dbus_message_type_to_string (rule->message_type)))
goto nomem;
}
@@ -187,7 +151,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "interface", rule->interface))
+ if (!_dbus_string_append_printf (&str, "interface='%s'", rule->interface))
goto nomem;
}
@@ -199,7 +163,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "member", rule->member))
+ if (!_dbus_string_append_printf (&str, "member='%s'", rule->member))
goto nomem;
}
@@ -211,7 +175,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "path", rule->path))
+ if (!_dbus_string_append_printf (&str, "path='%s'", rule->path))
goto nomem;
}
@@ -223,7 +187,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "path_namespace", rule->path))
+ if (!_dbus_string_append_printf (&str, "path_namespace='%s'", rule->path))
goto nomem;
}
@@ -235,7 +199,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "sender", rule->sender))
+ if (!_dbus_string_append_printf (&str, "sender='%s'", rule->sender))
goto nomem;
}
@@ -247,7 +211,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "destination", rule->destination))
+ if (!_dbus_string_append_printf (&str, "destination='%s'", rule->destination))
goto nomem;
}
@@ -259,7 +223,7 @@
goto nomem;
}
- if (!append_key_and_escaped_value (&str, "eavesdrop",
+ if (!_dbus_string_append_printf (&str, "eavesdrop='%s'",
(rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) ?
"true" : "false"))
goto nomem;
@@ -288,12 +252,11 @@
is_namespace = (rule->arg_lens[i] & BUS_MATCH_ARG_NAMESPACE) != 0;
if (!_dbus_string_append_printf (&str,
- "arg%d%s",
+ "arg%d%s='%s'",
i,
is_path ? "path" :
- is_namespace ? "namespace" : ""))
- goto nomem;
- if (!append_key_and_escaped_value (&str, "", rule->args[i]))
+ is_namespace ? "namespace" : "",
+ rule->args[i]))
goto nomem;
}
@@ -309,9 +272,14 @@
nomem:
_dbus_string_free (&str);
- return NULL;
+ {
+ char *s;
+ while ((s = _dbus_strdup ("nomem")) == NULL)
+ ; /* only OK for debug spew... */
+ return s;
+ }
}
-#endif /* defined(DBUS_ENABLE_VERBOSE_MODE) || defined(DBUS_ENABLE_STATS) */
+#endif /* DBUS_ENABLE_VERBOSE_MODE */
dbus_bool_t
bus_match_rule_set_message_type (BusMatchRule *rule,
@@ -411,15 +379,6 @@
}
dbus_bool_t
-bus_match_rule_get_client_is_eavesdropping (BusMatchRule *rule)
-{
- if (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING)
- return TRUE;
- else
- return FALSE;
-}
-
-dbus_bool_t
bus_match_rule_set_path (BusMatchRule *rule,
const char *path,
dbus_bool_t is_namespace)
@@ -848,8 +807,7 @@
if (end != length)
{
- int len1 = strlen ("path");
- if ((end + len1) == length &&
+ if ((end + strlen ("path")) == length &&
_dbus_string_ends_with_c_str (&key_str, "path"))
{
is_path = TRUE;
@@ -1183,74 +1141,6 @@
RulePool rules_by_type[DBUS_NUM_MESSAGE_TYPES];
};
-#ifdef DBUS_ENABLE_STATS
-dbus_bool_t
-bus_match_rule_dump (BusMatchmaker *matchmaker,
- DBusConnection *conn_filter,
- DBusMessageIter *arr_iter)
-{
- int i;
-
- for (i = 0 ; i < DBUS_NUM_MESSAGE_TYPES ; i++)
- {
- DBusHashIter iter;
- DBusList **list;
- DBusList *link;
-
- _dbus_hash_iter_init (matchmaker->rules_by_type[i].rules_by_iface, &iter);
- while (_dbus_hash_iter_next (&iter))
- {
- list = _dbus_hash_iter_get_value (&iter);
- for (link = _dbus_list_get_first_link (list);
- link != NULL;
- link = _dbus_list_get_next_link (list, link))
- {
- BusMatchRule *rule = link->data;
-
- if (rule->matches_go_to == conn_filter)
- {
- char *s = match_rule_to_string (rule);
-
- if (s == NULL)
- return FALSE;
-
- if (!dbus_message_iter_append_basic (arr_iter, DBUS_TYPE_STRING, &s))
- {
- dbus_free (s);
- return FALSE;
- }
- dbus_free (s);
- }
- }
- }
- list = &matchmaker->rules_by_type[i].rules_without_iface;
- for (link = _dbus_list_get_first_link (list);
- link != NULL;
- link = _dbus_list_get_next_link (list, link))
- {
- BusMatchRule *rule = link->data;
-
- if (rule->matches_go_to == conn_filter)
- {
- char *s = match_rule_to_string (rule);
-
- if (s == NULL)
- return FALSE;
-
- if (!dbus_message_iter_append_basic (arr_iter, DBUS_TYPE_STRING, &s))
- {
- dbus_free (s);
- return FALSE;
- }
- dbus_free (s);
- }
- }
- }
-
- return TRUE;
-}
-#endif
-
static void
rule_list_free (DBusList **rules)
{
@@ -1469,7 +1359,7 @@
char *s = match_rule_to_string (rule);
_dbus_verbose ("Added match rule %s to connection %p\n",
- s ? s : "nomem", rule->matches_go_to);
+ s, rule->matches_go_to);
dbus_free (s);
}
#endif
@@ -1562,7 +1452,7 @@
char *s = match_rule_to_string (rule);
_dbus_verbose ("Removed match rule %s for connection %p\n",
- s ? s : "nomem", rule->matches_go_to);
+ s, rule->matches_go_to);
dbus_free (s);
}
#endif
@@ -1599,7 +1489,7 @@
char *s = match_rule_to_string (rule);
_dbus_verbose ("Removed match rule %s for connection %p\n",
- s ? s : "nomem", rule->matches_go_to);
+ s, rule->matches_go_to);
dbus_free (s);
}
#endif
@@ -1946,11 +1836,8 @@
* 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 (len > 1 && path[len] != '\0' && path[len] != '/')
+ if (path[len] != '\0' && path[len] != '/')
return FALSE;
}
@@ -2076,7 +1963,7 @@
char *s = match_rule_to_string (rule);
_dbus_verbose ("Checking whether message matches rule %s for connection %p\n",
- s ? s : "nomem", rule->matches_go_to);
+ s, rule->matches_go_to);
dbus_free (s);
}
#endif
@@ -2093,10 +1980,12 @@
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);
@@ -2167,7 +2056,7 @@
return TRUE;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "test.h"
#include <stdlib.h>
@@ -2349,7 +2238,7 @@
rule = check_parse (TRUE, "arg7path='/foo'");
if (rule != NULL)
{
- _dbus_assert (rule->flags == BUS_MATCH_ARGS);
+ _dbus_assert (rule->flags = BUS_MATCH_ARGS);
_dbus_assert (rule->args != NULL);
_dbus_assert (rule->args_len == 8);
_dbus_assert (rule->args[7] != NULL);
@@ -2511,12 +2400,7 @@
{ "type='method_call',arg3='foosh'", "arg3='foosh',type='method_call'" },
{ "arg3='fool'", "arg3='fool'" },
{ "arg0namespace='fool'", "arg0namespace='fool'" },
- { "member='food'", "member='food'" },
- { "member=escape", "member='escape'" },
- { "member=icecream", "member=ice'cream'" },
- { "arg0='comma,type=comma',type=signal", "type=signal,arg0='comma,type=comma'" },
- { "arg0=escap\\e", "arg0='escap\\e'" },
- { "arg0=Time: 8 o\\'clock", "arg0='Time: 8 o'\\''clock'" },
+ { "member='food'", "member='food'" }
};
static void
@@ -2529,8 +2413,6 @@
{
BusMatchRule *first;
BusMatchRule *second;
- char *first_str, *second_str;
- BusMatchRule *first_reparsed, *second_reparsed;
int j;
first = check_parse (TRUE, equality_tests[i].first);
@@ -2546,21 +2428,6 @@
exit (1);
}
- /* Check match_rule_to_string */
- first_str = match_rule_to_string (first);
- _dbus_assert (first_str != NULL);
- second_str = match_rule_to_string (second);
- _dbus_assert (second_str != NULL);
- _dbus_assert (strcmp (first_str, second_str) == 0);
- first_reparsed = check_parse (TRUE, first_str);
- second_reparsed = check_parse (TRUE, second_str);
- _dbus_assert (match_rule_equal (first, first_reparsed));
- _dbus_assert (match_rule_equal (second, second_reparsed));
- bus_match_rule_unref (first_reparsed);
- bus_match_rule_unref (second_reparsed);
- dbus_free (first_str);
- dbus_free (second_str);
-
bus_match_rule_unref (second);
/* Check that the rule is not equal to any of the
@@ -2852,7 +2719,6 @@
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
@@ -2867,7 +2733,6 @@
static const char*
path_namespace_should_match_message_2[] = {
- "type='signal',path_namespace='/'",
"type='signal',path_namespace='/foo/TheObjectManager'",
NULL
};
@@ -2879,7 +2744,6 @@
static const char*
path_namespace_should_match_message_3[] = {
- "type='signal',path_namespace='/'",
NULL
};
@@ -2889,25 +2753,12 @@
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);
@@ -2924,11 +2775,6 @@
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);
@@ -2938,11 +2784,7 @@
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);
@@ -2969,5 +2811,5 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/signals.h b/bus/signals.h
index 0edfb07..a71d2e4 100644
--- a/bus/signals.h
+++ b/bus/signals.h
@@ -73,18 +73,10 @@
void bus_match_rule_set_client_is_eavesdropping (BusMatchRule *rule,
dbus_bool_t is_eavesdropping);
-dbus_bool_t bus_match_rule_get_client_is_eavesdropping (BusMatchRule *rule);
-
BusMatchRule* bus_match_rule_parse (DBusConnection *matches_go_to,
const DBusString *rule_text,
DBusError *error);
-#ifdef DBUS_ENABLE_STATS
-dbus_bool_t bus_match_rule_dump (BusMatchmaker *matchmaker,
- DBusConnection *conn_filter,
- DBusMessageIter *arr_iter);
-#endif
-
BusMatchmaker* bus_matchmaker_new (void);
BusMatchmaker* bus_matchmaker_ref (BusMatchmaker *matchmaker);
void bus_matchmaker_unref (BusMatchmaker *matchmaker);
diff --git a/bus/stats.c b/bus/stats.c
index dace0e2..28fd49b 100644
--- a/bus/stats.c
+++ b/bus/stats.c
@@ -1,8 +1,5 @@
/* 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
@@ -24,25 +21,168 @@
#include <config.h>
#include "stats.h"
-#include <dbus/dbus-asv-util.h>
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection-internal.h>
#include "connection.h"
-#include "driver.h"
#include "services.h"
-#include "signals.h"
#include "utils.h"
#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,
DBusMessage *message,
DBusError *error)
{
- BusContext *context;
BusConnections *connections;
DBusMessage *reply = NULL;
DBusMessageIter iter, arr_iter;
@@ -51,56 +191,49 @@
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!bus_driver_check_message_is_for_us (message, error))
- return FALSE;
+ connections = bus_transaction_get_connections (transaction);
- context = bus_transaction_get_context (transaction);
- connections = bus_context_get_connections (context);
-
- reply = _dbus_asv_new_method_return (message, &iter, &arr_iter);
+ reply = new_asv_reply (message, &iter, &arr_iter);
if (reply == NULL)
goto oom;
/* Globals */
- _dbus_list_get_stats (&in_use, &in_free_list, &allocated);
+ if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++))
+ 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;
- }
+ _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;
/* Connections */
- if (!_dbus_asv_add_uint32 (&arr_iter, "ActiveConnections",
+ if (!asv_add_uint32 (&iter, &arr_iter, "ActiveConnections",
bus_connections_get_n_active (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "IncompleteConnections",
+ !asv_add_uint32 (&iter, &arr_iter, "IncompleteConnections",
bus_connections_get_n_incomplete (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "MatchRules",
+ !asv_add_uint32 (&iter, &arr_iter, "MatchRules",
bus_connections_get_total_match_rules (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules",
bus_connections_get_peak_match_rules (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRulesPerConnection",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRulesPerConnection",
bus_connections_get_peak_match_rules_per_conn (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "BusNames",
+ !asv_add_uint32 (&iter, &arr_iter, "BusNames",
bus_connections_get_total_bus_names (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames",
bus_connections_get_peak_bus_names (connections)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNamesPerConnection",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakBusNamesPerConnection",
bus_connections_get_peak_bus_names_per_conn (connections)))
- {
- _dbus_asv_abandon (&iter, &arr_iter);
- goto oom;
- }
+ goto oom;
/* end */
- if (!_dbus_asv_close (&iter, &arr_iter))
+ if (!close_asv_reply (&iter, &arr_iter))
goto oom;
if (!bus_transaction_send_from_driver (transaction, connection, reply))
@@ -136,9 +269,6 @@
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!bus_driver_check_message_is_for_us (message, error))
- return FALSE;
-
registry = bus_connection_get_registry (caller_connection);
if (! dbus_message_get_args (message, error,
@@ -159,28 +289,25 @@
stats_connection = bus_service_get_primary_owners_connection (service);
_dbus_assert (stats_connection != NULL);
- reply = _dbus_asv_new_method_return (message, &iter, &arr_iter);
+ reply = new_asv_reply (message, &iter, &arr_iter);
if (reply == NULL)
goto oom;
/* Bus daemon per-connection stats */
- if (!_dbus_asv_add_uint32 (&arr_iter, "Serial", stats_serial++) ||
- !_dbus_asv_add_uint32 (&arr_iter, "MatchRules",
+ if (!asv_add_uint32 (&iter, &arr_iter, "Serial", stats_serial++) ||
+ !asv_add_uint32 (&iter, &arr_iter, "MatchRules",
bus_connection_get_n_match_rules (stats_connection)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakMatchRules",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakMatchRules",
bus_connection_get_peak_match_rules (stats_connection)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "BusNames",
+ !asv_add_uint32 (&iter, &arr_iter, "BusNames",
bus_connection_get_n_services_owned (stats_connection)) ||
- !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames",
+ !asv_add_uint32 (&iter, &arr_iter, "PeakBusNames",
bus_connection_get_peak_bus_names (stats_connection)) ||
- !_dbus_asv_add_string (&arr_iter, "UniqueName",
+ !asv_add_string (&iter, &arr_iter, "UniqueName",
bus_connection_get_name (stats_connection)))
- {
- _dbus_asv_abandon (&iter, &arr_iter);
- goto oom;
- }
+ goto oom;
/* DBusConnection per-connection stats */
@@ -190,24 +317,21 @@
&out_messages, &out_bytes, &out_fds,
&out_peak_bytes, &out_peak_fds);
- 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;
- }
+ 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;
/* end */
- if (!_dbus_asv_close (&iter, &arr_iter))
+ if (!close_asv_reply (&iter, &arr_iter))
goto oom;
if (!bus_transaction_send_from_driver (transaction, caller_connection,
@@ -225,120 +349,4 @@
return FALSE;
}
-
-dbus_bool_t
-bus_stats_handle_get_all_match_rules (DBusConnection *caller_connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error)
-{
- BusContext *context;
- DBusString bus_name_str;
- DBusMessage *reply = NULL;
- DBusMessageIter iter, hash_iter, entry_iter, arr_iter;
- BusRegistry *registry;
- char **services = NULL;
- int services_len;
- DBusConnection *conn_filter = NULL;
- BusMatchmaker *matchmaker;
- int i;
-
- _DBUS_ASSERT_ERROR_IS_CLEAR (error);
-
- registry = bus_connection_get_registry (caller_connection);
- context = bus_transaction_get_context (transaction);
- matchmaker = bus_context_get_matchmaker (context);
-
- if (!bus_registry_list_services (registry, &services, &services_len))
- return FALSE;
-
- reply = dbus_message_new_method_return (message);
- if (reply == NULL)
- goto oom;
-
- dbus_message_iter_init_append (reply, &iter);
-
- if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sas}",
- &hash_iter))
- goto oom;
-
- for (i = 0 ; i < services_len ; i++)
- {
- BusService *service;
-
- /* To avoid duplicate entries, only look for unique names */
- if (services[i][0] != ':')
- continue;
-
- _dbus_string_init_const (&bus_name_str, services[i]);
- service = bus_registry_lookup (registry, &bus_name_str);
- _dbus_assert (service != NULL);
-
- conn_filter = bus_service_get_primary_owners_connection (service);
- _dbus_assert (conn_filter != NULL);
-
- if (!dbus_message_iter_open_container (&hash_iter, DBUS_TYPE_DICT_ENTRY, NULL,
- &entry_iter))
- {
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
-
- if (!dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING, &services[i]))
- {
- dbus_message_iter_abandon_container (&hash_iter, &entry_iter);
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
-
- if (!dbus_message_iter_open_container (&entry_iter, DBUS_TYPE_ARRAY, "s",
- &arr_iter))
- {
- dbus_message_iter_abandon_container (&hash_iter, &entry_iter);
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
-
- if (!bus_match_rule_dump (matchmaker, conn_filter, &arr_iter))
- {
- dbus_message_iter_abandon_container (&entry_iter, &arr_iter);
- dbus_message_iter_abandon_container (&hash_iter, &entry_iter);
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
-
- if (!dbus_message_iter_close_container (&entry_iter, &arr_iter))
- {
- dbus_message_iter_abandon_container (&hash_iter, &entry_iter);
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
- if (!dbus_message_iter_close_container (&hash_iter, &entry_iter))
- {
- dbus_message_iter_abandon_container (&iter, &hash_iter);
- goto oom;
- }
- }
-
- if (!dbus_message_iter_close_container (&iter, &hash_iter))
- goto oom;
-
- if (!bus_transaction_send_from_driver (transaction, caller_connection,
- reply))
- goto oom;
-
- dbus_message_unref (reply);
- dbus_free_string_array (services);
- return TRUE;
-
-oom:
- if (reply != NULL)
- dbus_message_unref (reply);
-
- dbus_free_string_array (services);
-
- BUS_SET_OOM (error);
- return FALSE;
-}
-
#endif
diff --git a/bus/stats.h b/bus/stats.h
index dcb022c..0f843db 100644
--- a/bus/stats.h
+++ b/bus/stats.h
@@ -35,9 +35,4 @@
DBusMessage *message,
DBusError *error);
-dbus_bool_t bus_stats_handle_get_all_match_rules (DBusConnection *caller_connection,
- BusTransaction *transaction,
- DBusMessage *message,
- DBusError *error);
-
#endif /* multiple-inclusion guard */
diff --git a/bus/system.conf.in b/bus/system.conf.in
index 9f9bf45..92f4cc4 100644
--- a/bus/system.conf.in
+++ b/bus/system.conf.in
@@ -63,56 +63,21 @@
<allow receive_type="signal"/>
<!-- Allow anyone to talk to the message bus -->
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus" />
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Introspectable"/>
+ <allow send_destination="org.freedesktop.DBus"/>
<!-- But disallow some specific bus services -->
<deny send_destination="org.freedesktop.DBus"
send_interface="org.freedesktop.DBus"
send_member="UpdateActivationEnvironment"/>
- <deny send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Debug.Stats"/>
- <deny send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.systemd1.Activator"/>
</policy>
- <!-- Only systemd, which runs as root, may report activation failures. -->
- <policy user="root">
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.systemd1.Activator"/>
- </policy>
-
- <!-- root may monitor the system bus. -->
- <policy user="root">
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Monitoring"/>
- </policy>
-
- <!-- If the Stats interface was enabled at compile-time, root may use it.
- Copy this into system.local.conf or system.d/*.conf if you want to
- enable other privileged users to view statistics and debug info -->
- <policy user="root">
- <allow send_destination="org.freedesktop.DBus"
- send_interface="org.freedesktop.DBus.Debug.Stats"/>
- </policy>
-
- <!-- Include legacy configuration location -->
- <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system.conf</include>
-
<!-- Config files are placed here that among other things, punch
holes in the above policy for specific services. -->
<includedir>system.d</includedir>
- <includedir>@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system.d</includedir>
-
<!-- This is included last so local configuration can override what's
in this standard file -->
- <include ignore_missing="yes">@SYSCONFDIR_FROM_PKGDATADIR@/dbus-1/system-local.conf</include>
+ <include ignore_missing="yes">system-local.conf</include>
<include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
- <!-- Chromium talks to most services on the bus so needs a relatively
- large number of match rules. -->
- <limit name="max_match_rules_per_connection">4096</limit>
</busconfig>
diff --git a/bus/systemd-user/dbus.service.in b/bus/systemd-user/dbus.service.in
deleted file mode 100644
index b41f522..0000000
--- a/bus/systemd-user/dbus.service.in
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=D-Bus User Message Bus
-Documentation=man:dbus-daemon(1)
-Requires=dbus.socket
-
-[Service]
-ExecStart=@EXPANDED_BINDIR@/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation
-ExecReload=@EXPANDED_BINDIR@/dbus-send --print-reply --session --type=method_call --dest=org.freedesktop.DBus / org.freedesktop.DBus.ReloadConfig
-
-[Install]
-Also=dbus.socket
diff --git a/bus/systemd-user/dbus.socket.in b/bus/systemd-user/dbus.socket.in
deleted file mode 100644
index 4793d1d..0000000
--- a/bus/systemd-user/dbus.socket.in
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=D-Bus User Message Bus Socket
-
-[Socket]
-ListenStream=%t/bus
-ExecStartPost=-@SYSTEMCTL@ --user set-environment DBUS_SESSION_BUS_ADDRESS=unix:path=%t/bus
-
-[Install]
-WantedBy=sockets.target
-Also=dbus.service
diff --git a/bus/test-launch-helper.c b/bus/test-launch-helper.c
index c58d06e..ab36b6e 100644
--- a/bus/test-launch-helper.c
+++ b/bus/test-launch-helper.c
@@ -28,9 +28,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus-internals.h>
-#include <dbus/dbus-misc.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static void
die (const char *failure)
{
@@ -57,7 +56,7 @@
{
check_memleaks (name);
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
#ifdef ACTIVATION_LAUNCHER_DO_OOM
@@ -98,11 +97,11 @@
int
main (int argc, char **argv)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
const char *dir;
DBusString config_file;
- if (argc > 1 && strcmp (argv[1], "--tap") != 0)
+ if (argc > 1)
dir = argv[1];
else
dir = _dbus_getenv ("DBUS_TEST_DATA");
@@ -123,8 +122,8 @@
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);
@@ -138,7 +137,7 @@
printf ("%s: Success\n", argv[0]);
return 0;
-#else /* DBUS_ENABLE_EMBEDDED_TESTS */
+#else /* DBUS_BUILD_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test-main.c b/bus/test-main.c
index faa6395..0f736c7 100644
--- a/bus/test-main.c
+++ b/bus/test-main.c
@@ -31,11 +31,7 @@
#include <dbus/dbus-message-internal.h>
#include "selinux.h"
-#ifdef DBUS_UNIX
-# include <dbus/dbus-sysdeps-unix.h>
-#endif
-
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static void
die (const char *failure)
{
@@ -56,7 +52,7 @@
die ("memleaks");
}
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
static DBusInitialFDs *initial_fds = NULL;
@@ -88,14 +84,14 @@
int
main (int argc, char **argv)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
const char *dir;
const char *only;
DBusString test_data_dir;
progname = argv[0];
- if (argc > 1 && strcmp (argv[1], "--tap") != 0)
+ if (argc > 1)
dir = argv[1];
else
dir = _dbus_getenv ("DBUS_TEST_DATA");
@@ -113,11 +109,6 @@
_dbus_string_init_const (&test_data_dir, dir);
-#ifdef DBUS_UNIX
- /* close any inherited fds so dbus-spawn's check for close-on-exec works */
- _dbus_close_all ();
-#endif
-
if (!_dbus_threads_init_debug ())
die ("initializing debug threads");
@@ -190,7 +181,7 @@
return 0;
-#else /* DBUS_ENABLE_EMBEDDED_TESTS */
+#else /* DBUS_BUILD_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test-system.c b/bus/test-system.c
index 2d7848c..56a7d4e 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static void
die (const char *failure)
{
@@ -50,7 +50,7 @@
die ("memleaks");
}
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
static void
test_pre_hook (void)
@@ -67,13 +67,13 @@
int
main (int argc, char **argv)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
const char *dir;
DBusString test_data_dir;
progname = argv[0];
- if (argc > 1 && strcmp (argv[1], "--tap") != 0)
+ if (argc > 1)
dir = argv[1];
else
dir = _dbus_getenv ("DBUS_TEST_DATA");
@@ -98,7 +98,7 @@
printf ("%s: Success\n", argv[0]);
return 0;
-#else /* DBUS_ENABLE_EMBEDDED_TESTS */
+#else /* DBUS_BUILD_TESTS */
printf ("Not compiled with test support\n");
diff --git a/bus/test.c b/bus/test.c
index 31ef4c8..1ca9607 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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 38b74e8..98a2c6b 100644
--- a/bus/test.h
+++ b/bus/test.h
@@ -24,7 +24,7 @@
#ifndef BUS_TEST_H
#define BUS_TEST_H
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <dbus/dbus.h>
#include <dbus/dbus-string.h>
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 4db9c67..000acda 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -1,9 +1,3 @@
-# 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
@@ -12,36 +6,15 @@
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
-if(CMAKE_MAJOR_VERSION GREATER 2)
- cmake_policy(SET CMP0026 NEW)
- if (CMAKE_MAJOR_VERSION GREATER 4 OR CMAKE_MINOR_VERSION GREATER 1)
- cmake_policy(SET CMP0053 NEW)
- cmake_policy(SET CMP0054 NEW)
- endif()
-endif()
+# 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)
-autoinit(../configure.ac)
-autoversion(dbus)
-
-if(EXISTS ../config.h.in)
- autoheaderchecks(../config.h.in ConfigureChecks.cmake config.h.cmake)
-else()
- message(STATUS "Generate config.h.in with autogen.sh to enable cmake header difference check.")
-endif()
-
+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)
@@ -78,46 +51,21 @@
SET(DBUS_DATADIR ${DATADIR})
endif()
-set(DBUS_PREFIX ${DBUS_INSTALL_DIR})
-
set(prefix ${DBUS_INSTALL_DIR})
set(exec_prefix ${prefix})
set(EXPANDED_LIBDIR ${DBUS_INSTALL_DIR}/lib)
set(EXPANDED_INCLUDEDIR ${DBUS_INSTALL_DIR}/include)
set(EXPANDED_BINDIR ${DBUS_INSTALL_DIR}/bin)
set(EXPANDED_SYSCONFDIR ${DBUS_INSTALL_DIR}/etc)
-set(EXPANDED_LOCALSTATEDIR ${DBUS_INSTALL_DIR}/var)
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_LOCALSTATEDIR ${EXPANDED_LOCALSTATEDIR})
+set(DBUS_DAEMONDIR ${EXPANDED_BINDIR})
-# On Windows this is relative to where we put the bus setup, in
-# ${datadir}/dbus-1. For simplicity, we only do this if
-# ${sysconfdir} = ${prefix}/etc and ${datadir} = ${prefix}/share.
-#
-# On Unix, or on Windows with weird install layouts, it's the absolute path.
-if(WIN32 AND ${EXPANDED_SYSCONFDIR} STREQUAL ${prefix}/etc AND ${EXPANDED_DATADIR} STREQUAL ${prefix}/share)
-set(SYSCONFDIR_FROM_PKGDATADIR ../../etc)
-set(DATADIR_FROM_PKGSYSCONFDIR ../../share)
-else()
-set(SYSCONFDIR_FROM_PKGDATADIR ${EXPANDED_SYSCONFDIR})
-set(DATADIR_FROM_PKGSYSCONFDIR ${EXPANDED_DATADIR})
-endif()
-
-set(DBUS_LIBEXECDIR ${EXPANDED_LIBDIR})
-set(DBUS_DATADIR ${EXPANDED_DATADIR})
#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)
@@ -131,30 +79,30 @@
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)
-option (DBUS_DISABLE_ASSERT "Disable assertion checking" OFF)
+#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_ENABLE_STATS "enable bus daemon usage statistics" OFF)
-if(WIN32)
- set(FD_SETSIZE "8192" CACHE STRING "The maximum number of connections that can be handled at once")
-endif()
+option (DBUS_ENABLE_STATS "enable bus daemon usage statistics" OFF)
-find_package(EXPAT)
+if (DBUS_USE_EXPAT)
+ find_package(LibExpat)
+else ()
+ find_package(LibXml2)
+endif ()
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_GNU_SOURCE)
+add_definitions(-D_POSIX_C_SOURCE=199309L -D_GNU_SOURCE)
# do config checks
INCLUDE(ConfigureChecks.cmake)
@@ -170,6 +118,7 @@
endif(VCS)
if(WIN32)
+ set(CMAKE_DEBUG_POSTFIX "d")
if(MSVC)
# controll folders in msvc projects
include(ProjectSourceGroup)
@@ -208,26 +157,14 @@
endif(MSVC)
endif(WIN32)
-if (UNIX AND NOT DBUS_DISABLE_ASSERT)
+if (UNIX AND NOT DBUS_DISABLE_ASSERTS)
# 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_ASSERT)
-
-if(DBUS_WITH_GLIB)
- autodefine(GLIB_VERSION_MIN_REQUIRED)
- autodefine(GLIB_VERSION_MAX_ALLOWED)
-endif()
+endif (UNIX AND NOT DBUS_DISABLE_ASSERTS)
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
-if(MSVC)
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w14018")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w14018")
-else()
- SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare")
- SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare")
-endif()
#########################################################################
# Windows CE (>= 5.0.0)
@@ -290,12 +227,11 @@
########### 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)
- set (DBUS_ENABLE_EMBEDDED_TESTS ON)
- set (DBUS_ENABLE_MODULAR_TESTS ON)
- add_definitions(-DDBUS_ENABLE_EMBEDDED_TESTS -DDBUS_ENABLE_MODULAR_TESTS)
+ add_definitions(-DDBUS_BUILD_TESTS -DDBUS_ENABLE_EMBEDDED_TESTS)
endif(DBUS_BUILD_TESTS)
option (DBUS_USE_OUTPUT_DEBUG_STRING "enable win32 debug port for message output" OFF)
@@ -308,6 +244,7 @@
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)
@@ -317,11 +254,14 @@
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)
@@ -331,22 +271,21 @@
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_INOTIFY "build with inotify support (linux only)" ON)
- if(DBUS_BUS_ENABLE_INOTIFY)
- 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)
- 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)
+ option (DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX "build with dnotify support (linux only)" ON) # add a check !
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)
@@ -355,14 +294,31 @@
endif(HAVE_CONSOLE_OWNER_FILE)
endif("${sysname}" MATCHES ".*SOLARIS.*")
-if(NOT EXPAT_FOUND)
- message(FATAL_ERROR "expat not found!")
-endif(NOT EXPAT_FOUND)
+#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)
-SET(XML_LIB "Expat")
-SET(XML_LIBRARY ${EXPAT_LIBRARIES})
-SET(XML_INCLUDE_DIR ${EXPAT_INCLUDE_DIR})
+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]))
# all missing or hardcoded for now
# 'hidden' ones
@@ -397,8 +353,9 @@
# test binary names
if (WIN32)
- # follow Automake's naming convention so we can share .in files
- set (EXEEXT ${CMAKE_EXECUTABLE_SUFFIX})
+ # 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")
endif(WIN32)
if (MSVC_IDE)
@@ -433,7 +390,7 @@
else (NOT $ENV{TMP} STREQUAL "")
if (WIN32)
#Should never happen, both TMP and TEMP seem always set on Windows
- message(FATAL_ERROR "Could not determine a usable temporary directory")
+ message(FATAL "Could not determine a usable temporary directory")
else(WIN32)
set (DBUS_SESSION_SOCKET_DIR /tmp)
endif(WIN32)
@@ -441,8 +398,28 @@
endif (NOT $ENV{TEMP} STREQUAL "")
endif (NOT $ENV{TMPDIR} STREQUAL "")
- # Not used on Windows, where there is no system bus
-set (DBUS_SYSTEM_PID_FILE ${DBUS_LOCALSTATEDIR}/run/dbus/pid)
+#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
+ set (DBUS_SYSTEM_PID_FILE "/dbus-pid")
+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 "")
@@ -450,38 +427,27 @@
set (DBUS_CONSOLE_AUTH_DIR "/var/run/console/")
endif (WIN32)
-# 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=${DBUS_LOCALSTATEDIR}/run/dbus/system_bus_socket" CACHE STRING "system bus default address")
+#AC_ARG_WITH(dbus_user, AS_HELP_STRING([--with-dbus-user=<user>],[User for running the DBUS daemon (messagebus)]))
+
+set (DBUS_USER )
+
if (WIN32)
- set (DBUS_SESSION_BUS_LISTEN_ADDRESS "autolaunch:" CACHE STRING "session bus default listening address")
- set (DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:" CACHE STRING "session bus fallback address for clients")
+ 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_SYSTEM_CONFIG_FILE "share/dbus-1/system.conf")
- set (DBUS_SESSION_CONFIG_FILE "share/dbus-1/session.conf")
+ 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")
- set (DBUS_TEST_USER "guest")
- set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<!--<auth>EXTERNAL</auth>-->")
else (WIN32)
- 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 (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 (sysconfdir "")
set (configdir ${sysconfdir}/dbus-1 )
set (DBUS_SYSTEM_CONFIG_FILE ${configdir}/system.conf)
set (DBUS_SESSION_CONFIG_FILE ${configdir}/session.conf)
- set (DBUS_USER "messagebus")
- set (DBUS_TEST_USER "nobody")
- # For best security, assume that all non-Windows platforms can do
- # credentials-passing.
- set (DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL "<auth>EXTERNAL</auth>")
+ set (DBUS_USER "root")
endif (WIN32)
set (DBUS_DAEMON_NAME "dbus-daemon" CACHE STRING "The name of the dbus daemon executable")
@@ -506,7 +472,6 @@
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)
@@ -518,8 +483,11 @@
set(DBUS_LIBRARIES dbus-1)
set(DBUS_INTERNAL_LIBRARIES dbus-internal)
+# settings for building and using static internal lib
+# 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_CLIENT_DEFINITIONS "-DDBUS_COMPILATION")
+set (DBUS_INTERNAL_LIBRARY_DEFINITIONS "-DDBUS_STATIC_BUILD")
+set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
@@ -536,9 +504,6 @@
add_subdirectory( bus )
if (DBUS_BUILD_TESTS)
add_subdirectory( test )
- add_custom_target(check
- COMMAND ctest -R ^test-.*
- )
endif (DBUS_BUILD_TESTS)
add_subdirectory( tools )
add_subdirectory( doc )
@@ -554,13 +519,14 @@
GET_FILENAME_COMPONENT(CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME)
message(" D-BUS ${DBUS_VERSION} ")
-message(" ============ ")
+message(" =========== ")
message(" ")
message(" install prefix: ${prefix} ")
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} ")
@@ -579,24 +545,27 @@
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_ASSERT} ")
+message(" Building w/o assertions: ${DBUS_DISABLE_ASSERTS} ")
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 inotify support: ${DBUS_BUS_ENABLE_INOTIFY} ")
-message(" Building kqueue support: ${DBUS_BUS_ENABLE_KQUEUE} ")
+#message(" Building SELinux support: ${have_selinux} ")
+#message(" Building dnotify support: ${have_dnotify} ")
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 listens on: ${DBUS_SESSION_BUS_LISTEN_ADDRESS} ")
-message(" Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS} ")
+message(" Session bus address: ${DBUS_SESSION_BUS_DEFAULT_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} ")
@@ -615,9 +584,9 @@
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_ASSERT)
+if (DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERTS)
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_ASSERT)
+endif(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERTS)
if (DBUS_GCOV_ENABLED)
message("NOTE: building with coverage profiling is definitely for developers only.")
@@ -627,18 +596,13 @@
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_ASSERT)
+if(NOT DBUS_DISABLE_ASSERTS)
message("NOTE: building with assertions increases library size and decreases performance.")
-endif(NOT DBUS_DISABLE_ASSERT)
+endif(NOT DBUS_DISABLE_ASSERTS)
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.")
endif(DBUS_DISABLE_CHECKS)
-
-foreach(_note ${FOOTNOTES})
- message(${_note})
-endforeach()
-
MESSAGE(" ")
INCLUDE(modules/CPackInstallConfig.cmake)
diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake
index 119b83e..33a9cee 100644
--- a/cmake/ConfigureChecks.cmake
+++ b/cmake/ConfigureChecks.cmake
@@ -1,43 +1,25 @@
include(CheckIncludeFile)
-include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckStructMember)
include(CheckTypeSize)
-check_include_file(alloca.h HAVE_ALLOCA_H)
-check_include_file(byteswap.h HAVE_BYTESWAP_H)
-check_include_file(crt/externs.h HAVE_CRT_EXTERNS_H)
check_include_file(dirent.h HAVE_DIRENT_H) # dbus-sysdeps-util.c
-check_include_file(dlfcn.h HAVE_DLFCN_H)
-check_include_file(execinfo.h HAVE_EXECINFO_H)
-check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c
-check_include_file(expat.h HAVE_EXPAT_H)
-check_include_file(grp.h HAVE_GRP_H) # dbus-sysdeps-util-win.c
-check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h
check_include_file(io.h HAVE_IO_H) # internal
-check_include_file(locale.h HAVE_LOCALE_H)
-check_include_file(memory.h HAVE_MEMORY_H)
-check_include_file(signal.h HAVE_SIGNAL_H)
-check_include_file(stdint.h HAVE_STDINT_H) # dbus-pipe.h
-check_include_file(stdlib.h HAVE_STDLIB_H)
-check_include_file(stdio.h HAVE_STDIO_H) # dbus-sysdeps.h
-check_include_file(string.h HAVE_STRING_H)
-check_include_file(strings.h HAVE_STRINGS_H)
-check_include_file(syslog.h HAVE_SYSLOG_H)
-check_include_files("stdint.h;sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
-check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
-check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
-check_include_file(sys/stat.h HAVE_SYS_STAT_H)
-check_include_file(sys/types.h HAVE_SYS_TYPES_H)
-check_include_file(sys/uio.h HAVE_SYS_UIO_H)
+check_include_file(grp.h HAVE_GRP_H) # dbus-sysdeps-util-win.c
check_include_file(sys/poll.h HAVE_POLL) # dbus-sysdeps.c, dbus-sysdeps-win.c
-check_include_file(sys/prctl.h HAVE_SYS_PRCTL_H)
-check_include_file(sys/syslimits.h HAVE_SYS_SYSLIMITS_H) # dbus-sysdeps-unix.c
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
+check_include_file(errno.h HAVE_ERRNO_H) # dbus-sysdeps.c
+check_include_file(signal.h HAVE_SIGNAL_H)
+check_include_file(locale.h HAVE_LOCALE_H)
+check_include_file(inttypes.h HAVE_INTTYPES_H) # dbus-pipe.h
+check_include_file(stdint.h HAVE_STDINT_H) # dbus-pipe.h
check_symbol_exists(backtrace "execinfo.h" HAVE_BACKTRACE) # dbus-sysdeps.c, dbus-sysdeps-win.c
check_symbol_exists(getgrouplist "grp.h" HAVE_GETGROUPLIST) # dbus-sysdeps.c
@@ -50,18 +32,11 @@
check_symbol_exists(writev "sys/uio.h" HAVE_WRITEV) # dbus-sysdeps.c, dbus-sysdeps-win.c
check_symbol_exists(setrlimit "sys/resource.h" HAVE_SETRLIMIT) # dbus-sysdeps.c, dbus-sysdeps-win.c, test/test-segfault.c
check_symbol_exists(socketpair "sys/socket.h" HAVE_SOCKETPAIR) # dbus-sysdeps.c
+check_symbol_exists(socklen_t "sys/socket.h" HAVE_SOCKLEN_T) # dbus-sysdeps-unix.c
check_symbol_exists(setlocale "locale.h" HAVE_SETLOCALE) # dbus-test-main.c
check_symbol_exists(localeconv "locale.h" HAVE_LOCALECONV) # dbus-sysdeps.c
check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL) # dbus-send.c
check_symbol_exists(strtoull "stdlib.h" HAVE_STRTOULL) # dbus-send.c
-set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
-check_symbol_exists(pipe2 "fcntl.h;unistd.h" HAVE_PIPE2)
-check_symbol_exists(accept4 "sys/socket.h" HAVE_ACCEPT4)
-check_symbol_exists(dirfd "dirent.h" HAVE_DIRFD)
-check_symbol_exists(inotify_init1 "sys/inotify.h" HAVE_INOTIFY_INIT1)
-check_symbol_exists(SCM_RIGHTS "sys/types.h;sys/socket.h;sys/un.h" HAVE_UNIX_FD_PASSING)
-check_symbol_exists(prctl "sys/prctl.h" HAVE_PRCTL)
-check_symbol_exists(raise "signal.h" HAVE_RAISE)
check_struct_member(cmsgcred cmcred_pid "sys/types.h sys/socket.h" HAVE_CMSGCRED) # dbus-sysdeps.c
@@ -74,29 +49,28 @@
check_type_size("long" SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)
check_type_size("__int64" SIZEOF___INT64)
-set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
-check_type_size("socklen_t" SOCKLEN_T) # dbus-sysdeps-unix.c
-set(CMAKE_EXTRA_INCLUDE_FILES)
# 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
@@ -119,7 +93,7 @@
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
new file mode 100644
index 0000000..e00984e
--- /dev/null
+++ b/cmake/Doxyfile.cmake
@@ -0,0 +1,182 @@
+# 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 0dcae65..faf9a8e 100644
--- a/cmake/bus/CMakeLists.txt
+++ b/cmake/bus/CMakeLists.txt
@@ -1,18 +1,18 @@
+project(bus)
+
add_definitions(-DDBUS_COMPILATION)
SET(EFENCE "")
SET(BUS_DIR ${CMAKE_SOURCE_DIR}/../bus)
+set (config_DATA
+ session.conf
+ system.conf
+)
+
# config files for installation
CONFIGURE_FILE( "${BUS_DIR}/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/session.conf" IMMEDIATE @ONLY)
-CONFIGURE_FILE( "${BUS_DIR}/legacy-config/session.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/legacy-config/session.conf" IMMEDIATE @ONLY)
-FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/session.d)
-
-if(NOT WIN32)
- CONFIGURE_FILE( "${BUS_DIR}/system.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/system.conf" IMMEDIATE @ONLY)
- CONFIGURE_FILE( "${BUS_DIR}/legacy-config/system.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/legacy-config/system.conf" IMMEDIATE @ONLY)
- FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/system.d)
-endif()
+CONFIGURE_FILE( "system.conf.cmake" "${CMAKE_CURRENT_BINARY_DIR}/system.conf" IMMEDIATE @ONLY)
# copy services for local daemon start to local service dir data/dbus-1/services
SET (SERVICE_FILES test/data/valid-service-files)
@@ -26,34 +26,31 @@
configure_file(${FILE} ${TARGET} )
ENDFOREACH(FILE)
-SET (XML_SOURCES ${BUS_DIR}/config-loader-expat.c)
+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)
-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)
+# after next cvs update
+#set (DIR_WATCH_SOURCE ${BUS_DIR}/dir-watch-default.c)
+set (DIR_WATCH_SOURCE )
set (BUS_SOURCES
${BUS_DIR}/activation.c
${BUS_DIR}/activation.h
- ${BUS_DIR}/apparmor.c
- ${BUS_DIR}/apparmor.h
- ${BUS_DIR}/audit.c
- ${BUS_DIR}/audit.h
${BUS_DIR}/bus.c
${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
@@ -81,13 +78,9 @@
${BUS_DIR}/stats.c
${BUS_DIR}/stats.h
)
-endif(DBUS_ENABLE_STATS)
+endif()
-include_directories(
- ${CMAKE_BINARY_DIR}
- ${CMAKE_SOURCE_DIR}/..
- ${XML_INCLUDE_DIR}
-)
+include_directories(${XML_INCLUDE_DIR})
add_executable(dbus-daemon ${BUS_SOURCES} ${BUS_DIR}/main.c)
target_link_libraries(dbus-daemon ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY})
@@ -95,18 +88,8 @@
set_target_properties(dbus-daemon PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
install_targets(/bin dbus-daemon)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/session.conf DESTINATION share/dbus-1)
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/legacy-config/session.conf DESTINATION etc/dbus-1)
-install(DIRECTORY DESTINATION share/dbus-1/session.d)
-install(DIRECTORY DESTINATION share/dbus-1/services)
-
-if(NOT WIN32)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/system.conf DESTINATION share/dbus-1)
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/legacy-config/system.conf DESTINATION etc/dbus-1)
- install(DIRECTORY DESTINATION share/dbus-1/system.d)
- install(DIRECTORY DESTINATION share/dbus-1/system-services)
- install(DIRECTORY DESTINATION var/run/dbus)
-endif()
+install_files(/etc/dbus-1 FILES ${config_DATA})
+install(DIRECTORY . DESTINATION etc/dbus-1/session.d FILES_MATCHING PATTERN "*.conf")
if (DBUS_SERVICE)
set (dbus_service_SOURCES
@@ -122,21 +105,12 @@
install_targets(/bin dbus-service )
endif (DBUS_SERVICE)
-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})
- if (NOT WIN32)
- set(test_bus_system_SOURCES
- ${XML_SOURCES}
- ${BUS_DIR}/config-parser-common.c
- ${BUS_DIR}/config-parser-trivial.c
- ${BUS_DIR}/utils.c
- ${BUS_DIR}/test-system.c
- )
- add_test_executable(test-bus-system "${test_bus_system_SOURCES}" ${DBUS_INTERNAL_LIBRARIES} ${XML_LIBRARY} ${DBUS_BUS_LIBS})
- endif()
-endif (DBUS_ENABLE_EMBEDDED_TESTS)
+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(MSVC)
project_source_group(${GROUP_CODE} bus_test_SOURCES dummy)
@@ -172,10 +146,11 @@
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} )
- 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")
- install_targets(/lib dbus-daemon-launch-helper)
+ 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 )
+
endif(NOT WIN32)
#### Init scripts fun
diff --git a/cmake/bus/dbus-daemon.xml b/cmake/bus/dbus-daemon.xml
new file mode 100644
index 0000000..f331699
--- /dev/null
+++ b/cmake/bus/dbus-daemon.xml
@@ -0,0 +1,752 @@
+<?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. -->
+
+<refmeta>
+<refentrytitle>dbus-daemon</refentrytitle>
+<manvolnum>1</manvolnum>
+</refmeta>
+<refnamediv id='name'>
+<refname>dbus-daemon</refname>
+<refpurpose>Message bus daemon</refpurpose>
+</refnamediv>
+<!-- body begins here -->
+<refsynopsisdiv id='synopsis'>
+<cmdsynopsis>
+ <command>dbus-daemon</command></cmdsynopsis>
+<cmdsynopsis>
+ <command>dbus-daemon</command> <arg choice='opt'>--version </arg>
+ <arg choice='opt'>--session </arg>
+ <arg choice='opt'>--system </arg>
+ <arg choice='opt'>--config-file=<replaceable>FILE</replaceable></arg>
+ <arg choice='opt'><arg choice='plain'>--print-address </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
+ <arg choice='opt'><arg choice='plain'>--print-pid </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
+ <arg choice='opt'>--fork </arg>
+ <sbr/>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<refsect1 id='description'><title>DESCRIPTION</title>
+<para><command>dbus-daemon</command> is the D-Bus message bus daemon. See
+<ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more information about
+the big picture. D-Bus is first a library that provides one-to-one
+communication between any two applications; <command>dbus-daemon</command> 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.</para>
+
+
+<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
+a different configuration file.</para>
+
+
+<para>The --session option is equivalent to
+"--config-file=/etc/dbus-1/session.conf" and the --system
+option is equivalent to
+"--config-file=/etc/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 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
+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
+only take effect if you restart the daemon. Policy changes should take effect
+with SIGHUP.</para>
+
+</refsect1>
+
+<refsect1 id='options'><title>OPTIONS</title>
+<para>The following options are supported:</para>
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><option>--config-file=FILE</option></term>
+ <listitem>
+<para>Use the given configuration file.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--fork</option></term>
+ <listitem>
+<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>
+ </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
+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
+launch the message bus.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--session</option></term>
+ <listitem>
+<para>Use the standard configuration file for the per-login-session message
+bus.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--system</option></term>
+ <listitem>
+<para>Use the standard configuration file for the systemwide message bus.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--version</option></term>
+ <listitem>
+<para>Print the version of the daemon.</para>
+
+ </listitem>
+ </varlistentry>
+</variablelist>
+</refsect1>
+
+<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,
+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
+<include> a system-local.conf or session-local.conf; you can put local
+overrides in those files to avoid modifying the primary configuration
+files.</para>
+
+
+<para>The configuration file is an XML document. It must have the following
+doctype declaration:</para>
+<literallayout remap='.nf'>
+
+ <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "<ulink url='http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd'>http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd</ulink>">
+
+</literallayout> <!-- .fi -->
+
+
+<para>The following elements may be present in the configuration file.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><busconfig></emphasis></term>
+ <listitem>
+<para></para>
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>Root element.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><type></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<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
+<type> element "wins" (previous values are ignored).</para>
+
+
+<para>Example: <type>session</type></para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><include></emphasis></term>
+ <listitem>
+<para></para>
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>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.</para>
+
+
+<para><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.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><includedir></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>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.</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
+this message and allowed the printer daemon user to send it.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><user></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<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.
+If this element is not present, the daemon will not change or care
+about its UID.</para>
+
+
+<para>The last <user> entry in the file "wins", the others are ignored.</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
+privileges for writing.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><fork></emphasis></term>
+ <listitem>
+<para></para>
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<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'><listen></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<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: <listen>unix:path=/tmp/foo</listen></para>
+
+
+<para>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.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><auth></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>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.</para>
+
+
+<para>Example: <auth>EXTERNAL</auth></para>
+
+
+<para>Example: <auth>DBUS_COOKIE_SHA1</auth></para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><servicedir></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<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
+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,
+not the systemwide bus.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><standard_session_servicedirs/></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para><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.</para>
+
+
+<para>The "XDG Base Directory Specification" can be found at
+<ulink url='http://freedesktop.org/wiki/Standards/basedir-spec'>http://freedesktop.org/wiki/Standards/basedir-spec</ulink> if it hasn't moved,
+otherwise try your favorite search engine.</para>
+
+
+<para>The <standard_session_servicedirs/> option is only relevant to the
+per-user-session bus daemon defined in
+/etc/dbus-1/session.conf. Putting it in any other
+configuration file would probably be nonsense.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><limit></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para><limit> establishes a resource limit. For example:</para>
+<literallayout remap='.nf'>
+ <limit name="max_message_size">64</limit>
+ <limit name="max_completed_connections">512</limit>
+</literallayout> <!-- .fi -->
+
+
+<para>The name attribute is mandatory.
+Available limit names are:</para>
+<literallayout remap='.nf'>
+ "max_incoming_bytes" : total size in bytes of messages
+ incoming from a single connection
+ "max_outgoing_bytes" : total size in bytes 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
+ 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
+</literallayout> <!-- .fi -->
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<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'><policy></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>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.</para>
+
+
+<para>The <policy> element has one of three attributes:</para>
+<literallayout remap='.nf'>
+ context="(default|mandatory)"
+ user="username or userid"
+ group="group name or gid"
+</literallayout> <!-- .fi -->
+
+
+<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 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
+in the config file.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><deny></emphasis></term>
+ <listitem>
+<para><emphasis remap='I'><allow></emphasis></para>
+
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>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.</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_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"
+</literallayout> <!-- .fi -->
+
+
+<para>Examples:</para>
+<literallayout remap='.nf'>
+ <deny send_interface="org.freedesktop.System" send_member="Reboot"/>
+ <deny receive_interface="org.freedesktop.System" receive_member="Reboot"/>
+ <deny own="org.freedesktop.System"/>
+ <deny send_destination="org.freedesktop.System"/>
+ <deny receive_sender="org.freedesktop.System"/>
+ <deny user="john"/>
+ <deny group="enemies"/>
+</literallayout> <!-- .fi -->
+
+
+<para>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).</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>
+
+
+<para>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
+receive rules (with receive_* attributes).</para>
+
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>user and group denials mean that the given user or group may
+not connect to the message bus.</para>
+
+
+<para>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.</para>
+
+<para><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).</para>
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>Be careful with send_interface/receive_interface, because the
+interface field in messages is optional.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><selinux></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>The <selinux> element contains settings related to Security Enhanced Linux.
+More details below.</para>
+
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><emphasis remap='I'><associate></emphasis></term>
+ <listitem>
+
+<para></para> <!-- FIXME: blank list item -->
+ </listitem>
+ </varlistentry>
+</variablelist>
+
+<para>An <associate> element appears below an <selinux> element and
+creates a mapping. Right now only one kind of association is possible:</para>
+<literallayout remap='.nf'>
+ <associate own="org.freedesktop.Foobar" context="foo_t"/>
+</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
+short discussion of SELinux below.</para>
+
+
+<para>Note, the context here is the target context when requesting a name,
+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'>
+ <associate own="*" context="foo_t"/>
+</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>
+
+
+<para>If two <associate> elements specify the same name, the element
+appearing later in the configuration file will be used.</para>
+
+</refsect1>
+
+<refsect1 id='selinux'><title>SELinux</title>
+<para>See <ulink url='http://www.nsa.gov/selinux/'>http://www.nsa.gov/selinux/</ulink> for full details on SELinux. Some useful excerpts:</para>
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>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.</para>
+
+
+<para>D-Bus performs SELinux security checks in two places.</para>
+
+
+<para>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".</para>
+
+
+<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
+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
+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".</para>
+
+
+<para>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.</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>
+
+</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/cmake/bus/system.conf.cmake b/cmake/bus/system.conf.cmake
new file mode 100644
index 0000000..ee85ecc
--- /dev/null
+++ b/cmake/bus/system.conf.cmake
@@ -0,0 +1,62 @@
+<!-- This configuration file controls the systemwide message bus.
+ Add a system-local.conf and edit that rather than changing this
+ file directly. -->
+
+<!-- Note that there are any number of ways you can hose yourself
+ security-wise by screwing up this file; in particular, you
+ probably don't want to listen on any more addresses, add any more
+ auth mechanisms, run as a different user, etc. -->
+
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+
+ <!-- Our well-known bus type, do not change this -->
+ <type>system</type>
+
+ <!-- Run as special user -->
+ <user>@DBUS_USER@</user>
+
+ <!-- Fork into daemon mode -->
+ <fork/>
+
+ <!-- Write a pid file -->
+ <pidfile>@DBUS_SYSTEM_PID_FILE@</pidfile>
+
+ <!-- Only allow socket-credentials-based authentication -->
+ <auth>EXTERNAL</auth>
+
+ <!-- Only listen on a local socket. (abstract=/path/to/socket
+ means use abstract namespace, don't really create filesystem
+ file; only Linux supports this. Use path=/whatever on other
+ systems.) -->
+ <listen>@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@</listen>
+
+ <policy context="default">
+ <!-- Deny everything then punch holes -->
+ <deny send_interface="*"/>
+ <deny receive_interface="*"/>
+ <deny own="*"/>
+ <!-- But allow all users to connect -->
+ <allow user="*"/>
+ <!-- Allow anyone to talk to the message bus -->
+ <!-- FIXME I think currently these allow rules are always implicit
+ even if they aren't in here -->
+ <allow send_destination="org.freedesktop.DBus"/>
+ <allow receive_sender="org.freedesktop.DBus"/>
+ <!-- valid replies are always allowed -->
+ <allow send_requested_reply="true"/>
+ <allow receive_requested_reply="true"/>
+ </policy>
+
+ <!-- Config files are placed here that among other things, punch
+ holes in the above policy for specific services. -->
+ <includedir>system.d</includedir>
+
+ <!-- This is included last so local configuration can override what's
+ in this standard file -->
+ <include ignore_missing="yes">system-local.conf</include>
+
+ <include if_selinux_enabled="yes" selinux_root_relative="yes">contexts/dbus_contexts</include>
+
+</busconfig>
diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake
index d2af3c9..6221c19 100644
--- a/cmake/config.h.cmake
+++ b/cmake/config.h.cmake
@@ -6,46 +6,44 @@
/* 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@"
#cmakedefine DBUS_DATADIR "@DBUS_DATADIR@"
#cmakedefine DBUS_BINDIR "@DBUS_BINDIR@"
-#cmakedefine DBUS_PREFIX "@DBUS_PREFIX@"
#cmakedefine DBUS_SYSTEM_CONFIG_FILE "@DBUS_SYSTEM_CONFIG_FILE@"
#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
+
#define TEST_LISTEN "@TEST_LISTEN@"
// test binaries
#define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@"
#define DBUS_EXEEXT "@EXEEXT@"
-#cmakedefine TEST_BUS_LAUNCH_BINARY "@TEST_BUS_LAUNCH_BINARY@"
+
+/* Full path to test file test/test-exit in builddir */
+#define TEST_BUS_BINARY "@TEST_BUS_BINARY@"
/* Some dbus features */
+#cmakedefine DBUS_BUILD_TESTS 1
#cmakedefine DBUS_ENABLE_ANSI 1
#cmakedefine DBUS_ENABLE_VERBOSE_MODE 1
-#cmakedefine DBUS_DISABLE_ASSERT 1
-#ifndef DBUS_DISABLE_ASSERT
-# define DBUS_ENABLE_ASSERT 1
-#endif
+#cmakedefine DBUS_DISABLE_ASSERTS 1
#cmakedefine DBUS_DISABLE_CHECKS 1
-#ifndef DBUS_DISABLE_CHECKS
-# define DBUS_ENABLE_CHECKS 1
-#endif
/* xmldocs */
/* doxygen */
#cmakedefine DBUS_GCOV_ENABLED 1
@@ -65,6 +63,7 @@
#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@"
@@ -96,84 +95,57 @@
#cmakedefine DBUS_VA_COPY_AS_ARRAY @DBUS_VA_COPY_AS_ARRAY@
-#cmakedefine DBUS_WITH_GLIB 1
-#cmakedefine GLIB_VERSION_MIN_REQUIRED @GLIB_VERSION_MIN_REQUIRED@
-#cmakedefine GLIB_VERSION_MAX_ALLOWED @GLIB_VERSION_MAX_ALLOWED@
-
// headers
-#cmakedefine HAVE_ALLOCA_H
-#cmakedefine HAVE_BYTESWAP_H
-#cmakedefine HAVE_CRT_EXTERNS_H
-
/* Define to 1 if you have dirent.h */
#cmakedefine HAVE_DIRENT_H 1
-#cmakedefine HAVE_DLFCN_H
-
-/* Define to 1 if you have errno.h */
-#cmakedefine HAVE_ERRNO_H 1
-
-#cmakedefine HAVE_EXECINFO_H
-#cmakedefine HAVE_EXPAT_H
-
-/* Define to 1 if you have grp.h */
-#cmakedefine HAVE_GRP_H 1
-
-/* Define to 1 if you have inttypes.h */
-#cmakedefine HAVE_INTTYPES_H 1
-
/* Define to 1 if you have io.h */
#cmakedefine HAVE_IO_H 1
-/* Define to 1 if you have locale.h */
-#cmakedefine HAVE_LOCALE_H 1
-
-#cmakedefine HAVE_MEMORY_H
+/* Define to 1 if you have grp.h */
+#cmakedefine HAVE_GRP_H 1
/* Define to 1 if you have sys/poll.h */
#cmakedefine HAVE_POLL 1
-/* Define to 1 if you have signal.h */
-#cmakedefine HAVE_SIGNAL_H 1
-
-/* Define to 1 if you have stdint.h */
-#cmakedefine HAVE_STDINT_H 1
-
-#cmakedefine HAVE_STDLIB_H
-
-/* Define to 1 if you have stdio.h */
-#cmakedefine HAVE_STDIO_H 1
-
-#cmakedefine HAVE_STRINGS_H
-#cmakedefine HAVE_STRING_H
-#cmakedefine HAVE_SYSLOG_H
-#cmakedefine HAVE_SYS_EVENTS_H
-#cmakedefine HAVE_SYS_INOTIFY_H
-#cmakedefine HAVE_SYS_PRCTL_H
-#cmakedefine HAVE_SYS_RESOURCE_H
-#cmakedefine HAVE_SYS_STAT_H
-
-/* Define to 1 if you have sys/syslimits.h */
-#cmakedefine HAVE_SYS_SYSLIMITS_H 1
-
/* Define to 1 if you have sys/time.h */
-#cmakedefine HAVE_SYS_TIME_H 1
-
-#cmakedefine HAVE_SYS_TYPES_H
-
-#cmakedefine HAVE_SYS_UIO_H
+#cmakedefine HAVE_SYS_TIME 1
/* Define to 1 if you have sys/wait.h */
-#cmakedefine HAVE_SYS_WAIT_H 1
+#cmakedefine HAVE_SYS_WAIT 1
/* Define to 1 if you have time.h */
#cmakedefine HAVE_TIME_H 1
+/* 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
-/* Define to 1 if you have ws2tcpip.h */
-#cmakedefine HAVE_WS2TCPIP_H
+/* Define to 1 if you have stdio.h */
+#cmakedefine HAVE_STDIO_H 1
+
+/* Define to 1 if you have sys/syslimits.h */
+#cmakedefine HAVE_SYS_SYSLIMITS_H 1
+
+/* Define to 1 if you have errno.h */
+#cmakedefine HAVE_ERRNO_H 1
+
+/* Define to 1 if you have signal.h */
+#cmakedefine HAVE_SIGNAL_H 1
+
+/* Define to 1 if you have locale.h */
+#cmakedefine HAVE_LOCALE_H 1
+
+/* Define to 1 if you have inttypes.h */
+#cmakedefine HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have stdint.h */
+#cmakedefine HAVE_STDINT_H 1
// symbols
/* Define to 1 if you have backtrace */
@@ -221,23 +193,10 @@
/* Define to 1 if you have strtoull */
#cmakedefine HAVE_STRTOULL 1
-/* Define to 1 if you have pip2 */
-#cmakedefine HAVE_PIPE2
-
-#cmakedefine HAVE_ACCEPT4 1
-#cmakedefine HAVE_DIRFD 1
-#cmakedefine HAVE_INOTIFY_INIT1 1
-#cmakedefine HAVE_UNIX_FD_PASSING 1
-
// structs
/* Define to 1 if you have struct cmsgred */
#cmakedefine HAVE_CMSGCRED 1
-#cmakedefine FD_SETSIZE @FD_SETSIZE@
-
-#cmakedefine DBUS_USER "@DBUS_USER@"
-#cmakedefine DBUS_TEST_USER "@DBUS_TEST_USER@"
-
// system type defines
#if defined(_WIN32) || defined(_WIN64) || defined (_WIN32_WCE)
# define DBUS_WIN
@@ -290,8 +249,4 @@
#define inline __inline
#endif
-#ifdef DBUS_WIN
-#define FD_SETSIZE @FD_SETSIZE@
-#endif
-
#endif // _DBUS_CONFIG_H
diff --git a/cmake/cross-compile.sh b/cmake/cross-compile.sh
new file mode 100755
index 0000000..49e66e5
--- /dev/null
+++ b/cmake/cross-compile.sh
@@ -0,0 +1,110 @@
+#!/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 d859ce0..85f7005 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_CONNECT_ADDRESS@
+set DBUS_SESSION_BUS_ADDRESS=@DBUS_SESSION_BUS_DEFAULT_ADDRESS@
:: system bus address
-set DBUS_SYSTEM_BUS_DEFAULT_ADDRESS=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
+set DBUS_SYSTEM_BUS_DEFAULT_ADDRESS=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
\ No newline at end of file
diff --git a/cmake/dbus/CMakeLists.txt b/cmake/dbus/CMakeLists.txt
index 1701408..d09e63d 100644
--- a/cmake/dbus/CMakeLists.txt
+++ b/cmake/dbus/CMakeLists.txt
@@ -1,3 +1,5 @@
+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 )
@@ -147,7 +149,6 @@
### 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
@@ -164,15 +165,14 @@
${DBUS_DIR}/dbus-sysdeps-util.c
)
-if (DBUS_ENABLE_EMBEDDED_TESTS)
+if (DBUS_BUILD_TESTS)
set (DBUS_UTIL_SOURCES
${DBUS_UTIL_SOURCES}
${DBUS_DIR}/dbus-test.c
)
-endif (DBUS_ENABLE_EMBEDDED_TESTS)
+endif (DBUS_BUILD_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,7 +186,6 @@
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
@@ -214,12 +213,14 @@
${DBUS_DIR}/dbus-sysdeps-unix.c
${DBUS_DIR}/dbus-sysdeps-pthread.c
${DBUS_DIR}/dbus-userdb.c
+ ${DBUS_DIR}/sd-daemon.c
)
set (DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS}
${DBUS_DIR}/dbus-server-unix.h
${DBUS_DIR}/dbus-transport-unix.h
${DBUS_DIR}/dbus-sysdeps-unix.h
${DBUS_DIR}/dbus-userdb.h
+ ${DBUS_DIR}/sd-daemon.h
)
set (DBUS_UTIL_SOURCES ${DBUS_UTIL_SOURCES}
${DBUS_DIR}/dbus-spawn.c
@@ -259,62 +260,48 @@
${libdbus_SOURCES}
${libdbus_HEADERS}
)
-if(DEFINED DBUS_LIBRARY_REVISION)
- math(EXPR DBUS_LIBRARY_MAJOR "${DBUS_LIBRARY_CURRENT} - ${DBUS_LIBRARY_AGE}")
-endif()
-
if(WIN32)
- if(DEFINED DBUS_LIBRARY_REVISION)
- set_target_properties(dbus-1 PROPERTIES SUFFIX "-${DBUS_LIBRARY_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
- add_custom_command(TARGET dbus-1 POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:dbus-1>" "$<TARGET_FILE_DIR:dbus-1>/${CMAKE_SHARED_LIBRARY_PREFIX}dbus-1${CMAKE_SHARED_LIBRARY_SUFFIX}"
- COMMENT "Create non versioned dbus-1 library for legacy applications"
- )
- install(FILES ${LEGACY_FILE_NAME} DESTINATION bin)
- endif()
if(WINCE)
target_link_libraries(dbus-1 ws2)
else(WINCE)
- target_link_libraries(dbus-1 ws2_32 advapi32 netapi32 iphlpapi)
+ target_link_libraries(dbus-1 ws2_32 advapi32 netapi32)
endif(WINCE)
else(WIN32)
- if(DEFINED DBUS_LIBRARY_REVISION)
- set_target_properties(dbus-1 PROPERTIES VERSION ${DBUS_LIBRARY_MAJOR}.${DBUS_LIBRARY_AGE}.${DBUS_LIBRARY_REVISION} SOVERSION ${DBUS_LIBRARY_MAJOR})
- endif()
- target_link_libraries(dbus-1 ${CMAKE_THREAD_LIBS_INIT} rt)
+ target_link_libraries(dbus-1 ${CMAKE_THREAD_LIBS_INIT})
endif(WIN32)
-# Assume that Linux has -Wl,--version-script and other platforms do not
-if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
- set(SOVERSION ${DBUS_LIBRARY_MAJOR})
- configure_file(${DBUS_DIR}/Version.in ${CMAKE_CURRENT_BINARY_DIR}/Version)
- set_target_properties(dbus-1 PROPERTIES LINK_FLAGS -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/Version)
-endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
-
-install(TARGETS dbus-1 ${INSTALL_TARGETS_DEFAULT_ARGS})
+install_targets(/lib dbus-1 )
install_files(/include/dbus FILES ${dbusinclude_HEADERS})
### Internal library, used for the daemon, tools and tests, compiled statically.
add_library(dbus-internal ${DBUS_INTERNAL_ADD_LIBRARY_OPTIONS}
+ ${DBUS_LIB_SOURCES}
+ ${DBUS_LIB_HEADERS}
+ ${DBUS_SHARED_SOURCES}
+ ${DBUS_SHARED_HEADERS}
${DBUS_UTIL_SOURCES}
${DBUS_UTIL_HEADERS}
)
-target_link_libraries(dbus-internal dbus-1)
+target_link_libraries(dbus-internal)
+set_target_properties(dbus-internal PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_LIBRARY_DEFINITIONS})
if(WIN32)
if(WINCE)
target_link_libraries(dbus-internal ws2)
else(WINCE)
- target_link_libraries(dbus-internal ws2_32 advapi32 netapi32 iphlpapi)
+ target_link_libraries(dbus-internal ws2_32 advapi32 netapi32)
endif(WINCE)
else(WIN32)
- target_link_libraries(dbus-internal ${CMAKE_THREAD_LIBS_INIT} rt)
+ target_link_libraries(dbus-internal ${CMAKE_THREAD_LIBS_INIT})
endif(WIN32)
-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 (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 (UNIX)
# set version info
diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt
index f21e84e..df6b587 100644
--- a/cmake/doc/CMakeLists.txt
+++ b/cmake/doc/CMakeLists.txt
@@ -6,10 +6,9 @@
if (DBUS_ENABLE_DOXYGEN_DOCS)
set (top_srcdir ${CMAKE_SOURCE_DIR}/..)
- configure_file(${CMAKE_SOURCE_DIR}/../Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile )
+ configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.cmake ${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)
@@ -20,89 +19,56 @@
find_program(XMLTO_EXECUTABLE xmlto)
-find_program(CYGPATH_EXECUTABLE cygpath)
-
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 (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)
+if (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(STYLESHEET_HTML file:///usr/share/kde4/apps/ksgmltools2/customization/kde-nochunk.xsl)
+ set(_meinproc_install_path ${CMAKE_INSTALL_PREFIX})
endif(WIN32)
-endif ()
+ 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)
if (DBUS_ENABLE_XML_DOCS)
-macro (DOCBOOK _sources _format)
+macro (DOCBOOK _sources _options)
get_filename_component(_infile ${_sources} ABSOLUTE)
- get_filename_component(_name ${_infile} NAME)
- set(_deps ${CMAKE_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt)
+ get_filename_component(_basename ${_infile} NAME_WE)
+ set(_outfile ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.html)
- 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_COMMAND(
- OUTPUT ${_outfile}
- COMMAND ${MEINPROC4_EXECUTABLE} --stylesheet ${STYLESHEET} -o ${_outfile} ${_infile}
- DEPENDS ${_infile} ${STYLESHEET} ${_deps}
+ ADD_CUSTOM_TARGET(${_basename}.html ALL
+ ${MEINPROC4_EXECUTABLE} --stylesheet ${STYLESHEET} -o ${_outfile} ${_infile}
+ DEPENDS ${_infile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif ()
if (XMLTO_EXECUTABLE)
- if (MSYS)
- if (CYGPATH_EXECUTABLE)
- execute_process(
- COMMAND cygpath ${_infile}
- OUTPUT_VARIABLE _infile)
- else ()
- execute_process(COMMAND dirname ${_infile} OUTPUT_VARIABLE _path)
- string(STRIP ${_path} _path)
- execute_process(COMMAND sh -c "cd ${_path}; pwd -W" OUTPUT_VARIABLE _path)
- string(STRIP ${_path} _path)
- set(_infile "${_path}/${_name}")
- endif(CYGPATH_EXECUTABLE)
- endif (MSYS)
- ADD_CUSTOM_COMMAND(
- OUTPUT ${_outfile}
- COMMAND ${XMLTO_EXECUTABLE} -vv ${_format} ${_infile}
- DEPENDS ${_infile} ${_deps}
+ ADD_CUSTOM_TARGET(${_basename}.html ALL
+ ${XMLTO_EXECUTABLE} -vv ${_options} ${_infile}
+ DEPENDS ${_infile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif ()
- if (${_format} STREQUAL "man")
- install(FILES ${_outfile} DESTINATION share/man/man1)
- else ()
- install(FILES ${_outfile} DESTINATION share/doc/dbus)
- endif ()
+ install(FILES ${_outfile} DESTINATION share/doc/dbus)
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
@@ -132,32 +98,11 @@
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)
-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-test-tool.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-test-tool.1.xml)
-configure_file(${CMAKE_SOURCE_DIR}/../doc/dbus-update-activation-environment.1.xml.in ${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.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-test-tool.1.xml html-nochunks)
-DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-uuidgen.1.xml html-nochunks)
-DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.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-test-tool.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)
- DOCBOOK(${CMAKE_BINARY_DIR}/doc/dbus-update-activation-environment.1.xml man)
-endif()
+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)
+
#
# handle html index file
#
diff --git a/cmake/i686-w64-mingw32.cmake b/cmake/i686-w64-mingw32.cmake
deleted file mode 100644
index 1be4e78..0000000
--- a/cmake/i686-w64-mingw32.cmake
+++ /dev/null
@@ -1,20 +0,0 @@
-# Toolchain for mingw-w64 32-bit compilers, as shipped in Debian/Ubuntu.
-
-set(GNU_HOST i686-w64-mingw32)
-set(CMAKE_SYSTEM_PROCESSOR "i686")
-
-set(COMPILER_PREFIX "${GNU_HOST}-")
-
-set(CMAKE_SYSTEM_NAME "Windows")
-set(CMAKE_CROSSCOMPILING TRUE)
-set(WIN32 TRUE)
-set(MINGW TRUE)
-
-include(CMakeForceCompiler)
-cmake_force_c_compiler(${COMPILER_PREFIX}gcc GNU)
-cmake_force_cxx_compiler(${COMPILER_PREFIX}g++ GNU)
-set(CMAKE_RC_COMPILER ${COMPILER_PREFIX}windres)
-
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/cmake/modules/COPYING-CMAKE-SCRIPTS b/cmake/modules/COPYING-CMAKE-SCRIPTS
deleted file mode 100644
index 53b6b71..0000000
--- a/cmake/modules/COPYING-CMAKE-SCRIPTS
+++ /dev/null
@@ -1,22 +0,0 @@
-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 74b6689..f8073a2 100644
--- a/cmake/modules/CPackInstallConfig.cmake
+++ b/cmake/modules/CPackInstallConfig.cmake
@@ -1,7 +1,14 @@
if (DBUS_INSTALL_SYSTEM_LIBS)
if (MINGW)
- install_files(/bin FILES ${LIBEXPAT_LIBRARIES})
+ 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)
else (MINGW)
INCLUDE(InstallRequiredSystemLibraries)
endif (MINGW)
diff --git a/cmake/modules/FindGLIB.cmake b/cmake/modules/FindGLIB.cmake
new file mode 100644
index 0000000..1fdaee9
--- /dev/null
+++ b/cmake/modules/FindGLIB.cmake
@@ -0,0 +1,42 @@
+# - 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
deleted file mode 100644
index d72b2a0..0000000
--- a/cmake/modules/FindGLib2.cmake
+++ /dev/null
@@ -1,60 +0,0 @@
-# - 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
deleted file mode 100644
index af0c9f7..0000000
--- a/cmake/modules/FindGObject.cmake
+++ /dev/null
@@ -1,52 +0,0 @@
-# - 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
new file mode 100644
index 0000000..a07c8de
--- /dev/null
+++ b/cmake/modules/FindLibExpat.cmake
@@ -0,0 +1,61 @@
+# - 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 8d6cf11..b637156 100644
--- a/cmake/modules/Macros.cmake
+++ b/cmake/modules/Macros.cmake
@@ -1,62 +1,15 @@
-if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
- if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
- find_file(WINE_EXECUTABLE
- NAMES wine
- PATHS /usr/bin /usr/local/bin
- NO_CMAKE_FIND_ROOT_PATH
- )
- find_file(HAVE_BINFMT_WINE_SUPPORT
- NAMES DOSWin wine Wine windows Windows
- PATHS /proc/sys/fs/binfmt_misc
- NO_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH
- )
- if(WINE_EXECUTABLE AND HAVE_BINFMT_WINE_SUPPORT)
- list(APPEND FOOTNOTES "NOTE: The requirements to run cross compiled applications on your host system are achieved. You may run 'make check'.")
- endif()
- if(NOT WINE_EXECUTABLE)
- list(APPEND FOOTNOTES "NOTE: You may install the Windows emulator 'wine' to be able to run cross compiled test applications.")
- endif()
- if(NOT HAVE_BINFMT_WINE_SUPPORT)
- list(APPEND FOOTNOTES "NOTE: You may activate binfmt_misc support for wine to be able to run cross compiled test applications.")
- endif()
- else()
- list(APPEND FOOTNOTES "NOTE: You will not be able to run cross compiled applications on your host system.")
- endif()
-endif()
MACRO(TIMESTAMP RESULT)
- if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
+ IF(WIN32)
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}")
- else ()
+ ELSEIF(UNIX)
EXECUTE_PROCESS(COMMAND "date" "+%Y%m%d%H%M" OUTPUT_VARIABLE ${RESULT})
- endif ()
+ ELSE()
+ MESSAGE(SEND_ERROR "date not implemented")
+ SET(${RESULT} 000000000000)
+ 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}> --tap)
- else()
- set(PREFIX)
- set(_env "DBUS_TEST_DAEMON=${CMAKE_BINARY_DIR}/bin/dbus-daemon${EXEEXT}")
- add_test(NAME ${_target} COMMAND $<TARGET_FILE:${_target}> --tap)
- 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 8bb83cd..ff30eaf 100644
--- a/cmake/modules/MacrosAutotools.cmake
+++ b/cmake/modules/MacrosAutotools.cmake
@@ -1,21 +1,6 @@
#
-# cmake package for autotools support
-#
# @Author Ralf Habacker
#
-
-#
-# load autotools configure file into an internal list named _configure_ac
-#
-macro(autoinit config)
- set(_configure_ac_name ${config})
- file(READ ${config} _configure_ac_raw)
- # Convert file contents into a CMake list (where each element in the list
- # is one line of the file)
- STRING(REGEX REPLACE ";" "\\\\;" _configure_ac "${_configure_ac_raw}")
- STRING(REGEX REPLACE "\n" ";" _configure_ac "${_configure_ac}")
-endmacro()
-
# extracts version information from autoconf config file
# and set related cmake variables
#
@@ -25,132 +10,19 @@
# ${prefix}_MAJOR_VERSION
# ${prefix}_MINOR_VERSION
# ${prefix}_MICRO_VERSION
-# ${prefix}_LIBRARY_AGE
-# ${prefix}_LIBRARY_REVISION
-# ${prefix}_LIBRARY_CURRENT
#
-macro(autoversion prefix)
- string(TOUPPER ${prefix} prefix_upper)
- string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac_raw})
- string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac_raw})
- string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac_raw})
- set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION})
- set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
- string (REGEX REPLACE ".*LT_AGE=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_AGE ${_configure_ac_raw})
- string (REGEX REPLACE ".*LT_CURRENT=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_CURRENT ${_configure_ac_raw})
- string (REGEX REPLACE ".*LT_REVISION=([0-9]+).*" "\\1" ${prefix_upper}_LIBRARY_REVISION ${_configure_ac_raw})
+macro(autoversion config prefix)
+ file (READ ${config} _configure_ac)
+ string(TOUPPER ${prefix} prefix_upper)
+ string (REGEX REPLACE ".*${prefix}_major_version], .([0-9]+).*" "\\1" ${prefix_upper}_MAJOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_minor_version], .([0-9]+).*" "\\1" ${prefix_upper}_MINOR_VERSION ${_configure_ac})
+ string (REGEX REPLACE ".*${prefix}_micro_version], .([0-9]+).*" "\\1" ${prefix_upper}_MICRO_VERSION ${_configure_ac})
+ set (${prefix_upper}_VERSION ${${prefix_upper}_MAJOR_VERSION}.${${prefix_upper}_MINOR_VERSION}.${${prefix_upper}_MICRO_VERSION})
+ set (${prefix_upper}_VERSION_STRING "${${prefix_upper}_VERSION}")
+
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})
-
- string(CONFIGURE "/* 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@\"
-" AUTOPACKAGE_CONFIG_H_TEMPLATE)
-endmacro(autopackage)
-
-#
-# define a cmake variable from autotools AC_DEFINE statement
-#
-macro(autodefine name)
- foreach(line ${_configure_ac})
- if(line MATCHES ".*AC_DEFINE(.*${name}.*).*")
- string (REGEX REPLACE ".*AC_DEFINE(.*).*" "\\1" value ${line})
- string (REGEX REPLACE ".*,(.*),.*" "\\1" value2 ${value})
- string (REPLACE "[" "" value3 ${value2})
- string (REPLACE "]" "" value4 ${value3})
- set(${name} ${value4})
- endif()
- endforeach()
-endmacro()
-
-macro(autoheaderchecks config_h_in configure_checks_file config_h_cmake)
- file(READ ${configure_checks_file} configure_checks_file_raw)
- file(READ ${config_h_in} _config_h_in_raw)
- file(READ ${config_h_cmake} _config_h_cmake_raw)
- STRING(REGEX REPLACE ";" "\\\\;" _config_h_in "${_config_h_in_raw}")
- STRING(REGEX REPLACE "\n" ";" _config_h_in "${_config_h_in}")
- foreach(line ${_config_h_in})
- #message(STATUS ${line})
- if(line MATCHES ".*HAVE_.*_H.*")
- string (REGEX REPLACE ".*HAVE_(.*)_H.*" "\\1" key ${line})
- set(full_key "HAVE_${key}_H")
- if(key MATCHES ".*_.*")
- string(REGEX MATCH "^[A-Z0-9]+" dir ${key})
- string(REGEX MATCH "[A-Z0-9]+$" file ${key})
- string(TOLOWER ${dir} dirname)
- string(TOLOWER ${file} filename)
- set(check "check_include_file(${dirname}/${filename}.h ${full_key})")
- set(config_define "#cmakedefine ${full_key}")
- else()
- set(file ${key})
- string(TOLOWER ${file} filename)
- set(check "check_include_file(${filename}.h ${full_key})")
- set(config_define "#cmakedefine ${full_key}")
- endif()
- if(NOT configure_checks_file_raw MATCHES ".*${full_key}.*")
- message("${check}")
- endif()
- if(NOT _config_h_cmake_raw MATCHES "${full_key}")
- message("${config_define}")
- endif()
- endif()
- endforeach()
-endmacro(autoheaderchecks)
-
-#
# parses config.h template and create cmake equivalent
# not implemented yet
#
diff --git a/cmake/test/CMakeLists.txt b/cmake/test/CMakeLists.txt
index e78af7a..8657e4c 100644
--- a/cmake/test/CMakeLists.txt
+++ b/cmake/test/CMakeLists.txt
@@ -1,11 +1,7 @@
-include_directories(${CMAKE_SOURCE_DIR}/../test)
+project(test)
add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
-include_directories(${CMAKE_SOURCE_DIR}/../test)
-
-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
@@ -14,10 +10,6 @@
add_subdirectory( name-test )
-set (manual-dir-iter_SOURCES
- ${CMAKE_SOURCE_DIR}/../test/manual-dir-iter.c
-)
-
set (test-service_SOURCES
${CMAKE_SOURCE_DIR}/../test/test-service.c
)
@@ -34,11 +26,11 @@
${CMAKE_SOURCE_DIR}/../test/test-shell-service.c
)
-set (test-shell_SOURCES
+set (shell-test_SOURCES
${CMAKE_SOURCE_DIR}/../test/shell-test.c
)
-set (test-spawn_SOURCES
+set (spawn-test_SOURCES
${CMAKE_SOURCE_DIR}/../test/spawn-test.c
)
@@ -54,62 +46,30 @@
${CMAKE_SOURCE_DIR}/../test/test-sleep-forever.c
)
-set (manual-tcp_SOURCES
- ${CMAKE_SOURCE_DIR}/../test/manual-tcp.c
-)
+add_executable(test-service ${test-service_SOURCES})
+target_link_libraries(test-service dbus-testutils)
-set (manual-paths_SOURCES
- ${CMAKE_SOURCE_DIR}/../test/manual-paths.c
-)
+add_executable(test-names ${test-names_SOURCES})
+target_link_libraries(test-names dbus-testutils)
-add_helper_executable(manual-dir-iter ${manual-dir-iter_SOURCES} ${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})
-add_helper_executable(manual-tcp ${manual-tcp_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
-if(WIN32)
- add_helper_executable(manual-paths ${manual-paths_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
-endif()
+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})
-if(DBUS_WITH_GLIB)
- message(STATUS "with glib test apps")
+add_executable(test-shell-service ${test-shell-service_SOURCES})
+target_link_libraries(test-shell-service dbus-testutils)
- add_library(dbus-testutils-glib STATIC
- ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.h
- ${CMAKE_SOURCE_DIR}/../test/test-utils-glib.c
- )
- target_link_libraries(dbus-testutils-glib dbus-testutils ${DBUS_INTERNAL_LIBRARIES})
+add_executable(spawn-test ${spawn-test_SOURCES})
+target_link_libraries(spawn-test ${DBUS_INTERNAL_LIBRARIES})
- add_definitions(
- ${GLIB2_DEFINITIONS}
- ${GOBJECT_DEFINITIONS}
- )
- include_directories(
- ${GLIB2_INCLUDE_DIR}
- ${GOBJECT_INCLUDE_DIR}
- )
+add_executable(test-exit ${test-exit_SOURCES})
+target_link_libraries(test-exit ${DBUS_INTERNAL_LIBRARIES})
- set(TEST_LIBRARIES ${DBUS_INTERNAL_LIBRARIES} dbus-testutils dbus-testutils-glib ${GLIB2_LIBRARIES} ${GOBJECT_LIBRARIES})
+add_executable(test-segfault ${test-segfault_SOURCES})
+target_link_libraries(test-segfault ${DBUS_INTERNAL_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-fdpass ${CMAKE_SOURCE_DIR}/../test/fdpass.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-monitor ${CMAKE_SOURCE_DIR}/../test/monitor.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()
+add_executable(test-sleep-forever ${test-sleep-forever_SOURCES})
+target_link_libraries(test-sleep-forever ${DBUS_INTERNAL_LIBRARIES})
### keep these in creation order, i.e. uppermost dirs first
set (TESTDIRS
@@ -119,12 +79,10 @@
test/data/incomplete-messages
test/data/auth
test/data/sha-1
- test/data/systemd-activation
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-config-files-system/system.d
test/data/valid-introspection-files
test/data/valid-messages
test/data/valid-service-files
@@ -141,16 +99,13 @@
)
set (CONFIG_VERBOSE 0)
-FOREACH(DIR ${TESTDIRS})
- FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR})
-ENDFOREACH(DIR)
-
### copy tests to builddir so that generated tests and static tests
### are all in one place.
MESSAGE(STATUS "Copying test files to test directory")
FOREACH(FILE_TYPE *.message *.message-raw *.auth-script *.sha1 *.txt *.conf *.service)
FOREACH(DIR ${TESTDIRS})
FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${DIR}/${FILE_TYPE}" )
+ FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR})
FOREACH(FILE ${FILES})
GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME)
SET (TARGET ${CMAKE_BINARY_DIR}/${DIR}/${FILENAME})
@@ -168,6 +123,7 @@
FOREACH(FILE_TYPE *.conf.in *.service.in)
FOREACH(DIR ${TESTDIRS})
FILE(GLOB FILES "${CMAKE_SOURCE_DIR}/../${DIR}/${FILE_TYPE}" )
+ FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${DIR})
FOREACH(FILE ${FILES})
GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME)
STRING(REGEX REPLACE "\\.in$" "" FILENAME ${FILENAME})
@@ -181,5 +137,19 @@
ENDFOREACH(FILE_TYPE)
MESSAGE(STATUS "Copying generated bus config files to test directory")
-configure_file("${CMAKE_SOURCE_DIR}/../bus/session.conf.in" ${CMAKE_BINARY_DIR}/test/data/valid-config-files/session.conf @ONLY)
-configure_file("${CMAKE_SOURCE_DIR}/../bus/system.conf.in" ${CMAKE_BINARY_DIR}/test/data/valid-config-files-system/system.conf @ONLY)
+set (OUTDIR ${CMAKE_BINARY_DIR}/test/data/valid-config-files)
+
+FILE(GLOB FILES "${CMAKE_BINARY_DIR}/bus/*.conf" )
+FILE(MAKE_DIRECTORY ${OUTDIR})
+FOREACH(FILE ${FILES})
+ GET_FILENAME_COMPONENT(FILENAME ${FILE} NAME)
+ SET (TARGET ${OUTDIR}/${FILENAME})
+ configure_file(${FILE} ${TARGET} COPYONLY)
+ 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
+#
diff --git a/cmake/test/name-test/CMakeLists.txt b/cmake/test/name-test/CMakeLists.txt
index befb28f..80b9908 100644
--- a/cmake/test/name-test/CMakeLists.txt
+++ b/cmake/test/name-test/CMakeLists.txt
@@ -1,15 +1,39 @@
-if (DBUS_ENABLE_EMBEDDED_TESTS)
+if (DBUS_BUILD_TESTS)
set (NAMEtest-DIR ../../../test/name-test)
-add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
+add_definitions(-DDBUS_COMPILATION)
-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)
+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)
diff --git a/cmake/tools/CMakeLists.txt b/cmake/tools/CMakeLists.txt
index 6a2e999..101c7e6 100644
--- a/cmake/tools/CMakeLists.txt
+++ b/cmake/tools/CMakeLists.txt
@@ -1,34 +1,15 @@
-add_definitions("-DDBUS_COMPILATION")
+project(tools)
set (dbus_send_SOURCES
../../tools/dbus-print-message.c
../../tools/dbus-print-message.h
../../tools/dbus-send.c
- ../../tools/tool-common.c
- ../../tools/tool-common.h
)
set (dbus_monitor_SOURCES
../../tools/dbus-monitor.c
../../tools/dbus-print-message.c
../../tools/dbus-print-message.h
- ../../tools/tool-common.c
- ../../tools/tool-common.h
-)
-
-set (dbus_test_tool_SOURCES
- ../../tools/dbus-echo.c
- ../../tools/dbus-spam.c
- ../../tools/tool-common.c
- ../../tools/tool-common.h
- ../../tools/test-tool.c
- ../../tools/test-tool.h
-)
-
-set (dbus_update_activation_environment_SOURCES
- ../../tools/dbus-update-activation-environment.c
- ../../tools/tool-common.c
- ../../tools/tool-common.h
)
if (WIN32)
@@ -38,8 +19,6 @@
else (WIN32)
set (dbus_launch_SOURCES
../../tools/dbus-launch.c
- ../../tools/tool-common.c
- ../../tools/tool-common.h
)
endif (WIN32)
@@ -58,16 +37,8 @@
target_link_libraries(dbus-send ${DBUS_LIBRARIES})
install_targets(/bin dbus-send )
-add_executable(dbus-test-tool ${dbus_test_tool_SOURCES})
-target_link_libraries(dbus-test-tool ${DBUS_LIBRARIES})
-install_targets(/bin dbus-test-tool )
-
-add_executable(dbus-update-activation-environment ${dbus_update_activation_environment_SOURCES})
-target_link_libraries(dbus-update-activation-environment ${DBUS_LIBRARIES})
-install_targets(/bin dbus-update-activation-environment )
-
add_executable(dbus-launch ${dbus_launch_SOURCES})
-target_link_libraries(dbus-launch ${DBUS_LIBRARIES})
+target_link_libraries(dbus-launch )
if (DBUS_BUILD_X11)
target_link_libraries(dbus-launch ${X11_LIBRARIES} )
endif (DBUS_BUILD_X11)
@@ -76,6 +47,3 @@
add_executable(dbus-monitor ${dbus_monitor_SOURCES})
target_link_libraries(dbus-monitor ${DBUS_LIBRARIES})
install_targets(/bin dbus-monitor )
-
-# create the /var/lib/dbus directory for dbus-uuidgen
-install(DIRECTORY DESTINATION var/lib/dbus)
diff --git a/doc/dbus-launch.1.xml.in b/cmake/tools/dbus-launch.xml
similarity index 72%
rename from doc/dbus-launch.1.xml.in
rename to cmake/tools/dbus-launch.xml
index 5135d9c..dc34898 100644
--- a/doc/dbus-launch.1.xml.in
+++ b/cmake/tools/dbus-launch.xml
@@ -1,33 +1,27 @@
<?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">
+<!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='dbuslaunch1'>
-
-<!-- dbus\-launch manual page.
- Copyright (C) 2003 Red Hat, Inc. -->
+<!-- -->
+<!-- dbus\-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>
+<refnamediv id='name'>
<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>
- <arg choice='opt'>--help </arg>
+ <command>dbus-launch</command> <arg choice='opt'>--version </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>
@@ -39,7 +33,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
@@ -47,7 +41,7 @@
<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>
@@ -60,7 +54,7 @@
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
@@ -70,7 +64,7 @@
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
+--auto-syntax, you may explicity 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>
@@ -79,62 +73,44 @@
<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>
-<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>
-
- <blockquote remap='RS'>
-<para><emphasis remap='B'>dbus-launch --exit-with-session gnome-session</emphasis></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>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>
-
-<para>To start a D-Bus session within a text-mode session,
- do not use <emphasis remap='B'>dbus-launch</emphasis>.
- Instead, see <citerefentry><refentrytitle>dbus-run-session</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
-</para>
-
+<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'>
+
## 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`
+ eval `dbus-launch --sh-syntax --exit-with-session`
echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
fi
+
</literallayout> <!-- .fi -->
-<para>Note that in this case, dbus-launch will exit, and dbus-daemon will not be
-terminated automatically on logout.</para>
+<para>You might run something like that in your login scripts.</para>
+
+
+<para>Another way to use <command>dbus-launch</command> is to run your main session
+program, like so:</para>
+<literallayout remap='.nf'>
+
+dbus-launch gnome-session
+
+</literallayout> <!-- .fi -->
+<para>The above would likely be appropriate for ~/.xsession or ~/.Xclients.</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>
@@ -142,7 +118,7 @@
<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>
@@ -179,12 +155,8 @@
<listitem>
<para>Choose --csh-syntax or --sh-syntax based on the SHELL environment variable.</para>
- </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
+<para><option>--binary-syntax</option>
+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>
@@ -204,7 +176,7 @@
<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>
@@ -219,7 +191,7 @@
<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>
@@ -252,30 +224,9 @@
</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>
@@ -286,3 +237,4 @@
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.xml.in b/cmake/tools/dbus-monitor.xml
similarity index 74%
rename from doc/dbus-monitor.1.xml.in
rename to cmake/tools/dbus-monitor.xml
index 2f807d2..b41cace 100644
--- a/doc/dbus-monitor.1.xml.in
+++ b/cmake/tools/dbus-monitor.xml
@@ -1,28 +1,26 @@
<?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">
+<!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='dbusmonitor1'>
-
-<!-- dbus\-monitor manual page.
- Copyright (C) 2003 Red Hat, Inc. -->
+<!-- -->
+<!-- dbus\-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>
+<refnamediv id='name'>
<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><arg choice='plain'>--pcap </arg><arg choice='plain'>--binary </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>
<sbr/>
</cmdsynopsis>
@@ -44,22 +42,11 @@
specified, <command>dbus-monitor</command> monitors the session bus.</para>
-<para><command>dbus-monitor</command> has two different text output
-modes: the 'classic'-style
-monitoring mode, and profiling mode. The profiling format is a compact
+<para><command>dbus-monitor</command> 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.</para>
-
-<para><command>dbus-monitor</command> also has two binary output modes.
- The binary mode, selected by <literal>--binary</literal>, outputs the
- entire binary message stream (without the initial authentication handshake).
- The PCAP mode, selected by <literal>--pcap</literal>, adds a
- PCAP file header to the beginning of the output, and prepends a PCAP
- message header to each message; this produces a binary file that can
- be read by, for instance, Wireshark.</para>
-
-<para>If no mode is specified,
+and monitoring output format respectively. If neither is specified,
<command>dbus-monitor</command> uses the monitoring output format.</para>
@@ -131,3 +118,4 @@
see <ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink></para>
</refsect1>
</refentry>
+
diff --git a/cmake/tools/dbus-send.xml b/cmake/tools/dbus-send.xml
new file mode 100644
index 0000000..7fefc03
--- /dev/null
+++ b/cmake/tools/dbus-send.xml
@@ -0,0 +1,143 @@
+<?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='dbussend1'>
+<!-- -->
+<!-- dbus\-send manual page. -->
+<!-- Copyright (C) 2003 Red Hat, Inc. -->
+
+<refmeta>
+<refentrytitle>dbus-send</refentrytitle>
+<manvolnum>1</manvolnum>
+</refmeta>
+<refnamediv id='name'>
+<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>
+ <arg choice='opt'>--dest=<replaceable>NAME</replaceable></arg>
+ <arg choice='opt'>--print-reply </arg>
+ <arg choice='opt'>--type=<replaceable>TYPE</replaceable></arg>
+ <arg choice='plain'><replaceable><destination</replaceable></arg>
+ <arg choice='plain'><replaceable>object</replaceable></arg>
+ <arg choice='plain'><replaceable>path></replaceable></arg>
+ <arg choice='plain'><replaceable><message</replaceable></arg>
+ <arg choice='plain'><replaceable>name></replaceable></arg>
+ <arg choice='opt' rep='repeat'><replaceable>contents</replaceable></arg>
+ <sbr/>
+</cmdsynopsis>
+</refsynopsisdiv>
+
+
+<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
+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
+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>
+
+
+<para>Nearly all uses of <command>dbus-send</command> must provide the --dest 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>
+
+
+<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
+may include containers (arrays, dicts, and variants) as described below.</para>
+
+<literallayout remap='.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
+</literallayout> <!-- .fi -->
+
+<para>D-Bus supports more types than these, but <command>dbus-send</command> currently
+does not. Also, <command>dbus-send</command> does not permit empty containers
+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
+
+</literallayout> <!-- .fi -->
+
+<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>
+
+</refsect1>
+
+<refsect1 id='options'><title>OPTIONS</title>
+<para>The following options are supported:</para>
+<variablelist remap='TP'>
+ <varlistentry>
+ <term><option>--dest=NAME</option></term>
+ <listitem>
+<para>Specify the name of the connection to receive the message.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--print-reply</option></term>
+ <listitem>
+<para>Block for a reply to the message sent, and print any reply received.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--system</option></term>
+ <listitem>
+<para>Send to the system message bus.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--session</option></term>
+ <listitem>
+<para>Send to the session message bus. (This is the default.)</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--type=TYPE</option></term>
+ <listitem>
+<para>Specify "method_call" or "signal" (defaults to "signal").</para>
+
+ </listitem>
+ </varlistentry>
+</variablelist>
+</refsect1>
+
+<refsect1 id='author'><title>AUTHOR</title>
+<para>dbus-send was written by Philip Blundell.</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/config.h b/config.h
index 065e11d..86707e2 100644
--- a/config.h
+++ b/config.h
@@ -1,89 +1,59 @@
-/* config.h. Generated from config.h.in by configure. */
-/* config.h.in. Generated from configure.ac by autoheader. */
-
-/* Define if building universal (internal helper macro) */
-/* #undef AC_APPLE_UNIVERSAL_BUILD */
-
-/* poll doesn't work on devices */
-/* #undef BROKEN_POLL */
+/* config.h.in. Generated from configure.in by autoheader. */
+#include <cutils/sockets.h>
/* Directory for installing the binaries */
#define DBUS_BINDIR "/system/bin"
-/* Define to build X11 functionality */
-/* #undef DBUS_BUILD_X11 */
+/* Build test code */
+#undef DBUS_BUILD_TESTS
+
+/* Build X11-dependent code */
+#undef DBUS_BUILD_X11
/* whether -export-dynamic was passed to libtool */
-/* #undef DBUS_BUILT_R_DYNAMIC */
+#undef DBUS_BUILT_R_DYNAMIC
-/* Use inotify */
-#define DBUS_BUS_ENABLE_INOTIFY 1
+/* Use dnotify on Linux */
+#undef DBUS_BUS_ENABLE_DNOTIFY_ON_LINUX
/* Use kqueue */
-/* #undef DBUS_BUS_ENABLE_KQUEUE */
+#undef DBUS_BUS_ENABLE_KQUEUE
/* Directory to check for console ownerhip */
#define DBUS_CONSOLE_AUTH_DIR "/etc"
/* File to check for console ownerhip */
-/* #undef DBUS_CONSOLE_OWNER_FILE */
-
-/* Defined if we run on a cygwin API based system */
-/* #undef DBUS_CYGWIN */
+#undef DBUS_CONSOLE_OWNER_FILE
/* Directory for installing the DBUS daemon */
#define DBUS_DAEMONDIR "/system/bin"
-/* Name of executable */
-#define DBUS_DAEMON_NAME "dbus-daemon"
-
/* Directory for installing DBUS data files */
#define DBUS_DATADIR "/data"
/* Disable assertion checking */
-/* #undef DBUS_DISABLE_ASSERT */
+#undef DBUS_DISABLE_ASSERT
/* Disable public API sanity checking */
-/* #undef DBUS_DISABLE_CHECKS */
-
-/* Define to build test code into the library and binaries */
-/* #undef DBUS_ENABLE_EMBEDDED_TESTS */
-
-/* Use launchd autolaunch */
-/* #undef DBUS_ENABLE_LAUNCHD */
-
-/* Define to build independent test binaries */
-/* #undef DBUS_ENABLE_MODULAR_TESTS */
-
-/* Define to enable bus daemon usage statistics */
-/* #undef DBUS_ENABLE_STATS */
+#undef DBUS_DISABLE_CHECKS
/* Support a verbose mode */
-/* #undef DBUS_ENABLE_VERBOSE_MODE */
-
-/* Define to enable X11 auto-launch */
-/* #undef DBUS_ENABLE_X11_AUTOLAUNCH */
-
-/* Extension for executables, typically empty or .exe */
-#define DBUS_EXEEXT ""
+#undef DBUS_ENABLE_VERBOSE_MODE
/* Defined if gcov is enabled to force a rebuild due to config.h changing */
-/* #undef DBUS_GCOV_ENABLED */
+#undef DBUS_GCOV_ENABLED
-/* Define to use epoll(4) on Linux */
-#define DBUS_HAVE_LINUX_EPOLL 1
+/* Some atomic integer implementation present */
+#undef DBUS_HAVE_ATOMIC_INT
-/* Define to printf modifier for 64 bit integer type */
-#define DBUS_INT64_PRINTF_MODIFIER "ll"
-/* Directory for installing the libexec binaries */
-#define DBUS_LIBEXECDIR "/system/bin"
+ #if (defined(__i386__) || defined(__x86_64__))
+ # define DBUS_HAVE_ATOMIC_INT 1
+ #endif
+
-/* Prefix for installing DBUS */
-#define DBUS_PREFIX "/system"
-
-/* Fallback address for session bus clients */
-#define DBUS_SESSION_BUS_CONNECT_ADDRESS "autolaunch:"
+/* Defined if we have gcc 3.3 and thus the new gcov format */
+#undef DBUS_HAVE_GCC33_GCOV
/* Where per-session bus puts its sockets */
#define DBUS_SESSION_SOCKET_DIR "/data"
@@ -92,108 +62,55 @@
#define DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "unix:path="DBUS_SYSTEM_SOCKET
/* The name of the socket the system bus listens on by default */
-#define DBUS_SYSTEM_SOCKET "/dev/socket/dbus"
-
-/* Full path to the daemon in the builddir */
-#define DBUS_TEST_EXEC "/system/bin/dbus-test"
-
-/* Full path to the launch helper test program in the builddir */
-#define DBUS_TEST_LAUNCH_HELPER_BINARY "/system/bin/dbus-daemon-launch-helper-test"
+#define DBUS_SYSTEM_SOCKET ANDROID_SOCKET_DIR"/dbus"
/* Where to put test sockets */
#define DBUS_TEST_SOCKET_DIR "/data"
-/* Unprivileged user used in some regression tests */
-#define DBUS_TEST_USER "nobody"
-
-/* Defined if we run on a Unix-based system */
-#define DBUS_UNIX 1
-
/* User for running the system BUS daemon */
-/* #undef DBUS_USER "messagebus" */
+#undef DBUS_USER
-/* Use the gcc __sync extension */
-#define DBUS_USE_SYNC 1
+/* Use atomic integer implementation for 486 */
+#undef DBUS_USE_ATOMIC_INT_486
+
+
+ #if (defined(__i386__) || defined(__x86_64__))
+ # define DBUS_USE_ATOMIC_INT_486 1
+ #endif
+
/* A 'va_copy' style function */
#define DBUS_VA_COPY va_copy
/* 'va_lists' cannot be copies as values */
-/* #undef DBUS_VA_COPY_AS_ARRAY */
-
-/* Defined if we run on a W32 API based system */
-/* #undef DBUS_WIN */
-
-/* Defined if we run on a W32 CE API based system */
-/* #undef DBUS_WINCE */
-
-/* Define if GLib, GObject, GIO are available */
-/* #undef DBUS_WITH_GLIB */
-
-/* The maximum number of connections that can be handled at once */
-/* #undef FD_SETSIZE */
+#undef DBUS_VA_COPY_AS_ARRAY
/* The name of the gettext domain */
-/* #undef GETTEXT_PACKAGE "dbus-1" */
+#undef GETTEXT_PACKAGE
-/* Prevent post-2.38 APIs */
-#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_38
-
-/* Ignore post-2.36 deprecations */
-#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_36
+/* Disable GLib assertion macros */
+#undef G_DISABLE_ASSERT
/* Disable GLib public API sanity checking */
-/* #undef G_DISABLE_CHECKS */
+#undef G_DISABLE_CHECKS
/* Have abstract socket namespace */
-#define HAVE_ABSTRACT_SOCKETS 1
+#undef HAVE_ABSTRACT_SOCKETS
-/* Define to 1 if you have the `accept4' function. */
-#define HAVE_ACCEPT4 1
-
-/* Adt audit API */
-/* #undef HAVE_ADT */
-
-/* Define to 1 if you have the <alloca.h> header file. */
-#define HAVE_ALLOCA_H 1
-
-/* AppArmor Support */
-/* #undef HAVE_APPARMOR */
-
-/* Define to 1 if you have backtrace(). */
-/* #undef HAVE_BACKTRACE */
-
-/* Define to 1 if you have the <byteswap.h> header file. */
-#define HAVE_BYTESWAP_H 1
-
-/* Define to 1 if you have the `clearenv' function. */
-#define HAVE_CLEARENV 1
+/* Define to 1 if you have the `backtrace' function. */
+#undef HAVE_BACKTRACE
/* Have cmsgcred structure */
-/* #undef HAVE_CMSGCRED */
+#undef HAVE_CMSGCRED
/* Have console owner file */
-/* #undef HAVE_CONSOLE_OWNER_FILE */
-
-/* Define to 1 if you have the <crt_externs.h> header file. */
-/* #undef HAVE_CRT_EXTERNS_H */
+#undef HAVE_CONSOLE_OWNER_FILE
/* Have the ddfd member of DIR */
-/* #undef HAVE_DDFD */
-
-/* Define to 1 if you have the declaration of `LOG_PERROR', and to 0 if you
- don't. */
-#define HAVE_DECL_LOG_PERROR 1
-
-/* Define to 1 if you have the declaration of `MSG_NOSIGNAL', and to 0 if you
- don't. */
-#define HAVE_DECL_MSG_NOSIGNAL 1
-
-/* Define to 1 if you have the <dirent.h> header file. */
-#define HAVE_DIRENT_H 1
+#undef HAVE_DDFD
/* Have dirfd function */
-/* #undef HAVE_DIRFD */
+#undef HAVE_DIRFD
/* Define to 1 if you have the <dlfcn.h> header file. */
#define HAVE_DLFCN_H 1
@@ -208,28 +125,19 @@
#define HAVE_EXPAT_H 1
/* Define to 1 if you have the `fpathconf' function. */
-/* #undef HAVE_FPATHCONF */
+#undef HAVE_FPATHCONF
/* Define to 1 if you have the `getgrouplist' function. */
#define HAVE_GETGROUPLIST 1
/* Define to 1 if you have the `getpeereid' function. */
-/* #undef HAVE_GETPEEREID */
+#undef HAVE_GETPEEREID
/* Define to 1 if you have the `getpeerucred' function. */
-/* #undef HAVE_GETPEERUCRED */
-
-/* Define to 1 if you have the `getresuid' function. */
-#define HAVE_GETRESUID 1
-
-/* Define to 1 if you have the `getrlimit' function. */
-#define HAVE_GETRLIMIT 1
+#undef HAVE_GETPEERUCRED
/* Have GNU-style varargs macros */
-/* #undef HAVE_GNUC_VARARGS */
-
-/* Define to 1 if you have the `inotify_init1' function. */
-#define HAVE_INOTIFY_INIT1 1
+#undef HAVE_GNUC_VARARGS
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
@@ -237,69 +145,33 @@
/* Have ISO C99 varargs macros */
#define HAVE_ISO_VARARGS 1
-/* Define to 1 if you have the `issetugid' function. */
-/* #undef HAVE_ISSETUGID */
-
-/* audit daemon SELinux support */
-/* #undef HAVE_LIBAUDIT */
-
/* Define to 1 if you have the `nsl' library (-lnsl). */
-/* #undef HAVE_LIBNSL */
+#undef HAVE_LIBNSL
-/* Define to 1 if you have the `localeconv' function. */
-#define HAVE_LOCALECONV 1
-
-/* Define to 1 if you have the <locale.h> header file. */
-#define HAVE_LOCALE_H 1
+/* Define to 1 if you have the `socket' library (-lsocket). */
+#undef HAVE_LIBSOCKET
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
-/* Define if we have CLOCK_MONOTONIC */
-#define HAVE_MONOTONIC_CLOCK 1
-
/* Define to 1 if you have the `nanosleep' function. */
#define HAVE_NANOSLEEP 1
/* Have non-POSIX function getpwnam_r */
-/* #undef HAVE_NONPOSIX_GETPWNAM_R */
-
-/* Define if your system needs _NSGetEnviron to set up the environment */
-/* #undef HAVE_NSGETENVIRON */
-
-/* Define to 1 if you have the `pipe2' function. */
-#define HAVE_PIPE2 1
+#undef HAVE_NONPOSIX_GETPWNAM_R
/* Define to 1 if you have the `poll' function. */
#define HAVE_POLL 1
/* Have POSIX function getpwnam_r */
-/* #undef HAVE_POSIX_GETPWNAM_R */
-
-/* Define to 1 if you have the `prctl' function. */
-#define HAVE_PRCTL 1
-
-/* Define to 1 if you have the `raise' function. */
-#define HAVE_RAISE 1
+#undef HAVE_POSIX_GETPWNAM_R
/* SELinux support */
-/* #undef HAVE_SELINUX */
+#undef HAVE_SELINUX
/* Define to 1 if you have the `setenv' function. */
#define HAVE_SETENV 1
-/* Define to 1 if you have the `setlocale' function. */
-#define HAVE_SETLOCALE 1
-
-/* Define to 1 if you have the `setresuid' function. */
-#define HAVE_SETRESUID 1
-
-/* Define to 1 if you have the `setrlimit' function. */
-#define HAVE_SETRLIMIT 1
-
-/* Define to 1 if you have the <signal.h> header file. */
-#define HAVE_SIGNAL_H 1
-
/* Define to 1 if you have the `socketpair' function. */
#define HAVE_SOCKETPAIR 1
@@ -318,48 +190,21 @@
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
-/* Define to 1 if you have the `strtoll' function. */
-#define HAVE_STRTOLL 1
-
-/* Define to 1 if you have the `strtoull' function. */
-#define HAVE_STRTOULL 1
-
-/* Define to 1 if you have the <syslog.h> header file. */
-#define HAVE_SYSLOG_H 1
-
-/* Have systemd */
-/* #undef HAVE_SYSTEMD */
-
-/* Define to 1 if you have the <sys/inotify.h> header file. */
-#define HAVE_SYS_INOTIFY_H 1
-
-/* Define to 1 if you have the <sys/prctl.h> header file. */
-#define HAVE_SYS_PRCTL_H 1
-
-/* Define to 1 if you have the <sys/resource.h> header file. */
-#define HAVE_SYS_RESOURCE_H 1
-
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/syslimits.h> header file. */
-/* #undef HAVE_SYS_SYSLIMITS_H */
+#undef HAVE_SYS_SYSLIMITS_H
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <sys/uio.h> header file. */
-#define HAVE_SYS_UIO_H 1
+/* actually defined by AndroidConfig.h, commented to get rid of compiler warnings #define HAVE_SYS_UIO_H 1 */
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
-/* Supports sending UNIX file descriptors */
-#define HAVE_UNIX_FD_PASSING 1
-
-/* Have unpcbid structure */
-/* #undef HAVE_UNPCBID */
-
/* Define to 1 if you have the `unsetenv' function. */
#define HAVE_UNSETENV 1
@@ -369,112 +214,81 @@
/* Define to 1 if you have the `vasprintf' function. */
#define HAVE_VASPRINTF 1
-/* Define to 1 or 0, depending whether the compiler supports simple visibility
- declarations. */
-#define HAVE_VISIBILITY 1
-
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
/* Define to 1 if you have the `writev' function. */
#define HAVE_WRITEV 1
-/* Define to 1 if you have the <ws2tcpip.h> header file. */
-/* #undef HAVE_WS2TCPIP_H */
-
-/* Define to the sub-directory where libtool stores uninstalled libraries. */
-#define LT_OBJDIR ".libs/"
-
/* Name of package */
#define PACKAGE "dbus"
/* Define to the address where bug reports for this package should be sent. */
-/* #undef PACKAGE_BUGREPORT */
+#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#define PACKAGE_NAME "dbus"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "dbus-1.10.12"
+#define PACKAGE_STRING "dbus-0.95"
/* Define to the one symbol short name of this package. */
-/* #undef PACKAGE_TARNAME */
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL ""
+#undef PACKAGE_TARNAME
/* Define to the version of this package. */
-#define PACKAGE_VERSION "1.10.12"
+#define PACKAGE_VERSION "0.95"
-/* The size of `char', as computed by sizeof. */
-#define SIZEOF_CHAR 1
+/* The size of a `char', as computed by sizeof. */
+#define SIZEOF_CHAR sizeof(char)
-/* The size of `int', as computed by sizeof. */
-#define SIZEOF_INT 4
+/* The size of a `int', as computed by sizeof. */
+#define SIZEOF_INT sizeof(int)
-/* The size of `long', as computed by sizeof. */
-#define SIZEOF_LONG 4
+/* The size of a `long', as computed by sizeof. */
+#define SIZEOF_LONG sizeof(long)
-/* The size of `long long', as computed by sizeof. */
-#define SIZEOF_LONG_LONG 8
+/* The size of a `long long', as computed by sizeof. */
+#define SIZEOF_LONG_LONG sizeof(long long)
-/* The size of `short', as computed by sizeof. */
-#define SIZEOF_SHORT 2
+/* The size of a `short', as computed by sizeof. */
+#define SIZEOF_SHORT sizeof(short)
-/* The size of `void *', as computed by sizeof. */
-#define SIZEOF_VOID_P 4
+/* The size of a `void *', as computed by sizeof. */
+#define SIZEOF_VOID_P sizeof(void *)
-/* The size of `__int64', as computed by sizeof. */
-#define SIZEOF___INT64 8
+/* The size of a `__int64', as computed by sizeof. */
+#define SIZEOF___INT64 sizeof(long long)
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
-/* Full path to the dbus-launch in the builddir */
-#define TEST_BUS_LAUNCH_BINARY "/system/bin/dbus-launch"
+/* Full path to the daemon in the builddir */
+#define TEST_BUS_BINARY "/system/bin/dbus-test"
-/* Listening address for regression tests */
-#define TEST_LISTEN "unix:tmpdir=/data"
+/* Full path to test file test/test-exit in builddir */
+#define TEST_EXIT_BINARY "/system/bin/dbus-test-exit"
-/* Enable extensions on AIX 3, Interix. */
-#ifndef _ALL_SOURCE
-# define _ALL_SOURCE 1
-#endif
-/* Enable GNU extensions on systems that have them. */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-/* Enable threading extensions on Solaris. */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-/* Enable extensions on HP NonStop. */
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-/* Enable general extensions on Solaris. */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
+/* Full path to test file test/test-segfault in builddir */
+#define TEST_SEGFAULT_BINARY "/system/bin/dbus-test-segfault"
+/* Full path to test file test/test-service in builddir */
+#define TEST_SERVICE_BINARY "/system/bin/dbus-test-service"
+
+/* Full path to test file test/data/valid-service-files in builddir */
+#define TEST_SERVICE_DIR "/etc/dbus-test-data/valid-service-files"
+
+/* Full path to test file test/test-shell-service in builddir */
+#define TEST_SHELL_SERVICE_BINARY "/system/bin/dbus-shell-service"
+
+/* Full path to test file test/test-sleep-forever in builddir */
+#define TEST_SLEEP_FOREVER_BINARY "/system/bin/dbus-sleep-forever"
/* Version number of package */
-#define VERSION "1.10.12"
+#define VERSION "0.95"
-/* Define to add Valgrind instrumentation */
-/* #undef WITH_VALGRIND */
-
-/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
- significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-# define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-/* # undef WORDS_BIGENDIAN */
-# endif
-#endif
+/* Define to 1 if your processor stores words with the most significant byte
+ first (like Motorola and SPARC, unlike Intel and VAX). */
+#undef WORDS_BIGENDIAN
/* Use the compiler-provided endianness defines to allow universal compiling. */
@@ -486,49 +300,4 @@
/* Define to 1 if the X Window System is missing or not being used. */
#define X_DISPLAY_MISSING 1
-
-#if defined(HAVE_NSGETENVIRON) && defined(HAVE_CRT_EXTERNS_H)
-# include <sys/time.h>
-# include <crt_externs.h>
-# define environ (*_NSGetEnviron())
-#endif
-
-
-/* Enable large inode numbers on Mac OS X 10.5. */
-#ifndef _DARWIN_USE_64_BIT_INODE
-# define _DARWIN_USE_64_BIT_INODE 1
-#endif
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-#define _FILE_OFFSET_BITS 64
-
-/* Define for large files, on AIX-style hosts. */
-/* #undef _LARGE_FILES */
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
- this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-/* Defined to get newer W32 CE APIs */
-/* #undef _WIN32_WCE */
-
-/* Define to `__inline__' or `__inline' if that's what the C compiler
- calls it, or to nothing if 'inline' is not supported under any name. */
-#ifndef __cplusplus
-/* #undef inline */
-#endif
-
-
-/* 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
+#define HAVE_UNIX_FD_PASSING 1
diff --git a/configure.ac b/configure.ac
index b75a106..24fcc9e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,19 +2,18 @@
AC_PREREQ([2.63])
m4_define([dbus_major_version], [1])
-m4_define([dbus_minor_version], [10])
-m4_define([dbus_micro_version], [12])
+m4_define([dbus_minor_version], [6])
+m4_define([dbus_micro_version], [8])
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])
-AC_CONFIG_AUX_DIR([build-aux])
AC_CANONICAL_HOST
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
-AM_INIT_AUTOMAKE([1.13 tar-ustar -Wno-portability subdir-objects])
+AM_INIT_AUTOMAKE([1.10 tar-ustar -Wno-portability])
GETTEXT_PACKAGE=dbus-1
AC_SUBST(GETTEXT_PACKAGE)
@@ -34,22 +33,20 @@
#
## increment if the interface has additions, changes, removals.
-LT_CURRENT=17
+LT_CURRENT=10
## increment any time the source changes; set to
## 0 if you increment CURRENT
-LT_REVISION=8
+LT_REVISION=2
## 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=14
+LT_AGE=7
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
-SOVERSION=`expr ${LT_CURRENT} - ${LT_AGE}`
-AC_SUBST([SOVERSION])
DBUS_MAJOR_VERSION=dbus_major_version
DBUS_MINOR_VERSION=dbus_minor_version
@@ -65,7 +62,6 @@
AM_PROG_CC_C_O
AC_PROG_CXX
AC_USE_SYSTEM_EXTENSIONS
-AC_SYS_LARGEFILE
AC_ISC_POSIX
AC_HEADER_STDC
AC_C_INLINE
@@ -75,15 +71,6 @@
COMPILER_OPTIMISATIONS
PKG_PROG_PKG_CONFIG
-# TAP test driver support
-AC_PROG_AWK
-AC_REQUIRE_AUX_FILE([tap-driver.sh])
-
-# This must come before we set up compiler warnings because it assumes
-# non-use of -Werror=missing-prototypes
-gl_VISIBILITY
-AM_CONDITIONAL([HAVE_VISIBILITY], [test "x$HAVE_VISIBILITY" = x1])
-
# Initialize libtool
LT_INIT([win32-dll])
LT_LANG([Windows Resource])
@@ -112,9 +99,6 @@
# Special defines for certain platforms
if test "$dbus_win" = yes; then
AC_DEFINE(DBUS_WIN,1,[Defined if we run on a W32 API based system])
- # Yes, on Windows it really does work like this.
- # http://support.microsoft.com/kb/111855
- AC_DEFINE(FD_SETSIZE,8192,[The maximum number of connections that can be handled at once])
BUILD_TIMESTAMP=`date --iso-8601=minutes`
AC_SUBST(BUILD_TIMESTAMP)
# Assume DBUS_VERSION is always three numbers
@@ -135,13 +119,6 @@
AC_DEFINE(DBUS_CYGWIN,1,[Defined if we run on a cygwin API based system])
fi
-# For best security, assume that all non-Windows platforms can do
-# credentials-passing.
-AS_IF([test "$dbus_win" = yes],
- [DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL="<!--<auth>EXTERNAL</auth>-->"],
- [DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL="<auth>EXTERNAL</auth>"])
-AC_SUBST([DBUS_SESSION_CONF_MAYBE_AUTH_EXTERNAL])
-
AM_CONDITIONAL(DBUS_WIN, test "$dbus_win" = yes)
AM_CONDITIONAL(DBUS_WINCE, test "$dbus_wince" = yes)
AM_CONDITIONAL(DBUS_UNIX, test "$dbus_unix" = yes)
@@ -170,23 +147,18 @@
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([ducktype-docs],
- AS_HELP_STRING([--enable-ducktype-docs],
- [build Ducktype documentation (requires Ducktype)]),
- [enable_ducktype_docs=$enableval], [enable_ducktype_docs=auto])
AC_ARG_ENABLE(abstract-sockets, AS_HELP_STRING([--enable-abstract-sockets],[use abstract socket namespace (linux only)]),enable_abstract_sockets=$enableval,enable_abstract_sockets=auto)
AC_ARG_ENABLE(selinux, AS_HELP_STRING([--enable-selinux],[build with SELinux support]),enable_selinux=$enableval,enable_selinux=auto)
-AC_ARG_ENABLE([apparmor],
- [AS_HELP_STRING([--enable-apparmor], [build with AppArmor support])],
- [enable_apparmor=$enableval],
- [enable_apparmor=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]))
@@ -196,10 +168,8 @@
AC_ARG_WITH(console-owner-file, AS_HELP_STRING([--with-console-owner-file=[filename]],[file whose owner determines current console owner]))
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([test_user],
- [AS_HELP_STRING([--with-test-user=<user>],
- [Unprivileged user for regression tests, other than root and the dbus_user (default: nobody)])])
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],
@@ -217,7 +187,7 @@
[
if test "x$enableval" = xyes; then
AC_MSG_NOTICE([Full test coverage was requested with --enable-tests=yes])
- AC_MSG_NOTICE([This has many dependencies (GLib, Python etc.)])
+ AC_MSG_NOTICE([This has many dependencies (GLib, dbus-glib, Python)])
fi
enable_embedded_tests=$enableval
enable_modular_tests=$enableval
@@ -225,12 +195,16 @@
[])
# DBUS_ENABLE_EMBEDDED_TESTS controls unit tests built in to .c files
-# and also some stuff in the test/ subdir.
+# 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])
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.
@@ -238,14 +212,10 @@
# 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_36], [Ignore post-2.36 deprecations])
-AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_38], [Prevent post-2.38 APIs])
-
with_glib=yes
-AS_IF([test "x$enable_modular_tests" != xno],
- [
- PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.36, gio-2.0 >= 2.36],
+if test "x$enable_modular_tests" != xno; then
+ PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24, gio-2.0 >= 2.24],
[],
[if test "x$enable_modular_tests" = xyes; then
AC_MSG_NOTICE([Full test coverage (--enable-modular-tests=yes or --enable-tests=yes) requires GLib])
@@ -253,9 +223,16 @@
else # assumed to be "auto"
with_glib=no
fi])
- ],
- [with_glib=no])
-
+ # If dbus-gmain.[ch] returned to libdbus then we wouldn't need this
+ 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
if test "x$enable_modular_tests" != xno; then
AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1],
[Define to build independent test binaries])
@@ -278,14 +255,14 @@
if test "x$enable_tests" = xyes; then
# full test coverage is required, Python is a hard dependency
- AC_MSG_NOTICE([Full test coverage (--enable-tests=yes) requires Python, dbus-python, pygi])
+ AC_MSG_NOTICE([Full test coverage (--enable-tests=yes) requires Python, dbus-python, pygobject])
AM_PATH_PYTHON([2.6])
AC_MSG_CHECKING([for Python modules for full test coverage])
- if "$PYTHON" -c "import dbus, gi.repository.GObject, dbus.mainloop.glib"; then
+ if "$PYTHON" -c "import dbus, gobject, dbus.mainloop.glib"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
- AC_MSG_ERROR([cannot import dbus, gi.repository.GObject, dbus.mainloop.glib Python modules])
+ AC_MSG_ERROR([cannot import dbus, gobject, dbus.mainloop.glib Python modules])
fi
else
# --enable-tests not given: do not abort if Python is missing
@@ -300,11 +277,6 @@
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
@@ -324,14 +296,9 @@
DISABLE_UNUSED_WARNINGS="unused-label"
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_userdb_cache = xyes; then
+ AC_DEFINE(DBUS_ENABLE_USERDB_CACHE,1,[Build with caching of user data])
+fi
if test x$enable_compiler_coverage = xyes; then
## so that config.h changes when you toggle gcov support
@@ -373,6 +340,12 @@
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])
@@ -411,17 +384,33 @@
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])
+ 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.])
],
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
@@ -433,6 +422,7 @@
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])
@@ -606,17 +596,13 @@
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 issetugid getresuid setresuid getrlimit])
+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
AC_CHECK_DECLS([LOG_PERROR], [], [], [[#include <syslog.h>]])
fi
-# For test-segfault.c
-AC_CHECK_HEADERS_ONCE([sys/prctl.h])
-AC_CHECK_FUNCS_ONCE([prctl raise])
-
#### Check for broken poll; taken from Glib's configure
AC_MSG_CHECKING([for broken poll])
@@ -684,10 +670,7 @@
AC_CHECK_HEADERS(dirent.h)
-AC_CHECK_HEADERS([execinfo.h],
- [AC_SEARCH_LIBS([backtrace], [execinfo],
- [AC_DEFINE([HAVE_BACKTRACE], [1],
- [Define to 1 if you have backtrace().])])])
+AC_CHECK_HEADERS(execinfo.h, [AC_CHECK_FUNCS(backtrace)])
AC_CHECK_HEADERS(errno.h)
@@ -699,11 +682,9 @@
AC_CHECK_HEADERS(unistd.h)
-AC_CHECK_HEADERS([stdint.h])
-
AC_CHECK_HEADERS(ws2tcpip.h)
-AC_CHECK_HEADERS(alloca.h)
+AC_CHECK_HEADERS(wspiapi.h)
# Add -D_POSIX_PTHREAD_SEMANTICS if on Solaris
#
@@ -835,11 +816,6 @@
AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure])
fi
-AC_CHECK_MEMBER([struct unpcbid.unp_pid],
- [AC_DEFINE([HAVE_UNPCBID], 1, [Have unpcbid structure])],
- [],
- [[#include <sys/un.h>]])
-
AC_CHECK_FUNCS(getpeerucred getpeereid)
AC_CHECK_FUNCS(pipe2 accept4)
@@ -926,66 +902,66 @@
# 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, [],
- [AC_MSG_ERROR([Could not find expat.h, check config.log for failed attempts])]) ],
- [ AC_MSG_ERROR([Explicitly requested expat but expat not found]) ])
+ [ AC_CHECK_HEADERS(expat.h, have_expat=true, have_expat=false) ],
+ have_expat=false)
-XML_LIBS=-lexpat
-XML_CFLAGS=
+# 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)
+
+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
AC_SUBST([XML_CFLAGS])
AC_SUBST([XML_LIBS])
# Thread lib detection
-AC_ARG_VAR([THREAD_LIBS])
+AC_CHECK_FUNC(pthread_cond_timedwait,[AC_CHECK_LIB(pthread,pthread_cond_timedwait,
+ [THREAD_LIBS="-lpthread"])])
save_libs="$LIBS"
LIBS="$LIBS $THREAD_LIBS"
-
-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>
+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>
#include <pthread.h>
]], [[
struct timespec monotonic_timer;
@@ -994,17 +970,15 @@
pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
clock_getres (CLOCK_MONOTONIC,&monotonic_timer);
]])],
- [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
-
+[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
LIBS="$save_libs"
AC_SUBST([THREAD_LIBS])
@@ -1055,22 +1029,6 @@
SELINUX_LIBS=
fi
-# AppArmor detection
-AS_IF([test x$enable_apparmor = xno],
- [have_apparmor=no],
- [
- PKG_CHECK_MODULES([APPARMOR], [libapparmor >= 2.8.95],
- [have_apparmor=yes], [have_apparmor=no])
-
- AS_IF([test x$enable_apparmor = xauto && test x$have_apparmor = xno],
- [AC_MSG_WARN([Sufficiently new AppArmor library not found])])
- AS_IF([test x$enable_apparmor != xauto && test x$have_apparmor = xno],
- [AC_MSG_ERROR([AppArmor explicitly required, and AppArmor library not found])])
- ])
-
-AS_IF([test x$have_apparmor = xyes],
- [AC_DEFINE([HAVE_APPARMOR], [1], [AppArmor Support])])
-
# inotify checks
if test x$enable_inotify = xno ; then
have_inotify=no;
@@ -1086,6 +1044,24 @@
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.
@@ -1188,13 +1164,10 @@
if test x$enable_systemd = xno ; then
have_systemd=no;
else
- PKG_CHECK_MODULES([SYSTEMD],
- [libsystemd >= 209],
- [have_systemd=yes],
- [PKG_CHECK_MODULES([SYSTEMD],
- [libsystemd-login >= 32, libsystemd-daemon >= 32, libsystemd-journal >= 32],
- [have_systemd=yes],
- [have_systemd=no])])
+ PKG_CHECK_MODULES(SYSTEMD,
+ [libsystemd-login >= 32, libsystemd-daemon >= 32],
+ have_systemd=yes,
+ have_systemd=no)
fi
if test x$have_systemd = xyes; then
@@ -1205,12 +1178,6 @@
AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
fi
-# If not found in $PATH, we might still have systemd and systemctl at runtime
-# (perhaps dbus is being compiled in a minimal chroot with no systemd).
-# Assume the upstream-recommended location. Distributors with split /usr
-# can override this with ./configure SYSTEMCTL=/bin/systemctl
-AC_PATH_PROG([SYSTEMCTL], [systemctl], [/usr/bin/systemctl])
-
# libaudit detection
if test x$enable_libaudit = xno ; then
have_libaudit=no;
@@ -1268,7 +1235,7 @@
if test x$dbus_wince = xyes ; then
NETWORK_libs="-lws2"
else
- NETWORK_libs="-lws2_32 -liphlpapi"
+ NETWORK_libs="-lws2_32"
fi
fi
@@ -1280,17 +1247,13 @@
[],
[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
#### Set up final flags
-LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs $SYSTEMD_LIBS"
+LIBDBUS_LIBS="$THREAD_LIBS $NETWORK_libs"
AC_SUBST([LIBDBUS_LIBS])
### X11 detection
@@ -1383,13 +1346,13 @@
dnl - unused-parameter is to make writing callbacks less annoying
dnl
dnl To be fixed one day:
- dnl - pointer-sign is a workaround for fd.o #15522
+ dnl - sign-compare and pointer-sign are workarounds for fd.o #17433
dnl - type-limits is probably a bug too, but having the rest of -Wextra
dnl is better than nothing
[$DISABLE_UNUSED_WARNINGS \
- deprecated-declarations \
missing-field-initializers \
unused-parameter \
+ sign-compare \
pointer-sign \
type-limits \
])
@@ -1425,11 +1388,6 @@
;;
esac
-### Detect if ld supports --version-script
-
-gl_LD_VERSION_SCRIPT
-AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT],
- [test "x$have_ld_version_script" = xyes])
### Doxygen Documentation
AC_PATH_PROG(DOXYGEN, doxygen, no)
@@ -1462,36 +1420,6 @@
AC_CHECK_PROGS([XSLTPROC], [xsltproc])
AM_CONDITIONAL([DBUS_HAVE_XSLTPROC], [test "x$XSLTPROC" != "x"])
-### Ducktype/Yelp documentation
-
-AC_PATH_PROG([DUCKTYPE],[ducktype],[no])
-AC_PATH_PROG([YELP_BUILD],[yelp-build],[no])
-
-AC_MSG_CHECKING([whether to build Ducktype documentation])
-
-AS_IF([test "$DUCKTYPE" = "no"],[have_ducktype=no],[have_ducktype=yes])
-AS_IF([test "$YELP_BUILD" = "no"],[have_yelp_build=no],[have_yelp_build=yes])
-
-AS_IF([test "$enable_ducktype_docs" = "auto"],[
- AS_IF([test "$have_ducktype" = "no" || test "$have_yelp_build" = "no"],[
- enable_ducktype_docs=no
- ],[
- enable_ducktype_docs=yes
- ])
-])
-
-AS_IF([test "$enable_ducktype_docs" = "yes"],[
- AS_IF([test "$have_ducktype" = "no"],[
- AC_MSG_ERROR([Building Ducktype docs explicitly required, but ducktype not found])
- ])
- AS_IF([test "$have_yelp_build" = "no"],[
- AC_MSG_ERROR([Building Ducktype docs explicitly required, but yelp-build not found])
- ])
-])
-
-AM_CONDITIONAL([DBUS_DUCKTYPE_DOCS_ENABLED],[test "$enable_ducktype_docs" = "yes"])
-AC_MSG_RESULT([$enable_ducktype_docs])
-
### XML Documentation
AC_PATH_PROG(XMLTO, xmlto, no)
@@ -1521,9 +1449,13 @@
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 && test x$enable_xml_docs = xyes &&
- test x$enable_ducktype_docs = xyes])
+ test x$enable_doxygen_docs = xyes -a x$enable_xml_docs = xyes -a \
+ x$MAN2HTML != x)
#### Have to go $localstatedir->$prefix/var->/usr/local/var
@@ -1579,17 +1511,7 @@
if test "x$with_systemdsystemunitdir" != xno; then
AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
fi
-AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$have_systemd" != "xno" -a -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
-
-AC_ARG_WITH([systemduserunitdir],
-AS_HELP_STRING([--with-systemduserunitdir=DIR], [Directory for systemd user service files]),
- [],
- [
- PKG_CHECK_EXISTS([systemd],
- [with_systemduserunitdir=$($PKG_CONFIG --variable=systemduserunitdir systemd)],
- [with_systemduserunitdir='${libdir}/systemd/user'])
- ])
-AC_SUBST([systemduserunitdir], [$with_systemduserunitdir])
+AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
##### Set up location for system bus socket
if ! test -z "$with_system_socket"; then
@@ -1601,17 +1523,8 @@
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).
-##
-## 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.
+## system bus only listens on local domain sockets, and never
+## on an abstract socket (so only root can create the socket)
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])
@@ -1660,13 +1573,6 @@
AC_SUBST(DBUS_USER)
AC_DEFINE_UNQUOTED(DBUS_USER,"$DBUS_USER", [User for running the system BUS daemon])
-#### User for regression tests
-AS_IF([test -z "$with_test_user"], [with_test_user=nobody])
-DBUS_TEST_USER="$with_test_user"
-AC_SUBST([DBUS_TEST_USER])
-AC_DEFINE_UNQUOTED([DBUS_TEST_USER], ["$DBUS_TEST_USER"],
- [Unprivileged user used in some regression tests])
-
#### Prefix to install into
DBUS_PREFIX=$EXPANDED_PREFIX
AC_SUBST(DBUS_PREFIX)
@@ -1680,13 +1586,10 @@
#### Directory to install dbus-daemon
if test -z "$with_dbus_daemondir" ; then
DBUS_DAEMONDIR=$EXPANDED_BINDIR
- dbus_daemondir='$bindir'
else
DBUS_DAEMONDIR=$with_dbus_daemondir
- dbus_daemondir=$with_dbus_daemondir
fi
AC_SUBST(DBUS_DAEMONDIR)
-AC_SUBST(dbus_daemondir)
AC_DEFINE_UNQUOTED(DBUS_DAEMONDIR,"$DBUS_DAEMONDIR", [Directory for installing the DBUS daemon])
#### Directory to install the other binaries
@@ -1699,23 +1602,6 @@
AC_SUBST(DBUS_LIBEXECDIR)
AC_DEFINE_UNQUOTED(DBUS_LIBEXECDIR,"$DBUS_LIBEXECDIR", [Directory for installing the libexec binaries])
-#### Directory to source sysconfdir configuration from
-
-# On Windows this is relative to where we put the bus setup, in
-# ${datadir}/dbus-1. For simplicity, we only do this if
-# ${sysconfdir} = ${prefix}/etc and ${datadir} = ${prefix}/share.
-#
-# On Unix, or on Windows with weird install layouts, it's the absolute path.
-AS_IF([test "${dbus_win}" = yes && \
- test "$EXPANDED_SYSCONFDIR" = "$EXPANDED_PREFIX/etc" && \
- test "$EXPANDED_DATADIR" = "$EXPANDED_PREFIX/share"],
- [SYSCONFDIR_FROM_PKGDATADIR="../../etc"
- DATADIR_FROM_PKGSYSCONFDIR="../../share"],
- [SYSCONFDIR_FROM_PKGDATADIR="$EXPANDED_SYSCONFDIR"
- DATADIR_FROM_PKGSYSCONFDIR="$EXPANDED_DATADIR"])
-AC_SUBST([SYSCONFDIR_FROM_PKGDATADIR])
-AC_SUBST([DATADIR_FROM_PKGSYSCONFDIR])
-
#### Tell tests where to find certain stuff in builddir
DBUS_PWD=`pwd`
@@ -1734,8 +1620,9 @@
AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"],
[Extension for executables, typically empty or .exe])
-AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"],
- [Full path to the dbus-launch in the builddir])
+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)
## Export the non-setuid external helper
TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT"
@@ -1781,64 +1668,14 @@
AC_DEFINE_UNQUOTED(DBUS_SESSION_SOCKET_DIR, "$DBUS_SESSION_SOCKET_DIR", [Where per-session bus puts its sockets])
AC_SUBST(DBUS_SESSION_SOCKET_DIR)
-# 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:"
+if test x$dbus_win = xyes; then
+ DBUS_SESSION_BUS_DEFAULT_ADDRESS="$with_dbus_session_bus_default_address"
elif test x$have_launchd = xyes; then
- # Mac OS X default is to use launchd
- DBUS_SESSION_BUS_LISTEN_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
+ DBUS_SESSION_BUS_DEFAULT_ADDRESS="launchd:env=DBUS_LAUNCHD_SESSION_BUS_SOCKET"
else
- # The default on all other Unix platforms (notably Linux)
- # is to create a randomly named socket in /tmp or similar
- DBUS_SESSION_BUS_LISTEN_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
+ DBUS_SESSION_BUS_DEFAULT_ADDRESS="unix:tmpdir=$DBUS_SESSION_SOCKET_DIR"
fi
-AC_SUBST([DBUS_SESSION_BUS_LISTEN_ADDRESS])
-
-# This must be an address you can connect to. It doesn't necessarily
-# need to be an address you can listen on - it can be "autolaunch:",
-# even on Unix.
-#
-# The default varies by platform.
-AC_ARG_WITH([dbus_session_bus_connect_address],
- AS_HELP_STRING([--with-dbus-session-bus-connect-address=[ADDRESS]],
- [fallback address for a session bus client to connect to (see configure.ac)]),
- [with_dbus_session_bus_connect_address=$withval],
- [with_dbus_session_bus_connect_address=])
-
-if test "x$with_dbus_session_bus_connect_address" != "x"; then
- # the user specified something, trust them
- DBUS_SESSION_BUS_CONNECT_ADDRESS="$with_dbus_session_bus_connect_address"
-elif test x$dbus_win = xyes; then
- # Windows autolaunching is a bit different; leaving it in its own
- # branch of the conditional because the default might conceivably
- # change (see #38201)
- DBUS_SESSION_BUS_CONNECT_ADDRESS="autolaunch:"
-else
- # 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])
+AC_SUBST(DBUS_SESSION_BUS_DEFAULT_ADDRESS)
# darwin needs this to initialize the environment
AC_CHECK_HEADERS(crt_externs.h)
@@ -1853,40 +1690,26 @@
])
AC_ARG_ENABLE([stats],
- [AS_HELP_STRING([--disable-stats],
- [disable bus daemon usage statistics])],
- [], [enable_stats=yes])
+ [AS_HELP_STRING([--enable-stats],
+ [enable bus daemon usage statistics])],
+ [], [enable_stats=no])
if test "x$enable_stats" = xyes; then
AC_DEFINE([DBUS_ENABLE_STATS], [1],
[Define to enable bus daemon usage statistics])
fi
-AC_ARG_ENABLE([user-session],
- [AS_HELP_STRING([--enable-user-session],
- [enable user-session semantics for session bus under systemd])],
- [], [enable_user_session=no])
-AM_CONDITIONAL([DBUS_ENABLE_USER_SESSION],
- [test "x$enable_user_session" = xyes])
-
AC_CONFIG_FILES([
Doxyfile
-dbus/Version
dbus/versioninfo.rc
dbus/dbus-arch-deps.h
bus/system.conf
bus/session.conf
-bus/legacy-config/system.conf
-bus/legacy-config/session.conf
-bus/example-system-enable-stats.conf
-bus/example-session-disable-stats.conf
bus/messagebus
bus/messagebus-config
bus/org.freedesktop.dbus-session.plist
bus/rc.messagebus
bus/dbus.service
bus/dbus.socket
-bus/systemd-user/dbus.service
-bus/systemd-user/dbus.socket
Makefile
dbus/Makefile
bus/Makefile
@@ -1894,17 +1717,26 @@
test/Makefile
test/name-test/Makefile
doc/Makefile
-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-test-tool.1.xml
-doc/dbus-update-activation-environment.1.xml
-doc/dbus-uuidgen.1.xml
+doc/dbus-daemon.1
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-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
+test/data/valid-service-files/org.freedesktop.DBus.TestSuiteEchoService.service
+test/data/valid-service-files/org.freedesktop.DBus.TestSuiteForkingEchoService.service
+test/data/valid-service-files/org.freedesktop.DBus.TestSuiteSegfaultService.service
+test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service
+test/data/valid-service-files/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service
+test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteEchoService.service
+test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteSegfaultService.service
+test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceSuccess.service
+test/data/valid-service-files-system/org.freedesktop.DBus.TestSuiteShellEchoServiceFail.service
+test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service
+test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service
+test/data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service
])
AC_OUTPUT
@@ -1931,8 +1763,7 @@
16-bit int: ${DBUS_INT16_TYPE}
Doxygen: ${DOXYGEN:-not found}
xmlto: ${XMLTO:-not found}
- ducktype: ${DUCKTYPE:-not found}
- yelp-build: ${YELP_BUILD:-not found}"
+ man2html: ${MAN2HTML:-not found}"
echo "
Rebuilding generated files: ${USE_MAINTAINER_MODE}
@@ -1940,28 +1771,27 @@
Building embedded tests: ${enable_embedded_tests}
Building modular tests: ${enable_modular_tests}
- with GLib: ${with_glib}
- Installing tests: ${enable_installed_tests}
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 AppArmor support: ${have_apparmor}
Building inotify support: ${have_inotify}
+ Building dnotify support: ${have_dnotify}
Building kqueue support: ${have_kqueue}
Building systemd support: ${have_systemd}
- Building X11 code: ${have_x11}
+ Building X11 code: ${enable_x11}
Building Doxygen docs: ${enable_doxygen_docs}
- Building Ducktype docs: ${enable_ducktype_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 listens on: ${DBUS_SESSION_BUS_LISTEN_ADDRESS}
- Session clients connect to: ${DBUS_SESSION_BUS_CONNECT_ADDRESS}
+ Session bus address: ${DBUS_SESSION_BUS_DEFAULT_ADDRESS}
Console auth dir: ${DBUS_CONSOLE_AUTH_DIR}
Console owner file: ${have_console_owner_file}
Console owner file path: ${DBUS_CONSOLE_OWNER_FILE}
@@ -1992,3 +1822,20 @@
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 b66ad2f..038c83e 100644
--- a/dbus-1-uninstalled.pc.in
+++ b/dbus-1-uninstalled.pc.in
@@ -2,15 +2,12 @@
abs_top_srcdir=@abs_top_srcdir@
prefix=
exec_prefix=
-bindir=@bindir@
system_bus_default_address=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
-datarootdir=@datarootdir@
-datadir=@datadir@
-sysconfdir=@sysconfdir@
-session_bus_services_dir=${datadir}/dbus-1/services
-system_bus_services_dir=${datadir}/dbus-1/system-services
-interfaces_dir=${datadir}/dbus-1/interfaces
-daemondir=@dbus_daemondir@
+sysconfdir=@EXPANDED_SYSCONFDIR@
+session_bus_services_dir=@EXPANDED_DATADIR@/dbus-1/services
+system_bus_services_dir=@EXPANDED_DATADIR@/dbus-1/system-services
+interfaces_dir=@EXPANDED_DATADIR@/dbus-1/interfaces
+daemondir=@DBUS_DAEMONDIR@
Name: dbus
Description: Free desktop message bus (uninstalled copy)
diff --git a/dbus-1.pc.in b/dbus-1.pc.in
index f93d156..25f8bce 100644
--- a/dbus-1.pc.in
+++ b/dbus-1.pc.in
@@ -1,16 +1,13 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
-bindir=@bindir@
libdir=@libdir@
includedir=@includedir@
system_bus_default_address=@DBUS_SYSTEM_BUS_DEFAULT_ADDRESS@
-datarootdir=@datarootdir@
-datadir=@datadir@
-sysconfdir=@sysconfdir@
-session_bus_services_dir=${datadir}/dbus-1/services
-system_bus_services_dir=${datadir}/dbus-1/system-services
-interfaces_dir=${datadir}/dbus-1/interfaces
-daemondir=@dbus_daemondir@
+sysconfdir=@EXPANDED_SYSCONFDIR@
+session_bus_services_dir=@EXPANDED_DATADIR@/dbus-1/services
+system_bus_services_dir=@EXPANDED_DATADIR@/dbus-1/system-services
+interfaces_dir=@EXPANDED_DATADIR@/dbus-1/interfaces
+daemondir=@DBUS_DAEMONDIR@
Name: dbus
Description: Free desktop message bus
diff --git a/dbus/Android.bp b/dbus/Android.bp
new file mode 100644
index 0000000..5d12346
--- /dev/null
+++ b/dbus/Android.bp
@@ -0,0 +1,86 @@
+cc_library_shared {
+ name: "libdbus",
+
+ srcs: [
+ "dbus-address.c",
+ "dbus-auth.c",
+ "dbus-bus.c",
+ "dbus-connection.c",
+ "dbus-credentials.c",
+ "dbus-dataslot.c",
+ "dbus-errors.c",
+ "dbus-file.c",
+ "dbus-file-unix.c",
+ "dbus-hash.c",
+ "dbus-internals.c",
+ "dbus-keyring.c",
+ "dbus-list.c",
+ "dbus-mainloop.c",
+ "dbus-marshal-basic.c",
+ "dbus-marshal-byteswap.c",
+ "dbus-marshal-header.c",
+ "dbus-marshal-recursive.c",
+ "dbus-marshal-validate.c",
+ "dbus-mempool.c",
+ "dbus-memory.c",
+ "dbus-message.c",
+ "dbus-misc.c",
+ "dbus-nonce.c",
+ "dbus-pending-call.c",
+ "dbus-pipe.c",
+ "dbus-pipe-unix.c",
+ "dbus-resources.c",
+ "dbus-server.c",
+ "dbus-server-socket.c",
+ "dbus-server-unix.c",
+ "dbus-sha.c",
+ "dbus-shell.c",
+ "dbus-signature.c",
+ "dbus-socket-set.c",
+ "dbus-socket-set-poll.c",
+ "dbus-spawn.c",
+ "dbus-string.c",
+ "dbus-string-util.c",
+ "dbus-sysdeps.c",
+ "dbus-sysdeps-pthread.c",
+ "dbus-sysdeps-unix.c",
+ "dbus-sysdeps-util.c",
+ "dbus-sysdeps-util-unix.c",
+ "dbus-timeout.c",
+ "dbus-threads.c",
+ "dbus-transport.c",
+ "dbus-transport-socket.c",
+ "dbus-transport-unix.c",
+ "dbus-object-tree.c",
+ "dbus-userdb.c",
+ "dbus-userdb-util.c",
+ "dbus-watch.c",
+ "sd-daemon.c",
+ ],
+
+ cflags: [
+ "-DDBUS_ANDROID_LOG",
+ "-DDBUS_COMPILATION",
+ "-DANDROID_MANAGED_SOCKET",
+ "-DHAVE_MONOTONIC_CLOCK",
+ "-DDBUS_MACHINE_UUID_FILE=\\\"/etc/machine-id\\\"",
+ "-DDBUS_SYSTEM_CONFIG_FILE=\\\"/system/etc/dbus.conf\\\"",
+ "-DDBUS_SESSION_CONFIG_FILE=\\\"/system/etc/session.conf\\\"",
+ "-Wno-empty-body",
+ "-Wno-missing-field-initializers",
+ "-Wno-pointer-sign",
+ "-Wno-sign-compare",
+ "-Wno-tautological-compare",
+ "-Wno-type-limits",
+ "-Wno-unused-parameter",
+ ],
+ clang: true,
+
+ static_libs: ["libdbus-headers"],
+ export_static_lib_headers: ["libdbus-headers"],
+
+ shared_libs: [
+ "libcutils",
+ "liblog",
+ ],
+}
diff --git a/dbus/Android.mk b/dbus/Android.mk
deleted file mode 100644
index 1e7ed8a..0000000
--- a/dbus/Android.mk
+++ /dev/null
@@ -1,113 +0,0 @@
-# Set to true to write libdbus logs to logcat instead of stderr
-# See also config.h to turn on verbose logs
-LOG_TO_ANDROID_LOGCAT := true
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- dbus-address.c \
- dbus-asv-util.c \
- dbus-auth.c \
- dbus-bus.c \
- dbus-connection.c \
- dbus-credentials.c \
- dbus-dataslot.c \
- dbus-errors.c \
- dbus-file.c \
- dbus-file-unix.c \
- dbus-hash.c \
- dbus-internals.c \
- dbus-keyring.c \
- dbus-list.c \
- dbus-mainloop.c \
- dbus-marshal-basic.c \
- dbus-marshal-byteswap.c \
- dbus-marshal-header.c \
- dbus-marshal-recursive.c \
- dbus-marshal-validate.c \
- dbus-memory.c \
- dbus-mempool.c \
- dbus-message.c \
- dbus-misc.c \
- dbus-nonce.c \
- dbus-object-tree.c \
- dbus-pending-call.c \
- dbus-pipe.c \
- dbus-pipe-unix.c \
- dbus-resources.c \
- dbus-server.c \
- dbus-server-debug-pipe.c \
- dbus-server-launchd.c \
- dbus-server-socket.c \
- dbus-server-unix.c \
- dbus-sha.c \
- dbus-shell.c \
- dbus-signature.c \
- dbus-socket-set.c \
- dbus-socket-set-epoll.c \
- dbus-socket-set-poll.c \
- dbus-spawn.c \
- dbus-string.c \
- dbus-string-util.c \
- dbus-syntax.c \
- dbus-sysdeps.c \
- dbus-sysdeps-pthread.c \
- dbus-sysdeps-unix.c \
- dbus-sysdeps-util.c \
- dbus-sysdeps-util-unix.c \
- dbus-threads.c \
- dbus-timeout.c \
- dbus-transport.c \
- dbus-transport-socket.c \
- dbus-transport-unix.c \
- dbus-userdb.c \
- dbus-userdb-util.c \
- dbus-uuidgen.c \
- dbus-watch.c
-
-LOCAL_C_INCLUDES+= $(LOCAL_PATH)/..
-
-LOCAL_MODULE:=libdbus
-
-LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/..
-
-LOCAL_CFLAGS+= \
- -DDBUS_COMPILATION \
- -DHAVE_MONOTONIC_CLOCK \
- -DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\" \
- -DDBUS_SYSTEM_CONFIG_FILE=\"/etc/dbus-1/system.conf\" \
- -DDBUS_SESSION_CONFIG_FILE=\"/etc/dbus-1/session.conf\" \
- -Wno-empty-body \
- -Wno-missing-field-initializers \
- -Wno-pointer-sign \
- -Wno-sign-compare \
- -Wno-tautological-compare \
- -Wno-type-limits \
- -Wno-unused-parameter
-
-LOCAL_CLANG := true
-
-ifeq ($(LOG_TO_ANDROID_LOGCAT),true)
-ifneq ($(TARGET_ARCH), x86-64)
-LOCAL_CFLAGS+= \
- -DDBUS_ANDROID_LOG \
- -DANDROID_MANAGED_SOCKET
-
-LOCAL_SHARED_LIBRARIES+= libcutils liblog
-endif
-endif
-
-ifeq ($(TARGET_ARCH), x86-64)
-LOCAL_CFLAGS+= -D_GNU_SOURCE
-endif
-
-ifeq ($(BUILD_EUREKA),true)
-# Copy the headers to the build sysroot directory.
-include_dir := $(LOCAL_PATH)/..
-include_files := $(shell find $(include_dir) -type f -name '*.h')
-LOCAL_TOOLCHAIN_PREBUILTS := \
- $(join $(include_files),\
- $(patsubst $(include_dir)/%,:usr/include/%,$(include_files)))
-endif
-include $(BUILD_SHARED_LIBRARY)
diff --git a/dbus/Makefile.am b/dbus/Makefile.am
index a7b3491..bb5ccca 100644
--- a/dbus/Makefile.am
+++ b/dbus/Makefile.am
@@ -1,30 +1,17 @@
-dbusdatadir=$(datadir)/dbus-1
+configdir=$(sysconfdir)/dbus-1
AM_CPPFLAGS = \
-I$(top_builddir) \
-I$(top_srcdir) \
- $(DBUS_STATIC_BUILD_CPPFLAGS) \
$(SYSTEMD_CFLAGS) \
$(VALGRIND_CFLAGS) \
-DDBUS_COMPILATION \
-DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\" \
- -DDBUS_SYSTEM_CONFIG_FILE=\""$(dbusdatadir)/system.conf"\" \
- -DDBUS_SESSION_CONFIG_FILE=\""$(dbusdatadir)/session.conf"\" \
+ -DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\" \
+ -DDBUS_SESSION_CONFIG_FILE=\""$(configdir)/session.conf"\" \
$(NULL)
-AM_CFLAGS =
-
-if HAVE_VISIBILITY
-if !DBUS_WIN
-AM_CFLAGS += $(CFLAG_VISIBILITY)
-AM_CPPFLAGS += \
- -DDBUS_EXPORT='__attribute__((__visibility__("default")))' \
- -DDBUS_PRIVATE_EXPORT='__attribute__((__visibility__("default")))' \
- $(NULL)
-endif
-endif
-
# if assertions are enabled, improve backtraces
AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
@@ -48,13 +35,16 @@
no_undefined = -no-undefined
export_symbols =
-EXTRA_libdbus_1_la_DEPENDENCIES = $(dbus_res)
+libdbus_1_la_DEPENDENCIES = $(dbus_res)
intllibs =
else
dbus_res =
dbus_res_ldflag =
no_undefined =
+## don't export symbols that start with "_" (we use this
+## convention for internal symbols)
+export_symbols = -export-symbols-regex "^[^_].*"
intllibs = @LTLIBINTL@
@@ -114,7 +104,8 @@
dbus-transport-unix.h \
dbus-userdb.c \
dbus-userdb.h \
- $(NULL)
+ sd-daemon.c \
+ sd-daemon.h
DBUS_UTIL_arch_sources = \
dbus-sysdeps-util-unix.c \
@@ -242,8 +233,6 @@
### 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 \
@@ -273,56 +262,51 @@
$(DBUS_SHARED_SOURCES)
libdbus_internal_la_SOURCES= \
+ $(DBUS_LIB_SOURCES) \
+ $(DBUS_SHARED_SOURCES) \
$(DBUS_UTIL_SOURCES)
BUILT_SOURCES=$(nodist_dbusarchinclude_HEADERS)
EXTRA_DIST=dbus-arch-deps.h.in
+## this library is the same as libdbus, but exports all the symbols
+## and is only used for static linking within the dbus package.
noinst_LTLIBRARIES=libdbus-internal.la
libdbus_1_la_CPPFLAGS = \
$(AM_CPPFLAGS) \
-Ddbus_1_EXPORTS \
$(NULL)
-
-if HAVE_LD_VERSION_SCRIPT
-SYMBOL_EXPORT_LDFLAGS=-Wl,--version-script=Version
-else
-SYMBOL_EXPORT_LDFLAGS=
-endif
-
libdbus_1_la_LIBADD= $(LIBDBUS_LIBS)
libdbus_1_la_LDFLAGS = \
$(AM_LDFLAGS) \
+ $(export_symbols) \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
- $(SYMBOL_EXPORT_LDFLAGS) \
-no-undefined \
$(NULL)
-libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) libdbus-1.la
-
-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
-endif
+libdbus_internal_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -DDBUS_STATIC_BUILD \
+ $(NULL)
+libdbus_internal_la_LIBADD=$(LIBDBUS_LIBS) $(SYSTEMD_LIBS)
noinst_PROGRAMS =
-if DBUS_ENABLE_EMBEDDED_TESTS
+if DBUS_BUILD_TESTS
# We can't actually run this til we've reached test/
-noinst_PROGRAMS += test-dbus
+noinst_PROGRAMS += dbus-test
endif
-test_dbus_SOURCES= \
+dbus_test_SOURCES= \
dbus-test-main.c
-test_dbus_LDADD = libdbus-internal.la
+dbus_test_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
diff --git a/dbus/Version.in b/dbus/Version.in
deleted file mode 100644
index f6cc367..0000000
--- a/dbus/Version.in
+++ /dev/null
@@ -1,10 +0,0 @@
-LIBDBUS_1_@SOVERSION@ {
- global:
- dbus_*;
- local:
- *;
-};
-LIBDBUS_PRIVATE_@DBUS_VERSION@ {
- global:
- _dbus_*;
-};
diff --git a/dbus/dbus-address.c b/dbus/dbus-address.c
index c4cfbbe..90484dc 100644
--- a/dbus/dbus-address.c
+++ b/dbus/dbus-address.c
@@ -104,15 +104,15 @@
_dbus_address_append_escaped (DBusString *escaped,
const DBusString *unescaped)
{
- const unsigned char *p;
- const unsigned char *end;
+ const char *p;
+ const char *end;
dbus_bool_t ret;
int orig_len;
ret = FALSE;
orig_len = _dbus_string_get_length (escaped);
- p = (const unsigned char *) _dbus_string_get_const_data (unescaped);
+ p = _dbus_string_get_const_data (unescaped);
end = p + _dbus_string_get_length (unescaped);
while (p != end)
{
@@ -648,7 +648,7 @@
/** @} */ /* End of public API */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -678,9 +678,7 @@
{ "Z", "Z" },
{ "a", "a" },
{ "i", "i" },
- { "z", "z" },
- /* Bug: https://bugs.freedesktop.org/show_bug.cgi?id=53499 */
- { "%c3%b6", "\xc3\xb6" }
+ { "z", "z" }
};
static const char* invalid_escaped_values[] = {
diff --git a/dbus/dbus-arch-deps.h b/dbus/dbus-arch-deps.h
index 361b02f..c8359c8 100644
--- a/dbus/dbus-arch-deps.h
+++ b/dbus/dbus-arch-deps.h
@@ -31,7 +31,7 @@
DBUS_BEGIN_DECLS
-/* D-Bus no longer supports platforms with no 64-bit integer type. */
+#if 1
#define DBUS_HAVE_INT64 1
_DBUS_GNUC_EXTENSION typedef long long dbus_int64_t;
_DBUS_GNUC_EXTENSION typedef unsigned long long dbus_uint64_t;
@@ -39,6 +39,12 @@
#define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##LL))
#define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##ULL))
+#else
+#undef DBUS_HAVE_INT64
+#undef DBUS_INT64_CONSTANT
+#undef DBUS_UINT64_CONSTANT
+#endif
+
typedef int dbus_int32_t;
typedef unsigned int dbus_uint32_t;
@@ -49,12 +55,12 @@
* creating an additional generated header just for this
*/
#define DBUS_MAJOR_VERSION 1
-#define DBUS_MINOR_VERSION 10
-#define DBUS_MICRO_VERSION 12
+#define DBUS_MINOR_VERSION 4
+#define DBUS_MICRO_VERSION 0
-#define DBUS_VERSION_STRING "1.10.12"
+#define DBUS_VERSION_STRING "1.4.0"
-#define DBUS_VERSION ((1 << 16) | (10 << 8) | (12))
+#define DBUS_VERSION ((1 << 16) | (4 << 8) | (0))
DBUS_END_DECLS
diff --git a/dbus/dbus-arch-deps.h.in b/dbus/dbus-arch-deps.h.in
index dfc3589..45952cf 100644
--- a/dbus/dbus-arch-deps.h.in
+++ b/dbus/dbus-arch-deps.h.in
@@ -31,7 +31,7 @@
DBUS_BEGIN_DECLS
-/* D-Bus no longer supports platforms with no 64-bit integer type. */
+#if @DBUS_HAVE_INT64@
#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,6 +39,12 @@
#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
deleted file mode 100644
index d3ac5e9..0000000
--- a/dbus/dbus-asv-util.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/* 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;
-}
-
-/**
- * Create a new entry in an a{sv} (map from string to variant)
- * with a byte array 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
- * @param n_elements the number of elements to append
- * @returns #TRUE on success, or #FALSE if not enough memory
- */
-dbus_bool_t
-_dbus_asv_add_byte_array (DBusMessageIter *arr_iter,
- const char *key,
- const void *value,
- int n_elements)
-{
- DBusMessageIter entry_iter;
- DBusMessageIter var_iter;
- DBusMessageIter byte_array_iter;
-
- if (!_dbus_asv_open_entry (arr_iter, &entry_iter, key, "ay", &var_iter))
- return FALSE;
-
- if (!dbus_message_iter_open_container (&var_iter, DBUS_TYPE_ARRAY,
- DBUS_TYPE_BYTE_AS_STRING,
- &byte_array_iter))
- {
- _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
- return FALSE;
- }
-
- if (!dbus_message_iter_append_fixed_array (&byte_array_iter, DBUS_TYPE_BYTE,
- &value, n_elements))
- {
- dbus_message_iter_abandon_container (&var_iter, &byte_array_iter);
- _dbus_asv_abandon_entry (arr_iter, &entry_iter, &var_iter);
- return FALSE;
- }
-
- if (!dbus_message_iter_close_container (&var_iter, &byte_array_iter))
- {
- _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
deleted file mode 100644
index 277ab80..0000000
--- a/dbus/dbus-asv-util.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 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);
-dbus_bool_t _dbus_asv_add_byte_array (DBusMessageIter *arr_iter,
- const char *key,
- const void *value,
- int n_elements);
-
-#endif
diff --git a/dbus/dbus-auth-script.c b/dbus/dbus-auth-script.c
index aaaed30..6285e3b 100644
--- a/dbus/dbus-auth-script.c
+++ b/dbus/dbus-auth-script.c
@@ -22,12 +22,9 @@
*/
#include <config.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-auth-script.h"
-
-#include <stdio.h>
-
#include "dbus-auth.h"
#include "dbus-string.h"
#include "dbus-hash.h"
@@ -224,15 +221,10 @@
_dbus_assert_not_reached ("no memory");
if (uid != DBUS_UID_UNSET)
- {
- if (!_dbus_credentials_add_unix_uid (credentials, uid))
- _dbus_assert_not_reached ("no memory");
- }
+ _dbus_credentials_add_unix_uid (credentials, uid);
if (pid != DBUS_PID_UNSET)
- {
- if (!_dbus_credentials_add_pid (credentials, pid))
- _dbus_assert_not_reached ("no memory");
- }
+ _dbus_credentials_add_unix_pid (credentials, pid);
+
_dbus_auth_set_credentials (auth, credentials);
_dbus_credentials_unref (credentials);
@@ -342,7 +334,7 @@
"UNIX_ONLY"))
{
/* skip this file */
- fprintf (stderr, "skipping unix only auth script\n");
+ _dbus_warn ("skipping unix only auth script\n");
retval = TRUE;
goto out;
}
@@ -358,7 +350,7 @@
"WIN_ONLY"))
{
/* skip this file */
- fprintf (stderr, "skipping windows only auth script\n");
+ _dbus_warn ("skipping windows only auth script\n");
retval = TRUE;
goto out;
}
@@ -535,7 +527,7 @@
goto out;
}
- _dbus_string_delete (&to_send, where, (int) strlen ("USERID_HEX"));
+ _dbus_string_delete (&to_send, where, strlen ("USERID_HEX"));
if (!_dbus_string_hex_encode (&username, 0,
&to_send, where))
@@ -568,7 +560,7 @@
goto out;
}
- _dbus_string_delete (&to_send, where, (int) strlen ("USERNAME_HEX"));
+ _dbus_string_delete (&to_send, where, strlen ("USERNAME_HEX"));
if (!_dbus_string_hex_encode (&username, 0,
&to_send, where))
@@ -592,11 +584,11 @@
{
_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);
+ _dbus_auth_return_buffer (auth, buffer, 0);
goto out;
}
- _dbus_auth_return_buffer (auth, buffer);
+ _dbus_auth_return_buffer (auth, buffer, _dbus_string_get_length (&to_send));
}
_dbus_string_free (&to_send);
@@ -808,4 +800,4 @@
}
/** @} */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-auth-util.c b/dbus/dbus-auth-util.c
index 10cbc49..776e8e2 100644
--- a/dbus/dbus-auth-util.c
+++ b/dbus/dbus-auth-util.c
@@ -33,7 +33,8 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
+#include "dbus-test.h"
#include "dbus-auth-script.h"
#include <stdio.h>
@@ -166,4 +167,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-auth.c b/dbus/dbus-auth.c
index ea43ce7..d2c37a7 100644
--- a/dbus/dbus-auth.c
+++ b/dbus/dbus-auth.c
@@ -37,7 +37,7 @@
* @brief DBusAuth object
*
* DBusAuth manages the authentication negotiation when a connection
- * is first established, and also manages any encryption used over a
+ * is first established, and also manage any encryption used over a
* connection.
*
* @todo some SASL profiles require sending the empty string as a
@@ -282,9 +282,6 @@
static const DBusAuthStateData client_state_waiting_for_data = {
"WaitingForData", handle_client_state_waiting_for_data
};
-/* The WaitingForOK state doesn't appear to be used.
- * See https://bugs.freedesktop.org/show_bug.cgi?id=97298 */
-_DBUS_GNUC_UNUSED
static const DBusAuthStateData client_state_waiting_for_ok = {
"WaitingForOK", handle_client_state_waiting_for_ok
};
@@ -527,8 +524,10 @@
*/
DBusString tmp;
DBusString tmp2;
- dbus_bool_t retval = FALSE;
- DBusError error = DBUS_ERROR_INIT;
+ dbus_bool_t retval;
+ DBusError error;
+
+ retval = FALSE;
_dbus_string_set_length (&auth->challenge, 0);
@@ -579,6 +578,7 @@
if (auth->keyring == NULL)
{
+ dbus_error_init (&error);
auth->keyring = _dbus_keyring_new_for_credentials (auth->desired_identity,
&auth->context,
&error);
@@ -610,6 +610,7 @@
_dbus_assert (auth->keyring != NULL);
+ dbus_error_init (&error);
auth->cookie_id = _dbus_keyring_get_best_key (auth->keyring, &error);
if (auth->cookie_id < 0)
{
@@ -639,25 +640,8 @@
if (!_dbus_string_append (&tmp2, " "))
goto out;
- if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES, &error))
- {
- if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
- {
- dbus_error_free (&error);
- goto out;
- }
- else
- {
- _DBUS_ASSERT_ERROR_IS_SET (&error);
- _dbus_verbose ("%s: Error generating challenge: %s\n",
- DBUS_AUTH_NAME (auth), error.message);
- if (send_rejected (auth))
- retval = TRUE; /* retval is only about mem */
-
- dbus_error_free (&error);
- goto out;
- }
- }
+ if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES))
+ goto out;
_dbus_string_set_length (&auth->challenge, 0);
if (!_dbus_string_hex_encode (&tmp, 0, &auth->challenge, 0))
@@ -842,7 +826,7 @@
* name, the cookie ID, and the server challenge, separated by
* spaces. We send back our challenge string and the correct hash.
*/
- dbus_bool_t retval = FALSE;
+ dbus_bool_t retval;
DBusString context;
DBusString cookie_id_str;
DBusString server_challenge;
@@ -851,8 +835,9 @@
DBusString tmp;
int i, j;
long val;
- DBusError error = DBUS_ERROR_INIT;
-
+
+ retval = FALSE;
+
if (!_dbus_string_find_blank (data, 0, &i))
{
if (send_error (auth,
@@ -918,6 +903,9 @@
if (auth->keyring == NULL)
{
+ DBusError error;
+
+ dbus_error_init (&error);
auth->keyring = _dbus_keyring_new_for_credentials (NULL,
&context,
&error);
@@ -954,28 +942,9 @@
if (!_dbus_string_init (&tmp))
goto out_3;
-
- if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES, &error))
- {
- if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
- {
- dbus_error_free (&error);
- goto out_4;
- }
- else
- {
- _DBUS_ASSERT_ERROR_IS_SET (&error);
-
- _dbus_verbose ("%s: Failed to generate challenge: %s\n",
- DBUS_AUTH_NAME (auth), error.message);
-
- if (send_error (auth, "Failed to generate challenge"))
- retval = TRUE; /* retval is only about mem */
-
- dbus_error_free (&error);
- goto out_4;
- }
- }
+
+ if (!_dbus_generate_random_bytes (&tmp, N_CHALLENGE_BYTES))
+ goto out_4;
if (!_dbus_string_init (&client_challenge))
goto out_4;
@@ -1133,23 +1102,20 @@
auth->desired_identity))
return FALSE;
- /* also copy misc process info from the socket credentials
+ /* also copy process ID from the socket credentials
*/
if (!_dbus_credentials_add_credential (auth->authorized_identity,
DBUS_CREDENTIAL_UNIX_PROCESS_ID,
auth->credentials))
return FALSE;
+ /* also copy audit data from the socket credentials
+ */
if (!_dbus_credentials_add_credential (auth->authorized_identity,
DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID,
auth->credentials))
return FALSE;
-
- if (!_dbus_credentials_add_credential (auth->authorized_identity,
- DBUS_CREDENTIAL_LINUX_SECURITY_LABEL,
- auth->credentials))
- return FALSE;
-
+
if (!send_ok (auth))
return FALSE;
@@ -2272,8 +2238,8 @@
/**
* Creates a new auth conversation object for the server side.
- * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
- * for full details on what this object does.
+ * See doc/dbus-sasl-profile.txt for full details on what
+ * this object does.
*
* @returns the new object or #NULL if no memory
*/
@@ -2318,8 +2284,8 @@
/**
* Creates a new auth conversation object for the client side.
- * See http://dbus.freedesktop.org/doc/dbus-specification.html#auth-protocol
- * for full details on what this object does.
+ * See doc/dbus-sasl-profile.txt for full details on what
+ * this object does.
*
* @returns the new object or #NULL if no memory
*/
@@ -2567,10 +2533,12 @@
*
* @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)
+ DBusString *buffer,
+ int bytes_read)
{
_dbus_assert (buffer == &auth->incoming);
_dbus_assert (auth->buffer_outstanding);
diff --git a/dbus/dbus-auth.h b/dbus/dbus-auth.h
index e032302..ae3f364 100644
--- a/dbus/dbus-auth.h
+++ b/dbus/dbus-auth.h
@@ -41,35 +41,24 @@
DBUS_AUTH_STATE_AUTHENTICATED
} DBusAuthState;
-DBUS_PRIVATE_EXPORT
DBusAuth* _dbus_auth_server_new (const DBusString *guid);
-DBUS_PRIVATE_EXPORT
DBusAuth* _dbus_auth_client_new (void);
-DBUS_PRIVATE_EXPORT
DBusAuth* _dbus_auth_ref (DBusAuth *auth);
-DBUS_PRIVATE_EXPORT
void _dbus_auth_unref (DBusAuth *auth);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_auth_set_mechanisms (DBusAuth *auth,
const char **mechanisms);
-DBUS_PRIVATE_EXPORT
DBusAuthState _dbus_auth_do_work (DBusAuth *auth);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_auth_get_bytes_to_send (DBusAuth *auth,
const DBusString **str);
-DBUS_PRIVATE_EXPORT
void _dbus_auth_bytes_sent (DBusAuth *auth,
int bytes_sent);
-DBUS_PRIVATE_EXPORT
void _dbus_auth_get_buffer (DBusAuth *auth,
DBusString **buffer);
-DBUS_PRIVATE_EXPORT
void _dbus_auth_return_buffer (DBusAuth *auth,
- DBusString *buffer);
-DBUS_PRIVATE_EXPORT
+ DBusString *buffer,
+ int bytes_read);
void _dbus_auth_get_unused_bytes (DBusAuth *auth,
const DBusString **str);
-DBUS_PRIVATE_EXPORT
void _dbus_auth_delete_unused_bytes (DBusAuth *auth);
dbus_bool_t _dbus_auth_needs_encoding (DBusAuth *auth);
dbus_bool_t _dbus_auth_encode_data (DBusAuth *auth,
@@ -79,12 +68,9 @@
dbus_bool_t _dbus_auth_decode_data (DBusAuth *auth,
const DBusString *encoded,
DBusString *plaintext);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_auth_set_credentials (DBusAuth *auth,
DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
DBusCredentials* _dbus_auth_get_identity (DBusAuth *auth);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_auth_set_context (DBusAuth *auth,
const DBusString *context);
const char* _dbus_auth_get_guid_from_server(DBusAuth *auth);
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index 0fd4831..fadc3a8 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -28,7 +28,6 @@
#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"
@@ -96,6 +95,19 @@
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)
{
@@ -180,12 +192,12 @@
if (!retval)
return FALSE;
- /* We have a hard-coded (but compile-time-configurable) fallback address for
- * the session bus. */
+ /* The DBUS_SESSION_BUS_DEFAULT_ADDRESS should have really been named
+ * DBUS_SESSION_BUS_FALLBACK_ADDRESS.
+ */
if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
bus_connection_addresses[DBUS_BUS_SESSION] =
- _dbus_strdup (DBUS_SESSION_BUS_CONNECT_ADDRESS);
-
+ _dbus_strdup (DBUS_SESSION_BUS_DEFAULT_ADDRESS);
if (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
return FALSE;
@@ -294,6 +306,12 @@
* 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;
@@ -312,11 +330,7 @@
if (bd->is_well_known)
{
int i;
-
- if (!_DBUS_LOCK (bus))
- _dbus_assert_not_reached ("global locks should have been initialized "
- "when we attached bus data");
-
+ _DBUS_LOCK (bus);
/* 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
@@ -387,13 +401,8 @@
_dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection)
{
int i;
-
- 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;
- }
+
+ _DBUS_LOCK (bus);
/* 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
@@ -427,12 +436,7 @@
connection = NULL;
- if (!_DBUS_LOCK (bus))
- {
- _DBUS_SET_OOM (error);
- /* do not "goto out", that would try to unlock */
- return NULL;
- }
+ _DBUS_LOCK (bus);
if (!init_connections_unlocked ())
{
@@ -502,10 +506,8 @@
*/
dbus_connection_set_exit_on_disconnect (connection,
TRUE);
-
- if (!_DBUS_LOCK (bus_datas))
- _dbus_assert_not_reached ("global locks were initialized already");
-
+
+ _DBUS_LOCK (bus_datas);
bd = ensure_bus_data (connection);
_dbus_assert (bd != NULL); /* it should have been created on
register, so OOM not possible */
@@ -552,7 +554,7 @@
*
* @param type bus type
* @param error address where an error can be returned.
- * @returns a #DBusConnection with new ref or #NULL on error
+ * @returns a #DBusConnection with new ref
*/
DBusConnection *
dbus_bus_get (DBusBusType type,
@@ -658,12 +660,7 @@
message = NULL;
reply = NULL;
- if (!_DBUS_LOCK (bus_datas))
- {
- _DBUS_SET_OOM (error);
- /* do not "goto out", that would try to unlock */
- return FALSE;
- }
+ _DBUS_LOCK (bus_datas);
bd = ensure_bus_data (connection);
if (bd == NULL)
@@ -772,12 +769,8 @@
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (unique_name != NULL, FALSE);
- if (!_DBUS_LOCK (bus_datas))
- {
- /* do not "goto out", that would try to unlock */
- return FALSE;
- }
-
+ _DBUS_LOCK (bus_datas);
+
bd = ensure_bus_data (connection);
if (bd == NULL)
goto out;
@@ -819,13 +812,8 @@
_dbus_return_val_if_fail (connection != NULL, NULL);
- 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;
- }
-
+ _DBUS_LOCK (bus_datas);
+
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 4835732..3d37f18 100644
--- a/dbus/dbus-connection-internal.h
+++ b/dbus/dbus-connection-internal.h
@@ -44,15 +44,9 @@
/** default timeout value when waiting for a message reply, 25 seconds */
#define _DBUS_DEFAULT_TIMEOUT_VALUE (25 * 1000)
-typedef void (* DBusPendingFdsChangeFunction) (void *data);
-
-DBUS_PRIVATE_EXPORT
void _dbus_connection_lock (DBusConnection *connection);
-DBUS_PRIVATE_EXPORT
void _dbus_connection_unlock (DBusConnection *connection);
-DBUS_PRIVATE_EXPORT
DBusConnection * _dbus_connection_ref_unlocked (DBusConnection *connection);
-DBUS_PRIVATE_EXPORT
void _dbus_connection_unref_unlocked (DBusConnection *connection);
void _dbus_connection_queue_received_message_link (DBusConnection *connection,
DBusList *link);
@@ -100,26 +94,14 @@
void _dbus_connection_queue_synthesized_message_link (DBusConnection *connection,
DBusList *link);
-DBUS_PRIVATE_EXPORT
void _dbus_connection_test_get_locks (DBusConnection *conn,
DBusMutex **mutex_loc,
DBusMutex **dispatch_mutex_loc,
DBusMutex **io_path_mutex_loc,
DBusCondVar **dispatch_cond_loc,
DBusCondVar **io_path_cond_loc);
-DBUS_PRIVATE_EXPORT
-int _dbus_connection_get_pending_fds_count (DBusConnection *connection);
-DBUS_PRIVATE_EXPORT
-void _dbus_connection_set_pending_fds_function (DBusConnection *connection,
- DBusPendingFdsChangeFunction callback,
- void *data);
-
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_connection_get_linux_security_label (DBusConnection *connection,
- char **label_p);
/* if DBUS_ENABLE_STATS */
-DBUS_PRIVATE_EXPORT
void _dbus_connection_get_stats (DBusConnection *connection,
dbus_uint32_t *in_messages,
dbus_uint32_t *in_bytes,
@@ -133,7 +115,7 @@
dbus_uint32_t *out_peak_fds);
-/* if DBUS_ENABLE_EMBEDDED_TESTS */
+/* if DBUS_BUILD_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 e3a89b5..0362288 100644
--- a/dbus/dbus-connection.c
+++ b/dbus/dbus-connection.c
@@ -63,7 +63,7 @@
/* A "DO_NOT_HAVE_LOCK_CHECK" is impossible since we need the lock to check the flag */
#endif
-#define TRACE_LOCKS 1
+#define TRACE_LOCKS 0
#define CONNECTION_LOCK(connection) do { \
if (TRACE_LOCKS) { _dbus_verbose ("LOCK\n"); } \
@@ -204,19 +204,26 @@
* @{
*/
+#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);
-#endif
}
+#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
@@ -330,8 +337,8 @@
#ifndef DBUS_DISABLE_CHECKS
unsigned int have_connection_lock : 1; /**< Used to check locking */
#endif
-
-#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
+
+#ifndef DBUS_DISABLE_CHECKS
int generation; /**< _dbus_current_generation that should correspond to this connection */
#endif
};
@@ -440,7 +447,7 @@
(*connection->wakeup_main_function) (connection->wakeup_main_data);
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* Gets the locks so we can examine them
*
@@ -484,9 +491,9 @@
DBusPendingCall *pending;
dbus_uint32_t reply_serial;
DBusMessage *message;
-
- _dbus_assert (_dbus_transport_peek_is_authenticated (connection->transport));
-
+
+ _dbus_assert (_dbus_transport_get_is_authenticated (connection->transport));
+
_dbus_list_append_link (&connection->incoming_messages,
link);
message = link->data;
@@ -1348,7 +1355,7 @@
connection->disconnected_message_arrived = FALSE;
connection->disconnected_message_processed = FALSE;
-#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
+#ifndef DBUS_DISABLE_CHECKS
connection->generation = _dbus_current_generation;
#endif
@@ -1525,7 +1532,7 @@
return retval;
}
-/* Protected by _DBUS_LOCK (shared_connections) */
+_DBUS_DEFINE_GLOBAL_LOCK (shared_connections);
static DBusHashTable *shared_connections = NULL;
static DBusList *shared_connections_no_guid = NULL;
@@ -1549,14 +1556,9 @@
shared_connections_shutdown (void *data)
{
int n_entries;
-
- if (!_DBUS_LOCK (shared_connections))
- {
- /* We'd have initialized locks before adding anything, so there
- * can't be anything there. */
- return;
- }
-
+
+ _DBUS_LOCK (shared_connections);
+
/* This is a little bit unpleasant... better ideas? */
while ((n_entries = _dbus_hash_table_get_n_entries (shared_connections)) > 0)
{
@@ -1570,8 +1572,7 @@
_DBUS_UNLOCK (shared_connections);
close_connection_on_shutdown (connection);
- if (!_DBUS_LOCK (shared_connections))
- _dbus_assert_not_reached ("global locks were already initialized");
+ _DBUS_LOCK (shared_connections);
/* The connection should now be dead and not in our hash ... */
_dbus_assert (_dbus_hash_table_get_n_entries (shared_connections) < n_entries);
@@ -1590,8 +1591,7 @@
{
_DBUS_UNLOCK (shared_connections);
close_connection_on_shutdown (connection);
- if (!_DBUS_LOCK (shared_connections))
- _dbus_assert_not_reached ("global locks were already initialized");
+ _DBUS_LOCK (shared_connections);
connection = _dbus_list_pop_first (&shared_connections_no_guid);
}
}
@@ -1608,13 +1608,8 @@
_dbus_verbose ("checking for existing connection\n");
*result = NULL;
-
- if (!_DBUS_LOCK (shared_connections))
- {
- /* If it was shared, we'd have initialized global locks when we put
- * it in shared_connections. */
- return FALSE;
- }
+
+ _DBUS_LOCK (shared_connections);
if (shared_connections == NULL)
{
@@ -1712,8 +1707,7 @@
if (guid == NULL)
{
- if (!_DBUS_LOCK (shared_connections))
- return FALSE;
+ _DBUS_LOCK (shared_connections);
if (!_dbus_list_prepend (&shared_connections_no_guid, connection))
{
@@ -1740,14 +1734,8 @@
dbus_free (guid_key);
return FALSE;
}
-
- if (!_DBUS_LOCK (shared_connections))
- {
- dbus_free (guid_in_connection);
- dbus_free (guid_key);
- return FALSE;
- }
-
+
+ _DBUS_LOCK (shared_connections);
_dbus_assert (shared_connections != NULL);
if (!_dbus_hash_table_insert_string (shared_connections,
@@ -1778,14 +1766,9 @@
if (!connection->shareable)
return;
-
- 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;
- }
-
+
+ _DBUS_LOCK (shared_connections);
+
if (connection->server_guid != NULL)
{
_dbus_verbose ("dropping connection to %s out of the shared table\n",
@@ -2168,7 +2151,7 @@
* relatively long time for memory, if they were only willing to block
* briefly then we retry for memory at a rapid rate.
*
- * @param timeout_milliseconds the timeout requested for blocking
+ * @timeout_milliseconds the timeout requested for blocking
*/
static void
_dbus_memory_pause_based_on_timeout (int timeout_milliseconds)
@@ -2550,33 +2533,6 @@
dbus_pending_call_unref (pending);
}
-/**
- * Return how many file descriptors are pending in the loader
- *
- * @param connection the connection
- */
-int
-_dbus_connection_get_pending_fds_count (DBusConnection *connection)
-{
- return _dbus_transport_get_pending_fds_count (connection->transport);
-}
-
-/**
- * Register a function to be called whenever the number of pending file
- * descriptors in the loader change.
- *
- * @param connection the connection
- * @param callback the callback
- */
-void
-_dbus_connection_set_pending_fds_function (DBusConnection *connection,
- DBusPendingFdsChangeFunction callback,
- void *data)
-{
- _dbus_transport_set_pending_fds_function (connection->transport,
- callback, data);
-}
-
/** @} */
/**
@@ -2728,7 +2684,6 @@
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;
@@ -2998,9 +2953,9 @@
dbus_bool_t res;
_dbus_return_val_if_fail (connection != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- res = _dbus_transport_try_to_authenticate (connection->transport);
+ res = _dbus_transport_get_is_authenticated (connection->transport);
CONNECTION_UNLOCK (connection);
return res;
@@ -3984,7 +3939,7 @@
link = _dbus_list_pop_first_link (&connection->incoming_messages);
connection->n_incoming -= 1;
- _dbus_verbose ("Message %p (%s %s %s %s sig:'%s' serial:%u) removed from incoming queue %p, %d incoming\n",
+ _dbus_verbose ("Message %p (%s %s %s %s '%s') 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) ?
@@ -3997,7 +3952,6 @@
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,
@@ -4442,24 +4396,15 @@
"GetMachineId"))
{
DBusString uuid;
- DBusError error = DBUS_ERROR_INIT;
-
- if (!_dbus_string_init (&uuid))
+
+ ret = dbus_message_new_method_return (message);
+ if (ret == NULL)
goto out;
- if (_dbus_get_local_machine_uuid_encoded (&uuid, &error))
+ _dbus_string_init (&uuid);
+ if (_dbus_get_local_machine_uuid_encoded (&uuid))
{
- const char *v_STRING;
-
- ret = dbus_message_new_method_return (message);
-
- if (ret == NULL)
- {
- _dbus_string_free (&uuid);
- goto out;
- }
-
- v_STRING = _dbus_string_get_const_data (&uuid);
+ const char *v_STRING = _dbus_string_get_const_data (&uuid);
if (dbus_message_append_args (ret,
DBUS_TYPE_STRING, &v_STRING,
DBUS_TYPE_INVALID))
@@ -4467,23 +4412,6 @@
sent = _dbus_connection_send_unlocked_no_update (connection, ret, NULL);
}
}
- else if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
- {
- dbus_error_free (&error);
- goto out;
- }
- else
- {
- ret = dbus_message_new_error (message, error.name, error.message);
- dbus_error_free (&error);
-
- if (ret == NULL)
- goto out;
-
- sent = _dbus_connection_send_unlocked_no_update (connection, ret,
- NULL);
- }
-
_dbus_string_free (&uuid);
}
else
@@ -5181,19 +5109,14 @@
int *fd)
{
dbus_bool_t retval;
- DBusSocket s = DBUS_SOCKET_INIT;
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (connection->transport != NULL, FALSE);
CONNECTION_LOCK (connection);
- retval = _dbus_transport_get_socket_fd (connection->transport, &s);
-
- if (retval)
- {
- *fd = _dbus_socket_get_int (s);
- }
+ retval = _dbus_transport_get_socket_fd (connection->transport,
+ fd);
CONNECTION_UNLOCK (connection);
@@ -5231,10 +5154,10 @@
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (uid != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_try_to_authenticate (connection->transport))
+ if (!_dbus_transport_get_is_authenticated (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_unix_user (connection->transport,
@@ -5267,10 +5190,10 @@
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (pid != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_try_to_authenticate (connection->transport))
+ if (!_dbus_transport_get_is_authenticated (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_unix_process_id (connection->transport,
@@ -5288,8 +5211,7 @@
* connection.
*
* @param connection the connection
- * @param data return location for audit data
- * @param data_size return location for length of audit data
+ * @param data return location for audit data
* @returns #TRUE if audit data is filled in with a valid ucred pointer
*/
dbus_bool_t
@@ -5302,10 +5224,10 @@
_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_try_to_authenticate (connection->transport))
+ if (!_dbus_transport_get_is_authenticated (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_adt_audit_session_data (connection->transport,
@@ -5359,32 +5281,6 @@
(* old_free_function) (old_data);
}
-/* Same calling convention as dbus_connection_get_windows_user */
-dbus_bool_t
-_dbus_connection_get_linux_security_label (DBusConnection *connection,
- char **label_p)
-{
- dbus_bool_t result;
-
- _dbus_assert (connection != NULL);
- _dbus_assert (label_p != NULL);
-
- CONNECTION_LOCK (connection);
-
- if (!_dbus_transport_try_to_authenticate (connection->transport))
- result = FALSE;
- else
- result = _dbus_transport_get_linux_security_label (connection->transport,
- label_p);
-#ifndef __linux__
- _dbus_assert (!result);
-#endif
-
- CONNECTION_UNLOCK (connection);
-
- return result;
-}
-
/**
* Gets the Windows user SID of the connection if known. Returns
* #TRUE if the ID is filled in. Always returns #FALSE on non-Windows
@@ -5424,10 +5320,10 @@
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (windows_sid_p != NULL, FALSE);
-
+
CONNECTION_LOCK (connection);
- if (!_dbus_transport_try_to_authenticate (connection->transport))
+ if (!_dbus_transport_get_is_authenticated (connection->transport))
result = FALSE;
else
result = _dbus_transport_get_windows_user (connection->transport,
@@ -5545,7 +5441,7 @@
_dbus_return_if_fail (connection != NULL);
CONNECTION_LOCK (connection);
- connection->route_peer_messages = value;
+ connection->route_peer_messages = TRUE;
CONNECTION_UNLOCK (connection);
}
@@ -5962,8 +5858,8 @@
return retval;
}
-static DBusDataSlotAllocator slot_allocator =
- _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (connection_slots));
+static DBusDataSlotAllocator slot_allocator;
+_DBUS_DEFINE_GLOBAL_LOCK (connection_slots);
/**
* Allocates an integer ID to be used for storing application-specific
@@ -5983,6 +5879,7 @@
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);
}
@@ -6083,8 +5980,7 @@
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,
@@ -6153,7 +6049,7 @@
* result in disconnecting the connection.
*
* @param connection a #DBusConnection
- * @param n maximum message unix fds the connection can receive
+ * @param size maximum message unix fds the connection can receive
*/
void
dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
@@ -6251,7 +6147,7 @@
* The semantics are analogous to those of dbus_connection_set_max_received_size().
*
* @param connection the connection
- * @param n the maximum size in bytes of all outstanding messages
+ * @param size the maximum size in bytes of all outstanding messages
*/
void
dbus_connection_set_max_received_unix_fds (DBusConnection *connection,
@@ -6368,7 +6264,7 @@
return res;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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 94d7201..0277196 100644
--- a/dbus/dbus-credentials-util.c
+++ b/dbus/dbus-credentials-util.c
@@ -33,13 +33,14 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
+#include "dbus-test.h"
#include <stdio.h>
#include <string.h>
static DBusCredentials*
make_credentials(dbus_uid_t unix_uid,
- dbus_pid_t pid,
+ dbus_pid_t unix_pid,
const char *windows_sid)
{
DBusCredentials *credentials;
@@ -55,9 +56,9 @@
}
}
- if (pid != DBUS_PID_UNSET)
+ if (unix_pid != DBUS_PID_UNSET)
{
- if (!_dbus_credentials_add_pid (credentials, pid))
+ if (!_dbus_credentials_add_unix_pid (credentials, unix_pid))
{
_dbus_credentials_unref (credentials);
return NULL;
@@ -101,7 +102,7 @@
_dbus_assert (_dbus_credentials_include (creds, DBUS_CREDENTIAL_WINDOWS_SID));
_dbus_assert (_dbus_credentials_get_unix_uid (creds) == 12);
- _dbus_assert (_dbus_credentials_get_pid (creds) == 511);
+ _dbus_assert (_dbus_credentials_get_unix_pid (creds) == 511);
_dbus_assert (strcmp (_dbus_credentials_get_windows_sid (creds), SAMPLE_SID) == 0);
_dbus_assert (!_dbus_credentials_are_empty (creds));
@@ -117,7 +118,7 @@
_dbus_assert (_dbus_credentials_include (creds2, DBUS_CREDENTIAL_WINDOWS_SID));
_dbus_assert (_dbus_credentials_get_unix_uid (creds2) == 12);
- _dbus_assert (_dbus_credentials_get_pid (creds2) == 511);
+ _dbus_assert (_dbus_credentials_get_unix_pid (creds2) == 511);
_dbus_assert (strcmp (_dbus_credentials_get_windows_sid (creds2), SAMPLE_SID) == 0);
_dbus_assert (_dbus_credentials_are_superset (creds, creds2));
@@ -191,7 +192,7 @@
_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_pid (creds) == DBUS_PID_UNSET);
+ _dbus_assert (_dbus_credentials_get_unix_pid (creds) == DBUS_PID_UNSET);
_dbus_assert (_dbus_credentials_get_windows_sid (creds) == NULL);
_dbus_assert (_dbus_credentials_are_empty (creds));
@@ -202,4 +203,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-credentials.c b/dbus/dbus-credentials.c
index 151bb00..ff69f3b 100644
--- a/dbus/dbus-credentials.c
+++ b/dbus/dbus-credentials.c
@@ -48,9 +48,8 @@
struct DBusCredentials {
int refcount;
dbus_uid_t unix_uid;
- dbus_pid_t pid;
+ dbus_pid_t unix_pid;
char *windows_sid;
- char *linux_security_label;
void *adt_audit_data;
dbus_int32_t adt_audit_data_size;
};
@@ -78,9 +77,8 @@
creds->refcount = 1;
creds->unix_uid = DBUS_UID_UNSET;
- creds->pid = DBUS_PID_UNSET;
+ creds->unix_pid = DBUS_PID_UNSET;
creds->windows_sid = NULL;
- creds->linux_security_label = NULL;
creds->adt_audit_data = NULL;
creds->adt_audit_data_size = 0;
@@ -135,7 +133,6 @@
if (credentials->refcount == 0)
{
dbus_free (credentials->windows_sid);
- dbus_free (credentials->linux_security_label);
dbus_free (credentials->adt_audit_data);
dbus_free (credentials);
}
@@ -149,10 +146,10 @@
* @returns #FALSE if no memory
*/
dbus_bool_t
-_dbus_credentials_add_pid (DBusCredentials *credentials,
- dbus_pid_t pid)
+_dbus_credentials_add_unix_pid (DBusCredentials *credentials,
+ dbus_pid_t pid)
{
- credentials->pid = pid;
+ credentials->unix_pid = pid;
return TRUE;
}
@@ -196,30 +193,6 @@
}
/**
- * Add a Linux security label, as used by LSMs such as SELinux, Smack and
- * AppArmor, to the credentials.
- *
- * @param credentials the object
- * @param label the label
- * @returns #FALSE if no memory
- */
-dbus_bool_t
-_dbus_credentials_add_linux_security_label (DBusCredentials *credentials,
- const char *label)
-{
- char *copy;
-
- copy = _dbus_strdup (label);
- if (copy == NULL)
- return FALSE;
-
- dbus_free (credentials->linux_security_label);
- credentials->linux_security_label = copy;
-
- return TRUE;
-}
-
-/**
* Add ADT audit data to the credentials.
*
* @param credentials the object
@@ -258,13 +231,11 @@
switch (type)
{
case DBUS_CREDENTIAL_UNIX_PROCESS_ID:
- return credentials->pid != DBUS_PID_UNSET;
+ return credentials->unix_pid != DBUS_PID_UNSET;
case DBUS_CREDENTIAL_UNIX_USER_ID:
return credentials->unix_uid != DBUS_UID_UNSET;
case DBUS_CREDENTIAL_WINDOWS_SID:
return credentials->windows_sid != NULL;
- case DBUS_CREDENTIAL_LINUX_SECURITY_LABEL:
- return credentials->linux_security_label != NULL;
case DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID:
return credentials->adt_audit_data != NULL;
}
@@ -281,9 +252,9 @@
* @returns UNIX process ID
*/
dbus_pid_t
-_dbus_credentials_get_pid (DBusCredentials *credentials)
+_dbus_credentials_get_unix_pid (DBusCredentials *credentials)
{
- return credentials->pid;
+ return credentials->unix_pid;
}
/**
@@ -313,19 +284,6 @@
}
/**
- * Gets the Linux security label (as used by LSMs) from the credentials,
- * or #NULL if the credentials object doesn't contain a security label.
- *
- * @param credentials the object
- * @returns the security label
- */
-const char *
-_dbus_credentials_get_linux_security_label (DBusCredentials *credentials)
-{
- return credentials->linux_security_label;
-}
-
-/**
* Gets the ADT audit data in the credentials, or #NULL if
* the credentials object doesn't contain ADT audit data.
*
@@ -364,17 +322,13 @@
DBusCredentials *possible_subset)
{
return
- (possible_subset->pid == DBUS_PID_UNSET ||
- possible_subset->pid == credentials->pid) &&
+ (possible_subset->unix_pid == DBUS_PID_UNSET ||
+ possible_subset->unix_pid == credentials->unix_pid) &&
(possible_subset->unix_uid == DBUS_UID_UNSET ||
possible_subset->unix_uid == credentials->unix_uid) &&
(possible_subset->windows_sid == NULL ||
(credentials->windows_sid && strcmp (possible_subset->windows_sid,
credentials->windows_sid) == 0)) &&
- (possible_subset->linux_security_label == NULL ||
- (credentials->linux_security_label != NULL &&
- strcmp (possible_subset->linux_security_label,
- credentials->linux_security_label) == 0)) &&
(possible_subset->adt_audit_data == NULL ||
(credentials->adt_audit_data && memcmp (possible_subset->adt_audit_data,
credentials->adt_audit_data,
@@ -391,10 +345,9 @@
_dbus_credentials_are_empty (DBusCredentials *credentials)
{
return
- credentials->pid == DBUS_PID_UNSET &&
+ credentials->unix_pid == DBUS_PID_UNSET &&
credentials->unix_uid == DBUS_UID_UNSET &&
credentials->windows_sid == NULL &&
- credentials->linux_security_label == NULL &&
credentials->adt_audit_data == NULL;
}
@@ -435,9 +388,6 @@
DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID,
other_credentials) &&
_dbus_credentials_add_credential (credentials,
- DBUS_CREDENTIAL_LINUX_SECURITY_LABEL,
- other_credentials) &&
- _dbus_credentials_add_credential (credentials,
DBUS_CREDENTIAL_WINDOWS_SID,
other_credentials);
}
@@ -460,9 +410,9 @@
DBusCredentials *other_credentials)
{
if (which == DBUS_CREDENTIAL_UNIX_PROCESS_ID &&
- other_credentials->pid != DBUS_PID_UNSET)
+ other_credentials->unix_pid != DBUS_PID_UNSET)
{
- if (!_dbus_credentials_add_pid (credentials, other_credentials->pid))
+ if (!_dbus_credentials_add_unix_pid (credentials, other_credentials->unix_pid))
return FALSE;
}
else if (which == DBUS_CREDENTIAL_UNIX_USER_ID &&
@@ -477,13 +427,6 @@
if (!_dbus_credentials_add_windows_sid (credentials, other_credentials->windows_sid))
return FALSE;
}
- else if (which == DBUS_CREDENTIAL_LINUX_SECURITY_LABEL &&
- other_credentials->linux_security_label != NULL)
- {
- if (!_dbus_credentials_add_linux_security_label (credentials,
- other_credentials->linux_security_label))
- return FALSE;
- }
else if (which == DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID &&
other_credentials->adt_audit_data != NULL)
{
@@ -502,12 +445,10 @@
void
_dbus_credentials_clear (DBusCredentials *credentials)
{
- credentials->pid = DBUS_PID_UNSET;
+ credentials->unix_pid = DBUS_PID_UNSET;
credentials->unix_uid = DBUS_UID_UNSET;
dbus_free (credentials->windows_sid);
credentials->windows_sid = NULL;
- dbus_free (credentials->linux_security_label);
- credentials->linux_security_label = NULL;
dbus_free (credentials->adt_audit_data);
credentials->adt_audit_data = NULL;
credentials->adt_audit_data_size = 0;
@@ -582,9 +523,9 @@
goto oom;
join = TRUE;
}
- if (credentials->pid != DBUS_PID_UNSET)
+ if (credentials->unix_pid != DBUS_PID_UNSET)
{
- if (!_dbus_string_append_printf (string, "%spid=" DBUS_PID_FORMAT, join ? " " : "", credentials->pid))
+ if (!_dbus_string_append_printf (string, "%spid=" DBUS_PID_FORMAT, join ? " " : "", credentials->unix_pid))
goto oom;
join = TRUE;
}
@@ -599,15 +540,6 @@
else
join = FALSE;
- if (credentials->linux_security_label != NULL)
- {
- if (!_dbus_string_append_printf (string, "%slsm='%s'",
- join ? " " : "",
- credentials->linux_security_label))
- goto oom;
- join = TRUE;
- }
-
return TRUE;
oom:
return FALSE;
diff --git a/dbus/dbus-credentials.h b/dbus/dbus-credentials.h
index 6bf6c2b..ef6124f 100644
--- a/dbus/dbus-credentials.h
+++ b/dbus/dbus-credentials.h
@@ -34,50 +34,32 @@
DBUS_CREDENTIAL_UNIX_PROCESS_ID,
DBUS_CREDENTIAL_UNIX_USER_ID,
DBUS_CREDENTIAL_ADT_AUDIT_DATA_ID,
- DBUS_CREDENTIAL_LINUX_SECURITY_LABEL,
DBUS_CREDENTIAL_WINDOWS_SID
} DBusCredentialType;
-DBUS_PRIVATE_EXPORT
DBusCredentials* _dbus_credentials_new_from_current_process (void);
-DBUS_PRIVATE_EXPORT
DBusCredentials* _dbus_credentials_new (void);
-DBUS_PRIVATE_EXPORT
void _dbus_credentials_ref (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
void _dbus_credentials_unref (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_credentials_add_pid (DBusCredentials *credentials,
+dbus_bool_t _dbus_credentials_add_unix_pid (DBusCredentials *credentials,
dbus_pid_t pid);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_add_unix_uid (DBusCredentials *credentials,
dbus_uid_t uid);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_add_windows_sid (DBusCredentials *credentials,
const char *windows_sid);
-dbus_bool_t _dbus_credentials_add_linux_security_label (DBusCredentials *credentials,
- const char *label);
dbus_bool_t _dbus_credentials_add_adt_audit_data (DBusCredentials *credentials,
void *audit_data,
dbus_int32_t size);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_include (DBusCredentials *credentials,
DBusCredentialType type);
-DBUS_PRIVATE_EXPORT
-dbus_pid_t _dbus_credentials_get_pid (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
+dbus_pid_t _dbus_credentials_get_unix_pid (DBusCredentials *credentials);
dbus_uid_t _dbus_credentials_get_unix_uid (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
const char* _dbus_credentials_get_windows_sid (DBusCredentials *credentials);
-const char * _dbus_credentials_get_linux_security_label (DBusCredentials *credentials);
void * _dbus_credentials_get_adt_audit_data (DBusCredentials *credentials);
dbus_int32_t _dbus_credentials_get_adt_audit_data_size (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_are_superset (DBusCredentials *credentials,
DBusCredentials *possible_subset);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_are_empty (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_are_anonymous (DBusCredentials *credentials);
dbus_bool_t _dbus_credentials_add_credentials (DBusCredentials *credentials,
DBusCredentials *other_credentials);
@@ -85,14 +67,10 @@
dbus_bool_t _dbus_credentials_add_credential (DBusCredentials *credentials,
DBusCredentialType which,
DBusCredentials *other_credentials);
-DBUS_PRIVATE_EXPORT
void _dbus_credentials_clear (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
DBusCredentials* _dbus_credentials_copy (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_same_user (DBusCredentials *credentials,
DBusCredentials *other_credentials);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_credentials_to_string_append (DBusCredentials *credentials,
DBusString *string);
diff --git a/dbus/dbus-dataslot.c b/dbus/dbus-dataslot.c
index e37c9dd..0369612 100644
--- a/dbus/dbus-dataslot.c
+++ b/dbus/dbus-dataslot.c
@@ -43,14 +43,13 @@
* @param allocator the allocator to initialize
*/
dbus_bool_t
-_dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator,
- DBusGlobalLock lock)
+_dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator)
{
allocator->allocated_slots = NULL;
allocator->n_allocated_slots = 0;
allocator->n_used_slots = 0;
- allocator->lock = lock;
-
+ allocator->lock_loc = NULL;
+
return TRUE;
}
@@ -62,17 +61,29 @@
* 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;
- if (!_dbus_lock (allocator->lock))
- return FALSE;
+ _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 (*slot_id_p >= 0)
{
@@ -135,7 +146,7 @@
slot, allocator, allocator->n_allocated_slots, allocator->n_used_slots);
out:
- _dbus_unlock (allocator->lock);
+ _dbus_rmutex_unlock (*(allocator->lock_loc));
return slot >= 0;
}
@@ -154,10 +165,8 @@
_dbus_data_slot_allocator_free (DBusDataSlotAllocator *allocator,
dbus_int32_t *slot_id_p)
{
- if (!_dbus_lock (allocator->lock))
- _dbus_assert_not_reached ("we should have initialized global locks "
- "before we allocated this slot");
-
+ _dbus_rmutex_lock (*(allocator->lock_loc));
+
_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);
@@ -166,7 +175,7 @@
if (allocator->allocated_slots[*slot_id_p].refcount > 0)
{
- _dbus_unlock (allocator->lock);
+ _dbus_rmutex_unlock (*(allocator->lock_loc));
return;
}
@@ -181,12 +190,19 @@
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_unlock (allocator->lock);
+ _dbus_rmutex_unlock (*mutex_loc);
+ }
+ else
+ {
+ _dbus_rmutex_unlock (*(allocator->lock_loc));
+ }
}
/**
@@ -231,13 +247,10 @@
* be e.g. realloc()ing allocated_slots. We avoid doing this if asserts
* are disabled, since then the asserts are empty.
*/
- if (!_dbus_lock (allocator->lock))
- _dbus_assert_not_reached ("we should have initialized global locks "
- "before we allocated this slot");
-
+ _dbus_rmutex_lock (*(allocator->lock_loc));
_dbus_assert (slot < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
- _dbus_unlock (allocator->lock);
+ _dbus_rmutex_unlock (*(allocator->lock_loc));
#endif
if (slot >= list->n_slots)
@@ -291,14 +304,11 @@
* be e.g. realloc()ing allocated_slots. We avoid doing this if asserts
* are disabled, since then the asserts are empty.
*/
- if (!_dbus_lock (allocator->lock))
- _dbus_assert_not_reached ("we should have initialized global locks "
- "before we allocated this slot");
-
+ _dbus_rmutex_lock (*(allocator->lock_loc));
_dbus_assert (slot >= 0);
_dbus_assert (slot < allocator->n_allocated_slots);
_dbus_assert (allocator->allocated_slots[slot].slot_id == slot);
- _dbus_unlock (allocator->lock);
+ _dbus_rmutex_unlock (*(allocator->lock_loc));
#endif
if (slot >= list->n_slots)
@@ -348,7 +358,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -374,12 +384,17 @@
int i;
DBusFreeFunction old_free_func;
void *old_data;
-
- if (!_dbus_data_slot_allocator_init (&allocator, _DBUS_LOCK_server_slots))
+ DBusRMutex *mutex;
+
+ if (!_dbus_data_slot_allocator_init (&allocator))
_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;
@@ -390,8 +405,8 @@
* here.
*/
dbus_int32_t tmp = -1;
-
- _dbus_data_slot_allocator_alloc (&allocator, &tmp);
+
+ _dbus_data_slot_allocator_alloc (&allocator, &mutex, &tmp);
if (tmp != i)
_dbus_assert_not_reached ("did not allocate slots in numeric order\n");
@@ -456,7 +471,9 @@
++i;
}
+ _dbus_rmutex_free_at_location (&mutex);
+
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-dataslot.h b/dbus/dbus-dataslot.h
index 1e04fcb..3d9d5ed 100644
--- a/dbus/dbus-dataslot.h
+++ b/dbus/dbus-dataslot.h
@@ -57,11 +57,9 @@
DBusAllocatedSlot *allocated_slots; /**< Allocated slots */
int n_allocated_slots; /**< number of slots malloc'd */
int n_used_slots; /**< number of slots used */
- DBusGlobalLock lock; /**< index of thread lock */
+ DBusRMutex **lock_loc; /**< location 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.
@@ -72,9 +70,9 @@
int n_slots; /**< Slots we have storage for in data_slots */
};
-dbus_bool_t _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator,
- DBusGlobalLock lock);
+dbus_bool_t _dbus_data_slot_allocator_init (DBusDataSlotAllocator *allocator);
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 5a305ca..db3305b 100644
--- a/dbus/dbus-errors.c
+++ b/dbus/dbus-errors.c
@@ -189,10 +189,10 @@
{
DBusRealError *real;
- _DBUS_STATIC_ASSERT (sizeof (DBusError) == sizeof (DBusRealError));
-
_dbus_return_if_fail (error != NULL);
+ _dbus_assert (sizeof (DBusError) == sizeof (DBusRealError));
+
real = (DBusRealError *)error;
real->name = NULL;
@@ -235,7 +235,7 @@
* 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!!!)
*/
@@ -356,6 +356,8 @@
const char *format,
...)
{
+ DBusRealError *real;
+ DBusString str;
va_list args;
if (error == NULL)
@@ -364,26 +366,7 @@
/* it's a bug to pile up errors */
_dbus_return_if_error_is_set (error);
_dbus_return_if_fail (name != NULL);
-
- va_start (args, format);
- _dbus_set_error_valist (error, name, format, args);
- va_end (args);
-}
-
-void
-_dbus_set_error_valist (DBusError *error,
- const char *name,
- const char *format,
- va_list args)
-{
- DBusRealError *real;
- DBusString str;
-
- _dbus_assert (name != NULL);
-
- if (error == NULL)
- return;
-
+
_dbus_assert (error->name == NULL);
_dbus_assert (error->message == NULL);
@@ -396,16 +379,20 @@
message_from_error (name)))
{
_dbus_string_free (&str);
+ va_end (args);
goto nomem;
}
}
else
{
+ va_start (args, format);
if (!_dbus_string_append_printf_valist (&str, format, args))
{
_dbus_string_free (&str);
+ va_end (args);
goto nomem;
}
+ va_end (args);
}
real = (DBusRealError *)error;
diff --git a/dbus/dbus-file-unix.c b/dbus/dbus-file-unix.c
index 830d3fe..1975933 100644
--- a/dbus/dbus-file-unix.c
+++ b/dbus/dbus-file-unix.c
@@ -202,9 +202,9 @@
}
#define N_TMP_FILENAME_RANDOM_BYTES 8
- if (!_dbus_generate_random_ascii (&tmp_filename, N_TMP_FILENAME_RANDOM_BYTES,
- error))
+ if (!_dbus_generate_random_ascii (&tmp_filename, N_TMP_FILENAME_RANDOM_BYTES))
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_string_free (&tmp_filename);
return FALSE;
}
diff --git a/dbus/dbus-file-win.c b/dbus/dbus-file-win.c
index 0dbe11e..06a8ea1 100644
--- a/dbus/dbus-file-win.c
+++ b/dbus/dbus-file-win.c
@@ -251,9 +251,9 @@
}
#define N_TMP_FILENAME_RANDOM_BYTES 8
- if (!_dbus_generate_random_ascii (&tmp_filename, N_TMP_FILENAME_RANDOM_BYTES,
- error))
+ if (!_dbus_generate_random_ascii (&tmp_filename, N_TMP_FILENAME_RANDOM_BYTES))
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_string_free (&tmp_filename);
return FALSE;
}
diff --git a/dbus/dbus-file.h b/dbus/dbus-file.h
index 4fa30cd..24837f4 100644
--- a/dbus/dbus-file.h
+++ b/dbus/dbus-file.h
@@ -40,7 +40,6 @@
* File interface
*/
dbus_bool_t _dbus_file_exists (const char *file);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_file_get_contents (DBusString *str,
const DBusString *filename,
DBusError *error);
@@ -54,7 +53,6 @@
dbus_bool_t _dbus_create_file_exclusively (const DBusString *filename,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_delete_file (const DBusString *filename,
DBusError *error);
diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c
index 8f7d04b..c4c6f93 100644
--- a/dbus/dbus-hash.c
+++ b/dbus/dbus-hash.c
@@ -519,7 +519,7 @@
{
DBusRealHashIter *real;
- _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+ _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
@@ -544,7 +544,7 @@
{
DBusRealHashIter *real;
- _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+ _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
@@ -746,7 +746,7 @@
DBusHashEntry *entry;
DBusHashEntry **bucket;
- _DBUS_STATIC_ASSERT (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
+ _dbus_assert (sizeof (DBusHashIter) == sizeof (DBusRealHashIter));
real = (DBusRealHashIter*) iter;
@@ -1401,7 +1401,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1828,4 +1828,4 @@
return ret;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-hash.h b/dbus/dbus-hash.h
index 2898f51..5aa183c 100644
--- a/dbus/dbus-hash.h
+++ b/dbus/dbus-hash.h
@@ -71,66 +71,47 @@
DBUS_HASH_UINTPTR /**< Hash keys are integer capable to hold a pointer. */
} DBusHashType;
-DBUS_PRIVATE_EXPORT
DBusHashTable* _dbus_hash_table_new (DBusHashType type,
DBusFreeFunction key_free_function,
DBusFreeFunction value_free_function);
DBusHashTable* _dbus_hash_table_ref (DBusHashTable *table);
-DBUS_PRIVATE_EXPORT
void _dbus_hash_table_unref (DBusHashTable *table);
void _dbus_hash_table_remove_all (DBusHashTable *table);
-DBUS_PRIVATE_EXPORT
void _dbus_hash_iter_init (DBusHashTable *table,
DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_iter_next (DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
void _dbus_hash_iter_remove_entry (DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
void* _dbus_hash_iter_get_value (DBusHashIter *iter);
void _dbus_hash_iter_set_value (DBusHashIter *iter,
void *value);
-DBUS_PRIVATE_EXPORT
int _dbus_hash_iter_get_int_key (DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
const char* _dbus_hash_iter_get_string_key (DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
uintptr_t _dbus_hash_iter_get_uintptr_key (DBusHashIter *iter);
dbus_bool_t _dbus_hash_iter_lookup (DBusHashTable *table,
void *key,
dbus_bool_t create_if_not_found,
DBusHashIter *iter);
-DBUS_PRIVATE_EXPORT
void* _dbus_hash_table_lookup_string (DBusHashTable *table,
const char *key);
-DBUS_PRIVATE_EXPORT
void* _dbus_hash_table_lookup_int (DBusHashTable *table,
int key);
-DBUS_PRIVATE_EXPORT
void* _dbus_hash_table_lookup_uintptr (DBusHashTable *table,
uintptr_t key);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_remove_string (DBusHashTable *table,
const char *key);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_remove_int (DBusHashTable *table,
int key);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_remove_uintptr (DBusHashTable *table,
uintptr_t key);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_insert_string (DBusHashTable *table,
char *key,
void *value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_insert_int (DBusHashTable *table,
int key,
void *value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_table_insert_uintptr (DBusHashTable *table,
uintptr_t key,
void *value);
-DBUS_PRIVATE_EXPORT
int _dbus_hash_table_get_n_entries (DBusHashTable *table);
/* Preallocation */
@@ -138,70 +119,14 @@
/** A preallocated hash entry */
typedef struct DBusPreallocatedHash DBusPreallocatedHash;
-DBUS_PRIVATE_EXPORT
DBusPreallocatedHash *_dbus_hash_table_preallocate_entry (DBusHashTable *table);
-DBUS_PRIVATE_EXPORT
void _dbus_hash_table_free_preallocated_entry (DBusHashTable *table,
DBusPreallocatedHash *preallocated);
-DBUS_PRIVATE_EXPORT
void _dbus_hash_table_insert_string_preallocated (DBusHashTable *table,
DBusPreallocatedHash *preallocated,
char *key,
void *value);
-#ifdef DBUS_WIN
-# define DBUS_HASH_POLLABLE DBUS_HASH_UINTPTR
-#else
-# define DBUS_HASH_POLLABLE DBUS_HASH_INT
-#endif
-
-static inline DBusPollable
-_dbus_hash_iter_get_pollable_key (DBusHashIter *iter)
-{
-#ifdef DBUS_WIN
- DBusSocket s;
-
- s.sock = _dbus_hash_iter_get_uintptr_key (iter);
- return s;
-#else
- return _dbus_hash_iter_get_int_key (iter);
-#endif
-}
-
-static inline void *
-_dbus_hash_table_lookup_pollable (DBusHashTable *table,
- DBusPollable key)
-{
-#ifdef DBUS_WIN
- return _dbus_hash_table_lookup_uintptr (table, key.sock);
-#else
- return _dbus_hash_table_lookup_int (table, key);
-#endif
-}
-
-static inline dbus_bool_t
-_dbus_hash_table_remove_pollable (DBusHashTable *table,
- DBusPollable key)
-{
-#ifdef DBUS_WIN
- return _dbus_hash_table_remove_uintptr (table, key.sock);
-#else
- return _dbus_hash_table_remove_int (table, key);
-#endif
-}
-
-static inline dbus_bool_t
-_dbus_hash_table_insert_pollable (DBusHashTable *table,
- DBusPollable key,
- void *value)
-{
-#ifdef DBUS_WIN
- return _dbus_hash_table_insert_uintptr (table, key.sock, value);
-#else
- return _dbus_hash_table_insert_int (table, key, value);
-#endif
-}
-
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-init-win.cpp b/dbus/dbus-init-win.cpp
deleted file mode 100644
index 687f248..0000000
--- a/dbus/dbus-init-win.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 d7ef089..1ec4980 100644
--- a/dbus/dbus-internals.c
+++ b/dbus/dbus-internals.c
@@ -36,6 +36,11 @@
#include <mbstring.h>
#endif
+#ifdef DBUS_ANDROID_LOG
+#define LOG_TAG "libdbus"
+#include <cutils/log.h>
+#endif /* DBUS_ANDROID_LOG */
+
/**
* @defgroup DBusInternals D-Bus secret internal implementation details
* @brief Documentation useful when developing or debugging D-Bus itself.
@@ -163,11 +168,26 @@
*/
/**
+ * @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, initializing it first if necessary.
- *
- * @returns #FALSE if not enough memory
+ * Locks a global lock
*/
/**
@@ -236,7 +256,11 @@
init_warnings ();
va_start (args, format);
+#ifdef DBUS_ANDROID_LOG
+ LOG_PRI_VA(ANDROID_LOG_WARN, LOG_TAG, format, args);
+#else
vfprintf (stderr, format, args);
+#endif /* DBUS_ANDROID_LOG */
va_end (args);
if (fatal_warnings)
@@ -266,7 +290,11 @@
fprintf (stderr, "process %lu: ", _dbus_pid_for_log ());
va_start (args, format);
+#ifdef DBUS_ANDROID_LOG
+ LOG_PRI_VA(ANDROID_LOG_ERROR, LOG_TAG, format, args);
+#else
vfprintf (stderr, format, args);
+#endif /* DBUS_ANDROID_LOG */
va_end (args);
if (fatal_warnings_on_check_failed)
@@ -296,8 +324,14 @@
{
if (!verbose_initted)
{
- const char *p = _dbus_getenv ("DBUS_VERBOSE");
+#ifdef DBUS_ANDROID_LOG
+ /* Don't bother checking environment variable - just print the
+ verbose logs (can still be disabled with DBUS_ENABLE_VERBOSE_MODE) */
+ verbose = TRUE;
+#else
+ const char *p = _dbus_getenv ("DBUS_VERBOSE");
verbose = p != NULL && *p == '1';
+#endif
verbose_initted = TRUE;
#ifdef DBUS_USE_OUTPUT_DEBUG_STRING
{
@@ -332,22 +366,25 @@
*/
static char *_dbus_file_path_extract_elements_from_tail(const char *file,int level)
{
- int prefix = 0;
- char *p = (char *)file + strlen(file);
- int i = 0;
+ static int prefix = -1;
- for (;p >= file;p--)
+ if (prefix == -1)
{
- if (DBUS_IS_DIR_SEPARATOR(*p))
+ char *p = (char *)file + strlen(file);
+ int i = 0;
+ prefix = 0;
+ for (;p >= file;p--)
{
- if (++i >= level)
+ if (DBUS_IS_DIR_SEPARATOR(*p))
{
- prefix = p-file+1;
- break;
- }
- }
+ if (++i >= level)
+ {
+ prefix = p-file+1;
+ break;
+ }
+ }
+ }
}
-
return (char *)file+prefix;
}
@@ -363,16 +400,6 @@
return verbose;
}
-void _dbus_set_verbose (dbus_bool_t state)
-{
- verbose = state;
-}
-
-dbus_bool_t _dbus_get_verbose (void)
-{
- return verbose;
-}
-
/**
* Prints a warning message to stderr
* if the user has enabled verbose mode.
@@ -438,7 +465,11 @@
fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function);
#endif
+#ifdef DBUS_ANDROID_LOG
+ LOG_PRI_VA(ANDROID_LOG_DEBUG, LOG_TAG, format, args);
+#else
vfprintf (stderr, format, args);
+#endif /* DBUS_ANDROID_LOG */
va_end (args);
fflush (stderr);
@@ -509,7 +540,7 @@
{
VALGRIND_PRINTF_BACKTRACE ("%s %p ref stolen (%s)",
obj_name, obj, why);
- _dbus_verbose ("%s %p ref stolen (%s)\n",
+ _dbus_verbose ("%s %p ref stolen (%s)",
obj_name, obj, why);
}
else
@@ -517,7 +548,7 @@
VALGRIND_PRINTF_BACKTRACE ("%s %p %d -> %d refs (%s)",
obj_name, obj,
old_refcount, new_refcount, why);
- _dbus_verbose ("%s %p %d -> %d refs (%s)\n",
+ _dbus_verbose ("%s %p %d -> %d refs (%s)",
obj_name, obj, old_refcount, new_refcount, why);
}
}
@@ -646,18 +677,12 @@
* there's some text about it in the spec that should also change.
*
* @param uuid the uuid to initialize
- * @param error location to store reason for failure
- * @returns #TRUE on success
*/
-dbus_bool_t
-_dbus_generate_uuid (DBusGUID *uuid,
- DBusError *error)
+void
+_dbus_generate_uuid (DBusGUID *uuid)
{
- DBusError rand_error;
long now;
- dbus_error_init (&rand_error);
-
/* don't use monotonic time because the UUID may be saved to disk, e.g.
* it may persist across reboots
*/
@@ -665,17 +690,7 @@
uuid->as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
- if (!_dbus_generate_random_bytes_buffer (uuid->as_bytes,
- DBUS_UUID_LENGTH_BYTES - 4,
- &rand_error))
- {
- dbus_set_error (error, rand_error.name,
- "Failed to generate UUID: %s", rand_error.message);
- dbus_error_free (&rand_error);
- return FALSE;
- }
-
- return TRUE;
+ _dbus_generate_random_bytes_buffer (uuid->as_bytes, DBUS_UUID_LENGTH_BYTES - 4);
}
/**
@@ -771,18 +786,10 @@
return FALSE;
}
-/**
- * Write the give UUID to a file.
- *
- * @param filename the file to write
- * @param uuid the UUID to save
- * @param error used to raise an error
- * @returns #FALSE on error
- */
-dbus_bool_t
-_dbus_write_uuid_file (const DBusString *filename,
- const DBusGUID *uuid,
- DBusError *error)
+static dbus_bool_t
+_dbus_create_uuid_file_exclusively (const DBusString *filename,
+ DBusGUID *uuid,
+ DBusError *error)
{
DBusString encoded;
@@ -791,6 +798,8 @@
_DBUS_SET_OOM (error);
return FALSE;
}
+
+ _dbus_generate_uuid (uuid);
if (!_dbus_uuid_encode (uuid, &encoded))
{
@@ -857,15 +866,11 @@
else
{
dbus_error_free (&read_error);
-
- if (!_dbus_generate_uuid (uuid, error))
- return FALSE;
-
- return _dbus_write_uuid_file (filename, uuid, error);
+ return _dbus_create_uuid_file_exclusively (filename, uuid, error);
}
}
-/* Protected by _DBUS_LOCK (machine_uuid) */
+_DBUS_DEFINE_GLOBAL_LOCK (machine_uuid);
static int machine_uuid_initialized_generation = 0;
static DBusGUID machine_uuid;
@@ -877,52 +882,38 @@
* machine is reconfigured or its hardware is modified.
*
* @param uuid_str string to append hex-encoded machine uuid to
- * @param error location to store reason for failure
- * @returns #TRUE if successful
+ * @returns #FALSE if no memory
*/
dbus_bool_t
-_dbus_get_local_machine_uuid_encoded (DBusString *uuid_str,
- DBusError *error)
+_dbus_get_local_machine_uuid_encoded (DBusString *uuid_str)
{
- dbus_bool_t ok = TRUE;
+ dbus_bool_t ok;
- if (!_DBUS_LOCK (machine_uuid))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
-
+ _DBUS_LOCK (machine_uuid);
if (machine_uuid_initialized_generation != _dbus_current_generation)
{
- DBusError local_error = DBUS_ERROR_INIT;
+ DBusError error = DBUS_ERROR_INIT;
if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE,
- &local_error))
+ &error))
{
-#ifndef DBUS_ENABLE_EMBEDDED_TESTS
+#ifndef DBUS_BUILD_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.
*/
_dbus_warn_check_failed ("D-Bus library appears to be incorrectly set up; failed to read machine uuid: %s\n"
"See the manual page for dbus-uuidgen to correct this issue.\n",
- local_error.message);
+ error.message);
#endif
- dbus_error_free (&local_error);
+ dbus_error_free (&error);
- ok = _dbus_generate_uuid (&machine_uuid, error);
+ _dbus_generate_uuid (&machine_uuid);
}
}
- if (ok)
- {
- if (!_dbus_uuid_encode (&machine_uuid, uuid_str))
- {
- ok = FALSE;
- _DBUS_SET_OOM (error);
- }
- }
+ ok = _dbus_uuid_encode (&machine_uuid, uuid_str);
_DBUS_UNLOCK (machine_uuid);
@@ -985,7 +976,7 @@
}
#endif /* DBUS_DISABLE_ASSERT */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
run_failing_each_malloc (int n_mallocs,
const char *description,
@@ -1066,12 +1057,6 @@
max_failures_to_try = 4;
}
- if (max_failures_to_try < 1)
- {
- _dbus_verbose ("not testing OOM handling\n");
- return TRUE;
- }
-
i = setting ? max_failures_to_try - 1 : 1;
while (i < max_failures_to_try)
{
@@ -1086,6 +1071,6 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
/** @} */
diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h
index 5e6efd8..8036a2b 100644
--- a/dbus/dbus-internals.h
+++ b/dbus/dbus-internals.h
@@ -35,11 +35,13 @@
DBUS_BEGIN_DECLS
-DBUS_PRIVATE_EXPORT
+#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);
-DBUS_PRIVATE_EXPORT
void _dbus_warn_check_failed (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
@@ -91,24 +93,16 @@
#endif
#ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
-DBUS_PRIVATE_EXPORT
void _dbus_verbose_real (const char *file, const int line, const char *function,
const char *format,...) _DBUS_GNUC_PRINTF (4, 5);
# define _dbus_verbose(fmt,...) _dbus_verbose_real( __FILE__,__LINE__,__FUNCTION__,fmt, ## __VA_ARGS__)
#else
-DBUS_PRIVATE_EXPORT
void _dbus_verbose_real (const char *format,
...) _DBUS_GNUC_PRINTF (1, 2);
# define _dbus_verbose _dbus_verbose_real
#endif
-DBUS_PRIVATE_EXPORT
void _dbus_verbose_reset_real (void);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_is_verbose_real (void);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_get_verbose (void);
-DBUS_PRIVATE_EXPORT
-void _dbus_set_verbose (dbus_bool_t state);
# define _dbus_verbose_reset _dbus_verbose_reset_real
# define _dbus_is_verbose _dbus_is_verbose_real
@@ -124,7 +118,6 @@
# define _dbus_is_verbose() FALSE
#endif /* !DBUS_ENABLE_VERBOSE_MODE */
-DBUS_PRIVATE_EXPORT
void _dbus_trace_ref (const char *obj_name,
void *obj,
int old_refcount,
@@ -133,13 +126,11 @@
const char *env_var,
int *enabled);
-DBUS_PRIVATE_EXPORT
const char* _dbus_strerror (int error_number);
#ifdef DBUS_DISABLE_ASSERT
#define _dbus_assert(condition) do { } while (0)
#else
-DBUS_PRIVATE_EXPORT
void _dbus_real_assert (dbus_bool_t condition,
const char *condition_text,
const char *file,
@@ -152,7 +143,6 @@
#ifdef DBUS_DISABLE_ASSERT
#define _dbus_assert_not_reached(explanation) do { } while (0)
#else
-DBUS_PRIVATE_EXPORT
void _dbus_real_assert_not_reached (const char *explanation,
const char *file,
int line) _DBUS_GNUC_NORETURN;
@@ -165,7 +155,6 @@
#define _dbus_return_val_if_fail(condition, val)
#else
-DBUS_PRIVATE_EXPORT
extern const char *_dbus_return_if_fail_warning_format;
#define _dbus_return_if_fail(condition) do { \
@@ -196,9 +185,6 @@
#define _DBUS_STRUCT_OFFSET(struct_type, member) \
((intptr_t) ((unsigned char*) &((struct_type*) 0)->member))
-#define _DBUS_ALIGNOF(type) \
- (_DBUS_STRUCT_OFFSET (struct { char _1; type _2; }, _2))
-
#ifdef DBUS_DISABLE_CHECKS
/* this is an assert and not an error, but in the typical --disable-checks case (you're trying
* to really minimize code size), disabling these assertions makes sense.
@@ -206,20 +192,8 @@
#define _DBUS_ASSERT_ERROR_IS_SET(error) do { } while (0)
#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) do { } while (0)
#else
-static inline void
-_dbus_assert_error_is_set (const DBusError *error)
-{
- _dbus_assert (error == NULL || dbus_error_is_set (error));
-}
-
-static inline void
-_dbus_assert_error_is_clear (const DBusError *error)
-{
- _dbus_assert (error == NULL || !dbus_error_is_set (error));
-}
-
-#define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert_error_is_set(error)
-#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert_error_is_clear(error)
+#define _DBUS_ASSERT_ERROR_IS_SET(error) _dbus_assert ((error) == NULL || dbus_error_is_set ((error)))
+#define _DBUS_ASSERT_ERROR_IS_CLEAR(error) _dbus_assert ((error) == NULL || !dbus_error_is_set ((error)))
#endif
#define _dbus_return_if_error_is_set(error) _dbus_return_if_fail ((error) == NULL || !dbus_error_is_set ((error)))
@@ -243,11 +217,9 @@
((void*)_DBUS_ALIGN_VALUE(this, boundary))
-DBUS_PRIVATE_EXPORT
char* _dbus_strdup (const char *str);
void* _dbus_memdup (const void *mem,
size_t n_bytes);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_array_contains (const char **array,
const char *str);
char** _dbus_dup_string_array (const char **array);
@@ -262,8 +234,10 @@
#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)
@@ -283,24 +257,20 @@
typedef void (* DBusForeachFunction) (void *element,
void *data);
+dbus_bool_t _dbus_set_fd_nonblocking (int fd,
+ DBusError *error);
+
void _dbus_verbose_bytes (const unsigned char *data,
int len,
int offset);
-DBUS_PRIVATE_EXPORT
void _dbus_verbose_bytes_of_string (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
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)
-DBUS_PRIVATE_EXPORT
-void _dbus_set_error_valist (DBusError *error,
- const char *name,
- const char *format,
- va_list args) _DBUS_GNUC_PRINTF (3, 0);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/* Memory debugging */
void _dbus_set_fail_alloc_counter (int until_next_fail);
int _dbus_get_fail_alloc_counter (void);
@@ -308,11 +278,9 @@
int _dbus_get_fail_alloc_failures (void);
dbus_bool_t _dbus_decrement_fail_alloc_counter (void);
dbus_bool_t _dbus_disable_mem_pools (void);
-DBUS_PRIVATE_EXPORT
int _dbus_get_malloc_blocks_outstanding (void);
typedef dbus_bool_t (* DBusTestMemoryFunction) (void *data);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_test_oom_handling (const char *description,
DBusTestMemoryFunction func,
void *data);
@@ -326,49 +294,46 @@
#define _dbus_decrement_fail_alloc_counter() (FALSE)
#define _dbus_disable_mem_pools() (FALSE)
#define _dbus_get_malloc_blocks_outstanding (0)
-#endif /* !DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* !DBUS_BUILD_TESTS */
typedef void (* DBusShutdownFunction) (void *data);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
- void *data);
-dbus_bool_t _dbus_register_shutdown_func_unlocked (DBusShutdownFunction function,
- void *data);
+dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction function,
+ void *data);
extern int _dbus_current_generation;
-/* 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,
+/* 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)
- _DBUS_N_GLOBAL_LOCKS
-} DBusGlobalLock;
+/* 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);
-dbus_bool_t _dbus_lock (DBusGlobalLock lock) _DBUS_GNUC_WARN_UNUSED_RESULT;
-void _dbus_unlock (DBusGlobalLock lock);
+#if !DBUS_USE_SYNC
+_DBUS_DECLARE_GLOBAL_LOCK (atomic);
+#define _DBUS_N_GLOBAL_LOCKS (15)
+#else
+#define _DBUS_N_GLOBAL_LOCKS (14)
+#endif
-#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_PRIVATE_EXPORT
dbus_bool_t _dbus_threads_init_debug (void);
dbus_bool_t _dbus_address_append_escaped (DBusString *escaped,
@@ -393,10 +358,7 @@
char as_bytes[DBUS_UUID_LENGTH_BYTES]; /**< guid as 16 single-byte values */
};
-DBUS_PRIVATE_EXPORT _DBUS_GNUC_WARN_UNUSED_RESULT
-dbus_bool_t _dbus_generate_uuid (DBusGUID *uuid,
- DBusError *error);
-DBUS_PRIVATE_EXPORT
+void _dbus_generate_uuid (DBusGUID *uuid);
dbus_bool_t _dbus_uuid_encode (const DBusGUID *uuid,
DBusString *encoded);
dbus_bool_t _dbus_read_uuid_file (const DBusString *filename,
@@ -404,18 +366,13 @@
dbus_bool_t create_if_not_found,
DBusError *error);
-dbus_bool_t _dbus_write_uuid_file (const DBusString *filename,
- const DBusGUID *uuid,
- DBusError *error);
-
-dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str,
- DBusError *error);
+dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str);
#define _DBUS_PASTE2(a, b) a ## b
#define _DBUS_PASTE(a, b) _DBUS_PASTE2 (a, b)
#define _DBUS_STATIC_ASSERT(expr) \
typedef struct { char _assertion[(expr) ? 1 : -1]; } \
- _DBUS_PASTE (_DBUS_STATIC_ASSERT_, __LINE__) _DBUS_GNUC_UNUSED
+ _DBUS_PASTE (_DBUS_STATIC_ASSERT_, __LINE__)
DBUS_END_DECLS
diff --git a/dbus/dbus-keyring.c b/dbus/dbus-keyring.c
index bb7e4f8..3b9ce31 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#define MAX_KEYS_IN_FILE 10
#else
#define MAX_KEYS_IN_FILE 256
@@ -304,8 +304,11 @@
/* Generate an integer ID and then the actual key. */
retry:
- if (!_dbus_generate_random_bytes (&bytes, 4, error))
- goto out;
+ if (!_dbus_generate_random_bytes (&bytes, 4))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto out;
+ }
s = (const unsigned char*) _dbus_string_get_const_data (&bytes);
@@ -326,8 +329,9 @@
#define KEY_LENGTH_BYTES 24
_dbus_string_set_length (&bytes, 0);
- if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES, error))
+ if (!_dbus_generate_random_bytes (&bytes, KEY_LENGTH_BYTES))
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto out;
}
@@ -693,10 +697,10 @@
/**
* Creates a new keyring that lives in the ~/.dbus-keyrings directory
- * of the user represented by @p credentials. If the @p credentials are
- * #NULL or empty, uses those of the current process.
+ * of the given user credentials. If the credentials are #NULL or
+ * empty, uses those of the current process.
*
- * @param credentials a set of credentials representing a user or #NULL
+ * @param username username to get keyring for, or #NULL
* @param context which keyring to get
* @param error return location for errors
* @returns the keyring or #NULL on error
@@ -1019,7 +1023,7 @@
/** @} */ /* end of exposed API */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1152,5 +1156,5 @@
return FALSE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-list.c b/dbus/dbus-list.c
index c4c1856..7e11cc8 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,8 +56,7 @@
{
DBusList *link;
- if (!_DBUS_LOCK (list))
- return FALSE;
+ _DBUS_LOCK (list);
if (list_pool == NULL)
{
@@ -94,10 +93,7 @@
static void
free_link (DBusList *link)
{
- if (!_DBUS_LOCK (list))
- _dbus_assert_not_reached ("we should have initialized global locks "
- "before we allocated a linked-list link");
-
+ _DBUS_LOCK (list);
if (_dbus_mem_pool_dealloc (list_pool, link))
{
_dbus_mem_pool_free (list_pool);
@@ -156,14 +152,7 @@
dbus_uint32_t *in_free_list_p,
dbus_uint32_t *allocated_p)
{
- if (!_DBUS_LOCK (list))
- {
- *in_use_p = 0;
- *in_free_list_p = 0;
- *allocated_p = 0;
- return;
- }
-
+ _DBUS_LOCK (list);
_dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
_DBUS_UNLOCK (list);
}
@@ -788,7 +777,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
diff --git a/dbus/dbus-list.h b/dbus/dbus-list.h
index 9350a0d..910d738 100644
--- a/dbus/dbus-list.h
+++ b/dbus/dbus-list.h
@@ -37,78 +37,52 @@
DBusList *next; /**< Next list node. */
void *data; /**< Data stored at this element. */
};
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_append (DBusList **list,
void *data);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_prepend (DBusList **list,
void *data);
dbus_bool_t _dbus_list_insert_before (DBusList **list,
DBusList *before_this_link,
void *data);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_insert_after (DBusList **list,
DBusList *after_this_link,
void *data);
-DBUS_PRIVATE_EXPORT
void _dbus_list_insert_before_link (DBusList **list,
DBusList *before_this_link,
DBusList *link);
-DBUS_PRIVATE_EXPORT
void _dbus_list_insert_after_link (DBusList **list,
DBusList *after_this_link,
DBusList *link);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_remove (DBusList **list,
void *data);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_remove_last (DBusList **list,
void *data);
-DBUS_PRIVATE_EXPORT
void _dbus_list_remove_link (DBusList **list,
DBusList *link);
-DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_find_last (DBusList **list,
void *data);
-DBUS_PRIVATE_EXPORT
void _dbus_list_clear (DBusList **list);
-DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_first_link (DBusList **list);
-DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_last_link (DBusList **list);
-DBUS_PRIVATE_EXPORT
void* _dbus_list_get_last (DBusList **list);
-DBUS_PRIVATE_EXPORT
void* _dbus_list_get_first (DBusList **list);
-DBUS_PRIVATE_EXPORT
void* _dbus_list_pop_first (DBusList **list);
-DBUS_PRIVATE_EXPORT
void* _dbus_list_pop_last (DBusList **list);
-DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_pop_first_link (DBusList **list);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_copy (DBusList **list,
DBusList **dest);
-DBUS_PRIVATE_EXPORT
int _dbus_list_get_length (DBusList **list);
-DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_alloc_link (void *data);
-DBUS_PRIVATE_EXPORT
void _dbus_list_free_link (DBusList *link);
-DBUS_PRIVATE_EXPORT
void _dbus_list_unlink (DBusList **list,
DBusList *link);
-DBUS_PRIVATE_EXPORT
void _dbus_list_append_link (DBusList **list,
DBusList *link);
-DBUS_PRIVATE_EXPORT
void _dbus_list_prepend_link (DBusList **list,
DBusList *link);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_length_is_one (DBusList **list);
-DBUS_PRIVATE_EXPORT
void _dbus_list_foreach (DBusList **list,
DBusForeachFunction function,
void *data);
@@ -117,7 +91,6 @@
#define _dbus_list_get_prev_link(list, link) ((link) == *(list) ? NULL : (link)->prev)
/* if DBUS_ENABLE_STATS */
-DBUS_PRIVATE_EXPORT
void _dbus_list_get_stats (dbus_uint32_t *in_use_p,
dbus_uint32_t *in_free_list_p,
dbus_uint32_t *allocated_p);
diff --git a/dbus/dbus-macros.h b/dbus/dbus-macros.h
index a82d911..dcd3eeb 100644
--- a/dbus/dbus-macros.h
+++ b/dbus/dbus-macros.h
@@ -69,12 +69,9 @@
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
#define _DBUS_GNUC_NORETURN \
__attribute__((__noreturn__))
-#define _DBUS_GNUC_UNUSED \
- __attribute__((__unused__))
#else /* !__GNUC__ */
#define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
#define _DBUS_GNUC_NORETURN
-#define _DBUS_GNUC_UNUSED
#endif /* !__GNUC__ */
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
@@ -91,21 +88,13 @@
#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. */
/**
@@ -182,9 +171,7 @@
* platforms other than Windows.
*/
-#if defined(DBUS_EXPORT)
- /* value forced by compiler command line, don't redefine */
-#elif defined(_WIN32)
+#if defined(_WIN32)
# if defined(DBUS_STATIC_BUILD)
# define DBUS_EXPORT
# elif defined(dbus_1_EXPORTS)
@@ -192,28 +179,10 @@
# else
# define DBUS_EXPORT __declspec(dllimport)
# endif
-#elif defined(__GNUC__) && __GNUC__ >= 4
-# define DBUS_EXPORT __attribute__ ((__visibility__ ("default")))
#else
#define DBUS_EXPORT
#endif
-#if defined(DBUS_PRIVATE_EXPORT)
- /* value forced by compiler command line, don't redefine */
-#elif defined(_WIN32)
-# if defined(DBUS_STATIC_BUILD)
-# define DBUS_PRIVATE_EXPORT /* no decoration */
-# elif defined(dbus_1_EXPORTS)
-# define DBUS_PRIVATE_EXPORT __declspec(dllexport)
-# else
-# define DBUS_PRIVATE_EXPORT __declspec(dllimport)
-# endif
-#elif defined(__GNUC__) && __GNUC__ >= 4
-# define DBUS_PRIVATE_EXPORT __attribute__ ((__visibility__ ("default")))
-#else
-# define DBUS_PRIVATE_EXPORT /* no decoration */
-#endif
-
/** @} */
#endif /* DBUS_MACROS_H */
diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c
index f6736fe..cef676a 100644
--- a/dbus/dbus-mainloop.c
+++ b/dbus/dbus-mainloop.c
@@ -34,10 +34,31 @@
#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;
- /** DBusPollable => dbus_malloc'd DBusList ** of references to DBusWatch */
+ /** fd => dbus_malloc'd DBusList ** of references to DBusWatch */
DBusHashTable *watches;
DBusSocketSet *socket_set;
DBusList *timeouts;
@@ -54,8 +75,8 @@
typedef struct
{
DBusTimeout *timeout;
- long last_tv_sec;
- long last_tv_usec;
+ unsigned long last_tv_sec;
+ unsigned long last_tv_usec;
} TimeoutCallback;
#define TIMEOUT_CALLBACK(callback) ((TimeoutCallback*)callback)
@@ -112,7 +133,7 @@
if (loop == NULL)
return NULL;
- loop->watches = _dbus_hash_table_new (DBUS_HASH_POLLABLE, NULL,
+ loop->watches = _dbus_hash_table_new (DBUS_HASH_INT, NULL,
free_watch_table_entry);
loop->socket_set = _dbus_socket_set_new (0);
@@ -168,12 +189,12 @@
}
static DBusList **
-ensure_watch_table_entry (DBusLoop *loop,
- DBusPollable fd)
+ensure_watch_table_entry (DBusLoop *loop,
+ int fd)
{
DBusList **watches;
- watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_int (loop->watches, fd);
if (watches == NULL)
{
@@ -182,7 +203,7 @@
if (watches == NULL)
return watches;
- if (!_dbus_hash_table_insert_pollable (loop->watches, fd, watches))
+ if (!_dbus_hash_table_insert_int (loop->watches, fd, watches))
{
dbus_free (watches);
watches = NULL;
@@ -193,15 +214,14 @@
}
static void
-cull_watches_for_invalid_fd (DBusLoop *loop,
- DBusPollable fd)
+cull_watches_for_invalid_fd (DBusLoop *loop,
+ int fd)
{
DBusList *link;
DBusList **watches;
- _dbus_warn ("invalid request, socket fd %" DBUS_POLLABLE_FORMAT " not open\n",
- _dbus_pollable_printable (fd));
- watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
+ _dbus_warn ("invalid request, socket fd %d not open\n", fd);
+ watches = _dbus_hash_table_lookup_int (loop->watches, fd);
if (watches != NULL)
{
@@ -211,13 +231,13 @@
_dbus_watch_invalidate (link->data);
}
- _dbus_hash_table_remove_pollable (loop->watches, fd);
+ _dbus_hash_table_remove_int (loop->watches, fd);
}
static dbus_bool_t
-gc_watch_table_entry (DBusLoop *loop,
- DBusList **watches,
- DBusPollable fd)
+gc_watch_table_entry (DBusLoop *loop,
+ DBusList **watches,
+ int fd)
{
/* If watches is already NULL we have nothing to do */
if (watches == NULL)
@@ -227,23 +247,23 @@
if (*watches != NULL)
return FALSE;
- _dbus_hash_table_remove_pollable (loop->watches, fd);
+ _dbus_hash_table_remove_int (loop->watches, fd);
return TRUE;
}
static void
-refresh_watches_for_fd (DBusLoop *loop,
- DBusList **watches,
- DBusPollable fd)
+refresh_watches_for_fd (DBusLoop *loop,
+ DBusList **watches,
+ int fd)
{
DBusList *link;
unsigned int flags = 0;
dbus_bool_t interested = FALSE;
- _dbus_assert (_dbus_pollable_is_valid (fd));
+ _dbus_assert (fd != -1);
if (watches == NULL)
- watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_int (loop->watches, fd);
/* we allocated this in the first _dbus_loop_add_watch for the fd, and keep
* it until there are none left */
@@ -271,11 +291,11 @@
_dbus_loop_add_watch (DBusLoop *loop,
DBusWatch *watch)
{
- DBusPollable fd;
+ int fd;
DBusList **watches;
- fd = _dbus_watch_get_pollable (watch);
- _dbus_assert (_dbus_pollable_is_valid (fd));
+ fd = dbus_watch_get_socket (watch);
+ _dbus_assert (fd != -1);
watches = ensure_watch_table_entry (loop, fd);
@@ -296,7 +316,7 @@
dbus_watch_get_flags (watch),
dbus_watch_get_enabled (watch)))
{
- _dbus_hash_table_remove_pollable (loop->watches, fd);
+ _dbus_hash_table_remove_int (loop->watches, fd);
return FALSE;
}
}
@@ -315,7 +335,7 @@
_dbus_loop_toggle_watch (DBusLoop *loop,
DBusWatch *watch)
{
- refresh_watches_for_fd (loop, NULL, _dbus_watch_get_pollable (watch));
+ refresh_watches_for_fd (loop, NULL, dbus_watch_get_socket (watch));
}
void
@@ -324,15 +344,15 @@
{
DBusList **watches;
DBusList *link;
- DBusPollable fd;
+ int fd;
/* This relies on people removing watches before they invalidate them,
* which has been safe since fd.o #33336 was fixed. Assert about it
* so we don't regress. */
- fd = _dbus_watch_get_pollable (watch);
- _dbus_assert (_dbus_pollable_is_valid (fd));
+ fd = dbus_watch_get_socket (watch);
+ _dbus_assert (fd != -1);
- watches = _dbus_hash_table_lookup_pollable (loop->watches, fd);
+ watches = _dbus_hash_table_lookup_int (loop->watches, fd);
if (watches != NULL)
{
@@ -422,15 +442,15 @@
* to do this.
*/
static dbus_bool_t
-check_timeout (long tv_sec,
- long tv_usec,
+check_timeout (unsigned long tv_sec,
+ unsigned long tv_usec,
TimeoutCallback *tcb,
int *timeout)
{
long sec_remaining;
long msec_remaining;
- long expiration_tv_sec;
- long expiration_tv_usec;
+ unsigned long expiration_tv_sec;
+ unsigned long expiration_tv_usec;
long interval_seconds;
long interval_milliseconds;
int interval;
@@ -451,7 +471,10 @@
}
sec_remaining = expiration_tv_sec - tv_sec;
- msec_remaining = (expiration_tv_usec - tv_usec) / 1000L;
+ /* need to force this to be signed, as it is intended to sometimes
+ * produce a negative result
+ */
+ msec_remaining = ((long) expiration_tv_usec - (long) tv_usec) / 1000L;
#if MAINLOOP_SPEW
_dbus_verbose ("Interval is %ld seconds %ld msecs\n",
@@ -593,8 +616,8 @@
timeout = -1;
if (loop->timeout_count > 0)
{
- long tv_sec;
- long tv_usec;
+ unsigned long tv_sec;
+ unsigned long tv_usec;
_dbus_get_monotonic_time (&tv_sec, &tv_usec);
@@ -652,7 +675,7 @@
timeout = MIN (timeout, _dbus_get_oom_wait ());
#if MAINLOOP_SPEW
- _dbus_verbose (" polling on %d descriptors timeout %ld\n", _DBUS_N_ELEMENTS (ready_fds), timeout);
+ _dbus_verbose (" polling on %d descriptors timeout %ld\n", n_fds, timeout);
#endif
n_ready = _dbus_socket_set_poll (loop->socket_set, ready_fds,
@@ -670,11 +693,11 @@
while (_dbus_hash_iter_next (&hash_iter))
{
DBusList **watches;
- DBusPollable fd;
+ int fd;
dbus_bool_t changed;
changed = FALSE;
- fd = _dbus_hash_iter_get_pollable_key (&hash_iter);
+ fd = _dbus_hash_iter_get_int_key (&hash_iter);
watches = _dbus_hash_iter_get_value (&hash_iter);
for (link = _dbus_list_get_first_link (watches);
@@ -702,8 +725,8 @@
if (loop->timeout_count > 0)
{
- long tv_sec;
- long tv_usec;
+ unsigned long tv_sec;
+ unsigned long tv_usec;
_dbus_get_monotonic_time (&tv_sec, &tv_usec);
@@ -796,8 +819,8 @@
if (condition == 0)
continue;
- watches = _dbus_hash_table_lookup_pollable (loop->watches,
- ready_fds[i].fd);
+ watches = _dbus_hash_table_lookup_int (loop->watches,
+ ready_fds[i].fd);
if (watches == NULL)
continue;
@@ -899,7 +922,7 @@
int
_dbus_get_oom_wait (void)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/* make tests go fast */
return 0;
#else
diff --git a/dbus/dbus-marshal-basic.c b/dbus/dbus-marshal-basic.c
index 74fe3f9..88b19f3 100644
--- a/dbus/dbus-marshal-basic.c
+++ b/dbus/dbus-marshal-basic.c
@@ -58,10 +58,12 @@
_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
@@ -118,10 +120,15 @@
{
_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
}
/**
@@ -139,16 +146,65 @@
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
@@ -545,10 +601,15 @@
{
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;
@@ -599,7 +660,7 @@
dbus_bool_t retval;
int orig_len;
- _DBUS_STATIC_ASSERT (sizeof (value) == 2);
+ _dbus_assert (sizeof (value) == 2);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
value = DBUS_UINT16_SWAP_LE_BE (value);
@@ -628,7 +689,7 @@
dbus_bool_t retval;
int orig_len;
- _DBUS_STATIC_ASSERT (sizeof (value) == 4);
+ _dbus_assert (sizeof (value) == 4);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
value = DBUS_UINT32_SWAP_LE_BE (value);
@@ -657,7 +718,7 @@
dbus_bool_t retval;
int orig_len;
- _DBUS_STATIC_ASSERT (sizeof (value) == 8);
+ _dbus_assert (sizeof (value) == 8);
swap_8_octets (&value, byte_order);
@@ -904,7 +965,11 @@
{
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;
}
}
@@ -1436,7 +1501,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -1580,7 +1645,7 @@
#define DEMARSHAL_FIXED_ARRAY_AND_CHECK(typename, byte_order, literal) \
do { \
DEMARSHAL_FIXED_ARRAY (typename, byte_order); \
- if (memcmp (literal, v_ARRAY_##typename, sizeof (literal)) != 0) \
+ if (memcmp (literal, v_ARRAY_##typename, sizeof (literal) != 0)) \
{ \
_dbus_verbose ("MARSHALED DATA\n"); \
_dbus_verbose_bytes_of_string (&str, dump_pos, \
@@ -1609,10 +1674,12 @@
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;
@@ -1668,6 +1735,7 @@
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));
@@ -1675,6 +1743,7 @@
/* 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);
@@ -1716,8 +1785,10 @@
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
@@ -1725,6 +1796,7 @@
* FIXME restore the set/pack tests
*/
+#ifdef DBUS_HAVE_INT64
/* set/pack 64-bit integers */
_dbus_string_set_length (&str, 8);
@@ -1795,6 +1867,7 @@
_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);
@@ -1919,4 +1992,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-marshal-basic.h b/dbus/dbus-marshal-basic.h
index 68ff348..034fdab 100644
--- a/dbus/dbus-marshal-basic.h
+++ b/dbus/dbus-marshal-basic.h
@@ -57,6 +57,8 @@
#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 */
@@ -78,6 +80,7 @@
(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 */
@@ -87,8 +90,10 @@
#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))
-#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 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 */
#ifdef WORDS_BIGENDIAN
@@ -100,10 +105,12 @@
# 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))
-# 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))
+# 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 */
#else /* WORDS_BIGENDIAN */
@@ -115,10 +122,12 @@
# 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))
-# 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))
+# 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 */
#endif
/* The transformation is symmetric, so the FROM just maps to the TO. */
@@ -130,10 +139,12 @@
#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))
-#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_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 */
#ifdef DBUS_DISABLE_ASSERT
#define _dbus_unpack_uint16(byte_order, data) \
@@ -148,7 +159,6 @@
#endif
#ifndef _dbus_unpack_uint16
-DBUS_PRIVATE_EXPORT
dbus_uint16_t _dbus_unpack_uint16 (int byte_order,
const unsigned char *data);
#endif
@@ -157,7 +167,6 @@
int byte_order,
unsigned char *data);
#ifndef _dbus_unpack_uint32
-DBUS_PRIVATE_EXPORT
dbus_uint32_t _dbus_unpack_uint32 (int byte_order,
const unsigned char *data);
#endif
@@ -203,22 +212,18 @@
int element_type,
int byte_order,
int *pos);
-DBUS_PRIVATE_EXPORT
void _dbus_marshal_set_uint32 (DBusString *str,
int pos,
dbus_uint32_t value,
int byte_order);
-DBUS_PRIVATE_EXPORT
dbus_uint32_t _dbus_marshal_read_uint32 (const DBusString *str,
int pos,
int byte_order,
int *new_pos);
int _dbus_type_get_alignment (int typecode);
int _dbus_type_get_alignment (int typecode);
-DBUS_PRIVATE_EXPORT
const char* _dbus_type_to_string (int typecode);
-DBUS_PRIVATE_EXPORT
int _dbus_first_type_in_signature (const DBusString *str,
int pos);
diff --git a/dbus/dbus-marshal-byteswap-util.c b/dbus/dbus-marshal-byteswap-util.c
index 5787485..edb74ca 100644
--- a/dbus/dbus-marshal-byteswap-util.c
+++ b/dbus/dbus-marshal-byteswap-util.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-marshal-byteswap.h"
#include "dbus-test.h"
#include <stdio.h>
@@ -102,4 +102,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-marshal-byteswap.c b/dbus/dbus-marshal-byteswap.c
index e6711be..22d7e22 100644
--- a/dbus/dbus-marshal-byteswap.c
+++ b/dbus/dbus-marshal-byteswap.c
@@ -73,7 +73,11 @@
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-byteswap.h b/dbus/dbus-marshal-byteswap.h
index f66f2e2..be2dd75 100644
--- a/dbus/dbus-marshal-byteswap.h
+++ b/dbus/dbus-marshal-byteswap.h
@@ -27,7 +27,6 @@
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-marshal-recursive.h>
-DBUS_PRIVATE_EXPORT
void _dbus_marshal_byteswap (const DBusString *signature,
int signature_start,
int old_byte_order,
diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c
index 48151c6..88887a8 100644
--- a/dbus/dbus-marshal-header.c
+++ b/dbus/dbus-marshal-header.c
@@ -276,7 +276,6 @@
* 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
@@ -337,7 +336,6 @@
* 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
@@ -454,6 +452,7 @@
* 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
@@ -515,7 +514,6 @@
* 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-header.h b/dbus/dbus-marshal-header.h
index c8c0112..350fe5c 100644
--- a/dbus/dbus-marshal-header.h
+++ b/dbus/dbus-marshal-header.h
@@ -78,7 +78,6 @@
dbus_uint32_t _dbus_header_get_serial (DBusHeader *header);
void _dbus_header_update_lengths (DBusHeader *header,
int body_len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_header_set_field_basic (DBusHeader *header,
int field,
int type,
@@ -87,12 +86,10 @@
int field,
int type,
void *value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_header_get_field_raw (DBusHeader *header,
int field,
const DBusString **str,
int *pos);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_header_delete_field (DBusHeader *header,
int field);
void _dbus_header_toggle_flag (DBusHeader *header,
@@ -124,7 +121,6 @@
int len);
void _dbus_header_byteswap (DBusHeader *header,
int new_order);
-DBUS_PRIVATE_EXPORT
char _dbus_header_get_byte_order (const DBusHeader *header);
diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c
index 3bc26a8..9512414 100644
--- a/dbus/dbus-marshal-recursive-util.c
+++ b/dbus/dbus-marshal-recursive-util.c
@@ -23,7 +23,7 @@
#include <config.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-marshal-recursive.h"
#include "dbus-marshal-basic.h"
@@ -34,7 +34,13 @@
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
@@ -50,7 +56,12 @@
}
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
}
}
@@ -1774,13 +1785,10 @@
start_next_test ("All values in one big toplevel %d iteration\n", 1);
{
TestTypeNode *nodes[N_VALUES];
- TestTypeNode *node;
i = 0;
- while ((node = value_generator (&i)))
- {
- nodes[i - 1] = node;
- }
+ while ((nodes[i] = value_generator (&i)))
+ ;
run_test_nodes (nodes, N_VALUES);
@@ -2329,6 +2337,7 @@
return TRUE;
}
+#ifdef DBUS_HAVE_INT64
static dbus_int64_t
int64_from_seed (int seed)
{
@@ -2342,6 +2351,7 @@
return v;
}
+#endif
static dbus_bool_t
int64_write_value (TestTypeNode *node,
@@ -2349,6 +2359,7 @@
DBusTypeWriter *writer,
int seed)
{
+#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2357,6 +2368,9 @@
return _dbus_type_writer_write_basic (writer,
node->klass->typecode,
&v);
+#else
+ return TRUE;
+#endif
}
static dbus_bool_t
@@ -2364,6 +2378,7 @@
DBusTypeReader *reader,
int seed)
{
+#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2375,6 +2390,9 @@
_dbus_assert (v == int64_from_seed (seed));
return TRUE;
+#else
+ return TRUE;
+#endif
}
static dbus_bool_t
@@ -2383,6 +2401,7 @@
DBusTypeReader *realign_root,
int seed)
{
+#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
@@ -2391,6 +2410,9 @@
return _dbus_type_reader_set_basic (reader,
&v,
realign_root);
+#else
+ return TRUE;
+#endif
}
#define MAX_SAMPLE_STRING_LEN 10
@@ -2774,7 +2796,7 @@
{
/* try to avoid ascending, descending, or alternating length to help find bugs */
const char *sample_signatures[] = {
- "asax",
+ "asax"
"",
"asau(xxxx)",
"x",
@@ -3552,4 +3574,4 @@
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-marshal-recursive.c b/dbus/dbus-marshal-recursive.c
index 9ba16e9..4adfd2e 100644
--- a/dbus/dbus-marshal-recursive.c
+++ b/dbus/dbus-marshal-recursive.c
@@ -149,7 +149,6 @@
const DBusString *value_str,
int value_pos)
{
- _DBUS_ZERO (*reader);
reader->byte_order = byte_order;
reader->finished = FALSE;
reader->type_str = type_str;
@@ -737,11 +736,11 @@
const DBusString *value_str,
int value_pos)
{
+ reader->klass = &body_reader_class;
+
reader_init (reader, byte_order, type_str, type_pos,
value_str, value_pos);
- reader->klass = &body_reader_class;
-
#if RECURSIVE_MARSHAL_READ_TRACE
_dbus_verbose (" type reader %p init type_pos = %d value_pos = %d remaining sig '%s'\n",
reader, reader->type_pos, reader->value_pos,
@@ -762,11 +761,11 @@
const DBusString *type_str,
int type_pos)
{
+ reader->klass = &body_types_only_reader_class;
+
reader_init (reader, DBUS_COMPILER_BYTE_ORDER /* irrelevant */,
type_str, type_pos, NULL, _DBUS_INT_MAX /* crashes if we screw up */);
- reader->klass = &body_types_only_reader_class;
-
#if RECURSIVE_MARSHAL_READ_TRACE
_dbus_verbose (" type reader %p init types only type_pos = %d remaining sig '%s'\n",
reader, reader->type_pos,
@@ -989,7 +988,6 @@
_dbus_type_reader_recurse (DBusTypeReader *reader,
DBusTypeReader *sub)
{
- const DBusTypeReaderClass *klass;
int t;
t = _dbus_first_type_in_signature (reader->type_str, reader->type_pos);
@@ -998,27 +996,27 @@
{
case DBUS_TYPE_STRUCT:
if (reader->klass->types_only)
- klass = &struct_types_only_reader_class;
+ sub->klass = &struct_types_only_reader_class;
else
- klass = &struct_reader_class;
+ sub->klass = &struct_reader_class;
break;
case DBUS_TYPE_DICT_ENTRY:
if (reader->klass->types_only)
- klass = &dict_entry_types_only_reader_class;
+ sub->klass = &dict_entry_types_only_reader_class;
else
- klass = &dict_entry_reader_class;
+ sub->klass = &dict_entry_reader_class;
break;
case DBUS_TYPE_ARRAY:
if (reader->klass->types_only)
- klass = &array_types_only_reader_class;
+ sub->klass = &array_types_only_reader_class;
else
- klass = &array_reader_class;
+ sub->klass = &array_reader_class;
break;
case DBUS_TYPE_VARIANT:
if (reader->klass->types_only)
_dbus_assert_not_reached ("can't recurse into variant typecode");
else
- klass = &variant_reader_class;
+ sub->klass = &variant_reader_class;
break;
default:
_dbus_verbose ("recursing into type %s\n", _dbus_type_to_string (t));
@@ -1030,10 +1028,9 @@
_dbus_assert_not_reached ("don't yet handle recursing into this type");
}
- _dbus_assert (klass == all_reader_classes[klass->id]);
+ _dbus_assert (sub->klass == all_reader_classes[sub->klass->id]);
- (* klass->recurse) (sub, reader);
- sub->klass = klass;
+ (* sub->klass->recurse) (sub, reader);
#if RECURSIVE_MARSHAL_READ_TRACE
_dbus_verbose (" type reader %p RECURSED type_pos = %d value_pos = %d remaining sig '%s'\n",
diff --git a/dbus/dbus-marshal-recursive.h b/dbus/dbus-marshal-recursive.h
index fa1d1ef..acbfd73 100644
--- a/dbus/dbus-marshal-recursive.h
+++ b/dbus/dbus-marshal-recursive.h
@@ -96,48 +96,37 @@
int new_len; /**< the new value of the length in the written-out block */
};
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_init (DBusTypeReader *reader,
int byte_order,
const DBusString *type_str,
int type_pos,
const DBusString *value_str,
int value_pos);
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_init_types_only (DBusTypeReader *reader,
const DBusString *type_str,
int type_pos);
-DBUS_PRIVATE_EXPORT
int _dbus_type_reader_get_current_type (const DBusTypeReader *reader);
-DBUS_PRIVATE_EXPORT
int _dbus_type_reader_get_element_type (const DBusTypeReader *reader);
int _dbus_type_reader_get_value_pos (const DBusTypeReader *reader);
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_read_basic (const DBusTypeReader *reader,
void *value);
int _dbus_type_reader_get_array_length (const DBusTypeReader *reader);
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_read_fixed_multi (const DBusTypeReader *reader,
void *value,
int *n_elements);
void _dbus_type_reader_read_raw (const DBusTypeReader *reader,
const unsigned char **value_location);
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_recurse (DBusTypeReader *reader,
DBusTypeReader *subreader);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_reader_next (DBusTypeReader *reader);
dbus_bool_t _dbus_type_reader_has_next (const DBusTypeReader *reader);
-DBUS_PRIVATE_EXPORT
void _dbus_type_reader_get_signature (const DBusTypeReader *reader,
const DBusString **str_p,
int *start_p,
int *len_p);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_reader_set_basic (DBusTypeReader *reader,
const void *value,
const DBusTypeReader *realign_root);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_reader_delete (DBusTypeReader *reader,
const DBusTypeReader *realign_root);
@@ -147,7 +136,6 @@
void _dbus_type_signature_next (const char *signature,
int *type_pos);
-DBUS_PRIVATE_EXPORT
void _dbus_type_writer_init (DBusTypeWriter *writer,
int byte_order,
DBusString *type_str,
@@ -162,36 +150,30 @@
DBusString *type_str,
int type_pos);
void _dbus_type_writer_remove_types (DBusTypeWriter *writer);
-DBUS_PRIVATE_EXPORT
void _dbus_type_writer_init_values_only (DBusTypeWriter *writer,
int byte_order,
const DBusString *type_str,
int type_pos,
DBusString *value_str,
int value_pos);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_writer_write_basic (DBusTypeWriter *writer,
int type,
const void *value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_writer_write_fixed_multi (DBusTypeWriter *writer,
int element_type,
const void *value,
int n_elements);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_writer_recurse (DBusTypeWriter *writer,
int container_type,
const DBusString *contained_type,
int contained_type_start,
DBusTypeWriter *sub);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_writer_unrecurse (DBusTypeWriter *writer,
DBusTypeWriter *sub);
dbus_bool_t _dbus_type_writer_append_array (DBusTypeWriter *writer,
const DBusString *contained_type,
int contained_type_start,
DBusTypeWriter *sub);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_type_writer_write_reader (DBusTypeWriter *writer,
DBusTypeReader *reader);
diff --git a/dbus/dbus-marshal-validate-util.c b/dbus/dbus-marshal-validate-util.c
index e11e1ac..81135bc 100644
--- a/dbus/dbus-marshal-validate-util.c
+++ b/dbus/dbus-marshal-validate-util.c
@@ -22,7 +22,7 @@
*/
#include <config.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -61,6 +61,8 @@
v, tests[i].data);
_dbus_assert_not_reached ("test failed");
}
+
+ ++i;
}
}
@@ -81,7 +83,7 @@
DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION },
{ ")", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
{ "i)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
- { "a)", DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE },
+ { "a)", DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED },
{ "(", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
{ "(i", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
{ "(iiiii", DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED },
@@ -116,7 +118,7 @@
"bar",
"bar/baz",
"/foo/bar/",
- "/foo/",
+ "/foo/"
"foo/",
"boo//blah",
"//",
@@ -583,4 +585,4 @@
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-marshal-validate.h b/dbus/dbus-marshal-validate.h
index 8ab024f..0643420 100644
--- a/dbus/dbus-marshal-validate.h
+++ b/dbus/dbus-marshal-validate.h
@@ -116,11 +116,9 @@
DBUS_VALIDITY_LAST
} DBusValidity;
-DBUS_PRIVATE_EXPORT
DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
int type_pos,
int len);
-DBUS_PRIVATE_EXPORT
DBusValidity _dbus_validate_body_with_reason (const DBusString *expected_signature,
int expected_signature_start,
int byte_order,
@@ -131,31 +129,24 @@
const char *_dbus_validity_to_error_message (DBusValidity validity);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_path (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_interface (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_member (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_error_name (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_bus_name (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_bus_namespace (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_validate_signature (const DBusString *str,
int start,
int len);
diff --git a/dbus/dbus-memory.c b/dbus/dbus-memory.c
index 67d5cb0..a033b54 100644
--- a/dbus/dbus-memory.c
+++ b/dbus/dbus-memory.c
@@ -26,7 +26,6 @@
#include "dbus-internals.h"
#include "dbus-sysdeps.h"
#include "dbus-list.h"
-#include "dbus-threads.h"
#include <stdlib.h>
/**
@@ -97,7 +96,7 @@
* @{
*/
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static dbus_bool_t debug_initialized = FALSE;
static int fail_nth = -1;
static size_t fail_size = 0;
@@ -240,7 +239,7 @@
return n_failures_per_failure;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* Called when about to alloc some memory; if
* it returns #TRUE, then the allocation should
@@ -294,7 +293,7 @@
return FALSE;
}
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
/**
* Get the number of outstanding malloc()'d blocks.
@@ -460,7 +459,7 @@
void*
dbus_malloc (size_t bytes)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -472,7 +471,7 @@
if (bytes == 0) /* some system mallocs handle this, some don't */
return NULL;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -499,7 +498,7 @@
void *mem;
mem = malloc (bytes);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (mem)
{
_dbus_atomic_inc (&n_blocks_outstanding);
@@ -530,7 +529,7 @@
void*
dbus_malloc0 (size_t bytes)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -543,7 +542,7 @@
if (bytes == 0)
return NULL;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -571,7 +570,7 @@
void *mem;
mem = calloc (bytes, 1);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (mem)
{
_dbus_atomic_inc (&n_blocks_outstanding);
@@ -601,7 +600,7 @@
dbus_realloc (void *memory,
size_t bytes)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
_dbus_initialize_malloc_debug ();
if (_dbus_decrement_fail_alloc_counter ())
@@ -617,7 +616,7 @@
dbus_free (memory);
return NULL;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
else if (fail_size != 0 && bytes > fail_size)
return NULL;
else if (guards)
@@ -677,7 +676,7 @@
void *mem;
mem = realloc (memory, bytes);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (mem == NULL && malloc_cannot_fail)
{
_dbus_warn ("out of memory: malloc (%ld)\n", (long) bytes);
@@ -700,7 +699,7 @@
void
dbus_free (void *memory)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (guards)
{
check_guards (memory, TRUE);
@@ -724,7 +723,7 @@
if (memory) /* we guarantee it's safe to free (NULL) */
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#ifdef DBUS_DISABLE_ASSERT
_dbus_atomic_dec (&n_blocks_outstanding);
#else
@@ -795,7 +794,7 @@
void *data; /**< Data for function */
};
-/* Protected by _DBUS_LOCK (shutdown_funcs) */
+_DBUS_DEFINE_GLOBAL_LOCK (shutdown_funcs);
static ShutdownClosure *registered_globals = NULL;
/**
@@ -810,20 +809,6 @@
_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);
@@ -834,9 +819,13 @@
c->func = func;
c->data = data;
+ _DBUS_LOCK (shutdown_funcs);
+
c->next = registered_globals;
registered_globals = c;
+ _DBUS_UNLOCK (shutdown_funcs);
+
return TRUE;
}
@@ -856,19 +845,12 @@
* can be useful to free these internal data structures.
*
* dbus_shutdown() does NOT free memory that was returned
- * to the application. It only frees libdbus-internal
+ * to the application. It only returns libdbus-internal
* data structures.
*
* You MUST free all memory and release all reference counts
* returned to you by libdbus prior to calling dbus_shutdown().
*
- * If a shared connection is open, calling dbus_shutdown() will
- * drain its queue of messages and disconnect it. In particular,
- * this will result in processing of the special Disconnected
- * signal, which may result in a call to _exit(), unless you
- * have used dbus_connection_set_exit_on_disconnect() to disable
- * that behaviour.
- *
* You can't continue to use any D-Bus objects, such as connections,
* that were allocated prior to dbus_shutdown(). You can, however,
* start over; call dbus_threads_init() again, create new connections,
@@ -908,18 +890,12 @@
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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
/**
diff --git a/dbus/dbus-mempool.c b/dbus/dbus-mempool.c
index 5246615..33aabf9 100644
--- a/dbus/dbus-mempool.c
+++ b/dbus/dbus-mempool.c
@@ -173,7 +173,7 @@
_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 @@
{
DBusMemBlock *block;
- VALGRIND_DESTROY_MEMPOOL (pool);
+ VALGRIND_DESTROY_MEMPOOL (pool)
block = pool->blocks;
while (block != NULL)
@@ -213,7 +213,7 @@
void*
_dbus_mem_pool_alloc (DBusMemPool *pool)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (_dbus_disable_mem_pools ())
{
DBusMemBlock *block;
@@ -241,7 +241,7 @@
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 @@
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 @@
/* Need a new block */
DBusMemBlock *block;
int alloc_size;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
int saved_counter;
#endif
@@ -294,7 +294,7 @@
alloc_size = sizeof (DBusMemBlock) - ELEMENT_PADDING + pool->block_size;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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 @@
else
block = dbus_malloc (alloc_size);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
_dbus_set_fail_alloc_counter (saved_counter);
_dbus_assert (saved_counter == _dbus_get_fail_alloc_counter ());
#endif
@@ -329,7 +329,7 @@
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_mem_pool_dealloc (DBusMemPool *pool,
void *element)
{
- VALGRIND_MEMPOOL_FREE (pool, element);
+ VALGRIND_MEMPOOL_FREE (pool, element)
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (_dbus_disable_mem_pools ())
{
DBusMemBlock *block;
@@ -393,7 +393,7 @@
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 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
#include <time.h>
@@ -459,10 +459,8 @@
{
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];
@@ -472,10 +470,8 @@
_dbus_verbose (" malloc\n");
-#ifdef DBUS_ENABLE_VERBOSE_MODE
start = clock ();
-#endif
-
+
i = 0;
j = 0;
while (i < N_ITERATIONS)
@@ -500,7 +496,6 @@
++i;
}
-#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -511,7 +506,6 @@
_dbus_verbose (" mempools\n");
start = clock ();
-#endif
pool = _dbus_mem_pool_new (size, FALSE);
@@ -541,7 +535,6 @@
_dbus_mem_pool_free (pool);
-#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -550,7 +543,6 @@
_dbus_verbose (" zeroed malloc\n");
start = clock ();
-#endif
i = 0;
j = 0;
@@ -576,7 +568,6 @@
++i;
}
-#ifdef DBUS_ENABLE_VERBOSE_MODE
end = clock ();
_dbus_verbose (" created/destroyed %d elements in %g seconds\n",
@@ -585,7 +576,6 @@
_dbus_verbose (" zeroed mempools\n");
start = clock ();
-#endif
pool = _dbus_mem_pool_new (size, TRUE);
@@ -615,12 +605,10 @@
_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
}
/**
@@ -644,4 +632,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-mempool.h b/dbus/dbus-mempool.h
index bc465ac..6693eeb 100644
--- a/dbus/dbus-mempool.h
+++ b/dbus/dbus-mempool.h
@@ -32,14 +32,10 @@
typedef struct DBusMemPool DBusMemPool;
-DBUS_PRIVATE_EXPORT
DBusMemPool* _dbus_mem_pool_new (int element_size,
dbus_bool_t zero_elements);
-DBUS_PRIVATE_EXPORT
void _dbus_mem_pool_free (DBusMemPool *pool);
-DBUS_PRIVATE_EXPORT
void* _dbus_mem_pool_alloc (DBusMemPool *pool);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_mem_pool_dealloc (DBusMemPool *pool,
void *element);
diff --git a/dbus/dbus-message-factory.c b/dbus/dbus-message-factory.c
index b742e4c..efa4e02 100644
--- a/dbus/dbus-message-factory.c
+++ b/dbus/dbus-message-factory.c
@@ -24,7 +24,7 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-message-factory.h"
#include "dbus-message-private.h"
#include "dbus-signature.h"
@@ -1302,4 +1302,4 @@
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-message-factory.h b/dbus/dbus-message-factory.h
index fd7a476..b074750 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <dbus/dbus-string.h>
#include <dbus/dbus-marshal-basic.h>
@@ -56,6 +56,6 @@
DBUS_END_DECLS
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
#endif /* DBUS_MESSAGE_FACTORY_H */
diff --git a/dbus/dbus-message-internal.h b/dbus/dbus-message-internal.h
index 4bb4d8b..c194873 100644
--- a/dbus/dbus-message-internal.h
+++ b/dbus/dbus-message-internal.h
@@ -50,7 +50,6 @@
void _dbus_message_get_network_data (DBusMessage *message,
const DBusString **header,
const DBusString **body);
-DBUS_PRIVATE_EXPORT
void _dbus_message_get_unix_fds (DBusMessage *message,
const int **fds,
unsigned *n_fds);
@@ -64,54 +63,40 @@
void _dbus_message_remove_counter (DBusMessage *message,
DBusCounter *counter);
-DBUS_PRIVATE_EXPORT
DBusMessageLoader* _dbus_message_loader_new (void);
-DBUS_PRIVATE_EXPORT
DBusMessageLoader* _dbus_message_loader_ref (DBusMessageLoader *loader);
-DBUS_PRIVATE_EXPORT
void _dbus_message_loader_unref (DBusMessageLoader *loader);
-DBUS_PRIVATE_EXPORT
void _dbus_message_loader_get_buffer (DBusMessageLoader *loader,
DBusString **buffer);
-DBUS_PRIVATE_EXPORT
void _dbus_message_loader_return_buffer (DBusMessageLoader *loader,
- DBusString *buffer);
+ DBusString *buffer,
+ int bytes_read);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_message_loader_get_unix_fds (DBusMessageLoader *loader,
int **fds,
unsigned *max_n_fds);
-DBUS_PRIVATE_EXPORT
void _dbus_message_loader_return_unix_fds (DBusMessageLoader *loader,
int *fds,
unsigned n_fds);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_message_loader_queue_messages (DBusMessageLoader *loader);
DBusMessage* _dbus_message_loader_peek_message (DBusMessageLoader *loader);
-DBUS_PRIVATE_EXPORT
DBusMessage* _dbus_message_loader_pop_message (DBusMessageLoader *loader);
DBusList* _dbus_message_loader_pop_message_link (DBusMessageLoader *loader);
void _dbus_message_loader_putback_message_link (DBusMessageLoader *loader,
DBusList *link);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_message_loader_get_is_corrupted (DBusMessageLoader *loader);
DBusValidity _dbus_message_loader_get_corruption_reason (DBusMessageLoader *loader);
void _dbus_message_loader_set_max_message_size (DBusMessageLoader *loader,
long size);
-DBUS_PRIVATE_EXPORT
long _dbus_message_loader_get_max_message_size (DBusMessageLoader *loader);
void _dbus_message_loader_set_max_message_unix_fds(DBusMessageLoader *loader,
long n);
long _dbus_message_loader_get_max_message_unix_fds(DBusMessageLoader *loader);
-int _dbus_message_loader_get_pending_fds_count (DBusMessageLoader *loader);
-void _dbus_message_loader_set_pending_fds_function (DBusMessageLoader *loader,
- void (* callback) (void *),
- void *data);
typedef struct DBusInitialFDs DBusInitialFDs;
DBusInitialFDs *_dbus_check_fdleaks_enter (void);
diff --git a/dbus/dbus-message-private.h b/dbus/dbus-message-private.h
index 50c41a8..e1578ab 100644
--- a/dbus/dbus-message-private.h
+++ b/dbus/dbus-message-private.h
@@ -80,8 +80,6 @@
int *unix_fds; /**< File descriptors that have been read from the transport but not yet been handed to any message. Array will be allocated at first use. */
unsigned n_unix_fds_allocated; /**< Number of file descriptors this array has space for */
unsigned n_unix_fds; /**< Number of valid file descriptors in array */
- void (* unix_fds_change) (void *); /**< Notify when the pending fds change */
- void *unix_fds_change_data;
#endif
};
@@ -133,7 +131,6 @@
#endif
};
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_message_iter_get_args_valist (DBusMessageIter *iter,
DBusError *error,
int first_arg_type,
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c
index 5acd541..f785952 100644
--- a/dbus/dbus-message-util.c
+++ b/dbus/dbus-message-util.c
@@ -45,7 +45,7 @@
* @{
*/
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_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 @@
return retval;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include "dbus-message-factory.h"
#include <stdio.h>
@@ -493,7 +493,7 @@
_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);
+ _dbus_message_loader_return_buffer (loader, buffer, 1);
}
if (!check_loader_results (loader, expected_validity))
@@ -512,7 +512,7 @@
_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);
+ _dbus_message_loader_return_buffer (loader, buffer, 1);
}
if (!check_loader_results (loader, expected_validity))
@@ -536,7 +536,7 @@
if ((i+1) < len)
_dbus_string_append_byte (buffer,
_dbus_string_get_byte (data, i+1));
- _dbus_message_loader_return_buffer (loader, buffer);
+ _dbus_message_loader_return_buffer (loader, buffer, 1);
}
if (!check_loader_results (loader, expected_validity))
@@ -754,8 +754,10 @@
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;
@@ -828,12 +830,14 @@
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;
@@ -850,8 +854,10 @@
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,
@@ -861,10 +867,12 @@
&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,
@@ -892,10 +900,12 @@
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))
@@ -927,6 +937,7 @@
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 ||
@@ -940,6 +951,7 @@
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");
@@ -991,163 +1003,6 @@
_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;
-#ifdef HAVE_UNIX_FD_PASSING
- int our_unix_fd1;
- int our_unix_fd2;
-#endif
- 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.
@@ -1170,16 +1025,16 @@
{ 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 };
@@ -1194,30 +1049,19 @@
dbus_uint16_t v_UINT16;
dbus_int32_t v_INT32;
dbus_uint32_t v_UINT32;
- dbus_uint32_t v1_UINT32;
+#ifdef DBUS_HAVE_INT64
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;
- dbus_bool_t ok;
- char basic_types[] = DBUS_TYPE_BYTE_AS_STRING \
- DBUS_TYPE_BOOLEAN_AS_STRING \
- DBUS_TYPE_INT16_AS_STRING \
- DBUS_TYPE_INT32_AS_STRING \
- DBUS_TYPE_INT64_AS_STRING \
- DBUS_TYPE_UINT16_AS_STRING \
- DBUS_TYPE_UINT32_AS_STRING \
- DBUS_TYPE_UINT64_AS_STRING \
- DBUS_TYPE_DOUBLE_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING;
initial_fds = _dbus_check_fdleaks_enter ();
@@ -1357,8 +1201,10 @@
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;
@@ -1366,7 +1212,6 @@
v2_BYTE = 24;
#ifdef HAVE_UNIX_FD_PASSING
v_UNIX_FD = 1;
- v1_UNIX_FD = 2;
#endif
dbus_message_append_args (message,
@@ -1374,8 +1219,10 @@
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,
@@ -1385,10 +1232,12 @@
_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,
@@ -1405,8 +1254,10 @@
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;
@@ -1416,10 +1267,12 @@
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;
@@ -1500,7 +1353,7 @@
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_byte (buffer, data[i]);
- _dbus_message_loader_return_buffer (loader, buffer);
+ _dbus_message_loader_return_buffer (loader, buffer, 1);
}
/* Write the body data one byte at a time */
@@ -1511,7 +1364,7 @@
_dbus_message_loader_get_buffer (loader, &buffer);
_dbus_string_append_byte (buffer, data[i]);
- _dbus_message_loader_return_buffer (loader, buffer);
+ _dbus_message_loader_return_buffer (loader, buffer, 1);
}
#ifdef HAVE_UNIX_FD_PASSING
@@ -1608,56 +1461,6 @@
_dbus_check_fdleaks_leave (initial_fds);
initial_fds = _dbus_check_fdleaks_enter ();
- /* Test enumeration of array elements */
- for (i = strlen (basic_types) - 1; i > 0; i--)
- {
- DBusBasicValue val;
- int some;
- char* signature = _dbus_strdup ("?");
-
- signature[0] = basic_types[i];
- s = "SomeThingToSay";
- memset (&val, '\0', sizeof (val));
-
- message = dbus_message_new_method_call ("de.ende.test",
- "/de/ende/test", "de.ende.Test", "ArtistName");
- _dbus_assert (message != NULL);
- dbus_message_iter_init_append (message, &iter);
- dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
- signature, &array_iter);
- for (some = 0; some < 3; some++)
- {
- if (basic_types[i] == DBUS_TYPE_STRING)
- dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &s);
- else
- dbus_message_iter_append_basic (&array_iter, basic_types[i], &val);
- }
- dbus_message_iter_close_container (&iter, &array_iter);
- dbus_message_iter_init (message, &iter);
- _dbus_assert (dbus_message_iter_get_element_count (&iter) == some);
- dbus_message_unref (message);
- dbus_free (signature);
- }
- /* Array of structs */
- message = dbus_message_new_method_call ("de.ende.test",
- "/de/ende/test", "de.ende.Test", "ArtistName");
- _dbus_assert (message != NULL);
- dbus_message_iter_init_append (message, &iter);
- dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
- DBUS_STRUCT_BEGIN_CHAR_AS_STRING
- DBUS_TYPE_STRING_AS_STRING
- DBUS_STRUCT_END_CHAR_AS_STRING, &array_iter);
- dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
- NULL, &struct_iter);
- s = "SpamAndEggs";
- dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
- dbus_message_iter_close_container (&array_iter, &struct_iter);
- dbus_message_iter_close_container (&iter, &array_iter);
- dbus_message_iter_init (message, &iter);
- _dbus_assert (dbus_message_iter_get_element_count (&iter) == 1);
- dbus_message_unref (message);
- check_memleaks ();
-
/* Check that we can abandon a container */
message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService",
"/org/freedesktop/TestPath",
@@ -1666,19 +1469,18 @@
dbus_message_iter_init_append (message, &iter);
- ok = dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ _dbus_assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
(DBUS_STRUCT_BEGIN_CHAR_AS_STRING
DBUS_TYPE_STRING_AS_STRING
DBUS_TYPE_STRING_AS_STRING
DBUS_STRUCT_END_CHAR_AS_STRING),
- &array_iter);
- _dbus_assert (ok);
- ok = dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
- NULL, &struct_iter);
- _dbus_assert (ok);
+ &array_iter));
+ _dbus_assert (dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT,
+ NULL, &struct_iter));
+
s = "peaches";
- ok = dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s);
- _dbus_assert (ok);
+ _dbus_assert (dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING,
+ &s));
/* uh-oh, error, try and unwind */
@@ -1687,51 +1489,6 @@
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;
@@ -1785,4 +1542,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-message.c b/dbus/dbus-message.c
index e0d9c8b..71bcee6 100644
--- a/dbus/dbus-message.c
+++ b/dbus/dbus-message.c
@@ -35,7 +35,6 @@
#include "dbus-list.h"
#include "dbus-threads-internal.h"
#ifdef HAVE_UNIX_FD_PASSING
-#include "dbus-sysdeps.h"
#include "dbus-sysdeps-unix.h"
#endif
@@ -57,7 +56,7 @@
* @{
*/
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static dbus_bool_t
_dbus_enable_message_cache (void)
{
@@ -136,29 +135,6 @@
} u; /**< the type writer or reader that does all the work */
};
-/**
- * Layout of a DBusMessageIter on the stack in dbus 1.10.0. This is no
- * longer used, but for ABI compatibility we need to assert that the
- * new layout is the same size.
- */
-typedef struct
-{
- void *dummy1;
- void *dummy2;
- dbus_uint32_t dummy3;
- int dummy4;
- int dummy5;
- int dummy6;
- int dummy7;
- int dummy8;
- int dummy9;
- int dummy10;
- int dummy11;
- int pad1;
- int pad2;
- void *pad3;
-} DBusMessageIter_1_10_0;
-
static void
get_const_signature (DBusHeader *header,
const DBusString **type_str_p,
@@ -530,7 +506,7 @@
/** Avoid caching too many messages */
#define MAX_MESSAGE_CACHE_SIZE 5
-/* Protected by _DBUS_LOCK (message_cache) */
+_DBUS_DEFINE_GLOBAL_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;
@@ -540,9 +516,7 @@
{
int i;
- if (!_DBUS_LOCK (message_cache))
- _dbus_assert_not_reached ("we would have initialized global locks "
- "before registering a shutdown function");
+ _DBUS_LOCK (message_cache);
i = 0;
while (i < MAX_MESSAGE_CACHE_SIZE)
@@ -574,12 +548,7 @@
message = NULL;
- 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_LOCK (message_cache);
_dbus_assert (message_cache_count >= 0);
@@ -625,7 +594,7 @@
close_unix_fds(int *fds, unsigned *n_fds)
{
DBusError e;
- unsigned int i;
+ int i;
if (*n_fds <= 0)
return;
@@ -691,13 +660,7 @@
was_cached = FALSE;
- 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");
- }
+ _DBUS_LOCK (message_cache);
if (!message_cache_shutdown_registered)
{
@@ -753,7 +716,7 @@
dbus_message_finalize (message);
}
-#if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
+#ifndef DBUS_DISABLE_CHECKS
static dbus_bool_t
_dbus_message_iter_check (DBusMessageRealIter *iter)
{
@@ -801,13 +764,15 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_CHECKS || DBUS_ENABLE_ASSERT */
+#endif /* DBUS_DISABLE_CHECKS */
/**
* 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
@@ -822,9 +787,8 @@
va_list var_args)
{
DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
- int spec_type, msg_type, i, j;
+ int spec_type, msg_type, i;
dbus_bool_t retval;
- va_list copy_args;
_dbus_assert (_dbus_message_iter_check (real));
@@ -833,17 +797,12 @@
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,
@@ -851,7 +810,7 @@
_dbus_type_to_string (msg_type));
goto out;
- }
+ }
if (spec_type == DBUS_TYPE_UNIX_FD)
{
@@ -964,30 +923,30 @@
/* Now go through and dup each string */
_dbus_type_reader_recurse (&real->u.reader, &array);
- j = 0;
- while (j < n_elements)
+ i = 0;
+ while (i < n_elements)
{
const char *s;
_dbus_type_reader_read_basic (&array,
(void *) &s);
- str_array[j] = _dbus_strdup (s);
- if (str_array[j] == NULL)
+ str_array[i] = _dbus_strdup (s);
+ if (str_array[i] == NULL)
{
dbus_free_string_array (str_array);
_DBUS_SET_OOM (error);
goto out;
}
- ++j;
+ ++i;
if (!_dbus_type_reader_next (&array))
- _dbus_assert (j == n_elements);
+ _dbus_assert (i == n_elements);
}
_dbus_assert (_dbus_type_reader_get_current_type (&array) == DBUS_TYPE_INVALID);
- _dbus_assert (j == n_elements);
- _dbus_assert (str_array[j] == NULL);
+ _dbus_assert (i == n_elements);
+ _dbus_assert (str_array[i] == NULL);
*str_array_p = str_array;
*n_elements_p = n_elements;
@@ -1010,9 +969,6 @@
}
#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)
{
@@ -1020,71 +976,14 @@
"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;
}
@@ -1166,18 +1065,14 @@
dbus_message_set_reply_serial (DBusMessage *message,
dbus_uint32_t reply_serial)
{
- DBusBasicValue value;
-
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (!message->locked, FALSE);
_dbus_return_val_if_fail (reply_serial != 0, FALSE); /* 0 is invalid */
- value.u32 = reply_serial;
-
return _dbus_header_set_field_basic (&message->header,
DBUS_HEADER_FIELD_REPLY_SERIAL,
DBUS_TYPE_UINT32,
- &value);
+ &reply_serial);
}
/**
@@ -1351,7 +1246,7 @@
*
* @param destination name that the message should be sent to or #NULL
* @param path object path the message should be sent to
- * @param iface interface to invoke method on, or #NULL
+ * @param interface interface to invoke method on, or #NULL
* @param method method to invoke
*
* @returns a new DBusMessage, free with dbus_message_unref()
@@ -1359,7 +1254,7 @@
DBusMessage*
dbus_message_new_method_call (const char *destination,
const char *path,
- const char *iface,
+ const char *interface,
const char *method)
{
DBusMessage *message;
@@ -1369,8 +1264,8 @@
_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 (iface == NULL ||
- _dbus_check_is_valid_interface (iface), NULL);
+ _dbus_return_val_if_fail (interface == NULL ||
+ _dbus_check_is_valid_interface (interface), NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_member (method), NULL);
message = dbus_message_new_empty_header ();
@@ -1380,7 +1275,7 @@
if (!_dbus_header_create (&message->header,
DBUS_COMPILER_BYTE_ORDER,
DBUS_MESSAGE_TYPE_METHOD_CALL,
- destination, path, iface, method, NULL))
+ destination, path, interface, method, NULL))
{
dbus_message_unref (message);
return NULL;
@@ -1443,22 +1338,22 @@
* specification defines the syntax of these fields).
*
* @param path the path to the object emitting the signal
- * @param iface the interface the signal is emitted from
+ * @param interface 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 *iface,
+ const char *interface,
const char *name)
{
DBusMessage *message;
_dbus_return_val_if_fail (path != NULL, NULL);
- _dbus_return_val_if_fail (iface != NULL, NULL);
+ _dbus_return_val_if_fail (interface != 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 (iface), NULL);
+ _dbus_return_val_if_fail (_dbus_check_is_valid_interface (interface), NULL);
_dbus_return_val_if_fail (_dbus_check_is_valid_member (name), NULL);
message = dbus_message_new_empty_header ();
@@ -1468,7 +1363,7 @@
if (!_dbus_header_create (&message->header,
DBUS_COMPILER_BYTE_ORDER,
DBUS_MESSAGE_TYPE_SIGNAL,
- NULL, path, iface, name, NULL))
+ NULL, path, interface, name, NULL))
{
dbus_message_unref (message);
return NULL;
@@ -2052,21 +1947,7 @@
DBusMessageRealIter *real,
int iter_type)
{
- /* If these static assertions fail on your platform, report it as a bug. */
- _DBUS_STATIC_ASSERT (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
- _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageRealIter) <=
- _DBUS_ALIGNOF (DBusMessageIter));
- /* A failure of these two assertions would indicate that we've broken
- * ABI on this platform since 1.10.0. */
- _DBUS_STATIC_ASSERT (sizeof (DBusMessageIter_1_10_0) ==
- sizeof (DBusMessageIter));
- _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageIter_1_10_0) ==
- _DBUS_ALIGNOF (DBusMessageIter));
- /* If this static assertion fails, it means the DBusMessageIter struct
- * is not "packed", which might result in "iter = other_iter" not copying
- * every byte. */
- _DBUS_STATIC_ASSERT (sizeof (DBusMessageIter) ==
- 4 * sizeof (void *) + sizeof (dbus_uint32_t) + 9 * sizeof (int));
+ _dbus_assert (sizeof (DBusMessageRealIter) <= sizeof (DBusMessageIter));
/* Since the iterator will read or write who-knows-what from the
* message, we need to get in the right byte order
@@ -2366,56 +2247,20 @@
}
/**
- * Returns the number of elements in the array-typed value pointed
- * to by the iterator.
- * Note that this function is O(1) for arrays of fixed-size types
- * but O(n) for arrays of variable-length types such as strings,
- * so it may be a bad idea to use it.
- *
- * @param iter the iterator
- * @returns the number of elements in the array
- */
-int
-dbus_message_iter_get_element_count (DBusMessageIter *iter)
-{
- DBusMessageRealIter *real = (DBusMessageRealIter *)iter;
- DBusTypeReader array;
- int element_type;
- int n_elements = 0;
-
- _dbus_return_val_if_fail (_dbus_message_iter_check (real), 0);
- _dbus_return_val_if_fail (_dbus_type_reader_get_current_type (&real->u.reader)
- == DBUS_TYPE_ARRAY, 0);
-
- element_type = _dbus_type_reader_get_element_type (&real->u.reader);
- _dbus_type_reader_recurse (&real->u.reader, &array);
- if (dbus_type_is_fixed (element_type))
- {
- int alignment = _dbus_type_get_alignment (element_type);
- int total_len = _dbus_type_reader_get_array_length (&array);
- n_elements = total_len / alignment;
- }
- else
- {
- while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID)
- {
- ++n_elements;
- _dbus_type_reader_next (&array);
- }
- }
-
- return n_elements;
-}
-
-/**
* Returns the number of bytes in the array as marshaled in the wire
* protocol. The iterator must currently be inside an array-typed
* value.
*
* This function is deprecated on the grounds that it is stupid. Why
* would you want to know how many bytes are in the array as marshaled
- * in the wire protocol? Use dbus_message_iter_get_element_count() instead.
+ * in the wire protocol? For now, use the n_elements returned from
+ * dbus_message_iter_get_fixed_array() instead, or iterate over the
+ * array values and count them.
*
+ * @todo introduce a variant of this get_n_elements that returns
+ * the number of elements, though with a non-fixed array it will not
+ * be very efficient, so maybe it's not good.
+ *
* @param iter the iterator
* @returns the number of bytes in the array
*/
@@ -3268,23 +3113,23 @@
* in the D-Bus specification.
*
* @param message the message
- * @param iface the interface or #NULL to unset
+ * @param interface the interface or #NULL to unset
* @returns #FALSE if not enough memory
*/
dbus_bool_t
dbus_message_set_interface (DBusMessage *message,
- const char *iface)
+ const char *interface)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
_dbus_return_val_if_fail (!message->locked, FALSE);
- _dbus_return_val_if_fail (iface == NULL ||
- _dbus_check_is_valid_interface (iface),
+ _dbus_return_val_if_fail (interface == NULL ||
+ _dbus_check_is_valid_interface (interface),
FALSE);
return set_or_delete_string_field (message,
DBUS_HEADER_FIELD_INTERFACE,
DBUS_TYPE_STRING,
- iface);
+ interface);
}
/**
@@ -3319,28 +3164,28 @@
* Checks if the message has an interface
*
* @param message the message
- * @param iface the interface name
+ * @param interface the interface name
* @returns #TRUE if the interface field in the header matches
*/
dbus_bool_t
dbus_message_has_interface (DBusMessage *message,
- const char *iface)
+ const char *interface)
{
const char *msg_interface;
msg_interface = dbus_message_get_interface (message);
if (msg_interface == NULL)
{
- if (iface == NULL)
+ if (interface == NULL)
return TRUE;
else
return FALSE;
}
- if (iface == NULL)
+ if (interface == NULL)
return FALSE;
- if (strcmp (msg_interface, iface) == 0)
+ if (strcmp (msg_interface, interface) == 0)
return TRUE;
return FALSE;
@@ -3632,13 +3477,13 @@
static dbus_bool_t
_dbus_message_has_type_interface_member (DBusMessage *message,
int type,
- const char *iface,
+ const char *interface,
const char *member)
{
const char *n;
_dbus_assert (message != NULL);
- _dbus_assert (iface != NULL);
+ _dbus_assert (interface != NULL);
_dbus_assert (member != NULL);
if (dbus_message_get_type (message) != type)
@@ -3654,7 +3499,7 @@
{
n = dbus_message_get_interface (message);
- if (n == NULL || strcmp (n, iface) == 0)
+ if (n == NULL || strcmp (n, interface) == 0)
return TRUE;
}
@@ -3670,18 +3515,18 @@
* protocol allows method callers to leave out the interface name.
*
* @param message the message
- * @param iface the name to check (must not be #NULL)
+ * @param interface 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 *iface,
+ const char *interface,
const char *method)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
- _dbus_return_val_if_fail (iface != NULL, FALSE);
+ _dbus_return_val_if_fail (interface != 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
@@ -3689,7 +3534,7 @@
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_METHOD_CALL,
- iface, method);
+ interface, method);
}
/**
@@ -3698,18 +3543,18 @@
* has a different interface or member field, returns #FALSE.
*
* @param message the message
- * @param iface the name to check (must not be #NULL)
+ * @param interface 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 *iface,
+ const char *interface,
const char *signal_name)
{
_dbus_return_val_if_fail (message != NULL, FALSE);
- _dbus_return_val_if_fail (iface != NULL, FALSE);
+ _dbus_return_val_if_fail (interface != 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
@@ -3717,7 +3562,7 @@
return _dbus_message_has_type_interface_member (message,
DBUS_MESSAGE_TYPE_SIGNAL,
- iface, signal_name);
+ interface, signal_name);
}
/**
@@ -3957,7 +3802,7 @@
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 = DBUS_DEFAULT_MESSAGE_UNIX_FDS;
+ loader->max_message_unix_fds = 1024;
if (!_dbus_string_init (&loader->data))
{
@@ -4054,10 +3899,12 @@
*
* @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)
+ DBusString *buffer,
+ int bytes_read)
{
_dbus_assert (loader->buffer_outstanding);
_dbus_assert (buffer == &loader->data);
@@ -4121,7 +3968,7 @@
*
* @param loader the message loader.
* @param fds the array fds were read into
- * @param n_fds how many fds were read
+ * @param max_n_fds how many fds were read
*/
void
@@ -4136,9 +3983,6 @@
loader->n_unix_fds += n_fds;
loader->unix_fds_outstanding = FALSE;
-
- if (n_fds && loader->unix_fds_change)
- loader->unix_fds_change (loader->unix_fds_change_data);
#else
_dbus_assert_not_reached("Platform doesn't support unix fd passing");
#endif
@@ -4285,10 +4129,7 @@
message->n_unix_fds_allocated = message->n_unix_fds = n_unix_fds;
loader->n_unix_fds -= n_unix_fds;
- memmove (loader->unix_fds, loader->unix_fds + n_unix_fds, loader->n_unix_fds * sizeof (loader->unix_fds[0]));
-
- if (loader->unix_fds_change)
- loader->unix_fds_change (loader->unix_fds_change_data);
+ memmove(loader->unix_fds + n_unix_fds, loader->unix_fds, loader->n_unix_fds);
}
else
message->unix_fds = NULL;
@@ -4555,7 +4396,7 @@
* Sets the maximum unix fds per message we allow.
*
* @param loader the loader
- * @param n the max number of unix fds in a message
+ * @param size the max number of unix fds in a message
*/
void
_dbus_message_loader_set_max_message_unix_fds (DBusMessageLoader *loader,
@@ -4582,42 +4423,8 @@
return loader->max_message_unix_fds;
}
-/**
- * Return how many file descriptors are pending in the loader
- *
- * @param loader the loader
- */
-int
-_dbus_message_loader_get_pending_fds_count (DBusMessageLoader *loader)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- return loader->n_unix_fds;
-#else
- return 0;
-#endif
-}
-
-/**
- * Register a function to be called whenever the number of pending file
- * descriptors in the loader change.
- *
- * @param loader the loader
- * @param callback the callback
- * @param data the data for the callback
- */
-void
-_dbus_message_loader_set_pending_fds_function (DBusMessageLoader *loader,
- void (* callback) (void *),
- void *data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- loader->unix_fds_change = callback;
- loader->unix_fds_change_data = data;
-#endif
-}
-
-static DBusDataSlotAllocator slot_allocator =
- _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (message_slots));
+static DBusDataSlotAllocator slot_allocator;
+_DBUS_DEFINE_GLOBAL_LOCK (message_slots);
/**
* Allocates an integer ID to be used for storing application-specific
@@ -4637,6 +4444,7 @@
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);
}
@@ -4873,11 +4681,8 @@
return NULL;
_dbus_message_loader_get_buffer (loader, &buffer);
-
- if (!_dbus_string_append_len (buffer, str, len))
- goto fail_oom;
-
- _dbus_message_loader_return_buffer (loader, buffer);
+ _dbus_string_append_len (buffer, str, len);
+ _dbus_message_loader_return_buffer (loader, buffer, len);
if (!_dbus_message_loader_queue_messages (loader))
goto fail_oom;
@@ -4912,8 +4717,9 @@
* Generally, this function is only useful for encapsulating D-Bus messages in
* a different protocol.
*
- * @param buf data to be marshalled
- * @param len the length of @p buf
+ * @param str data to be marshalled
+ * @param len the length of str
+ * @param error the location to save errors to
* @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
*
*/
@@ -4956,54 +4762,6 @@
}
}
-/**
- * Sets a flag indicating that the caller of the method is prepared
- * to wait for interactive authorization to take place (for instance
- * via Polkit) before the actual method is processed.
- *
- * The flag is #FALSE by default; that is, by default the other end is
- * expected to make any authorization decisions non-interactively
- * and promptly. It may use the error
- * #DBUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED to signal that
- * authorization failed, but could have succeeded if this flag had
- * been used.
- *
- * For messages whose type is not #DBUS_MESSAGE_TYPE_METHOD_CALL,
- * this flag is meaningless and should not be set.
- *
- * On the protocol level this toggles
- * #DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION.
- *
- * @param message the message
- * @param allow #TRUE if interactive authorization is acceptable
- */
-void
-dbus_message_set_allow_interactive_authorization (DBusMessage *message,
- dbus_bool_t allow)
-{
- _dbus_return_if_fail (message != NULL);
- _dbus_return_if_fail (!message->locked);
-
- _dbus_header_toggle_flag (&message->header,
- DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION,
- allow);
-}
-
-/**
- * Returns whether the flag controlled by
- * dbus_message_set_allow_interactive_authorization() has been set.
- *
- * @param message the message
- */
-dbus_bool_t
-dbus_message_get_allow_interactive_authorization (DBusMessage *message)
-{
- _dbus_return_val_if_fail (message != NULL, FALSE);
-
- return _dbus_header_get_flag (&message->header,
- DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION);
-}
-
/** @} */
/* tests in dbus-message-util.c */
diff --git a/dbus/dbus-message.h b/dbus/dbus-message.h
index ac3e408..5500492 100644
--- a/dbus/dbus-message.h
+++ b/dbus/dbus-message.h
@@ -62,7 +62,7 @@
int dummy10; /**< Don't use this */
int dummy11; /**< Don't use this */
int pad1; /**< Don't use this */
- void *pad2; /**< Don't use this */
+ int pad2; /**< Don't use this */
void *pad3; /**< Don't use this */
};
@@ -71,13 +71,13 @@
DBUS_EXPORT
DBusMessage* dbus_message_new_method_call (const char *bus_name,
const char *path,
- const char *iface,
+ const char *interface,
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 *iface,
+ const char *interface,
const char *name);
DBUS_EXPORT
DBusMessage* dbus_message_new_error (DBusMessage *reply_to,
@@ -108,12 +108,12 @@
const char *object_path);
DBUS_EXPORT
dbus_bool_t dbus_message_set_interface (DBusMessage *message,
- const char *iface);
+ const char *interface);
DBUS_EXPORT
const char* dbus_message_get_interface (DBusMessage *message);
DBUS_EXPORT
dbus_bool_t dbus_message_has_interface (DBusMessage *message,
- const char *iface);
+ const char *interface);
DBUS_EXPORT
dbus_bool_t dbus_message_set_member (DBusMessage *message,
const char *member);
@@ -146,11 +146,11 @@
dbus_bool_t dbus_message_get_no_reply (DBusMessage *message);
DBUS_EXPORT
dbus_bool_t dbus_message_is_method_call (DBusMessage *message,
- const char *iface,
+ const char *interface,
const char *method);
DBUS_EXPORT
dbus_bool_t dbus_message_is_signal (DBusMessage *message,
- const char *iface,
+ const char *interface,
const char *signal_name);
DBUS_EXPORT
dbus_bool_t dbus_message_is_error (DBusMessage *message,
@@ -226,9 +226,6 @@
DBUS_EXPORT
void dbus_message_iter_get_basic (DBusMessageIter *iter,
void *value);
-DBUS_EXPORT
-int dbus_message_iter_get_element_count(DBusMessageIter *iter);
-
#ifndef DBUS_DISABLE_DEPRECATED
/* This function returns the wire protocol size of the array in bytes,
* you do not want to know that probably
@@ -305,14 +302,6 @@
int dbus_message_demarshal_bytes_needed (const char *str,
int len);
-DBUS_EXPORT
-void dbus_message_set_allow_interactive_authorization (DBusMessage *message,
- dbus_bool_t allow);
-
-DBUS_EXPORT
-dbus_bool_t dbus_message_get_allow_interactive_authorization (
- DBusMessage *message);
-
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-misc.c b/dbus/dbus-misc.c
index a2da562..b161013 100644
--- a/dbus/dbus-misc.c
+++ b/dbus/dbus-misc.c
@@ -80,11 +80,7 @@
if (!_dbus_string_init (&uuid))
return NULL;
- /* The documentation says dbus_get_local_machine_id() only fails on OOM;
- * this can actually also fail if the D-Bus installation is faulty
- * (no UUID) *and* reading a new random UUID fails, but we have no way
- * to report that */
- if (!_dbus_get_local_machine_uuid_encoded (&uuid, NULL) ||
+ if (!_dbus_get_local_machine_uuid_encoded (&uuid) ||
!_dbus_string_steal_data (&uuid, &s))
{
_dbus_string_free (&uuid);
@@ -177,7 +173,7 @@
/** @} */ /* End of public API */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
diff --git a/dbus/dbus-misc.h b/dbus/dbus-misc.h
index 6e72d9e..3504bca 100644
--- a/dbus/dbus-misc.h
+++ b/dbus/dbus-misc.h
@@ -44,10 +44,6 @@
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 3c0f6f3..e74c2dd 100644
--- a/dbus/dbus-nonce.c
+++ b/dbus/dbus-nonce.c
@@ -31,7 +31,7 @@
#include <stdio.h>
static dbus_bool_t
-do_check_nonce (DBusSocket fd, const DBusString *nonce, DBusError *error)
+do_check_nonce (int fd, const DBusString *nonce, DBusError *error)
{
DBusString buffer;
DBusString p;
@@ -53,14 +53,10 @@
while (nleft)
{
- int saved_errno;
-
n = _dbus_read_socket (fd, &p, nleft);
- saved_errno = _dbus_save_socket_errno ();
-
- if (n == -1 && _dbus_get_is_errno_eintr (saved_errno))
+ if (n == -1 && _dbus_get_is_errno_eintr())
;
- else if (n == -1 && _dbus_get_is_errno_eagain_or_ewouldblock (saved_errno))
+ else if (n == -1 && _dbus_get_is_errno_eagain_or_ewouldblock())
_dbus_sleep_milliseconds (100);
else if (n==-1)
{
@@ -78,13 +74,7 @@
}
else
{
- if (!_dbus_string_append_len (&buffer, _dbus_string_get_const_data (&p), n))
- {
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- _dbus_string_free (&p);
- _dbus_string_free (&buffer);
- return FALSE;
- }
+ _dbus_string_append_len(&buffer, _dbus_string_get_const_data (&p), n);
nleft -= n;
}
}
@@ -123,15 +113,7 @@
fp = fopen (_dbus_string_get_const_data (fname), "rb");
if (!fp)
- {
- 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;
- }
-
+ return FALSE;
nread = fread (buffer, 1, sizeof buffer - 1, fp);
fclose (fp);
if (!nread)
@@ -148,25 +130,25 @@
return TRUE;
}
-DBusSocket
-_dbus_accept_with_noncefile (DBusSocket listen_fd, const DBusNonceFile *noncefile)
+int
+_dbus_accept_with_noncefile (int listen_fd, const DBusNonceFile *noncefile)
{
- DBusSocket fd;
+ int fd;
DBusString nonce;
_dbus_assert (noncefile != NULL);
if (!_dbus_string_init (&nonce))
- return _dbus_socket_get_invalid ();
+ return -1;
//PENDING(kdab): set better errors
if (_dbus_read_nonce (_dbus_noncefile_get_path(noncefile), &nonce, NULL) != TRUE)
- return _dbus_socket_get_invalid ();
+ return -1;
fd = _dbus_accept (listen_fd);
- if (!_dbus_socket_is_valid (fd))
+ if (_dbus_socket_is_invalid (fd))
return fd;
if (do_check_nonce(fd, &nonce, NULL) != TRUE) {
_dbus_verbose ("nonce check failed. Closing socket.\n");
_dbus_close_socket(fd, NULL);
- return _dbus_socket_get_invalid ();
+ return -1;
}
return fd;
@@ -186,8 +168,9 @@
return FALSE;
}
- if (!_dbus_generate_random_bytes (&nonce, 16, error))
+ if (!_dbus_generate_random_bytes (&nonce, 16))
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_string_free (&nonce);
return FALSE;
}
@@ -209,9 +192,7 @@
* indicate whether the server accepted the nonce.
*/
dbus_bool_t
-_dbus_send_nonce (DBusSocket fd,
- const DBusString *noncefile,
- DBusError *error)
+_dbus_send_nonce (int fd, const DBusString *noncefile, DBusError *error)
{
dbus_bool_t read_result;
int send_result;
@@ -259,7 +240,6 @@
dbus_bool_t use_subdir)
{
DBusString randomStr;
- const char *tmp;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -271,16 +251,14 @@
goto on_error;
}
- if (!_dbus_generate_random_ascii (&randomStr, 8, error))
+ if (!_dbus_generate_random_ascii (&randomStr, 8))
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto on_error;
}
- tmp = _dbus_get_tmpdir ();
-
if (!_dbus_string_init (&noncefile->dir)
- || tmp == NULL
- || !_dbus_string_append (&noncefile->dir, tmp))
+ || !_dbus_string_append (&noncefile->dir, _dbus_get_tmpdir()))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto on_error;
@@ -437,7 +415,7 @@
* and matches the nonce from the given nonce file
*/
dbus_bool_t
-_dbus_noncefile_check_nonce (DBusSocket fd,
+_dbus_noncefile_check_nonce (int fd,
const DBusNonceFile *noncefile,
DBusError* error)
{
diff --git a/dbus/dbus-nonce.h b/dbus/dbus-nonce.h
index 99366fd..474ea72 100644
--- a/dbus/dbus-nonce.h
+++ b/dbus/dbus-nonce.h
@@ -27,7 +27,6 @@
#include <dbus/dbus-types.h>
#include <dbus/dbus-errors.h>
#include <dbus/dbus-string.h>
-#include <dbus/dbus-sysdeps.h>
DBUS_BEGIN_DECLS
@@ -47,13 +46,13 @@
dbus_bool_t _dbus_noncefile_delete (DBusNonceFile *noncefile,
DBusError *error);
-dbus_bool_t _dbus_noncefile_check_nonce (DBusSocket fd,
+dbus_bool_t _dbus_noncefile_check_nonce (int fd,
const DBusNonceFile *noncefile,
DBusError *error);
const DBusString* _dbus_noncefile_get_path (const DBusNonceFile *noncefile);
-DBusSocket _dbus_accept_with_noncefile(DBusSocket listen_fd,
+int _dbus_accept_with_noncefile (int listen_fd,
const DBusNonceFile *noncefile);
// shared
@@ -64,7 +63,7 @@
// client
-dbus_bool_t _dbus_send_nonce (DBusSocket fd,
+dbus_bool_t _dbus_send_nonce (int fd,
const DBusString *noncefile,
DBusError *error);
diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c
index e2a3b73..172c9d9 100644
--- a/dbus/dbus-object-tree.c
+++ b/dbus/dbus-object-tree.c
@@ -319,7 +319,6 @@
}
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
static DBusObjectSubtree*
find_subtree (DBusObjectTree *tree,
const char **path,
@@ -338,7 +337,6 @@
else
return subtree;
}
-#endif
static DBusObjectSubtree*
lookup_subtree (DBusObjectTree *tree,
@@ -436,185 +434,6 @@
}
/**
- * 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.
*
@@ -625,42 +444,66 @@
_dbus_object_tree_unregister_and_unlock (DBusObjectTree *tree,
const char **path)
{
- dbus_bool_t found_subtree;
- dbus_bool_t continue_removal_attempts;
+ int i;
+ DBusObjectSubtree *subtree;
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;
- found_subtree = unregister_and_free_path_recurse (tree->root,
- path,
- &continue_removal_attempts,
- &unregister_function,
- &user_data);
+ subtree = find_subtree (tree, path, &i);
#ifndef DBUS_DISABLE_CHECKS
- if (found_subtree == FALSE)
+ if (subtree == NULL)
{
_dbus_warn ("Attempted to unregister path (path[0] = %s path[1] = %s) which isn't registered\n",
path[0] ? path[0] : "null",
- (path[0] && path[1]) ? path[1] : "null");
+ path[1] ? path[1] : "null");
goto unlock;
}
#else
- _dbus_assert (found_subtree == TRUE);
+ _dbus_assert (subtree != NULL);
#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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (connection)
#endif
{
@@ -672,7 +515,7 @@
if (unregister_function)
(* unregister_function) (connection, user_data);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (connection)
#endif
dbus_connection_unref (connection);
@@ -795,7 +638,7 @@
DBUS_INTERFACE_INTROSPECTABLE,
"Introspect"))
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -810,7 +653,7 @@
if (!_dbus_string_init (&xml))
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -855,7 +698,7 @@
if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &v_STRING))
goto out;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -868,7 +711,7 @@
result = DBUS_HANDLER_RESULT_HANDLED;
out:
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -898,7 +741,6 @@
*
* @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
@@ -920,7 +762,7 @@
path = NULL;
if (!dbus_message_get_path_decomposed (message, &path))
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -935,7 +777,7 @@
if (path == NULL)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -1004,7 +846,7 @@
_dbus_verbose (" (invoking a handler)\n");
#endif
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -1021,7 +863,7 @@
message,
user_data);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
_dbus_connection_lock (tree->connection);
@@ -1044,7 +886,7 @@
}
else
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -1215,7 +1057,7 @@
parent_path,
child_entries);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (tree->connection)
#endif
{
@@ -1372,7 +1214,7 @@
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -1665,17 +1507,6 @@
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)
{
@@ -1688,13 +1519,6 @@
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;
@@ -2065,200 +1889,6 @@
++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))
@@ -2332,4 +1962,4 @@
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-pending-call-internal.h b/dbus/dbus-pending-call-internal.h
index 393e660..1875eea 100644
--- a/dbus/dbus-pending-call-internal.h
+++ b/dbus/dbus-pending-call-internal.h
@@ -51,13 +51,10 @@
dbus_bool_t _dbus_pending_call_set_timeout_error_unlocked (DBusPendingCall *pending,
DBusMessage *message,
dbus_uint32_t serial);
-DBUS_PRIVATE_EXPORT
DBusPendingCall* _dbus_pending_call_new_unlocked (DBusConnection *connection,
int timeout_milliseconds,
DBusTimeoutHandler timeout_handler);
-DBUS_PRIVATE_EXPORT
DBusPendingCall* _dbus_pending_call_ref_unlocked (DBusPendingCall *pending);
-DBUS_PRIVATE_EXPORT
void _dbus_pending_call_unref_and_unlock (DBusPendingCall *pending);
dbus_bool_t _dbus_pending_call_set_data_unlocked (DBusPendingCall *pending,
dbus_int32_t slot,
diff --git a/dbus/dbus-pending-call.c b/dbus/dbus-pending-call.c
index be53410..62c6c74 100644
--- a/dbus/dbus-pending-call.c
+++ b/dbus/dbus-pending-call.c
@@ -79,19 +79,26 @@
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);
-#endif
}
+#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;
@@ -482,8 +489,8 @@
return pending->completed;
}
-static DBusDataSlotAllocator slot_allocator =
- _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (pending_call_slots));
+static DBusDataSlotAllocator slot_allocator;
+_DBUS_DEFINE_GLOBAL_LOCK (pending_call_slots);
/**
* Stores a pointer on a #DBusPendingCall, along
@@ -761,6 +768,7 @@
_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-pipe.h b/dbus/dbus-pipe.h
index ca924cc..c2063b5 100644
--- a/dbus/dbus-pipe.h
+++ b/dbus/dbus-pipe.h
@@ -42,25 +42,18 @@
int fd;
};
-DBUS_PRIVATE_EXPORT
void _dbus_pipe_init (DBusPipe *pipe,
int fd);
-DBUS_PRIVATE_EXPORT
void _dbus_pipe_init_stdout (DBusPipe *pipe);
-DBUS_PRIVATE_EXPORT
int _dbus_pipe_write (DBusPipe *pipe,
const DBusString *buffer,
int start,
int len,
DBusError *error);
-DBUS_PRIVATE_EXPORT
int _dbus_pipe_close (DBusPipe *pipe,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_pipe_is_valid (DBusPipe *pipe);
-DBUS_PRIVATE_EXPORT
void _dbus_pipe_invalidate (DBusPipe *pipe);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_pipe_is_stdout_or_stderr (DBusPipe *pipe);
#endif
diff --git a/dbus/dbus-protocol.h b/dbus/dbus-protocol.h
index 933c365..60605ab 100644
--- a/dbus/dbus-protocol.h
+++ b/dbus/dbus-protocol.h
@@ -254,11 +254,6 @@
* message.
*/
#define DBUS_HEADER_FLAG_NO_AUTO_START 0x2
-/**
- * If set on a method call, this flag means that the caller is prepared to
- * wait for interactive authorization.
- */
-#define DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 0x4
/* Header fields */
@@ -451,10 +446,6 @@
/** The message meta data does not match the payload. e.g. expected
number of file descriptors were not sent over the socket this message was received on. */
#define DBUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage"
-/** The message is not allowed without performing interactive authorization,
- * but could have succeeded if an interactive authorization step was
- * allowed. */
-#define DBUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED "org.freedesktop.DBus.Error.InteractiveAuthorizationRequired"
/* XML introspection format */
diff --git a/dbus/dbus-resources.c b/dbus/dbus-resources.c
index 0617eae..80fb55b 100644
--- a/dbus/dbus-resources.c
+++ b/dbus/dbus-resources.c
@@ -69,7 +69,6 @@
DBusCounterNotifyFunction notify_function; /**< notify function */
void *notify_data; /**< data for notify function */
dbus_bool_t notify_pending : 1; /**< TRUE if the guard value has been crossed */
- DBusRMutex *mutex; /**< Lock on the entire DBusCounter */
};
/** @} */ /* end of resource limits internals docs */
@@ -96,13 +95,6 @@
counter->refcount = 1;
- _dbus_rmutex_new_at_location (&counter->mutex);
- if (counter->mutex == NULL)
- {
- dbus_free (counter);
- counter = NULL;
- }
-
return counter;
}
@@ -115,14 +107,10 @@
DBusCounter *
_dbus_counter_ref (DBusCounter *counter)
{
- _dbus_rmutex_lock (counter->mutex);
-
_dbus_assert (counter->refcount > 0);
counter->refcount += 1;
- _dbus_rmutex_unlock (counter->mutex);
-
return counter;
}
@@ -135,20 +123,13 @@
void
_dbus_counter_unref (DBusCounter *counter)
{
- dbus_bool_t last_ref = FALSE;
-
- _dbus_rmutex_lock (counter->mutex);
-
_dbus_assert (counter->refcount > 0);
counter->refcount -= 1;
- last_ref = (counter->refcount == 0);
- _dbus_rmutex_unlock (counter->mutex);
-
- if (last_ref)
+ if (counter->refcount == 0)
{
- _dbus_rmutex_free_at_location (&counter->mutex);
+
dbus_free (counter);
}
}
@@ -167,11 +148,7 @@
_dbus_counter_adjust_size (DBusCounter *counter,
long delta)
{
- long old = 0;
-
- _dbus_rmutex_lock (counter->mutex);
-
- old = counter->size_value;
+ long old = counter->size_value;
counter->size_value += delta;
@@ -191,8 +168,6 @@
(old >= counter->notify_size_guard_value &&
counter->size_value < counter->notify_size_guard_value)))
counter->notify_pending = TRUE;
-
- _dbus_rmutex_unlock (counter->mutex);
}
/**
@@ -206,20 +181,11 @@
void
_dbus_counter_notify (DBusCounter *counter)
{
- DBusCounterNotifyFunction notify_function = NULL;
- void *notify_data = NULL;
-
- _dbus_rmutex_lock (counter->mutex);
if (counter->notify_pending)
{
counter->notify_pending = FALSE;
- notify_function = counter->notify_function;
- notify_data = counter->notify_data;
+ (* counter->notify_function) (counter, counter->notify_data);
}
- _dbus_rmutex_unlock (counter->mutex);
-
- if (notify_function != NULL)
- (* notify_function) (counter, notify_data);
}
/**
@@ -236,11 +202,7 @@
_dbus_counter_adjust_unix_fd (DBusCounter *counter,
long delta)
{
- long old = 0;
-
- _dbus_rmutex_lock (counter->mutex);
-
- old = counter->unix_fd_value;
+ long old = counter->unix_fd_value;
counter->unix_fd_value += delta;
@@ -260,8 +222,6 @@
(old >= counter->notify_unix_fd_guard_value &&
counter->unix_fd_value < counter->notify_unix_fd_guard_value)))
counter->notify_pending = TRUE;
-
- _dbus_rmutex_unlock (counter->mutex);
}
/**
@@ -306,13 +266,11 @@
DBusCounterNotifyFunction function,
void *user_data)
{
- _dbus_rmutex_lock (counter->mutex);
counter->notify_size_guard_value = size_guard_value;
counter->notify_unix_fd_guard_value = unix_fd_guard_value;
counter->notify_function = function;
counter->notify_data = user_data;
counter->notify_pending = FALSE;
- _dbus_rmutex_unlock (counter->mutex);
}
#ifdef DBUS_ENABLE_STATS
diff --git a/dbus/dbus-server-debug-pipe.c b/dbus/dbus-server-debug-pipe.c
index ca0be87..419db5c 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* @defgroup DBusServerDebugPipe DBusServerDebugPipe
@@ -166,9 +166,8 @@
goto nomem_2;
if (!_dbus_server_init_base (&debug_server->base,
- &debug_vtable, &address,
- error))
- goto fail_3;
+ &debug_vtable, &address))
+ goto nomem_3;
if (!_dbus_hash_table_insert_string (server_pipe_hash,
debug_server->name,
@@ -184,7 +183,7 @@
nomem_4:
_dbus_server_finalize_base (&debug_server->base);
- fail_3:
+ nomem_3:
dbus_free (debug_server->name);
nomem_2:
_dbus_string_free (&address);
@@ -192,8 +191,7 @@
dbus_free (debug_server);
nomem_0:
pipe_hash_unref ();
- if (error != NULL && !dbus_error_is_set (error))
- _DBUS_SET_OOM (error);
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return NULL;
}
@@ -213,7 +211,7 @@
DBusTransport *client_transport;
DBusTransport *server_transport;
DBusConnection *connection;
- DBusSocket client_fd, server_fd;
+ int client_fd, server_fd;
DBusServer *server;
DBusString address;
@@ -248,7 +246,8 @@
return NULL;
}
- if (!_dbus_socketpair (&client_fd, &server_fd, FALSE, NULL))
+ if (!_dbus_full_duplex_pipe (&client_fd, &server_fd, FALSE,
+ NULL))
{
_dbus_verbose ("failed to create full duplex pipe\n");
dbus_set_error (error, DBUS_ERROR_FAILED, "Could not create full-duplex pipe");
@@ -269,7 +268,7 @@
_dbus_string_free (&address);
- _dbus_socket_invalidate (&client_fd);
+ client_fd = -1;
server_transport = _dbus_transport_new_for_socket (server_fd,
&server->guid_hex, NULL);
@@ -281,7 +280,7 @@
return NULL;
}
- _dbus_socket_invalidate (&server_fd);
+ server_fd = -1;
if (!_dbus_transport_set_auth_mechanisms (server_transport,
(const char**) server->auth_mechanisms))
@@ -428,5 +427,5 @@
/** @} */
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-server-launchd.c b/dbus/dbus-server-launchd.c
index 818ba8c..db4673c 100644
--- a/dbus/dbus-server-launchd.c
+++ b/dbus/dbus-server-launchd.c
@@ -40,9 +40,7 @@
#include <launch.h>
#include <errno.h>
-#include "dbus-misc.h"
#include "dbus-server-socket.h"
-#include "dbus-sysdeps-unix.h"
/* put other private launchd functions here */
@@ -178,16 +176,18 @@
else
{
display = launch_data_get_string(environment_param);
- dbus_setenv ("DISPLAY", display);
+ _dbus_setenv ("DISPLAY", display);
}
}
}
}
- server = _dbus_server_new_for_socket (&launchd_fd, 1, &address, 0, error);
+ server = _dbus_server_new_for_socket (&launchd_fd, 1, &address, 0);
if (server == NULL)
{
+ dbus_set_error (error, DBUS_ERROR_NO_SERVER,
+ "Unable to listen on launchd fd %d.", launchd_fd);
goto l_failed_0;
}
diff --git a/dbus/dbus-server-protected.h b/dbus/dbus-server-protected.h
index f613bf3..dd5234b 100644
--- a/dbus/dbus-server-protected.h
+++ b/dbus/dbus-server-protected.h
@@ -93,16 +93,15 @@
dbus_bool_t _dbus_server_init_base (DBusServer *server,
const DBusServerVTable *vtable,
- const DBusString *address,
- DBusError *error);
+ const DBusString *address);
void _dbus_server_finalize_base (DBusServer *server);
dbus_bool_t _dbus_server_add_watch (DBusServer *server,
DBusWatch *watch);
void _dbus_server_remove_watch (DBusServer *server,
DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
-void _dbus_server_toggle_all_watches (DBusServer *server,
- dbus_bool_t enabled);
+void _dbus_server_toggle_watch (DBusServer *server,
+ DBusWatch *watch,
+ dbus_bool_t enabled);
dbus_bool_t _dbus_server_add_timeout (DBusServer *server,
DBusTimeout *timeout);
void _dbus_server_remove_timeout (DBusServer *server,
@@ -111,9 +110,7 @@
DBusTimeout *timeout,
dbus_bool_t enabled);
-DBUS_PRIVATE_EXPORT
void _dbus_server_ref_unlocked (DBusServer *server);
-DBUS_PRIVATE_EXPORT
void _dbus_server_unref_unlocked (DBusServer *server);
typedef enum
diff --git a/dbus/dbus-server-socket.c b/dbus/dbus-server-socket.c
index d716f50..ae4b602 100644
--- a/dbus/dbus-server-socket.c
+++ b/dbus/dbus-server-socket.c
@@ -51,7 +51,7 @@
{
DBusServer base; /**< Parent class members. */
int n_fds; /**< Number of active file handles */
- DBusSocket *fds; /**< File descriptor or DBUS_SOCKET_INVALID if disconnected. */
+ int *fds; /**< File descriptor or -1 if disconnected. */
DBusWatch **watch; /**< File descriptor watch. */
char *socket_name; /**< Name of domain socket, to unlink if appropriate */
DBusNonceFile *noncefile; /**< Nonce file used to authenticate clients */
@@ -84,25 +84,24 @@
/* Return value is just for memory, not other failures. */
static dbus_bool_t
handle_new_client_fd_and_unlock (DBusServer *server,
- DBusSocket client_fd)
+ int client_fd)
{
DBusConnection *connection;
DBusTransport *transport;
DBusNewConnectionFunction new_connection_function;
void *new_connection_data;
- _dbus_verbose ("Creating new client connection with fd %" DBUS_SOCKET_FORMAT "\n",
- _dbus_socket_printable (client_fd));
+ _dbus_verbose ("Creating new client connection with fd %d\n", client_fd);
HAVE_LOCK_CHECK (server);
- if (!_dbus_set_socket_nonblocking (client_fd, NULL))
+ if (!_dbus_set_fd_nonblocking (client_fd, NULL))
{
SERVER_UNLOCK (server);
return TRUE;
}
- transport = _dbus_transport_new_for_socket (client_fd, &server->guid_hex, NULL);
+ transport = _dbus_transport_new_for_socket (client_fd, &server->guid_hex, FALSE);
if (transport == NULL)
{
_dbus_close_socket (client_fd, NULL);
@@ -183,28 +182,25 @@
if (flags & DBUS_WATCH_READABLE)
{
- DBusSocket client_fd;
- DBusSocket listen_fd;
- int saved_errno;
+ int client_fd;
+ int listen_fd;
- listen_fd = _dbus_watch_get_socket (watch);
+ listen_fd = dbus_watch_get_socket (watch);
if (socket_server->noncefile)
client_fd = _dbus_accept_with_noncefile (listen_fd, socket_server->noncefile);
else
client_fd = _dbus_accept (listen_fd);
- saved_errno = _dbus_save_socket_errno ();
-
- if (!_dbus_socket_is_valid (client_fd))
+ if (client_fd < 0)
{
/* EINTR handled for us */
- if (_dbus_get_is_errno_eagain_or_ewouldblock (saved_errno))
+ if (_dbus_get_is_errno_eagain_or_ewouldblock ())
_dbus_verbose ("No client available to accept after all\n");
else
_dbus_verbose ("Failed to accept a client connection: %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
SERVER_UNLOCK (server);
}
@@ -244,7 +240,7 @@
}
_dbus_close_socket (socket_server->fds[i], NULL);
- _dbus_socket_invalidate (&socket_server->fds[i]);
+ socket_server->fds[i] = -1;
}
if (socket_server->socket_name != NULL)
@@ -277,16 +273,14 @@
* @param n_fds number of file descriptors
* @param address the server's address
* @param noncefile to be used for authentication (NULL if not needed)
- * @param error location to store reason for failure
- * @returns the new server, or #NULL on OOM or other error.
+ * @returns the new server, or #NULL if no memory.
*
*/
DBusServer*
-_dbus_server_new_for_socket (DBusSocket *fds,
+_dbus_server_new_for_socket (int *fds,
int n_fds,
const DBusString *address,
- DBusNonceFile *noncefile,
- DBusError *error)
+ DBusNonceFile *noncefile)
{
DBusServerSocket *socket_server;
DBusServer *server;
@@ -294,11 +288,11 @@
socket_server = dbus_new0 (DBusServerSocket, 1);
if (socket_server == NULL)
- goto failed_0;
+ return NULL;
socket_server->noncefile = noncefile;
- socket_server->fds = dbus_new (DBusSocket, n_fds);
+ socket_server->fds = dbus_new (int, n_fds);
if (!socket_server->fds)
goto failed_0;
@@ -310,7 +304,7 @@
{
DBusWatch *watch;
- watch = _dbus_watch_new (_dbus_socket_get_pollable (fds[i]),
+ watch = _dbus_watch_new (fds[i],
DBUS_WATCH_READABLE,
TRUE,
socket_handle_watch, socket_server,
@@ -324,8 +318,7 @@
}
if (!_dbus_server_init_base (&socket_server->base,
- &socket_vtable, address,
- error))
+ &socket_vtable, address))
goto failed_2;
server = (DBusServer*)socket_server;
@@ -369,10 +362,6 @@
failed_0:
dbus_free (socket_server);
-
- if (error != NULL && !dbus_error_is_set (error))
- _DBUS_SET_OOM (error);
-
return NULL;
}
@@ -404,7 +393,7 @@
dbus_bool_t use_nonce)
{
DBusServer *server;
- DBusSocket *listen_fds = NULL;
+ int *listen_fds = NULL;
int nlisten_fds = 0, i;
DBusString address;
DBusString host_str;
@@ -485,13 +474,11 @@
}
- server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile, error);
+ server = _dbus_server_new_for_socket (listen_fds, nlisten_fds, &address, noncefile);
if (server == NULL)
{
- if (noncefile != NULL)
- goto failed_4;
- else
- goto failed_2;
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ goto failed_4;
}
_dbus_string_free (&port_str);
diff --git a/dbus/dbus-server-socket.h b/dbus/dbus-server-socket.h
index 1a589f7..3aec712 100644
--- a/dbus/dbus-server-socket.h
+++ b/dbus/dbus-server-socket.h
@@ -29,14 +29,12 @@
DBUS_BEGIN_DECLS
-DBusServer* _dbus_server_new_for_socket (DBusSocket *fds,
+DBusServer* _dbus_server_new_for_socket (int *fds,
int n_fds,
const DBusString *address,
- DBusNonceFile *noncefile,
- DBusError *error);
+ DBusNonceFile *noncefile);
DBusServer* _dbus_server_new_for_autolaunch (const DBusString *address,
DBusError *error);
-DBUS_PRIVATE_EXPORT
DBusServer* _dbus_server_new_for_tcp_socket (const char *host,
const char *bind,
const char *port,
diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
index 92664a8..130f66e 100644
--- a/dbus/dbus-server-unix.c
+++ b/dbus/dbus-server-unix.c
@@ -66,75 +66,25 @@
const char *path = dbus_address_entry_get_value (entry, "path");
const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir");
const char *abstract = dbus_address_entry_get_value (entry, "abstract");
- const char *runtime = dbus_address_entry_get_value (entry, "runtime");
- int mutually_exclusive_modes = 0;
- mutually_exclusive_modes = (path != NULL) + (tmpdir != NULL) +
- (abstract != NULL) + (runtime != NULL);
-
- if (mutually_exclusive_modes < 1)
+ if (path == NULL && tmpdir == NULL && abstract == NULL)
{
_dbus_set_bad_address(error, "unix",
- "path or tmpdir or abstract or runtime",
+ "path or tmpdir or abstract",
NULL);
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
- if (mutually_exclusive_modes > 1)
+ if ((path && tmpdir) ||
+ (path && abstract) ||
+ (tmpdir && abstract))
{
_dbus_set_bad_address(error, NULL, NULL,
- "cannot specify two of \"path\", \"tmpdir\", \"abstract\" and \"runtime\" at the same time");
+ "cannot specify two of \"path\" and \"tmpdir\" and \"abstract\" at the same time");
return DBUS_SERVER_LISTEN_BAD_ADDRESS;
}
- if (runtime != NULL)
- {
- DBusString full_path;
- DBusString filename;
- const char *runtimedir;
-
- if (strcmp (runtime, "yes") != 0)
- {
- _dbus_set_bad_address(error, NULL, NULL,
- "if given, the only value allowed for \"runtime\" is \"yes\"");
- return DBUS_SERVER_LISTEN_BAD_ADDRESS;
- }
-
- runtimedir = _dbus_getenv ("XDG_RUNTIME_DIR");
-
- if (runtimedir == NULL)
- {
- dbus_set_error (error,
- DBUS_ERROR_NOT_SUPPORTED, "\"XDG_RUNTIME_DIR\" is not set");
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
-
- _dbus_string_init_const (&filename, "bus");
-
- if (!_dbus_string_init (&full_path))
- {
- _DBUS_SET_OOM (error);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
-
- if (!_dbus_string_append (&full_path, runtimedir) ||
- !_dbus_concat_dir_and_file (&full_path, &filename))
- {
- _dbus_string_free (&full_path);
- _DBUS_SET_OOM (error);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
-
- /* We can safely use filesystem sockets in the runtime directory,
- * and they are preferred because they can be bind-mounted between
- * Linux containers. */
- *server_p = _dbus_server_new_for_domain_socket (
- _dbus_string_get_const_data (&full_path),
- FALSE, error);
-
- _dbus_string_free (&full_path);
- }
- else if (tmpdir != NULL)
+ if (tmpdir != NULL)
{
DBusString full_path;
DBusString filename;
@@ -152,22 +102,10 @@
return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
}
- if (!_dbus_string_append (&filename, "dbus-"))
- {
- _dbus_string_free (&full_path);
- _dbus_string_free (&filename);
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
-
- if (!_dbus_generate_random_ascii (&filename, 10, error))
- {
- _dbus_string_free (&full_path);
- _dbus_string_free (&filename);
- return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
- }
-
- if (!_dbus_string_append (&full_path, tmpdir) ||
+ if (!_dbus_string_append (&filename,
+ "dbus-") ||
+ !_dbus_generate_random_ascii (&filename, 10) ||
+ !_dbus_string_append (&full_path, tmpdir) ||
!_dbus_concat_dir_and_file (&full_path, &filename))
{
_dbus_string_free (&full_path);
@@ -211,8 +149,7 @@
}
else if (strcmp (method, "systemd") == 0)
{
- int i, n;
- DBusSocket *fds;
+ int n, *fds;
DBusString address;
n = _dbus_listen_systemd_sockets (&fds, error);
@@ -222,40 +159,27 @@
return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
}
- if (!_dbus_string_init (&address))
- goto systemd_oom;
+ _dbus_string_init_const (&address, "systemd:");
- for (i = 0; i < n; i++)
- {
- if (i > 0)
- {
- if (!_dbus_string_append (&address, ";"))
- goto systemd_oom;
- }
- if (!_dbus_append_address_from_socket (fds[i], &address, error))
- goto systemd_err;
- }
-
- *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL, error);
+ *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
if (*server_p == NULL)
- goto systemd_err;
+ {
+ int i;
+
+ for (i = 0; i < n; i++)
+ {
+ _dbus_close_socket (fds[i], NULL);
+ }
+ dbus_free (fds);
+
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+ return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
+ }
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)
{
@@ -303,7 +227,7 @@
DBusError *error)
{
DBusServer *server;
- DBusSocket listen_fd;
+ int listen_fd;
DBusString address;
char *path_copy;
DBusString path_str;
@@ -341,17 +265,18 @@
}
}
- listen_fd.fd = _dbus_listen_unix_socket (path, abstract, error);
+ listen_fd = _dbus_listen_unix_socket (path, abstract, error);
- if (listen_fd.fd < 0)
+ if (listen_fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed_1;
}
- server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0, error);
+ server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0);
if (server == NULL)
{
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed_2;
}
diff --git a/dbus/dbus-server.c b/dbus/dbus-server.c
index 9af906f..b62c2b4 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-server-debug-pipe.h"
#endif
#include "dbus-address.h"
@@ -105,14 +105,12 @@
* @param server the server.
* @param vtable the vtable for the subclass.
* @param address the server's address
- * @param error location to store reason for failure
* @returns #TRUE on success.
*/
dbus_bool_t
_dbus_server_init_base (DBusServer *server,
const DBusServerVTable *vtable,
- const DBusString *address,
- DBusError *error)
+ const DBusString *address)
{
server->vtable = vtable;
@@ -132,33 +130,29 @@
server->published_address = FALSE;
if (!_dbus_string_init (&server->guid_hex))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
+ return FALSE;
- if (!_dbus_generate_uuid (&server->guid, error))
- goto failed;
+ _dbus_generate_uuid (&server->guid);
if (!_dbus_uuid_encode (&server->guid, &server->guid_hex))
- goto oom;
+ goto failed;
server->address = copy_address_with_guid_appended (address,
&server->guid_hex);
if (server->address == NULL)
- goto oom;
+ goto failed;
_dbus_rmutex_new_at_location (&server->mutex);
if (server->mutex == NULL)
- goto oom;
+ goto failed;
server->watches = _dbus_watch_list_new ();
if (server->watches == NULL)
- goto oom;
+ goto failed;
server->timeouts = _dbus_timeout_list_new ();
if (server->timeouts == NULL)
- goto oom;
+ goto failed;
_dbus_data_slot_list_init (&server->slot_list);
@@ -166,8 +160,6 @@
return TRUE;
- oom:
- _DBUS_SET_OOM (error);
failed:
_dbus_rmutex_free_at_location (&server->mutex);
server->mutex = NULL;
@@ -320,17 +312,26 @@
}
/**
- * Toggles all watch and notifies app via server's
- * DBusWatchToggledFunction if available.
+ * Toggles a watch and notifies app via server's
+ * DBusWatchToggledFunction if available. It's an error to call this
+ * function on a watch that was not previously added.
*
* @param server the server.
+ * @param watch the watch to toggle.
* @param enabled whether to enable or disable
*/
void
-_dbus_server_toggle_all_watches (DBusServer *server,
- dbus_bool_t enabled)
+_dbus_server_toggle_watch (DBusServer *server,
+ DBusWatch *watch,
+ dbus_bool_t enabled)
{
- _dbus_watch_list_toggle_all_watches (server->watches, enabled);
+ _dbus_assert (watch != NULL);
+
+ HAVE_LOCK_CHECK (server);
+ protected_change_watch (server, watch,
+ NULL, NULL,
+ _dbus_watch_list_toggle_watch,
+ enabled);
}
/** Function to be called in protected_change_timeout() with refcount held */
@@ -528,7 +529,7 @@
} listen_funcs[] = {
{ _dbus_server_listen_socket }
, { _dbus_server_listen_platform_specific }
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
, { _dbus_server_listen_debug_pipe }
#endif
};
@@ -698,11 +699,13 @@
_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",
@@ -733,18 +736,13 @@
_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
- * 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
- */
+ /* undo side-effect first */
_dbus_atomic_inc (&server->refcount);
_dbus_warn_check_failed (_dbus_return_if_fail_warning_format,
_DBUS_FUNCTION_NAME, "old_refcount > 0",
@@ -779,7 +777,16 @@
{
_dbus_return_if_fail (server != NULL);
- dbus_server_ref (server);
+#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
+
SERVER_LOCK (server);
_dbus_assert (server->vtable->disconnect != NULL);
@@ -1051,10 +1058,7 @@
{
copy = _dbus_dup_string_array (mechanisms);
if (copy == NULL)
- {
- SERVER_UNLOCK (server);
- return FALSE;
- }
+ return FALSE;
}
else
copy = NULL;
@@ -1067,8 +1071,9 @@
return TRUE;
}
-static DBusDataSlotAllocator slot_allocator =
- _DBUS_DATA_SLOT_ALLOCATOR_INIT (_DBUS_LOCK_NAME (server_slots));
+
+static DBusDataSlotAllocator slot_allocator;
+_DBUS_DEFINE_GLOBAL_LOCK (server_slots);
/**
* Allocates an integer ID to be used for storing application-specific
@@ -1088,6 +1093,7 @@
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);
}
@@ -1184,7 +1190,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <string.h>
@@ -1240,4 +1246,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c
index febfba2..d182752 100644
--- a/dbus/dbus-sha.c
+++ b/dbus/dbus-sha.c
@@ -511,7 +511,7 @@
/** @} */ /* end of exported functions */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -966,4 +966,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-shared.h b/dbus/dbus-shared.h
index 7ab9103..6a57670 100644
--- a/dbus/dbus-shared.h
+++ b/dbus/dbus-shared.h
@@ -86,11 +86,6 @@
*/
/** The interface exported by the object with #DBUS_SERVICE_DBUS and #DBUS_PATH_DBUS */
#define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
-/** The monitoring interface exported by the dbus-daemon */
-#define DBUS_INTERFACE_MONITORING "org.freedesktop.DBus.Monitoring"
-
-/** The verbose interface exported by the dbus-daemon */
-#define DBUS_INTERFACE_VERBOSE "org.freedesktop.DBus.Verbose"
/** The interface supported by introspectable objects */
#define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
/** The interface supported by objects with properties */
diff --git a/dbus/dbus-shell.c b/dbus/dbus-shell.c
index 2384961..111d39d 100644
--- a/dbus/dbus-shell.c
+++ b/dbus/dbus-shell.c
@@ -150,7 +150,7 @@
* 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 @p quoted_string need not actually contain quoted or
+ * The @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 @@
* be escaped with backslash. Otherwise double quotes preserve things
* literally.
*
- * @param quoted_string shell-quoted string
+ * @quoted_string: shell-quoted string
**/
char*
_dbus_shell_unquote (const char *quoted_string)
@@ -544,10 +544,10 @@
* does contain such expansions, they are passed through
* literally. Free the returned vector with dbus_free_string_array().
*
- * @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
+ * @command_line: command line to parse
+ * @argcp: return location for number of args
+ * @argvp: return location for array of args
+ * @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 6f1521b..c130de5 100644
--- a/dbus/dbus-signature.c
+++ b/dbus/dbus-signature.c
@@ -410,7 +410,7 @@
/** @} */ /* end of DBusSignature group */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* @ingroup DBusSignatureInternals
@@ -428,7 +428,7 @@
const char *sig;
dbus_bool_t boolres;
- _DBUS_STATIC_ASSERT (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
+ _dbus_assert (sizeof (DBusSignatureIter) >= sizeof (DBusSignatureRealIter));
sig = "";
_dbus_assert (dbus_signature_validate (sig, NULL));
diff --git a/dbus/dbus-socket-set-epoll.c b/dbus/dbus-socket-set-epoll.c
index aedc26d..4cd9a56 100644
--- a/dbus/dbus-socket-set-epoll.c
+++ b/dbus/dbus-socket-set-epoll.c
@@ -136,7 +136,7 @@
static dbus_bool_t
socket_set_epoll_add (DBusSocketSet *set,
- DBusPollable fd,
+ int fd,
unsigned int flags,
dbus_bool_t enabled)
{
@@ -189,7 +189,7 @@
static void
socket_set_epoll_enable (DBusSocketSet *set,
- DBusPollable fd,
+ int fd,
unsigned int flags)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
@@ -229,7 +229,7 @@
static void
socket_set_epoll_disable (DBusSocketSet *set,
- DBusPollable fd)
+ int fd)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
struct epoll_event event;
@@ -264,7 +264,7 @@
static void
socket_set_epoll_remove (DBusSocketSet *set,
- DBusPollable fd)
+ int fd)
{
DBusSocketSetEpoll *self = socket_set_epoll_cast (set);
int err;
diff --git a/dbus/dbus-socket-set-poll.c b/dbus/dbus-socket-set-poll.c
index 623e28f..65a1fd2 100644
--- a/dbus/dbus-socket-set-poll.c
+++ b/dbus/dbus-socket-set-poll.c
@@ -44,7 +44,7 @@
#define MINIMUM_SIZE 8
/* If we're in the regression tests, force reallocation to happen sooner */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#define DEFAULT_SIZE_HINT 1
#else
#define DEFAULT_SIZE_HINT MINIMUM_SIZE
@@ -114,7 +114,7 @@
static dbus_bool_t
socket_set_poll_add (DBusSocketSet *set,
- DBusPollable fd,
+ int fd,
unsigned int flags,
dbus_bool_t enabled)
{
@@ -123,7 +123,7 @@
int i;
for (i = 0; i < self->n_fds; i++)
- _dbus_assert (!_dbus_pollable_equals (self->fds[i].fd, fd));
+ _dbus_assert (self->fds[i].fd != fd);
#endif
if (self->n_reserved >= self->n_allocated)
@@ -142,8 +142,8 @@
self->n_allocated += REALLOC_INCREMENT;
}
- _dbus_verbose ("before adding fd %" DBUS_POLLABLE_FORMAT " to %p, %d en/%d res/%d alloc\n",
- _dbus_pollable_printable (fd), self, self->n_fds, self->n_reserved, self->n_allocated);
+ _dbus_verbose ("before adding fd %d to %p, %d en/%d res/%d alloc\n",
+ fd, self, self->n_fds, self->n_reserved, self->n_allocated);
_dbus_assert (self->n_reserved >= self->n_fds);
_dbus_assert (self->n_allocated > self->n_reserved);
@@ -161,7 +161,7 @@
static void
socket_set_poll_enable (DBusSocketSet *set,
- DBusPollable fd,
+ int fd,
unsigned int flags)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
@@ -169,7 +169,7 @@
for (i = 0; i < self->n_fds; i++)
{
- if (_dbus_pollable_equals (self->fds[i].fd, fd))
+ if (self->fds[i].fd == fd)
{
self->fds[i].events = watch_flags_to_poll_events (flags);
return;
@@ -187,14 +187,14 @@
static void
socket_set_poll_disable (DBusSocketSet *set,
- DBusPollable fd)
+ int fd)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
int i;
for (i = 0; i < self->n_fds; i++)
{
- if (_dbus_pollable_equals (self->fds[i].fd, fd))
+ if (self->fds[i].fd == fd)
{
if (i != self->n_fds - 1)
{
@@ -210,15 +210,15 @@
static void
socket_set_poll_remove (DBusSocketSet *set,
- DBusPollable fd)
+ int fd)
{
DBusSocketSetPoll *self = socket_set_poll_cast (set);
socket_set_poll_disable (set, fd);
self->n_reserved--;
- _dbus_verbose ("after removing fd %" DBUS_POLLABLE_FORMAT " from %p, %d en/%d res/%d alloc\n",
- _dbus_pollable_printable (fd), self, self->n_fds, self->n_reserved, self->n_allocated);
+ _dbus_verbose ("after removing fd %d from %p, %d en/%d res/%d alloc\n",
+ fd, self, self->n_fds, self->n_reserved, self->n_allocated);
_dbus_assert (self->n_fds <= self->n_reserved);
_dbus_assert (self->n_reserved <= self->n_allocated);
diff --git a/dbus/dbus-socket-set.h b/dbus/dbus-socket-set.h
index bcc263a..3b71a92 100644
--- a/dbus/dbus-socket-set.h
+++ b/dbus/dbus-socket-set.h
@@ -29,10 +29,9 @@
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#include <dbus/dbus.h>
-#include <dbus/dbus-sysdeps.h>
typedef struct {
- DBusPollable fd;
+ int fd;
unsigned int flags;
} DBusSocketEvent;
@@ -42,16 +41,16 @@
struct DBusSocketSetClass {
void (*free) (DBusSocketSet *self);
dbus_bool_t (*add) (DBusSocketSet *self,
- DBusPollable fd,
+ int fd,
unsigned int flags,
dbus_bool_t enabled);
void (*remove) (DBusSocketSet *self,
- DBusPollable fd);
+ int fd);
void (*enable) (DBusSocketSet *self,
- DBusPollable fd,
+ int fd,
unsigned int flags);
void (*disable) (DBusSocketSet *self,
- DBusPollable fd);
+ int fd);
int (*poll) (DBusSocketSet *self,
DBusSocketEvent *revents,
int max_events,
@@ -72,7 +71,7 @@
static inline dbus_bool_t
_dbus_socket_set_add (DBusSocketSet *self,
- DBusPollable fd,
+ int fd,
unsigned int flags,
dbus_bool_t enabled)
{
@@ -81,14 +80,14 @@
static inline void
_dbus_socket_set_remove (DBusSocketSet *self,
- DBusPollable fd)
+ int fd)
{
(self->cls->remove) (self, fd);
}
static inline void
_dbus_socket_set_enable (DBusSocketSet *self,
- DBusPollable fd,
+ int fd,
unsigned int flags)
{
(self->cls->enable) (self, fd, flags);
@@ -96,7 +95,7 @@
static inline void
_dbus_socket_set_disable (DBusSocketSet *self,
- DBusPollable fd)
+ int fd)
{
(self->cls->disable) (self, fd);
}
diff --git a/dbus/dbus-sockets-win.h b/dbus/dbus-sockets-win.h
index a35d653..4e1ab8c 100644
--- a/dbus/dbus-sockets-win.h
+++ b/dbus/dbus-sockets-win.h
@@ -41,12 +41,25 @@
#include <errno.h>
#endif
+#define DBUS_SOCKET_IS_INVALID(s) ((SOCKET)(s) == INVALID_SOCKET)
#define DBUS_SOCKET_API_RETURNS_ERROR(n) ((n) == SOCKET_ERROR)
#define DBUS_SOCKET_SET_ERRNO() (_dbus_win_set_errno (WSAGetLastError()))
+#define DBUS_CLOSE_SOCKET(s) closesocket(s)
+
#else
-#error "dbus-sockets-win.h should not be included on non-Windows"
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <errno.h>
+
+#define DBUS_SOCKET_IS_INVALID(s) ((s) < 0)
+#define DBUS_SOCKET_API_RETURNS_ERROR(n) ((n) < 0)
+#define DBUS_SOCKET_SET_ERRNO() /* empty */
+
+#define DBUS_CLOSE_SOCKET(s) close(s)
#endif /* !Win32 */
diff --git a/dbus/dbus-spawn-win.c b/dbus/dbus-spawn-win.c
index f741f92..3dae4f3 100644
--- a/dbus/dbus-spawn-win.c
+++ b/dbus/dbus-spawn-win.c
@@ -60,15 +60,15 @@
*/
struct DBusBabysitter
{
- DBusAtomic refcount;
+ int refcount;
HANDLE start_sync_event;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
HANDLE end_sync_event;
#endif
- char *log_name;
+ char *executable;
DBusSpawnChildSetupFunc child_setup;
void *user_data;
@@ -77,8 +77,8 @@
char **envp;
HANDLE child_handle;
- DBusSocket socket_to_babysitter; /* Connection to the babysitter thread */
- DBusSocket socket_to_main;
+ int socket_to_babysitter; /* Connection to the babysitter thread */
+ int socket_to_main;
DBusWatchList *watches;
DBusWatch *sitter_watch;
@@ -91,33 +91,16 @@
int child_status;
};
-static void
-_dbus_babysitter_trace_ref (DBusBabysitter *sitter,
- int old_refcount,
- int new_refcount,
- const char *why)
-{
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- static int enabled = -1;
-
- _dbus_trace_ref ("DBusBabysitter", sitter, old_refcount, new_refcount, why,
- "DBUS_BABYSITTER_TRACE", &enabled);
-#endif
-}
-
static DBusBabysitter*
_dbus_babysitter_new (void)
{
DBusBabysitter *sitter;
- dbus_int32_t old_refcount;
sitter = dbus_new0 (DBusBabysitter, 1);
if (sitter == NULL)
return NULL;
- old_refcount = _dbus_atomic_inc (&sitter->refcount);
-
- _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount+1, __FUNCTION__);
+ sitter->refcount = 1;
sitter->start_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL);
if (sitter->start_sync_event == NULL)
@@ -126,7 +109,7 @@
return NULL;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
sitter->end_sync_event = CreateEvent (NULL, FALSE, FALSE, NULL);
if (sitter->end_sync_event == NULL)
{
@@ -137,7 +120,7 @@
sitter->child_handle = NULL;
- sitter->socket_to_babysitter = sitter->socket_to_main = _dbus_socket_get_invalid ();
+ sitter->socket_to_babysitter = sitter->socket_to_main = -1;
sitter->argc = 0;
sitter->argv = NULL;
@@ -165,13 +148,11 @@
DBusBabysitter *
_dbus_babysitter_ref (DBusBabysitter *sitter)
{
- dbus_int32_t old_refcount;
PING();
_dbus_assert (sitter != NULL);
+ _dbus_assert (sitter->refcount > 0);
- old_refcount = _dbus_atomic_inc (&sitter->refcount);
- _dbus_assert (old_refcount > 0);
- _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount+1, __FUNCTION__);
+ sitter->refcount += 1;
return sitter;
}
@@ -190,10 +171,10 @@
sitter->sitter_watch = NULL;
}
- if (sitter->socket_to_babysitter.sock != INVALID_SOCKET)
+ if (sitter->socket_to_babysitter != -1)
{
_dbus_close_socket (sitter->socket_to_babysitter, NULL);
- sitter->socket_to_babysitter.sock = INVALID_SOCKET;
+ sitter->socket_to_babysitter = -1;
}
}
@@ -206,23 +187,21 @@
_dbus_babysitter_unref (DBusBabysitter *sitter)
{
int i;
- dbus_int32_t old_refcount;
PING();
_dbus_assert (sitter != NULL);
+ _dbus_assert (sitter->refcount > 0);
- old_refcount = _dbus_atomic_dec (&sitter->refcount);
- _dbus_assert (old_refcount > 0);
- _dbus_babysitter_trace_ref (sitter, old_refcount, old_refcount-1, __FUNCTION__);
+ sitter->refcount -= 1;
- if (old_refcount == 1)
+ if (sitter->refcount == 0)
{
close_socket_to_babysitter (sitter);
- if (sitter->socket_to_main.sock != INVALID_SOCKET)
+ if (sitter->socket_to_main != -1)
{
_dbus_close_socket (sitter->socket_to_main, NULL);
- sitter->socket_to_main.sock = INVALID_SOCKET;
+ sitter->socket_to_main = -1;
}
PING();
@@ -271,7 +250,7 @@
sitter->start_sync_event = NULL;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (sitter->end_sync_event != NULL)
{
CloseHandle (sitter->end_sync_event);
@@ -279,7 +258,7 @@
}
#endif
- dbus_free (sitter->log_name);
+ dbus_free (sitter->executable);
dbus_free (sitter);
}
@@ -358,7 +337,7 @@
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->log_name, emsg);
+ sitter->executable, emsg);
_dbus_win_free_error_string (emsg);
}
else if (sitter->have_child_status)
@@ -366,14 +345,14 @@
PING();
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
"Process %s exited with status %d",
- sitter->log_name, sitter->child_status);
+ sitter->executable, sitter->child_status);
}
else
{
PING();
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited, status unknown",
- sitter->log_name);
+ sitter->executable);
}
PING();
}
@@ -603,28 +582,25 @@
static DWORD __stdcall
babysitter (void *parameter)
{
- int ret = 0;
DBusBabysitter *sitter = (DBusBabysitter *) parameter;
- HANDLE handle;
PING();
+ _dbus_babysitter_ref (sitter);
+
if (sitter->child_setup)
{
PING();
(*sitter->child_setup) (sitter->user_data);
}
- _dbus_verbose ("babysitter: spawning %s\n", sitter->log_name);
+ _dbus_verbose ("babysitter: spawning %s\n", sitter->executable);
PING();
- handle = spawn_program (sitter->log_name, sitter->argv, sitter->envp);
+ sitter->child_handle = spawn_program (sitter->executable,
+ sitter->argv, sitter->envp);
PING();
- if (handle != INVALID_HANDLE_VALUE)
- {
- sitter->child_handle = handle;
- }
- else
+ if (sitter->child_handle == (HANDLE) -1)
{
sitter->child_handle = NULL;
sitter->have_spawn_errno = TRUE;
@@ -636,39 +612,36 @@
if (sitter->child_handle != NULL)
{
+ int ret;
DWORD status;
PING();
- // wait until process finished
WaitForSingleObject (sitter->child_handle, INFINITE);
PING();
ret = GetExitCodeProcess (sitter->child_handle, &status);
- if (ret)
- {
- sitter->child_status = status;
- sitter->have_child_status = TRUE;
- }
+
+ sitter->child_status = status;
+ sitter->have_child_status = TRUE;
CloseHandle (sitter->child_handle);
sitter->child_handle = NULL;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
SetEvent (sitter->end_sync_event);
#endif
PING();
- send (sitter->socket_to_main.sock, " ", 1, 0);
+ send (sitter->socket_to_main, " ", 1, 0);
_dbus_babysitter_unref (sitter);
- return ret ? 0 : 1;
+ return 0;
}
dbus_bool_t
_dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
- const char *log_name,
char **argv,
char **envp,
DBusSpawnChildSetupFunc child_setup,
@@ -680,10 +653,8 @@
DWORD sitter_thread_id;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- _dbus_assert (argv[0] != NULL);
- if (sitter_p != NULL)
- *sitter_p = NULL;
+ *sitter_p = NULL;
PING();
sitter = _dbus_babysitter_new ();
@@ -696,26 +667,17 @@
sitter->child_setup = child_setup;
sitter->user_data = user_data;
- 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)
+ sitter->executable = _dbus_strdup (argv[0]);
+ if (sitter->executable == NULL)
{
_DBUS_SET_OOM (error);
goto out0;
}
PING();
- if (!_dbus_socketpair (&sitter->socket_to_babysitter,
- &sitter->socket_to_main,
- FALSE, error))
+ if (!_dbus_full_duplex_pipe (&sitter->socket_to_babysitter,
+ &sitter->socket_to_main,
+ FALSE, error))
goto out0;
sitter->sitter_watch = _dbus_watch_new (sitter->socket_to_babysitter,
@@ -751,7 +713,7 @@
PING();
sitter_thread = (HANDLE) CreateThread (NULL, 0, babysitter,
- _dbus_babysitter_ref (sitter), 0, &sitter_thread_id);
+ sitter, 0, &sitter_thread_id);
if (sitter_thread == 0)
{
@@ -791,7 +753,7 @@
sitter->finished_data = user_data;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static char *
get_test_exec (const char *exe,
@@ -842,7 +804,7 @@
/*** Test launching nonexistent binary */
argv[0] = "/this/does/not/exist/32542sdgafgafdg";
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
NULL, NULL,
&error))
{
@@ -895,7 +857,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
NULL, NULL,
&error))
{
@@ -950,7 +912,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
NULL, NULL,
&error))
{
@@ -1005,7 +967,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv, NULL,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv, NULL,
NULL, NULL,
&error))
{
diff --git a/dbus/dbus-spawn.c b/dbus/dbus-spawn.c
index 45f3d87..ef00801 100644
--- a/dbus/dbus-spawn.c
+++ b/dbus/dbus-spawn.c
@@ -38,12 +38,6 @@
#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;
@@ -180,48 +174,6 @@
* 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 */
@@ -240,10 +192,9 @@
{
int refcount; /**< Reference count */
- char *log_name; /**< the name under which to log messages about this
- process being spawned */
+ char *executable; /**< executable name to use in error messages */
- DBusSocket socket_to_babysitter; /**< Connection to the babysitter process */
+ int socket_to_babysitter; /**< Connection to the babysitter process */
int error_pipe_from_child; /**< Connection to the process that does the exec() */
pid_t sitter_pid; /**< PID Of the babysitter */
@@ -275,7 +226,7 @@
sitter->refcount = 1;
- sitter->socket_to_babysitter.fd = -1;
+ sitter->socket_to_babysitter = -1;
sitter->error_pipe_from_child = -1;
sitter->sitter_pid = -1;
@@ -357,18 +308,15 @@
if (ret == 0)
kill (sitter->sitter_pid, SIGKILL);
+ again:
if (ret == 0)
- {
- do
- {
- ret = waitpid (sitter->sitter_pid, &status, 0);
- }
- while (_DBUS_UNLIKELY (ret < 0 && errno == EINTR));
- }
+ ret = waitpid (sitter->sitter_pid, &status, 0);
if (ret < 0)
{
- if (errno == ECHILD)
+ if (errno == EINTR)
+ goto again;
+ else 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",
@@ -395,7 +343,7 @@
if (sitter->watches)
_dbus_watch_list_free (sitter->watches);
- dbus_free (sitter->log_name);
+ dbus_free (sitter->executable);
dbus_free (sitter);
}
@@ -454,25 +402,9 @@
{
if (what == CHILD_EXITED)
{
- /* Do not reset sitter->errnum to 0 here. We get here if
- * the babysitter reports that the grandchild process has
- * exited, and there are two ways that can happen:
- *
- * 1. grandchild successfully exec()s the desired process,
- * but then the desired process exits or is terminated
- * by a signal. The babysitter observes this and reports
- * CHILD_EXITED.
- *
- * 2. grandchild fails to exec() the desired process,
- * attempts to report the exec() failure (which
- * we will receive as CHILD_EXEC_FAILED), and then
- * exits itself (which will prompt the babysitter to
- * send CHILD_EXITED). We want the CHILD_EXEC_FAILED
- * to take precedence (and have its errno logged),
- * which _dbus_babysitter_set_child_exit_error() does.
- */
sitter->have_child_status = TRUE;
sitter->status = arg;
+ sitter->errnum = 0;
_dbus_verbose ("recorded child status exited = %d signaled = %d exitstatus = %d termsig = %d\n",
WIFEXITED (sitter->status), WIFSIGNALED (sitter->status),
WEXITSTATUS (sitter->status), WTERMSIG (sitter->status));
@@ -538,10 +470,10 @@
sitter->sitter_watch = NULL;
}
- if (sitter->socket_to_babysitter.fd >= 0)
+ if (sitter->socket_to_babysitter >= 0)
{
_dbus_close_socket (sitter->socket_to_babysitter, NULL);
- sitter->socket_to_babysitter.fd = -1;
+ sitter->socket_to_babysitter = -1;
}
}
@@ -561,7 +493,7 @@
if (sitter->error_pipe_from_child >= 0)
{
- _dbus_close (sitter->error_pipe_from_child, NULL);
+ _dbus_close_socket (sitter->error_pipe_from_child, NULL);
sitter->error_pipe_from_child = -1;
}
}
@@ -577,7 +509,7 @@
if (revents & _DBUS_POLLIN)
{
_dbus_verbose ("Reading data from babysitter\n");
- if (read_data (sitter, sitter->socket_to_babysitter.fd) != READ_STATUS_OK)
+ if (read_data (sitter, sitter->socket_to_babysitter) != READ_STATUS_OK)
close_socket_to_babysitter (sitter);
}
else if (revents & (_DBUS_POLLERR | _DBUS_POLLHUP))
@@ -623,9 +555,9 @@
++i;
}
- if (sitter->socket_to_babysitter.fd >= 0)
+ if (sitter->socket_to_babysitter >= 0)
{
- fds[i].fd = sitter->socket_to_babysitter.fd;
+ fds[i].fd = sitter->socket_to_babysitter;
fds[i].events = _DBUS_POLLIN;
fds[i].revents = 0;
++i;
@@ -659,7 +591,7 @@
--i;
if (fds[i].fd == sitter->error_pipe_from_child)
handle_error_pipe (sitter, fds[i].revents);
- else if (fds[i].fd == sitter->socket_to_babysitter.fd)
+ else if (fds[i].fd == sitter->socket_to_babysitter)
handle_babysitter_socket (sitter, fds[i].revents);
}
}
@@ -672,7 +604,7 @@
* Macro returns #TRUE if the babysitter still has live sockets open to the
* babysitter child or the grandchild.
*/
-#define LIVE_CHILDREN(sitter) ((sitter)->socket_to_babysitter.fd >= 0 || (sitter)->error_pipe_from_child >= 0)
+#define LIVE_CHILDREN(sitter) ((sitter)->socket_to_babysitter >= 0 || (sitter)->error_pipe_from_child >= 0)
/**
* Blocks until the babysitter process gives us the PID of the spawned grandchild,
@@ -712,7 +644,7 @@
;
/* We will have exited the babysitter when the child has exited */
- return sitter->socket_to_babysitter.fd < 0;
+ return sitter->socket_to_babysitter < 0;
}
/**
@@ -766,34 +698,34 @@
{
dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
"Failed to execute program %s: %s",
- sitter->log_name, _dbus_strerror (sitter->errnum));
+ sitter->executable, _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->log_name, _dbus_strerror (sitter->errnum));
+ sitter->executable, _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->log_name, WEXITSTATUS (sitter->status));
+ sitter->executable, WEXITSTATUS (sitter->status));
else if (WIFSIGNALED (sitter->status))
dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_SIGNALED,
"Process %s received signal %d",
- sitter->log_name, WTERMSIG (sitter->status));
+ sitter->executable, WTERMSIG (sitter->status));
else
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited abnormally",
- sitter->log_name);
+ sitter->executable);
}
else
{
dbus_set_error (error, DBUS_ERROR_FAILED,
"Process %s exited, reason unknown",
- sitter->log_name);
+ sitter->executable);
}
}
@@ -846,7 +778,7 @@
if (fd == sitter->error_pipe_from_child)
handle_error_pipe (sitter, revents);
- else if (fd == sitter->socket_to_babysitter.fd)
+ else if (fd == sitter->socket_to_babysitter)
handle_babysitter_socket (sitter, revents);
while (LIVE_CHILDREN (sitter) &&
@@ -855,7 +787,7 @@
/* fd.o #32992: if the handle_* methods closed their sockets, they previously
* didn't always remove the watches. Check that we don't regress. */
- _dbus_assert (sitter->socket_to_babysitter.fd != -1 || sitter->sitter_watch == NULL);
+ _dbus_assert (sitter->socket_to_babysitter != -1 || sitter->sitter_watch == NULL);
_dbus_assert (sitter->error_pipe_from_child != -1 || sitter->error_watch == NULL);
if (_dbus_babysitter_get_child_exited (sitter) &&
@@ -875,14 +807,9 @@
#define WRITE_END 1
-/* 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.
+/* Avoids a danger in threaded situations (calling close()
+ * on a file descriptor twice, and another thread has
+ * re-opened it since the first close)
*/
static int
close_and_invalidate (int *fd)
@@ -893,7 +820,7 @@
return -1;
else
{
- ret = _dbus_close (*fd, NULL);
+ ret = _dbus_close_socket (*fd, NULL);
*fd = -1;
}
@@ -1009,7 +936,7 @@
DBusSpawnChildSetupFunc child_setup,
void *user_data)
{
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
int i, max_open;
#endif
@@ -1020,7 +947,7 @@
if (child_setup)
(* child_setup) (user_data);
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
max_open = sysconf (_SC_OPEN_MAX);
for (i = 3; i < max_open; i++)
@@ -1033,7 +960,7 @@
retval = fcntl (i, F_GETFD);
if (retval != -1 && !(retval & FD_CLOEXEC))
- _dbus_warn ("Fd %d did not have the close-on-exec flag set!\n", i);
+ _dbus_warn ("Fd %d did not have the close-on-exec flag set!\n", i);
}
#endif
@@ -1188,7 +1115,8 @@
}
/**
- * Spawns a new process. The child_setup
+ * Spawns a new process. The executable name and argv[0]
+ * are the same, both are provided in argv[0]. The child_setup
* function is passed the given user_data and is run in the child
* just before calling exec().
*
@@ -1198,9 +1126,8 @@
* 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, or #NULL to copy the parent's
+ * @param env the environment (not used on unix yet)
* @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
@@ -1208,7 +1135,6 @@
*/
dbus_bool_t
_dbus_spawn_async_with_babysitter (DBusBabysitter **sitter_p,
- const char *log_name,
char **argv,
char **env,
DBusSpawnChildSetupFunc child_setup,
@@ -1217,15 +1143,10 @@
{
DBusBabysitter *sitter;
int child_err_report_pipe[2] = { -1, -1 };
- DBusSocket babysitter_pipe[2] = { DBUS_SOCKET_INIT, DBUS_SOCKET_INIT };
+ 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;
@@ -1239,17 +1160,8 @@
return FALSE;
}
- 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)
+ sitter->executable = _dbus_strdup (argv[0]);
+ if (sitter->executable == NULL)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto cleanup_and_fail;
@@ -1258,7 +1170,7 @@
if (!make_pipe (child_err_report_pipe, error))
goto cleanup_and_fail;
- if (!_dbus_socketpair (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error))
+ if (!_dbus_full_duplex_pipe (&babysitter_pipe[0], &babysitter_pipe[1], TRUE, error))
goto cleanup_and_fail;
/* Setting up the babysitter is only useful in the parent,
@@ -1287,7 +1199,7 @@
goto cleanup_and_fail;
}
- sitter->sitter_watch = _dbus_watch_new (babysitter_pipe[0].fd,
+ sitter->sitter_watch = _dbus_watch_new (babysitter_pipe[0],
DBUS_WATCH_READABLE,
TRUE, handle_watch, sitter, NULL);
if (sitter->sitter_watch == NULL)
@@ -1309,16 +1221,7 @@
}
_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)
@@ -1341,53 +1244,19 @@
/* Close the parent's end of the pipes. */
close_and_invalidate (&child_err_report_pipe[READ_END]);
- close_and_invalidate (&babysitter_pipe[0].fd);
+ close_and_invalidate (&babysitter_pipe[0]);
/* Create the child that will exec () */
grandchild_pid = fork ();
if (grandchild_pid < 0)
{
- write_err_and_exit (babysitter_pipe[1].fd,
+ write_err_and_exit (babysitter_pipe[1],
CHILD_FORK_FAILED);
_dbus_assert_not_reached ("Got to code after write_err_and_exit()");
}
else if (grandchild_pid == 0)
- {
-#ifdef __linux__
- int fd = -1;
-
-#ifdef O_CLOEXEC
- fd = open ("/proc/self/oom_score_adj", O_WRONLY | O_CLOEXEC);
-#endif
-
- if (fd < 0)
- {
- fd = open ("/proc/self/oom_score_adj", O_WRONLY);
- _dbus_fd_set_close_on_exec (fd);
- }
-
- if (fd >= 0)
- {
- if (write (fd, "0", sizeof (char)) < 0)
- _dbus_warn ("writing oom_score_adj error: %s\n", strerror (errno));
- _dbus_close (fd, NULL);
- }
-#endif
- /* Go back to ignoring SIGPIPE, since it's evil
- */
- signal (SIGPIPE, SIG_IGN);
-
- close_and_invalidate (&babysitter_pipe[1].fd);
-#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,
@@ -1396,12 +1265,7 @@
}
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].fd);
+ babysit (grandchild_pid, babysitter_pipe[1]);
_dbus_assert_not_reached ("Got to code after babysit()");
}
}
@@ -1409,14 +1273,10 @@
{
/* Close the uncared-about ends of the pipes */
close_and_invalidate (&child_err_report_pipe[WRITE_END]);
- close_and_invalidate (&babysitter_pipe[1].fd);
-#ifdef HAVE_SYSTEMD
- close_and_invalidate (&fd_out);
- close_and_invalidate (&fd_err);
-#endif
+ close_and_invalidate (&babysitter_pipe[1]);
sitter->socket_to_babysitter = babysitter_pipe[0];
- babysitter_pipe[0].fd = -1;
+ babysitter_pipe[0] = -1;
sitter->error_pipe_from_child = child_err_report_pipe[READ_END];
child_err_report_pipe[READ_END] = -1;
@@ -1441,12 +1301,8 @@
close_and_invalidate (&child_err_report_pipe[READ_END]);
close_and_invalidate (&child_err_report_pipe[WRITE_END]);
- close_and_invalidate (&babysitter_pipe[0].fd);
- close_and_invalidate (&babysitter_pipe[1].fd);
-#ifdef HAVE_SYSTEMD
- close_and_invalidate (&fd_out);
- close_and_invalidate (&fd_err);
-#endif
+ close_and_invalidate (&babysitter_pipe[0]);
+ close_and_invalidate (&babysitter_pipe[1]);
if (sitter != NULL)
_dbus_babysitter_unref (sitter);
@@ -1465,7 +1321,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static char *
get_test_exec (const char *exe,
@@ -1508,7 +1364,7 @@
/*** Test launching nonexistent binary */
argv[0] = "/this/does/not/exist/32542sdgafgafdg";
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_nonexistent", argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv,
NULL, NULL, NULL,
&error))
{
@@ -1557,7 +1413,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_segfault", argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv,
NULL, NULL, NULL,
&error))
{
@@ -1608,7 +1464,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_exit", argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv,
NULL, NULL, NULL,
&error))
{
@@ -1659,7 +1515,7 @@
return TRUE;
}
- if (_dbus_spawn_async_with_babysitter (&sitter, "spawn_and_kill", argv,
+ if (_dbus_spawn_async_with_babysitter (&sitter, argv,
NULL, NULL, NULL,
&error))
{
diff --git a/dbus/dbus-spawn.h b/dbus/dbus-spawn.h
index e6baae9..a8814fb 100644
--- a/dbus/dbus-spawn.h
+++ b/dbus/dbus-spawn.h
@@ -39,7 +39,6 @@
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 3babc05..922580d 100644
--- a/dbus/dbus-string-util.c
+++ b/dbus/dbus-string-util.c
@@ -115,7 +115,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
#include <stdio.h>
@@ -935,4 +935,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-string.c b/dbus/dbus-string.c
index 98d9f2b..9accdb1 100644
--- a/dbus/dbus-string.c
+++ b/dbus/dbus-string.c
@@ -133,11 +133,11 @@
int allocate_size)
{
DBusRealString *real;
-
- _DBUS_STATIC_ASSERT (sizeof (DBusString) == sizeof (DBusRealString));
-
+
_dbus_assert (str != NULL);
+ _dbus_assert (sizeof (DBusString) == sizeof (DBusRealString));
+
real = (DBusRealString*) str;
/* It's very important not to touch anything
@@ -234,23 +234,6 @@
}
/**
- * Initializes a string from another string. The
- * string must eventually be freed with _dbus_string_free().
- *
- * @param str memory to hold the string
- * @param from instance from which the string is initialized
- * @returns #TRUE on success, #FALSE if no memory
- */
-dbus_bool_t
-_dbus_string_init_from_string(DBusString *str,
- const DBusString *from)
-{
- if (!_dbus_string_init (str))
- return FALSE;
- return _dbus_string_append (str, _dbus_string_get_const_data (from));
-}
-
-/**
* Frees a string created by _dbus_string_init().
*
* @param str memory where the string is stored.
@@ -263,14 +246,6 @@
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;
@@ -302,9 +277,9 @@
return TRUE;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/* Not using this feature at the moment,
- * so marked DBUS_ENABLE_EMBEDDED_TESTS-only
+ * so marked DBUS_BUILD_TESTS-only
*/
/**
* Locks a string such that any attempts to change the string will
@@ -328,7 +303,7 @@
#define MAX_WASTE 48
compact (real, MAX_WASTE);
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
static dbus_bool_t
reallocate_for_length (DBusRealString *real,
@@ -352,11 +327,14 @@
* disable asserts to profile, you don't get this destroyer
* of profiles.
*/
-#if defined (DBUS_ENABLE_EMBEDDED_TESTS) && !defined (DBUS_DISABLE_ASSERT)
+#ifdef DBUS_DISABLE_ASSERT
+#else
+#ifdef DBUS_BUILD_TESTS
new_allocated = 0; /* ensure a realloc every time so that we go
* through all malloc failure codepaths
*/
-#endif
+#endif /* DBUS_BUILD_TESTS */
+#endif /* !DBUS_DISABLE_ASSERT */
/* But be sure we always alloc at least space for the new length */
new_allocated = MAX (new_allocated,
@@ -955,9 +933,29 @@
#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
@@ -971,7 +969,7 @@
dbus_bool_t
_dbus_string_insert_2_aligned (DBusString *str,
int insert_at,
- const unsigned char octets[2])
+ const unsigned char octets[4])
{
DBUS_STRING_PREAMBLE (str);
@@ -1073,7 +1071,6 @@
const char *format,
va_list args)
{
- dbus_bool_t ret = FALSE;
int len;
va_list args_copy;
@@ -1085,21 +1082,21 @@
len = _dbus_printf_string_upper_bound (format, args);
if (len < 0)
- goto out;
+ return FALSE;
if (!_dbus_string_lengthen (str, len))
{
- goto out;
+ /* don't leak the copy */
+ va_end (args_copy);
+ return FALSE;
}
vsprintf ((char*) (real->str + (real->len - len)),
format, args_copy);
- ret = TRUE;
-out:
va_end (args_copy);
- return ret;
+ return TRUE;
}
/**
@@ -1580,11 +1577,19 @@
*
* 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) & 0xFFFFF800) != 0xD800) && \
+ ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
+ ((Char) & 0xFFFE) != 0xFFFE)
/**
* Finds the given substring in the string,
@@ -1899,7 +1904,7 @@
* @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_ENABLE_EMBEDDED_TESTS
+ * code only with ifdef DBUS_BUILD_TESTS
*
* @param source the source string
* @param dest the destination string (contents are replaced)
@@ -1943,7 +1948,7 @@
return TRUE;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* Deletes up to and including the first blank space
* in the string.
@@ -1962,7 +1967,7 @@
}
#endif
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* Deletes any leading blanks in the string
*
@@ -2223,7 +2228,7 @@
*/
dbus_bool_t
_dbus_string_append_byte_as_hex (DBusString *str,
- unsigned char byte)
+ int 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 adf709b..4ef59db 100644
--- a/dbus/dbus-string.h
+++ b/dbus/dbus-string.h
@@ -67,72 +67,54 @@
#define _dbus_string_get_const_data_len(s,start,len) (((const char*)(((DBusString*)(s))->dummy1)) + (start))
#endif
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_init (DBusString *str);
-DBUS_PRIVATE_EXPORT
void _dbus_string_init_const (DBusString *str,
const char *value);
-DBUS_PRIVATE_EXPORT
void _dbus_string_init_const_len (DBusString *str,
const char *value,
int len);
dbus_bool_t _dbus_string_init_preallocated (DBusString *str,
int allocate_size);
-
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_string_init_from_string (DBusString *str,
- const DBusString *from);
-DBUS_PRIVATE_EXPORT
void _dbus_string_free (DBusString *str);
void _dbus_string_lock (DBusString *str);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_compact (DBusString *str,
int max_waste);
#ifndef _dbus_string_get_data
-DBUS_PRIVATE_EXPORT
char* _dbus_string_get_data (DBusString *str);
#endif /* _dbus_string_get_data */
#ifndef _dbus_string_get_const_data
-DBUS_PRIVATE_EXPORT
const char* _dbus_string_get_const_data (const DBusString *str);
#endif /* _dbus_string_get_const_data */
char* _dbus_string_get_data_len (DBusString *str,
int start,
int len);
#ifndef _dbus_string_get_const_data_len
-DBUS_PRIVATE_EXPORT
const char* _dbus_string_get_const_data_len (const DBusString *str,
int start,
int len);
#endif
#ifndef _dbus_string_set_byte
-DBUS_PRIVATE_EXPORT
void _dbus_string_set_byte (DBusString *str,
int i,
unsigned char byte);
#endif
#ifndef _dbus_string_get_byte
-DBUS_PRIVATE_EXPORT
unsigned char _dbus_string_get_byte (const DBusString *str,
int start);
#endif /* _dbus_string_get_byte */
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_insert_bytes (DBusString *str,
int i,
int n_bytes,
unsigned char byte);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_insert_byte (DBusString *str,
int i,
unsigned char byte);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_steal_data (DBusString *str,
char **data_return);
dbus_bool_t _dbus_string_steal_data_len (DBusString *str,
char **data_return,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_copy_data (const DBusString *str,
char **data_return);
dbus_bool_t _dbus_string_copy_data_len (const DBusString *str,
@@ -142,65 +124,37 @@
void _dbus_string_copy_to_buffer (const DBusString *str,
char *buffer,
int len);
-DBUS_PRIVATE_EXPORT
void _dbus_string_copy_to_buffer_with_nul (const DBusString *str,
char *buffer,
int avail_len);
#ifndef _dbus_string_get_length
-DBUS_PRIVATE_EXPORT
int _dbus_string_get_length (const DBusString *str);
#endif /* !_dbus_string_get_length */
-/**
- * Get the string's length as an unsigned integer, for comparison with
- * size_t and similar unsigned types that does not trigger compiler
- * warnings about potential value changes during conversion.
- *
- * DBusString lengths are signed for historical reasons, but we know that
- * the length is always >= 0 (and DBUS_GENERIC_STRING_PREAMBLE asserts
- * that this is the case) so we know that this cast does not change the
- * value.
- */
-static inline unsigned int
-_dbus_string_get_length_uint (const DBusString *str)
-{
- return (unsigned int) _dbus_string_get_length (str);
-}
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_lengthen (DBusString *str,
int additional_length);
-DBUS_PRIVATE_EXPORT
void _dbus_string_shorten (DBusString *str,
int length_to_remove);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_set_length (DBusString *str,
int length);
dbus_bool_t _dbus_string_align_length (DBusString *str,
int alignment);
dbus_bool_t _dbus_string_alloc_space (DBusString *str,
int extra_bytes);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append (DBusString *str,
const char *buffer);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_len (DBusString *str,
const char *buffer,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_int (DBusString *str,
long value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_uint (DBusString *str,
unsigned long value);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_byte (DBusString *str,
unsigned char byte);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_printf (DBusString *str,
const char *format,
...) _DBUS_GNUC_PRINTF (2, 3);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_append_printf_valist (DBusString *str,
const char *format,
va_list args);
@@ -216,16 +170,13 @@
dbus_bool_t _dbus_string_insert_alignment (DBusString *str,
int *insert_at,
int alignment);
-DBUS_PRIVATE_EXPORT
void _dbus_string_delete (DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_move (DBusString *source,
int start,
DBusString *dest,
int insert_at);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_copy (const DBusString *source,
int start,
DBusString *dest,
@@ -235,44 +186,36 @@
int len,
DBusString *dest,
int insert_at);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_copy_len (const DBusString *source,
int start,
int len,
DBusString *dest,
int insert_at);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_replace_len (const DBusString *source,
int start,
int len,
DBusString *dest,
int replace_at,
int replace_len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_split_on_byte (DBusString *source,
unsigned char byte,
DBusString *tail);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_parse_int (const DBusString *str,
int start,
long *value_return,
int *end_return);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_parse_uint (const DBusString *str,
int start,
unsigned long *value_return,
int *end_return);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_find (const DBusString *str,
int start,
const char *substr,
int *found);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_find_eol (const DBusString *str,
int start,
int *found,
int *found_len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_find_to (const DBusString *str,
int start,
int end,
@@ -282,80 +225,62 @@
int start,
unsigned char byte,
int *found);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_find_blank (const DBusString *str,
int start,
int *found);
-DBUS_PRIVATE_EXPORT
void _dbus_string_skip_blank (const DBusString *str,
int start,
int *end);
-DBUS_PRIVATE_EXPORT
void _dbus_string_skip_white (const DBusString *str,
int start,
int *end);
void _dbus_string_skip_white_reverse (const DBusString *str,
int end,
int *start);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_equal (const DBusString *a,
const DBusString *b);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_equal_c_str (const DBusString *a,
const char *c_str);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_equal_len (const DBusString *a,
const DBusString *b,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_equal_substring (const DBusString *a,
int a_start,
int a_len,
const DBusString *b,
int b_start);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_starts_with_c_str (const DBusString *a,
const char *c_str);
dbus_bool_t _dbus_string_ends_with_c_str (const DBusString *a,
const char *c_str);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_pop_line (DBusString *source,
DBusString *dest);
-DBUS_PRIVATE_EXPORT
void _dbus_string_delete_first_word (DBusString *str);
-DBUS_PRIVATE_EXPORT
void _dbus_string_delete_leading_blanks (DBusString *str);
-DBUS_PRIVATE_EXPORT
void _dbus_string_chop_white (DBusString *str);
dbus_bool_t _dbus_string_append_byte_as_hex (DBusString *str,
- unsigned char byte);
-DBUS_PRIVATE_EXPORT
+ int byte);
dbus_bool_t _dbus_string_hex_encode (const DBusString *source,
int start,
DBusString *dest,
int insert_at);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_hex_decode (const DBusString *source,
int start,
int *end_return,
DBusString *dest,
int insert_at);
-DBUS_PRIVATE_EXPORT
void _dbus_string_tolower_ascii (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
void _dbus_string_toupper_ascii (const DBusString *str,
int start,
int len);
dbus_bool_t _dbus_string_validate_ascii (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_validate_utf8 (const DBusString *str,
int start,
int len);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_string_validate_nul (const DBusString *str,
int start,
int len);
diff --git a/dbus/dbus-syntax.c b/dbus/dbus-syntax.c
index 7ef659c..4792287 100644
--- a/dbus/dbus-syntax.c
+++ b/dbus/dbus-syntax.c
@@ -93,7 +93,7 @@
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param name a potentially invalid interface name, which must not be #NULL
+ * @param path a potentially invalid interface name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -140,7 +140,7 @@
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param name a potentially invalid member name, which must not be #NULL
+ * @param path a potentially invalid member name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -187,7 +187,7 @@
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param name a potentially invalid error name, which must not be #NULL
+ * @param path a potentially invalid error name, which must not be #NULL
* @param error error return
* @returns #TRUE if name is valid
*/
@@ -234,7 +234,7 @@
* is also checked, since it assumes that the string ends at the first zero
* byte according to normal C conventions.
*
- * @param name a potentially invalid bus name, which must not be #NULL
+ * @param path 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 1300ec3..c60457b 100644
--- a/dbus/dbus-sysdeps-pthread.c
+++ b/dbus/dbus-sysdeps-pthread.c
@@ -36,14 +36,12 @@
#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 */
@@ -283,20 +281,5 @@
*/
check_monotonic_clock ();
(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);
+ return dbus_threads_init (NULL);
}
diff --git a/dbus/dbus-sysdeps-thread-win.c b/dbus/dbus-sysdeps-thread-win.c
index 0887a54..e30e7b8 100644
--- a/dbus/dbus-sysdeps-thread-win.c
+++ b/dbus/dbus-sysdeps-thread-win.c
@@ -30,21 +30,6 @@
#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 */
@@ -284,19 +269,6 @@
return FALSE;
}
- return TRUE;
+ return dbus_threads_init (NULL);
}
-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 6bba557..3f35d99 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -29,7 +29,6 @@
#include "dbus-sysdeps-unix.h"
#include "dbus-threads.h"
#include "dbus-protocol.h"
-#include "dbus-file.h"
#include "dbus-transport.h"
#include "dbus-string.h"
#include "dbus-userdb.h"
@@ -54,10 +53,9 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <netinet/in.h>
-#include <netinet/tcp.h>
#include <netdb.h>
#include <grp.h>
-#include <arpa/inet.h>
+#include <cutils/sockets.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
@@ -74,21 +72,12 @@
#ifdef HAVE_GETPEERUCRED
#include <ucred.h>
#endif
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
#ifdef HAVE_ADT
#include <bsm/adt.h>
#endif
-#ifdef HAVE_SYSTEMD
-#include <systemd/sd-daemon.h>
-#endif
-
-#if !DBUS_USE_SYNC
-#include <pthread.h>
-#endif
+#include "sd-daemon.h"
#ifndef O_BINARY
#define O_BINARY 0
@@ -134,84 +123,6 @@
#endif /* Solaris */
-/**
- * Ensure that the standard file descriptors stdin, stdout and stderr
- * are open, by opening /dev/null if necessary.
- *
- * This function does not use DBusError, to avoid calling malloc(), so
- * that it can be used in contexts where an async-signal-safe function
- * is required (for example after fork()). Instead, on failure it sets
- * errno and returns something like "Failed to open /dev/null" in
- * *error_str_p. Callers are expected to combine *error_str_p
- * with _dbus_strerror (errno) to get a full error report.
- *
- * This function can only be called while single-threaded: either during
- * startup of an executable, or after fork().
- */
-dbus_bool_t
-_dbus_ensure_standard_fds (DBusEnsureStandardFdsFlags flags,
- const char **error_str_p)
-{
- static int const relevant_flag[] = { DBUS_FORCE_STDIN_NULL,
- DBUS_FORCE_STDOUT_NULL,
- DBUS_FORCE_STDERR_NULL };
- /* Should always get replaced with the real error before use */
- const char *error_str = "Failed mysteriously";
- int devnull = -1;
- int saved_errno;
- /* This function relies on the standard fds having their POSIX values. */
- _DBUS_STATIC_ASSERT (STDIN_FILENO == 0);
- _DBUS_STATIC_ASSERT (STDOUT_FILENO == 1);
- _DBUS_STATIC_ASSERT (STDERR_FILENO == 2);
- int i;
-
- for (i = STDIN_FILENO; i <= STDERR_FILENO; i++)
- {
- /* Because we rely on being single-threaded, and we want the
- * standard fds to not be close-on-exec, we don't set it
- * close-on-exec. */
- if (devnull < i)
- devnull = open ("/dev/null", O_RDWR);
-
- if (devnull < 0)
- {
- error_str = "Failed to open /dev/null";
- goto out;
- }
-
- /* We already opened all fds < i, so the only way this assertion
- * could fail is if another thread closed one, and we document
- * this function as not safe for multi-threading. */
- _dbus_assert (devnull >= i);
-
- if (devnull != i && (flags & relevant_flag[i]) != 0)
- {
- if (dup2 (devnull, i) < 0)
- {
- error_str = "Failed to dup2 /dev/null onto a standard fd";
- goto out;
- }
- }
- }
-
- error_str = NULL;
-
-out:
- saved_errno = errno;
-
- if (devnull > STDERR_FILENO)
- close (devnull);
-
- if (error_str_p != NULL)
- *error_str_p = error_str;
-
- errno = saved_errno;
- return (error_str == NULL);
-}
-
-static dbus_bool_t _dbus_set_fd_nonblocking (int fd,
- DBusError *error);
-
static dbus_bool_t
_dbus_open_socket (int *fd_p,
int domain,
@@ -226,7 +137,7 @@
cloexec_done = *fd_p >= 0;
/* Check if kernel seems to be too old to know SOCK_CLOEXEC */
- if (*fd_p < 0 && (errno == EINVAL || errno == EPROTOTYPE))
+ if (*fd_p < 0 && errno == EINVAL)
#endif
{
*fd_p = socket (domain, type, protocol);
@@ -280,10 +191,10 @@
* @returns #FALSE if error is set
*/
dbus_bool_t
-_dbus_close_socket (DBusSocket fd,
+_dbus_close_socket (int fd,
DBusError *error)
{
- return _dbus_close (fd.fd, error);
+ return _dbus_close (fd, error);
}
/**
@@ -296,11 +207,11 @@
* @returns number of bytes appended to the string
*/
int
-_dbus_read_socket (DBusSocket fd,
+_dbus_read_socket (int fd,
DBusString *buffer,
int count)
{
- return _dbus_read (fd.fd, buffer, count);
+ return _dbus_read (fd, buffer, count);
}
/**
@@ -314,7 +225,7 @@
* @returns the number of bytes written or -1 on error
*/
int
-_dbus_write_socket (DBusSocket fd,
+_dbus_write_socket (int fd,
const DBusString *buffer,
int start,
int len)
@@ -327,7 +238,7 @@
again:
- bytes_written = send (fd.fd, data, len, MSG_NOSIGNAL);
+ bytes_written = send (fd, data, len, MSG_NOSIGNAL);
if (bytes_written < 0 && errno == EINTR)
goto again;
@@ -335,7 +246,7 @@
return bytes_written;
#else
- return _dbus_write (fd.fd, buffer, start, len);
+ return _dbus_write (fd, buffer, start, len);
#endif
}
@@ -352,7 +263,7 @@
* @returns number of bytes appended to string
*/
int
-_dbus_read_socket_with_unix_fds (DBusSocket fd,
+_dbus_read_socket_with_unix_fds (int fd,
DBusString *buffer,
int count,
int *fds,
@@ -402,15 +313,9 @@
m.msg_control = alloca(m.msg_controllen);
memset(m.msg_control, 0, m.msg_controllen);
- /* Do not include the padding at the end when we tell the kernel
- * how much we're willing to receive. This avoids getting
- * the padding filled with additional fds that we weren't expecting,
- * if a (potentially malicious) sender included them. (fd.o #83622) */
- m.msg_controllen = CMSG_LEN (*n_fds * sizeof(int));
-
again:
- bytes_read = recvmsg (fd.fd, &m, 0
+ bytes_read = recvmsg(fd, &m, 0
#ifdef MSG_CMSG_CLOEXEC
|MSG_CMSG_CLOEXEC
#endif
@@ -432,52 +337,33 @@
struct cmsghdr *cm;
dbus_bool_t found = FALSE;
+ if (m.msg_flags & MSG_CTRUNC)
+ {
+ /* Hmm, apparently the control data was truncated. The bad
+ thing is that we might have completely lost a couple of fds
+ without chance to recover them. Hence let's treat this as a
+ serious error. */
+
+ errno = ENOSPC;
+ _dbus_string_set_length (buffer, start);
+ return -1;
+ }
+
for (cm = CMSG_FIRSTHDR(&m); cm; cm = CMSG_NXTHDR(&m, cm))
if (cm->cmsg_level == SOL_SOCKET && cm->cmsg_type == SCM_RIGHTS)
{
- size_t i;
- int *payload = (int *) CMSG_DATA (cm);
- size_t payload_len_bytes = (cm->cmsg_len - CMSG_LEN (0));
- size_t payload_len_fds = payload_len_bytes / sizeof (int);
- size_t fds_to_use;
+ unsigned i;
- /* Every non-negative int fits in a size_t without truncation,
- * and we already know that *n_fds is non-negative, so
- * casting (size_t) *n_fds is OK */
- _DBUS_STATIC_ASSERT (sizeof (size_t) >= sizeof (int));
+ _dbus_assert(cm->cmsg_len <= CMSG_LEN(*n_fds * sizeof(int)));
+ *n_fds = (cm->cmsg_len - CMSG_LEN(0)) / sizeof(int);
- if (_DBUS_LIKELY (payload_len_fds <= (size_t) *n_fds))
- {
- /* The fds in the payload will fit in our buffer */
- fds_to_use = payload_len_fds;
- }
- else
- {
- /* Too many fds in the payload. This shouldn't happen
- * any more because we're setting m.msg_controllen to
- * the exact number we can accept, but be safe and
- * truncate. */
- fds_to_use = (size_t) *n_fds;
-
- /* Close the excess fds to avoid DoS: if they stayed open,
- * someone could send us an extra fd per message
- * and we'd eventually run out. */
- for (i = fds_to_use; i < payload_len_fds; i++)
- {
- close (payload[i]);
- }
- }
-
- memcpy (fds, payload, fds_to_use * sizeof (int));
+ memcpy(fds, CMSG_DATA(cm), *n_fds * sizeof(int));
found = TRUE;
- /* This cannot overflow because we have chosen fds_to_use
- * to be <= *n_fds */
- *n_fds = (int) fds_to_use;
/* Linux doesn't tell us whether MSG_CMSG_CLOEXEC actually
worked, hence we need to go through this list and set
CLOEXEC everywhere in any case */
- for (i = 0; i < fds_to_use; i++)
+ for (i = 0; i < *n_fds; i++)
_dbus_fd_set_close_on_exec(fds[i]);
break;
@@ -486,26 +372,6 @@
if (!found)
*n_fds = 0;
- if (m.msg_flags & MSG_CTRUNC)
- {
- int i;
-
- /* Hmm, apparently the control data was truncated. The bad
- thing is that we might have completely lost a couple of fds
- without chance to recover them. Hence let's treat this as a
- serious error. */
-
- /* We still need to close whatever fds we *did* receive,
- * otherwise they'll never get closed. (CVE-2020-12049) */
- for (i = 0; i < *n_fds; i++)
- close (fds[i]);
-
- *n_fds = 0;
- errno = ENOSPC;
- _dbus_string_set_length (buffer, start);
- return -1;
- }
-
/* put length back (doesn't actually realloc) */
_dbus_string_set_length (buffer, start + bytes_read);
@@ -520,7 +386,7 @@
}
int
-_dbus_write_socket_with_unix_fds(DBusSocket fd,
+_dbus_write_socket_with_unix_fds(int fd,
const DBusString *buffer,
int start,
int len,
@@ -541,7 +407,7 @@
}
int
-_dbus_write_socket_with_unix_fds_two(DBusSocket fd,
+_dbus_write_socket_with_unix_fds_two(int fd,
const DBusString *buffer1,
int start1,
int len1,
@@ -601,7 +467,7 @@
again:
- bytes_written = sendmsg (fd.fd, &m, 0
+ bytes_written = sendmsg (fd, &m, 0
#if HAVE_DECL_MSG_NOSIGNAL
|MSG_NOSIGNAL
#endif
@@ -633,7 +499,7 @@
* @returns total bytes written from both buffers, or -1 on error
*/
int
-_dbus_write_socket_two (DBusSocket fd,
+_dbus_write_socket_two (int fd,
const DBusString *buffer1,
int start1,
int len1,
@@ -676,7 +542,7 @@
again:
- bytes_written = sendmsg (fd.fd, &m, MSG_NOSIGNAL);
+ bytes_written = sendmsg (fd, &m, MSG_NOSIGNAL);
if (bytes_written < 0 && errno == EINTR)
goto again;
@@ -684,11 +550,17 @@
return bytes_written;
#else
- return _dbus_write_two (fd.fd, buffer1, start1, len1,
+ return _dbus_write_two (fd, buffer1, start1, len1,
buffer2, start2, len2);
#endif
}
+dbus_bool_t
+_dbus_socket_is_invalid (int fd)
+{
+ return fd < 0 ? TRUE : FALSE;
+}
+
/**
* Thin wrapper around the read() system call that appends
* the data it reads to the DBusString buffer. It appends
@@ -862,7 +734,7 @@
}
#else /* HAVE_WRITEV */
{
- int ret1, ret2;
+ int ret1;
ret1 = _dbus_write (fd, buffer1, start1, len1);
if (ret1 == len1 && buffer2 != NULL)
@@ -1013,24 +885,16 @@
{
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
- retval = socketpair (AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
- cloexec_done = (retval >= 0);
-
- if (retval < 0 && (errno == EINVAL || errno == EPROTOTYPE))
+ |SOCK_CLOEXEC
#endif
- {
- retval = socketpair (AF_UNIX, SOCK_STREAM, 0, fds);
- }
-
- if (retval < 0)
+ , 0, fds) < 0)
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
@@ -1039,11 +903,8 @@
return -1;
}
- if (!cloexec_done)
- {
- _dbus_fd_set_close_on_exec (fds[0]);
- _dbus_fd_set_close_on_exec (fds[1]);
- }
+ _dbus_fd_set_close_on_exec (fds[0]);
+ _dbus_fd_set_close_on_exec (fds[1]);
pid = fork ();
if (pid < 0)
@@ -1096,6 +957,39 @@
}
/**
+ * 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.
@@ -1120,11 +1014,35 @@
int listen_fd;
struct sockaddr_un addr;
size_t path_len;
+ unsigned int reuseaddr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("listening on unix socket %s abstract=%d\n",
path, abstract);
+#ifdef ANDROID_MANAGED_SOCKET
+ if (strncmp (path, ANDROID_SOCKET_DIR"/", strlen(ANDROID_SOCKET_DIR"/")) == 0)
+ {
+ const char* suffix;
+ /* init has created a socket for us, pick it up from environ */
+ suffix = &path[strlen (ANDROID_SOCKET_DIR"/")];
+ listen_fd = android_get_control_socket (suffix);
+ if (listen_fd == -1)
+ {
+ dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+ "Could not obtain fd for android socket %s\n", suffix);
+ return -1;
+ }
+
+ _dbus_verbose ("Obtained fd for android socket %s\n", suffix);
+ }
+ else
+ {
+ dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+ "Not an android socket: %s\n", path);
+ return -1;
+ }
+#else
if (!_dbus_open_unix_socket (&listen_fd, error))
{
@@ -1186,7 +1104,7 @@
if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
{
dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
- "Socket name too long\n");
+ "Abstract socket name too long\n");
_dbus_close (listen_fd, NULL);
return -1;
}
@@ -1194,6 +1112,13 @@
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),
@@ -1203,6 +1128,8 @@
return -1;
}
+#endif /* android init managed sockets */
+
if (listen (listen_fd, 30 /* backlog */) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -1212,6 +1139,15 @@
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);
@@ -1219,13 +1155,15 @@
return -1;
}
+#ifndef ANDROID_MANAGED_SOCKET
/* Try opening up the permissions, but if we can't, just go ahead
* and continue, maybe it will be good enough.
*/
if (!abstract && chmod (path, 0777) < 0)
_dbus_warn ("Could not set mode 0777 on socket %s\n",
path);
-
+#endif
+
return listen_fd;
}
@@ -1235,18 +1173,17 @@
*
* This will set FD_CLOEXEC for the sockets returned.
*
- * @param fds the file descriptors
+ * @oaram fds the file descriptors
* @param error return location for errors
* @returns the number of file descriptors
*/
int
-_dbus_listen_systemd_sockets (DBusSocket **fds,
- DBusError *error)
+_dbus_listen_systemd_sockets (int **fds,
+ DBusError *error)
{
-#ifdef HAVE_SYSTEMD
int r, n;
- int fd;
- DBusSocket *new_fds;
+ unsigned fd;
+ int *new_fds;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1288,7 +1225,7 @@
/* OK, the file descriptors are all good, so let's take posession of
them then. */
- new_fds = dbus_new (DBusSocket, n);
+ new_fds = dbus_new (int, n);
if (!new_fds)
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
@@ -1298,13 +1235,21 @@
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);
goto fail;
}
- new_fds[fd - SD_LISTEN_FDS_START].fd = fd;
+ new_fds[fd - SD_LISTEN_FDS_START] = fd;
}
*fds = new_fds;
@@ -1319,11 +1264,6 @@
dbus_free (new_fds);
return -1;
-#else
- dbus_set_error_const (error, DBUS_ERROR_NOT_SUPPORTED,
- "dbus was compiled without systemd support");
- return -1;
-#endif
}
/**
@@ -1339,7 +1279,7 @@
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
-DBusSocket
+int
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
@@ -1348,7 +1288,7 @@
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
-DBusSocket
+int
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
@@ -1356,8 +1296,7 @@
DBusError *error)
{
int saved_errno = 0;
- DBusSocket fd = DBUS_SOCKET_INIT;
- int res;
+ int fd = -1, res;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
@@ -1376,7 +1315,7 @@
dbus_set_error (error,
DBUS_ERROR_BAD_ADDRESS,
"Unknown address family %s", family);
- return _dbus_socket_get_invalid ();
+ return -1;
}
hints.ai_protocol = IPPROTO_TCP;
hints.ai_socktype = SOCK_STREAM;
@@ -1388,25 +1327,25 @@
_dbus_error_from_errno (errno),
"Failed to lookup host/port: \"%s:%s\": %s (%d)",
host, port, gai_strerror(res), res);
- return _dbus_socket_get_invalid ();
+ return -1;
}
tmp = ai;
while (tmp)
{
- if (!_dbus_open_socket (&fd.fd, tmp->ai_family, SOCK_STREAM, 0, error))
+ if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error))
{
freeaddrinfo(ai);
_DBUS_ASSERT_ERROR_IS_SET(error);
- return _dbus_socket_get_invalid ();
+ return -1;
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- if (connect (fd.fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
+ if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
{
saved_errno = errno;
- _dbus_close (fd.fd, NULL);
- fd.fd = -1;
+ _dbus_close(fd, NULL);
+ fd = -1;
tmp = tmp->ai_next;
continue;
}
@@ -1415,13 +1354,13 @@
}
freeaddrinfo(ai);
- if (fd.fd == -1)
+ if (fd == -1)
{
dbus_set_error (error,
_dbus_error_from_errno (saved_errno),
"Failed to connect to socket \"%s:%s\" %s",
host, port, _dbus_strerror(saved_errno));
- return _dbus_socket_get_invalid ();
+ return -1;
}
if (noncefile != NULL)
@@ -1433,16 +1372,16 @@
_dbus_string_free (&noncefileStr);
if (!ret)
- {
- _dbus_close (fd.fd, NULL);
- return _dbus_socket_get_invalid ();
+ {
+ _dbus_close (fd, NULL);
+ return -1;
}
}
- if (!_dbus_set_fd_nonblocking (fd.fd, error))
+ if (!_dbus_set_fd_nonblocking (fd, error))
{
- _dbus_close (fd.fd, NULL);
- return _dbus_socket_get_invalid ();
+ _dbus_close (fd, NULL);
+ return -1;
}
return fd;
@@ -1469,12 +1408,11 @@
const char *port,
const char *family,
DBusString *retport,
- DBusSocket **fds_p,
+ int **fds_p,
DBusError *error)
{
int saved_errno;
- int nlisten_fd = 0, res, i;
- DBusSocket *listen_fd = NULL;
+ int nlisten_fd = 0, *listen_fd = NULL, res, i;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
unsigned int reuseaddr;
@@ -1516,9 +1454,7 @@
tmp = ai;
while (tmp)
{
- int fd = -1, tcp_nodelay_on;
- DBusSocket *newlisten_fd;
-
+ int fd = -1, *newlisten_fd;
if (!_dbus_open_socket (&fd, tmp->ai_family, SOCK_STREAM, 0, error))
{
_DBUS_ASSERT_ERROR_IS_SET(error);
@@ -1533,33 +1469,15 @@
host ? host : "*", port, _dbus_strerror (errno));
}
- /* Nagle's algorithm imposes a huge delay on the initial messages
- going over TCP. */
- tcp_nodelay_on = 1;
- if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &tcp_nodelay_on, sizeof (tcp_nodelay_on)) == -1)
- {
- _dbus_warn ("Failed to set TCP_NODELAY socket option \"%s:%s\": %s",
- host ? host : "*", port, _dbus_strerror (errno));
- }
-
if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
{
saved_errno = errno;
_dbus_close(fd, NULL);
if (saved_errno == EADDRINUSE)
{
- /* Depending on kernel policy, binding to an IPv6 address
- might implicitly bind to a corresponding IPv4
- address or vice versa, resulting in EADDRINUSE for the
- other one (e.g. bindv6only=0 on Linux).
-
- Also, after we "goto redo_lookup_with_port" after binding
- a port on one of the possible addresses, we will
- try to bind that same port on every address, including the
- same address again for a second time; that one will
- also fail with EADDRINUSE.
-
- For both those reasons, ignore EADDRINUSE here */
+ /* Depending on kernel policy, it may or may not
+ be neccessary to bind to both IPv4 & 6 addresses
+ so ignore EADDRINUSE here */
tmp = tmp->ai_next;
continue;
}
@@ -1579,7 +1497,7 @@
goto failed;
}
- newlisten_fd = dbus_realloc(listen_fd, sizeof(DBusSocket)*(nlisten_fd+1));
+ newlisten_fd = dbus_realloc(listen_fd, sizeof(int)*(nlisten_fd+1));
if (!newlisten_fd)
{
saved_errno = errno;
@@ -1590,7 +1508,7 @@
goto failed;
}
listen_fd = newlisten_fd;
- listen_fd[nlisten_fd].fd = fd;
+ listen_fd[nlisten_fd] = fd;
nlisten_fd++;
if (!_dbus_string_get_length(retport))
@@ -1612,7 +1530,7 @@
if (result == -1 ||
(res = getnameinfo ((struct sockaddr*)&addr, addrlen, NULL, 0,
portbuf, sizeof(portbuf),
- NI_NUMERICHOST | NI_NUMERICSERV)) != 0)
+ NI_NUMERICHOST)) != 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to resolve port \"%s:%s\": %s (%s)",
@@ -1656,7 +1574,7 @@
for (i = 0 ; i < nlisten_fd ; i++)
{
- if (!_dbus_set_fd_nonblocking (listen_fd[i].fd, error))
+ if (!_dbus_set_fd_nonblocking (listen_fd[i], error))
{
goto failed;
}
@@ -1670,7 +1588,7 @@
if (ai)
freeaddrinfo(ai);
for (i = 0 ; i < nlisten_fd ; i++)
- _dbus_close(listen_fd[i].fd, NULL);
+ _dbus_close(listen_fd[i], NULL);
dbus_free(listen_fd);
return -1;
}
@@ -1713,19 +1631,13 @@
|MSG_NOSIGNAL
#endif
);
-
- /* 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
+#else
+ bytes_written = send (server_fd, buf, 1, 0
#if HAVE_DECL_MSG_NOSIGNAL
- |MSG_NOSIGNAL
+ |MSG_NOSIGNAL
#endif
- );
- }
+ );
+#endif
if (bytes_written < 0 && errno == EINTR)
goto again;
@@ -1751,130 +1663,12 @@
}
}
-/* return FALSE on OOM, TRUE otherwise, even if no credentials were found */
-static dbus_bool_t
-add_linux_security_label_to_credentials (int client_fd,
- DBusCredentials *credentials)
-{
-#if defined(__linux__) && defined(SO_PEERSEC)
- DBusString buf;
- socklen_t len = 1024;
- dbus_bool_t oom = FALSE;
-
- if (!_dbus_string_init_preallocated (&buf, len) ||
- !_dbus_string_set_length (&buf, len))
- return FALSE;
-
- while (getsockopt (client_fd, SOL_SOCKET, SO_PEERSEC,
- _dbus_string_get_data (&buf), &len) < 0)
- {
- int e = errno;
-
- _dbus_verbose ("getsockopt failed with %s, len now %lu\n",
- _dbus_strerror (e), (unsigned long) len);
-
- if (e != ERANGE || len <= _dbus_string_get_length_uint (&buf))
- {
- _dbus_verbose ("Failed to getsockopt(SO_PEERSEC): %s\n",
- _dbus_strerror (e));
- goto out;
- }
-
- /* If not enough space, len is updated to be enough.
- * Try again with a large enough buffer. */
- if (!_dbus_string_set_length (&buf, len))
- {
- oom = TRUE;
- goto out;
- }
-
- _dbus_verbose ("will try again with %lu\n", (unsigned long) len);
- }
-
- if (len <= 0)
- {
- _dbus_verbose ("getsockopt(SO_PEERSEC) yielded <= 0 bytes: %lu\n",
- (unsigned long) len);
- goto out;
- }
-
- if (len > _dbus_string_get_length_uint (&buf))
- {
- _dbus_verbose ("%lu > %u", (unsigned long) len,
- _dbus_string_get_length_uint (&buf));
- _dbus_assert_not_reached ("getsockopt(SO_PEERSEC) overflowed");
- }
-
- if (_dbus_string_get_byte (&buf, len - 1) == 0)
- {
- /* the kernel included the trailing \0 in its count,
- * but DBusString always has an extra \0 after the data anyway */
- _dbus_verbose ("subtracting trailing \\0\n");
- len--;
- }
-
- if (!_dbus_string_set_length (&buf, len))
- {
- _dbus_assert_not_reached ("shortening string should not lead to OOM");
- oom = TRUE;
- goto out;
- }
-
- if (strlen (_dbus_string_get_const_data (&buf)) != len)
- {
- /* LSM people on the linux-security-module@ mailing list say this
- * should never happen: the label should be a bytestring with
- * an optional trailing \0 */
- _dbus_verbose ("security label from kernel had an embedded \\0, "
- "ignoring it\n");
- goto out;
- }
-
- _dbus_verbose ("getsockopt(SO_PEERSEC): %lu bytes excluding \\0: %s\n",
- (unsigned long) len,
- _dbus_string_get_const_data (&buf));
-
- if (!_dbus_credentials_add_linux_security_label (credentials,
- _dbus_string_get_const_data (&buf)))
- {
- oom = TRUE;
- goto out;
- }
-
-out:
- _dbus_string_free (&buf);
- return !oom;
-#else
- /* no error */
- return TRUE;
-#endif
-}
-
/**
* Reads a single byte which must be nul (an error occurs otherwise),
* and reads unix credentials if available. Clears the credentials
* object, then adds pid/uid if available, so any previous credentials
* stored in the object are lost.
*
- * DBusServer makes the security assumption that the credentials
- * returned by this method are the credentials that were active
- * at the time the socket was opened. Do not add APIs to this
- * method that would break that assumption.
- *
- * In particular, it is incorrect to use any API of the form
- * "get the process ID at the other end of the connection, then
- * determine its uid, gid, or other credentials from the pid"
- * (e.g. looking in /proc on Linux). If we did that, we would
- * be vulnerable to several attacks. A malicious process could
- * queue up the rest of the authentication handshake and a malicious
- * message that it should not be allowed to send, then race with
- * the DBusServer to exec() a more privileged (e.g. setuid) binary that
- * would have been allowed to send that message; or it could exit,
- * and arrange for enough setuid processes to be started that its
- * pid would be recycled for one of those processes with high
- * probability; or it could fd-pass the connection to a more
- * privileged process.
- *
* Return value indicates whether 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
@@ -1891,7 +1685,7 @@
* @returns #TRUE on success
*/
dbus_bool_t
-_dbus_read_credentials_socket (DBusSocket client_fd,
+_dbus_read_credentials_socket (int client_fd,
DBusCredentials *credentials,
DBusError *error)
{
@@ -1907,23 +1701,35 @@
struct cmsghdr hdr;
char cred[CMSG_SPACE (sizeof (struct cmsgcred))];
} cmsg;
-#endif
- /* The POSIX spec certainly doesn't promise this, but
- * we need these assertions to fail as soon as we're wrong about
- * it so we can do the porting fixups
- */
- _DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
- _DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
- _DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
+#elif defined(LOCAL_CREDS)
+ struct {
+ struct cmsghdr hdr;
+ struct sockcred cred;
+ } cmsg;
+#endif
uid_read = DBUS_UID_UNSET;
pid_read = DBUS_PID_UNSET;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
+ /* The POSIX spec certainly doesn't promise this, but
+ * we need these assertions to fail as soon as we're wrong about
+ * it so we can do the porting fixups
+ */
+ _dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
+ _dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
+ _dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
+
_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;
@@ -1931,14 +1737,14 @@
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
-#if defined(HAVE_CMSGCRED)
+#if defined(HAVE_CMSGCRED) || defined(LOCAL_CREDS)
_DBUS_ZERO(cmsg);
msg.msg_control = (caddr_t) &cmsg;
msg.msg_controllen = CMSG_SPACE (sizeof (struct cmsgcred));
#endif
again:
- bytes_read = recvmsg (client_fd.fd, &msg, 0);
+ bytes_read = recvmsg (client_fd, &msg, 0);
if (bytes_read < 0)
{
@@ -1971,18 +1777,20 @@
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
@@ -1990,75 +1798,43 @@
#endif
int cr_len = sizeof (cr);
- if (getsockopt (client_fd.fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) != 0)
+ if (getsockopt (client_fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) == 0 &&
+ cr_len == sizeof (cr))
{
- _dbus_verbose ("Failed to getsockopt(SO_PEERCRED): %s\n",
- _dbus_strerror (errno));
- }
- else if (cr_len != sizeof (cr))
- {
- _dbus_verbose ("Failed to getsockopt(SO_PEERCRED), returned %d bytes, expected %d\n",
- cr_len, (int) sizeof (cr));
+ pid_read = cr.pid;
+ uid_read = cr.uid;
}
else
{
- pid_read = cr.pid;
- uid_read = cr.uid;
- }
-#elif defined(HAVE_UNPCBID) && defined(LOCAL_PEEREID)
- /* Another variant of the above - used on NetBSD
- */
- struct unpcbid cr;
- socklen_t cr_len = sizeof (cr);
-
- if (getsockopt (client_fd.fd, 0, LOCAL_PEEREID, &cr, &cr_len) != 0)
- {
- _dbus_verbose ("Failed to getsockopt(LOCAL_PEEREID): %s\n",
- _dbus_strerror (errno));
- }
- else if (cr_len != sizeof (cr))
- {
- _dbus_verbose ("Failed to getsockopt(LOCAL_PEEREID), returned %d bytes, expected %d\n",
- cr_len, (int) sizeof (cr));
- }
- else
- {
- pid_read = cr.unp_pid;
- uid_read = cr.unp_euid;
+ _dbus_verbose ("Failed to getsockopt() credentials, returned len %d/%d: %s\n",
+ 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;
- for (cmsgp = CMSG_FIRSTHDR (&msg);
- cmsgp != NULL;
- cmsgp = CMSG_NXTHDR (&msg, 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)
{
- 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;
- }
+ uid_read = euid;
}
-
+ else
+ {
+ _dbus_verbose ("Failed to getpeereid() credentials: %s\n", _dbus_strerror (errno));
+ }
#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.fd, &ucred) == 0)
+ if (getpeerucred (client_fd, &ucred) == 0)
{
pid_read = ucred_getpid (ucred);
uid_read = ucred_geteuid (ucred);
@@ -2100,54 +1876,7 @@
}
if (ucred != NULL)
ucred_free (ucred);
-
- /* ----------------------------------------------------------------
- * 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.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
-
+#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEEREID && !HAVE_GETPEERUCRED */
_dbus_verbose ("Socket credentials not supported on this OS\n");
#endif
}
@@ -2161,7 +1890,7 @@
if (pid_read != DBUS_PID_UNSET)
{
- if (!_dbus_credentials_add_pid (credentials, pid_read))
+ if (!_dbus_credentials_add_unix_pid (credentials, pid_read))
{
_DBUS_SET_OOM (error);
return FALSE;
@@ -2177,12 +1906,6 @@
}
}
- if (!add_linux_security_label_to_credentials (client_fd.fd, credentials))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
-
return TRUE;
}
@@ -2204,12 +1927,12 @@
* @returns #TRUE if the byte was sent
*/
dbus_bool_t
-_dbus_send_credentials_socket (DBusSocket server_fd,
+_dbus_send_credentials_socket (int server_fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (write_credentials_byte (server_fd.fd, error))
+ if (write_credentials_byte (server_fd, error))
return TRUE;
else
return FALSE;
@@ -2224,10 +1947,10 @@
* @param listen_fd the listen file descriptor
* @returns the connection fd of the client, or -1 on error
*/
-DBusSocket
-_dbus_accept (DBusSocket listen_fd)
+int
+_dbus_accept (int listen_fd)
{
- DBusSocket client_fd;
+ int client_fd;
struct sockaddr addr;
socklen_t addrlen;
#ifdef HAVE_ACCEPT4
@@ -2239,33 +1962,29 @@
retry:
#ifdef HAVE_ACCEPT4
- /*
- * 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.fd = accept4 (listen_fd.fd, &addr, &addrlen, SOCK_CLOEXEC);
- cloexec_done = client_fd.fd >= 0;
+ /* We assume that if accept4 is available SOCK_CLOEXEC is too */
+ client_fd = accept4 (listen_fd, &addr, &addrlen, SOCK_CLOEXEC);
+ cloexec_done = client_fd >= 0;
- if (client_fd.fd < 0 && (errno == ENOSYS || errno == EINVAL))
+ if (client_fd < 0 && errno == ENOSYS)
#endif
{
- client_fd.fd = accept (listen_fd.fd, &addr, &addrlen);
+ client_fd = accept (listen_fd, &addr, &addrlen);
}
- if (client_fd.fd < 0)
+ if (client_fd < 0)
{
if (errno == EINTR)
goto retry;
}
- _dbus_verbose ("client fd %d accepted\n", client_fd.fd);
+ _dbus_verbose ("client fd %d accepted\n", client_fd);
#ifdef HAVE_ACCEPT4
if (!cloexec_done)
#endif
{
- _dbus_fd_set_close_on_exec(client_fd.fd);
+ _dbus_fd_set_close_on_exec(client_fd);
}
return client_fd;
@@ -2297,16 +2016,6 @@
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))
{
@@ -2632,11 +2341,11 @@
* we need these assertions to fail as soon as we're wrong about
* it so we can do the porting fixups
*/
- _DBUS_STATIC_ASSERT (sizeof (pid_t) <= sizeof (dbus_pid_t));
- _DBUS_STATIC_ASSERT (sizeof (uid_t) <= sizeof (dbus_uid_t));
- _DBUS_STATIC_ASSERT (sizeof (gid_t) <= sizeof (dbus_gid_t));
+ _dbus_assert (sizeof (pid_t) <= sizeof (dbus_pid_t));
+ _dbus_assert (sizeof (uid_t) <= sizeof (dbus_uid_t));
+ _dbus_assert (sizeof (gid_t) <= sizeof (dbus_gid_t));
- if (!_dbus_credentials_add_pid(credentials, _dbus_getpid()))
+ if (!_dbus_credentials_add_unix_pid(credentials, _dbus_getpid()))
return FALSE;
if (!_dbus_credentials_add_unix_uid(credentials, _dbus_geteuid()))
return FALSE;
@@ -2743,12 +2452,7 @@
}
#if !DBUS_USE_SYNC
-/* 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;
+_DBUS_DEFINE_GLOBAL_LOCK (atomic);
#endif
/**
@@ -2764,12 +2468,10 @@
return __sync_add_and_fetch(&atomic->value, 1)-1;
#else
dbus_int32_t res;
-
- pthread_mutex_lock (&atomic_mutex);
+ _DBUS_LOCK (atomic);
res = atomic->value;
atomic->value += 1;
- pthread_mutex_unlock (&atomic_mutex);
-
+ _DBUS_UNLOCK (atomic);
return res;
#endif
}
@@ -2788,11 +2490,10 @@
#else
dbus_int32_t res;
- pthread_mutex_lock (&atomic_mutex);
+ _DBUS_LOCK (atomic);
res = atomic->value;
atomic->value -= 1;
- pthread_mutex_unlock (&atomic_mutex);
-
+ _DBUS_UNLOCK (atomic);
return res;
#endif
}
@@ -2813,10 +2514,9 @@
#else
dbus_int32_t res;
- pthread_mutex_lock (&atomic_mutex);
+ _DBUS_LOCK (atomic);
res = atomic->value;
- pthread_mutex_unlock (&atomic_mutex);
-
+ _DBUS_UNLOCK (atomic);
return res;
#endif
}
@@ -2835,17 +2535,38 @@
int timeout_milliseconds)
{
#if defined(HAVE_POLL) && !defined(BROKEN_POLL)
- /* DBusPollFD is a struct pollfd in this code path, so we can just poll() */
- if (timeout_milliseconds < -1)
+ /* This big thing is a constant expression and should get optimized
+ * out of existence. So it's more robust than a configure check at
+ * no cost.
+ */
+ if (_DBUS_POLLIN == POLLIN &&
+ _DBUS_POLLPRI == POLLPRI &&
+ _DBUS_POLLOUT == POLLOUT &&
+ _DBUS_POLLERR == POLLERR &&
+ _DBUS_POLLHUP == POLLHUP &&
+ _DBUS_POLLNVAL == POLLNVAL &&
+ sizeof (DBusPollFD) == sizeof (struct pollfd) &&
+ _DBUS_STRUCT_OFFSET (DBusPollFD, fd) ==
+ _DBUS_STRUCT_OFFSET (struct pollfd, fd) &&
+ _DBUS_STRUCT_OFFSET (DBusPollFD, events) ==
+ _DBUS_STRUCT_OFFSET (struct pollfd, events) &&
+ _DBUS_STRUCT_OFFSET (DBusPollFD, revents) ==
+ _DBUS_STRUCT_OFFSET (struct pollfd, revents))
{
- timeout_milliseconds = -1;
+ return poll ((struct pollfd*) fds,
+ n_fds,
+ timeout_milliseconds);
}
-
- return poll (fds,
- n_fds,
- timeout_milliseconds);
+ else
+ {
+ /* We have to convert the DBusPollFD to an array of
+ * struct pollfd, poll, and convert back.
+ */
+ _dbus_warn ("didn't implement poll() properly for this system yet\n");
+ return -1;
+ }
#else /* ! HAVE_POLL */
- /* Emulate poll() in terms of select() */
+
fd_set read_set, write_set, err_set;
int max_fd = 0;
int i;
@@ -3060,55 +2781,61 @@
#endif
}
+static dbus_bool_t
+_dbus_generate_pseudorandom_bytes (DBusString *str,
+ int n_bytes)
+{
+ int old_len;
+ char *p;
+
+ old_len = _dbus_string_get_length (str);
+
+ if (!_dbus_string_lengthen (str, n_bytes))
+ return FALSE;
+
+ p = _dbus_string_get_data_len (str, old_len, n_bytes);
+
+ _dbus_generate_pseudorandom_bytes_buffer (p, n_bytes);
+
+ return TRUE;
+}
+
/**
- * Generates the given number of securely random bytes,
+ * Generates the given number of random bytes,
* using the best mechanism we can come up with.
*
* @param str the string
* @param n_bytes the number of random bytes to append to string
- * @param error location to store reason for failure
- * @returns #TRUE on success, #FALSE on error
+ * @returns #TRUE on success, #FALSE if no memory
*/
dbus_bool_t
_dbus_generate_random_bytes (DBusString *str,
- int n_bytes,
- DBusError *error)
+ int n_bytes)
{
int old_len;
int fd;
- int result;
+
+ /* FALSE return means "no memory", if it could
+ * mean something else then we'd need to return
+ * a DBusError. So we always fall back to pseudorandom
+ * if the I/O fails.
+ */
old_len = _dbus_string_get_length (str);
fd = -1;
/* note, urandom on linux will fall back to pseudorandom */
fd = open ("/dev/urandom", O_RDONLY);
-
if (fd < 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Could not open /dev/urandom: %s",
- _dbus_strerror (errno));
- return FALSE;
- }
+ return _dbus_generate_pseudorandom_bytes (str, n_bytes);
_dbus_verbose ("/dev/urandom fd %d opened\n", fd);
- result = _dbus_read (fd, str, n_bytes);
-
- if (result != n_bytes)
+ if (_dbus_read (fd, str, n_bytes) != n_bytes)
{
- if (result < 0)
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Could not read /dev/urandom: %s",
- _dbus_strerror (errno));
- else
- dbus_set_error (error, DBUS_ERROR_IO_ERROR,
- "Short read from /dev/urandom");
-
_dbus_close (fd, NULL);
_dbus_string_set_length (str, old_len);
- return FALSE;
+ return _dbus_generate_pseudorandom_bytes (str, n_bytes);
}
_dbus_verbose ("Read %d bytes from /dev/urandom\n",
@@ -3167,7 +2894,7 @@
* @param fd the file descriptor
*/
void
-_dbus_fd_set_close_on_exec (int fd)
+_dbus_fd_set_close_on_exec (intptr_t fd)
{
int val;
@@ -3213,7 +2940,6 @@
* (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
@@ -3259,13 +2985,6 @@
* @returns #TRUE on success.
*/
dbus_bool_t
-_dbus_set_socket_nonblocking (DBusSocket fd,
- DBusError *error)
-{
- return _dbus_set_fd_nonblocking (fd.fd, error);
-}
-
-static dbus_bool_t
_dbus_set_fd_nonblocking (int fd,
DBusError *error)
{
@@ -3334,22 +3053,22 @@
}
/**
- * Creates pair of connect sockets (as in socketpair()).
- * Sets both ends of the pair nonblocking.
+ * Creates a full-duplex pipe (as in socketpair()).
+ * Sets both ends of the pipe nonblocking.
*
* Marks both file descriptors as close-on-exec
*
* @param fd1 return location for one end
* @param fd2 return location for the other end
- * @param blocking #TRUE if pair should be blocking
+ * @param blocking #TRUE if pipe should be blocking
* @param error error return
* @returns #FALSE on failure (if error is set)
*/
dbus_bool_t
-_dbus_socketpair (DBusSocket *fd1,
- DBusSocket *fd2,
- dbus_bool_t blocking,
- DBusError *error)
+_dbus_full_duplex_pipe (int *fd1,
+ int *fd2,
+ dbus_bool_t blocking,
+ DBusError *error)
{
#ifdef HAVE_SOCKETPAIR
int fds[2];
@@ -3361,7 +3080,7 @@
retval = socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0, fds);
cloexec_done = retval >= 0;
- if (retval < 0 && (errno == EINVAL || errno == EPROTOTYPE))
+ if (retval < 0 && errno == EINVAL)
#endif
{
retval = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
@@ -3397,17 +3116,17 @@
return FALSE;
}
- fd1->fd = fds[0];
- fd2->fd = fds[1];
+ *fd1 = fds[0];
+ *fd2 = fds[1];
_dbus_verbose ("full-duplex pipe %d <-> %d\n",
- fd1->fd, fd2->fd);
+ *fd1, *fd2);
return TRUE;
#else
- _dbus_warn ("_dbus_socketpair() not implemented on this OS\n");
+ _dbus_warn ("_dbus_full_duplex_pipe() not implemented on this OS\n");
dbus_set_error (error, DBUS_ERROR_FAILED,
- "_dbus_socketpair() not implemented on this OS");
+ "_dbus_full_duplex_pipe() not implemented on this OS");
return FALSE;
#endif
}
@@ -3427,11 +3146,8 @@
char static_buf[1024];
int bufsize = sizeof (static_buf);
int len;
- va_list args_copy;
- DBUS_VA_COPY (args_copy, args);
- len = vsnprintf (static_buf, bufsize, format, args_copy);
- va_end (args_copy);
+ len = vsnprintf (static_buf, bufsize, format, args);
/* If vsnprintf() returned non-negative, then either the string fits in
* static_buf, or this OS has the POSIX and C99 behaviour where vsnprintf
@@ -3447,12 +3163,8 @@
* 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. */
- DBUS_VA_COPY (args_copy, args);
-
- if (vsnprintf (static_buf, 1, format, args_copy) == 1)
+ if (vsnprintf (static_buf, 1, format, args) == 1)
len = -1;
-
- va_end (args_copy);
}
/* If vsnprintf() returned negative, we have to do more work.
@@ -3468,10 +3180,7 @@
if (buf == NULL)
return -1;
- DBUS_VA_COPY (args_copy, args);
- len = vsnprintf (buf, bufsize, format, args_copy);
- va_end (args_copy);
-
+ len = vsnprintf (buf, bufsize, format, args);
dbus_free (buf);
/* If the reported length is exactly the buffer size, round up to the
@@ -3488,17 +3197,13 @@
* 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, or #NULL if no memory for locking
+ * @returns location of temp directory
*/
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
@@ -3521,14 +3226,11 @@
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.
@@ -3625,12 +3327,15 @@
/* 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) /* setup stdin */
+ if (dup2 (fd, 0) == -1)
_exit (1);
- if (dup2 (result_pipe[WRITE_END], 1) == -1) /* setup stdout */
+ if (dup2 (result_pipe[WRITE_END], 1) == -1)
_exit (1);
- if (dup2 (errors_pipe[WRITE_END], 2) == -1) /* setup stderr */
+ if (dup2 (errors_pipe[WRITE_END], 2) == -1)
_exit (1);
_dbus_close_all ();
@@ -3730,7 +3435,6 @@
return retval;
}
-#endif
/**
* Returns the address of a new session bus.
@@ -3739,7 +3443,6 @@
* 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
@@ -3754,8 +3457,7 @@
* but that's done elsewhere, and if it worked, this function wouldn't
* be called.) */
const char *display;
- char *progpath;
- char *argv[6];
+ static char *argv[6];
int i;
DBusString uuid;
dbus_bool_t retval;
@@ -3772,12 +3474,7 @@
/* fd.o #19997: if $DISPLAY isn't set to something useful, then
* dbus-launch-x11 is just going to fail. Rather than trying to
- * run it, we might as well bail out early with a nice error.
- *
- * This is not strictly true in a world where the user bus exists,
- * because dbus-launch --autolaunch knows how to connect to that -
- * but if we were going to connect to the user bus, we'd have done
- * so before trying autolaunch: in any case. */
+ * run it, we might as well bail out early with a nice error. */
display = _dbus_getenv ("DISPLAY");
if (display == NULL || display[0] == '\0')
@@ -3793,22 +3490,12 @@
return FALSE;
}
- if (!_dbus_get_local_machine_uuid_encoded (&uuid, error))
+ if (!_dbus_get_local_machine_uuid_encoded (&uuid))
{
+ _DBUS_SET_OOM (error);
goto out;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
- if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL)
- progpath = TEST_BUS_LAUNCH_BINARY;
- else
-#endif
- progpath = DBUS_BINDIR "/dbus-launch";
- /*
- * argv[0] is always dbus-launch, that's the name what we'll
- * get from /proc, or ps(1), regardless what the progpath is,
- * see fd.o#69716
- */
i = 0;
argv[i] = "dbus-launch";
++i;
@@ -3825,7 +3512,7 @@
_dbus_assert (i == _DBUS_N_ELEMENTS (argv));
- retval = _read_subprocess_line_argv (progpath,
+ retval = _read_subprocess_line_argv (DBUS_BINDIR "/dbus-launch",
TRUE,
argv, address, error);
@@ -3868,7 +3555,7 @@
_dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
- b = _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
+ b = _dbus_read_uuid_file (&filename, machine_id, create_if_not_found, error);
if (b)
return TRUE;
@@ -3876,34 +3563,14 @@
/* Fallback to the system machine ID */
_dbus_string_init_const (&filename, "/etc/machine-id");
- b = _dbus_read_uuid_file (&filename, machine_id, FALSE, error);
-
- if (b)
- {
- /* try to copy it to the DBUS_MACHINE_UUID_FILE, but do not
- * complain if that isn't possible for whatever reason */
- _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
- _dbus_write_uuid_file (&filename, machine_id, NULL);
-
- return TRUE;
- }
-
- if (!create_if_not_found)
- return FALSE;
-
- /* if none found, try to make a new one */
- dbus_error_free (error);
- _dbus_string_init_const (&filename, DBUS_MACHINE_UUID_FILE);
-
- if (!_dbus_generate_uuid (machine_id, error))
- return FALSE;
-
- return _dbus_write_uuid_file (&filename, machine_id, error);
+ 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
@@ -4014,77 +3681,6 @@
}
#endif
-dbus_bool_t
-_dbus_lookup_user_bus (dbus_bool_t *supported,
- DBusString *address,
- DBusError *error)
-{
- const char *runtime_dir = _dbus_getenv ("XDG_RUNTIME_DIR");
- dbus_bool_t ret = FALSE;
- struct stat stbuf;
- DBusString user_bus_path;
-
- if (runtime_dir == NULL)
- {
- _dbus_verbose ("XDG_RUNTIME_DIR not found in environment");
- *supported = FALSE;
- return TRUE; /* Cannot use it, but not an error */
- }
-
- if (!_dbus_string_init (&user_bus_path))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
-
- if (!_dbus_string_append_printf (&user_bus_path, "%s/bus", runtime_dir))
- {
- _DBUS_SET_OOM (error);
- goto out;
- }
-
- if (lstat (_dbus_string_get_const_data (&user_bus_path), &stbuf) == -1)
- {
- _dbus_verbose ("XDG_RUNTIME_DIR/bus not available: %s",
- _dbus_strerror (errno));
- *supported = FALSE;
- ret = TRUE; /* Cannot use it, but not an error */
- goto out;
- }
-
- if (stbuf.st_uid != getuid ())
- {
- _dbus_verbose ("XDG_RUNTIME_DIR/bus owned by uid %ld, not our uid %ld",
- (long) stbuf.st_uid, (long) getuid ());
- *supported = FALSE;
- ret = TRUE; /* Cannot use it, but not an error */
- goto out;
- }
-
- if ((stbuf.st_mode & S_IFMT) != S_IFSOCK)
- {
- _dbus_verbose ("XDG_RUNTIME_DIR/bus is not a socket: st_mode = 0o%lo",
- (long) stbuf.st_mode);
- *supported = FALSE;
- ret = TRUE; /* Cannot use it, but not an error */
- goto out;
- }
-
- if (!_dbus_string_append (address, "unix:path=") ||
- !_dbus_address_append_escaped (address, &user_bus_path))
- {
- _DBUS_SET_OOM (error);
- goto out;
- }
-
- *supported = TRUE;
- ret = TRUE;
-
-out:
- _dbus_string_free (&user_bus_path);
- return ret;
-}
-
/**
* Determines the address of the session bus by querying a
* platform-specific method.
@@ -4113,23 +3709,177 @@
*supported = TRUE;
return _dbus_lookup_session_address_launchd (address, error);
#else
- *supported = FALSE;
-
- if (!_dbus_lookup_user_bus (supported, address, error))
- return FALSE;
- else if (*supported)
- return TRUE;
-
/* On non-Mac Unix platforms, if the session address isn't already
- * set in DBUS_SESSION_BUS_ADDRESS environment variable and the
- * $XDG_RUNTIME_DIR/bus can't be used, we punt and fall back to the
- * autolaunch: global default; see init_session_address in
- * dbus/dbus-bus.c. */
+ * set in DBUS_SESSION_BUS_ADDRESS environment variable, we punt and
+ * fall back to the autolaunch: global default; see
+ * init_session_address in dbus/dbus-bus.c. */
+ *supported = FALSE;
return TRUE;
#endif
}
/**
+ * 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.
@@ -4175,7 +3925,7 @@
if (!_dbus_homedir_from_uid (uid, &homedir))
goto failed;
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
{
const char *override;
@@ -4191,8 +3941,6 @@
}
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)
{
@@ -4240,12 +3988,12 @@
* See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently
* for Winsock so is abstracted)
*
- * @returns #TRUE if e == EAGAIN or e == EWOULDBLOCK
+ * @returns #TRUE if errno == EAGAIN or errno == EWOULDBLOCK
*/
dbus_bool_t
-_dbus_get_is_errno_eagain_or_ewouldblock (int e)
+_dbus_get_is_errno_eagain_or_ewouldblock (void)
{
- return e == EAGAIN || e == EWOULDBLOCK;
+ return errno == EAGAIN || errno == EWOULDBLOCK;
}
/**
@@ -4284,8 +4032,8 @@
*
*/
dbus_bool_t
-_dbus_socket_can_pass_unix_fd (DBusSocket fd)
-{
+_dbus_socket_can_pass_unix_fd(int fd) {
+
#ifdef SCM_RIGHTS
union {
struct sockaddr sa;
@@ -4297,7 +4045,7 @@
_DBUS_ZERO(sa_buf);
- if (getsockname(fd.fd, &sa_buf.sa, &sa_len) < 0)
+ if (getsockname(fd, &sa_buf.sa, &sa_len) < 0)
return FALSE;
return sa_buf.sa.sa_family == AF_UNIX;
@@ -4308,6 +4056,20 @@
#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).
@@ -4401,8 +4163,6 @@
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;
@@ -4428,90 +4188,4 @@
#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 (DBusSocket 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.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;
-}
-
-int
-_dbus_save_socket_errno (void)
-{
- return errno;
-}
-
-void
-_dbus_restore_socket_errno (int saved_errno)
-{
- errno = saved_errno;
-}
-
/* tests in dbus-sysdeps-util.c */
diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h
index 279cae2..9b70896 100644
--- a/dbus/dbus-sysdeps-unix.h
+++ b/dbus/dbus-sysdeps-unix.h
@@ -40,14 +40,11 @@
* @{
*/
-DBUS_PRIVATE_EXPORT
dbus_bool_t
_dbus_close (int fd,
DBusError *error);
-DBUS_PRIVATE_EXPORT
int _dbus_dup (int fd,
DBusError *error);
-DBUS_PRIVATE_EXPORT
int
_dbus_read (int fd,
DBusString *buffer,
@@ -77,8 +74,8 @@
char *const argv[],
DBusError *error);
-int _dbus_listen_systemd_sockets (DBusSocket **fd,
- DBusError *error);
+int _dbus_listen_systemd_sockets (int **fd,
+ DBusError *error);
dbus_bool_t _dbus_read_credentials (int client_fd,
DBusCredentials *credentials,
@@ -90,11 +87,6 @@
const char *launchd_env_var,
DBusError *error);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_lookup_user_bus (dbus_bool_t *supported,
- DBusString *address,
- DBusError *error);
-
/** Information about a UNIX user */
typedef struct DBusUserInfo DBusUserInfo;
/** Information about a UNIX group */
@@ -138,33 +130,14 @@
DBusError *error);
void _dbus_group_info_free (DBusGroupInfo *info);
-DBUS_PRIVATE_EXPORT
+dbus_uid_t _dbus_getuid (void);
dbus_uid_t _dbus_geteuid (void);
dbus_bool_t _dbus_parse_uid (const DBusString *uid_str,
dbus_uid_t *uid);
-DBUS_PRIVATE_EXPORT
void _dbus_close_all (void);
-dbus_bool_t _dbus_append_address_from_socket (DBusSocket fd,
- DBusString *address,
- DBusError *error);
-
-DBUS_PRIVATE_EXPORT
-void _dbus_fd_set_close_on_exec (int fd);
-
-typedef enum
-{
- DBUS_FORCE_STDIN_NULL = (1 << 0),
- DBUS_FORCE_STDOUT_NULL = (1 << 1),
- DBUS_FORCE_STDERR_NULL = (1 << 2)
-} DBusEnsureStandardFdsFlags;
-
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_ensure_standard_fds (DBusEnsureStandardFdsFlags flags,
- const char **error_str_p);
-
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
index 9b724cc..76423ab 100644
--- a/dbus/dbus-sysdeps-util-unix.c
+++ b/dbus/dbus-sysdeps-util-unix.c
@@ -49,19 +49,12 @@
#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
-#ifdef HAVE_SYSTEMD
-#include <systemd/sd-daemon.h>
-#endif
-
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -130,7 +123,6 @@
dup2 (dev_null_fd, 2);
else
_dbus_verbose ("keeping stderr open due to DBUS_DEBUG_OUTPUT\n");
- close (dev_null_fd);
}
if (!keep_umask)
@@ -380,156 +372,62 @@
}
#endif /* !HAVE_LIBAUDIT */
-#ifdef HAVE_SETRLIMIT
-/* We assume that if we have setrlimit, we also have getrlimit and
- * struct rlimit.
+/**
+ * Attempt to ensure that the current process can open
+ * at least @limit file descriptors.
+ *
+ * If @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
*/
-
-struct DBusRLimit {
- struct rlimit lim;
-};
-
-DBusRLimit *
-_dbus_rlimit_save_fd_limit (DBusError *error)
+void
+_dbus_request_file_descriptor_limit (unsigned int limit)
{
- DBusRLimit *self;
-
- self = dbus_new0 (DBusRLimit, 1);
-
- if (self == NULL)
- {
- _DBUS_SET_OOM (error);
- return NULL;
- }
-
- if (getrlimit (RLIMIT_NOFILE, &self->lim) < 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to get fd limit: %s", _dbus_strerror (errno));
- dbus_free (self);
- return NULL;
- }
-
- return self;
-}
-
-dbus_bool_t
-_dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
- DBusError *error)
-{
+#ifdef HAVE_SETRLIMIT
struct rlimit lim;
+ struct rlimit target_lim;
/* No point to doing this practically speaking
* if we're not uid 0. We expect the system
* bus to use this before we change UID, and
- * the session bus takes the Linux default,
- * currently 1024 for cur and 4096 for max.
+ * the session bus takes the Linux default
+ * of 1024 for both cur and max.
*/
if (getuid () != 0)
- {
- /* not an error, we're probably the session bus */
- return TRUE;
- }
+ return;
if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to get fd limit: %s", _dbus_strerror (errno));
- return FALSE;
- }
+ return;
- if (lim.rlim_cur == RLIM_INFINITY || lim.rlim_cur >= desired)
- {
- /* not an error, everything is fine */
- return TRUE;
- }
+ if (lim.rlim_cur >= limit)
+ return;
/* Ignore "maximum limit", assume we have the "superuser"
* privileges. On Linux this is CAP_SYS_RESOURCE.
*/
- lim.rlim_cur = lim.rlim_max = desired;
-
- if (setrlimit (RLIMIT_NOFILE, &lim) < 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to set fd limit to %u: %s",
- desired, _dbus_strerror (errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
-dbus_bool_t
-_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
- DBusError *error)
-{
- if (setrlimit (RLIMIT_NOFILE, &saved->lim) < 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to restore old fd limit: %s",
- _dbus_strerror (errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
-#else /* !HAVE_SETRLIMIT */
-
-static void
-fd_limit_not_supported (DBusError *error)
-{
- dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
- "cannot change fd limit on this platform");
-}
-
-DBusRLimit *
-_dbus_rlimit_save_fd_limit (DBusError *error)
-{
- fd_limit_not_supported (error);
- return NULL;
-}
-
-dbus_bool_t
-_dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
- DBusError *error)
-{
- fd_limit_not_supported (error);
- return FALSE;
-}
-
-dbus_bool_t
-_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
- DBusError *error)
-{
- fd_limit_not_supported (error);
- return FALSE;
-}
-
+ target_lim.rlim_cur = target_lim.rlim_max = limit;
+ /* Also ignore errors; if we fail, we will at least work
+ * up to whatever limit we had, which seems better than
+ * just outright aborting.
+ *
+ * However, in the future we should probably log this so OS builders
+ * have a chance to notice any misconfiguration like dbus-daemon
+ * being started without CAP_SYS_RESOURCE.
+ */
+ setrlimit (RLIMIT_NOFILE, &target_lim);
#endif
-
-void
-_dbus_rlimit_free (DBusRLimit *lim)
-{
- dbus_free (lim);
}
void
-_dbus_init_system_log (dbus_bool_t is_daemon)
+_dbus_init_system_log (void)
{
-#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);
+ openlog ("dbus", LOG_PID | LOG_PERROR, LOG_DAEMON);
+#else
+ openlog ("dbus", LOG_PID, LOG_DAEMON);
#endif
}
@@ -538,6 +436,8 @@
*
* @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, ...)
@@ -564,17 +464,12 @@
void
_dbus_system_logv (DBusSystemLogSeverity severity, const char *msg, va_list args)
{
- va_list tmp;
-#ifdef HAVE_SYSLOG_H
int flags;
switch (severity)
{
case DBUS_SYSTEM_LOG_INFO:
flags = LOG_DAEMON | LOG_NOTICE;
break;
- case DBUS_SYSTEM_LOG_WARNING:
- flags = LOG_DAEMON | LOG_WARNING;
- break;
case DBUS_SYSTEM_LOG_SECURITY:
flags = LOG_AUTH | LOG_NOTICE;
break;
@@ -585,14 +480,11 @@
return;
}
- DBUS_VA_COPY (tmp, args);
- vsyslog (flags, msg, tmp);
- va_end (tmp);
-#endif
-
-#if !defined(HAVE_SYSLOG_H) || !HAVE_DECL_LOG_PERROR
+#ifndef 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);
@@ -601,6 +493,8 @@
}
#endif
+ vsyslog (flags, msg, args);
+
if (severity == DBUS_SYSTEM_LOG_FATAL)
exit (1);
}
@@ -1249,7 +1143,6 @@
"Failed to read from \"%s\": %s",
_dbus_string_get_const_data (&path),
_dbus_strerror (errno));
- _dbus_close (fd, NULL);
goto fail;
}
@@ -1271,180 +1164,3 @@
_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 3b754db..111db9e 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_pipe file descriptor to print daemon's pid to, or -1 for none
+ * @param print_pid_fd 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,9 +65,7 @@
DBusError *error,
dbus_bool_t keep_umask)
{
- dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
- "Cannot daemonize on Windows");
- return FALSE;
+ return TRUE;
}
/**
@@ -258,46 +256,13 @@
return TRUE;
}
-static void
-fd_limit_not_supported (DBusError *error)
+void
+_dbus_request_file_descriptor_limit (unsigned int limit)
{
- dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
- "cannot change fd limit on this platform");
-}
-
-DBusRLimit *
-_dbus_rlimit_save_fd_limit (DBusError *error)
-{
- fd_limit_not_supported (error);
- return NULL;
-}
-
-dbus_bool_t
-_dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
- DBusError *error)
-{
- fd_limit_not_supported (error);
- return FALSE;
-}
-
-dbus_bool_t
-_dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
- DBusError *error)
-{
- fd_limit_not_supported (error);
- return FALSE;
}
void
-_dbus_rlimit_free (DBusRLimit *lim)
-{
- /* _dbus_rlimit_save_fd_limit() cannot return non-NULL on Windows
- * so there cannot be anything to free */
- _dbus_assert (lim == NULL);
-}
-
-void
-_dbus_init_system_log (dbus_bool_t is_daemon)
+_dbus_init_system_log (void)
{
/* OutputDebugStringA doesn't need any special initialization, do nothing */
}
@@ -307,6 +272,8 @@
*
* @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, ...)
@@ -335,18 +302,16 @@
{
char *s = "";
char buf[1024];
- char format[1024];
-
+
switch(severity)
{
case DBUS_SYSTEM_LOG_INFO: s = "info"; break;
- case DBUS_SYSTEM_LOG_WARNING: s = "warning"; break;
case DBUS_SYSTEM_LOG_SECURITY: s = "security"; break;
case DBUS_SYSTEM_LOG_FATAL: s = "fatal"; break;
}
- snprintf(format, sizeof(format), "%s%s", s ,msg);
- vsnprintf(buf, sizeof(buf), format, args);
+ sprintf(buf,"%s%s",s,msg);
+ vsprintf(buf,buf,args);
OutputDebugStringA(buf);
if (severity == DBUS_SYSTEM_LOG_FATAL)
@@ -381,6 +346,7 @@
const char *filename_c;
WIN32_FILE_ATTRIBUTE_DATA wfad;
char *lastdot;
+ DWORD rc;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -458,15 +424,155 @@
return TRUE;
}
+
+/* This file is part of the KDE project
+Copyright (C) 2000 Werner Almesberger
+
+libc/sys/linux/sys/dirent.h - Directory entry as returned by readdir
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+*/
+#define HAVE_NO_D_NAMLEN /* no struct dirent->d_namlen */
+#define HAVE_DD_LOCK /* have locking mechanism */
+
+#define MAXNAMLEN 255 /* sizeof(struct dirent.d_name)-1 */
+
+#define __dirfd(dir) (dir)->dd_fd
+
+/* struct dirent - same as Unix */
+struct dirent
+ {
+ long d_ino; /* inode (always 1 in WIN32) */
+ off_t d_off; /* offset to this dirent */
+ unsigned short d_reclen; /* length of d_name */
+ char d_name[_MAX_FNAME+1]; /* filename (null terminated) */
+ };
+
+/* typedef DIR - not the same as Unix */
+typedef struct
+ {
+ HANDLE handle; /* FindFirst/FindNext handle */
+ short offset; /* offset into directory */
+ short finished; /* 1 if there are not more files */
+ WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */
+ char *dir; /* the dir we are reading */
+ struct dirent dent; /* the dirent to return */
+ }
+DIR;
+
+/**********************************************************************
+* Implement dirent-style opendir/readdir/closedir on Window 95/NT
+*
+* Functions defined are opendir(), readdir() and closedir() with the
+* same prototypes as the normal dirent.h implementation.
+*
+* Does not implement telldir(), seekdir(), rewinddir() or scandir().
+* The dirent struct is compatible with Unix, except that d_ino is
+* always 1 and d_off is made up as we go along.
+*
+* Error codes are not available with errno but GetLastError.
+*
+* The DIR typedef is not compatible with Unix.
+**********************************************************************/
+
+static DIR * _dbus_opendir(const char *dir)
+{
+ DIR *dp;
+ char *filespec;
+ HANDLE handle;
+ int index;
+
+ filespec = malloc(strlen(dir) + 2 + 1);
+ strcpy(filespec, dir);
+ index = strlen(filespec) - 1;
+ if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\'))
+ filespec[index] = '\0';
+ strcat(filespec, "\\*");
+
+ dp = (DIR *)malloc(sizeof(DIR));
+ dp->offset = 0;
+ dp->finished = 0;
+ dp->dir = strdup(dir);
+
+ handle = FindFirstFileA(filespec, &(dp->fileinfo));
+ if (handle == INVALID_HANDLE_VALUE)
+ {
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ dp->finished = 1;
+ else
+ return NULL;
+ }
+
+ dp->handle = handle;
+ free(filespec);
+
+ return dp;
+}
+
+static struct dirent * _dbus_readdir(DIR *dp)
+{
+ int saved_err = GetLastError();
+
+ if (!dp || dp->finished)
+ return NULL;
+
+ if (dp->offset != 0)
+ {
+ if (FindNextFileA(dp->handle, &(dp->fileinfo)) == 0)
+ {
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ {
+ SetLastError(saved_err);
+ dp->finished = 1;
+ }
+ return NULL;
+ }
+ }
+ dp->offset++;
+
+ strncpy(dp->dent.d_name, dp->fileinfo.cFileName, _MAX_FNAME);
+ dp->dent.d_ino = 1;
+ dp->dent.d_reclen = strlen(dp->dent.d_name);
+ dp->dent.d_off = dp->offset;
+
+ return &(dp->dent);
+}
+
+
+static int _dbus_closedir(DIR *dp)
+{
+ if (!dp)
+ return 0;
+ FindClose(dp->handle);
+ if (dp->dir)
+ free(dp->dir);
+ if (dp)
+ free(dp);
+
+ return 0;
+}
+
+
/**
* Internals of directory iterator
*/
struct DBusDirIter
{
- HANDLE handle;
- WIN32_FIND_DATAA fileinfo; /* from FindFirst/FindNext */
- dbus_bool_t finished; /* true if there are no more entries */
- int offset;
+ DIR *d; /**< The DIR* from opendir() */
+
};
/**
@@ -480,66 +586,35 @@
_dbus_directory_open (const DBusString *filename,
DBusError *error)
{
+ DIR *d;
DBusDirIter *iter;
- DBusString filespec;
+ const char *filename_c;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!_dbus_string_init_from_string (&filespec, filename))
+ filename_c = _dbus_string_get_const_data (filename);
+
+ d = _dbus_opendir (filename_c);
+ if (d == NULL)
{
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
- "Could not allocate memory for directory filename copy");
+ char *emsg = _dbus_win_error_string (GetLastError ());
+ dbus_set_error (error, _dbus_win_error_from_last_error (),
+ "Failed to read directory \"%s\": %s",
+ filename_c, emsg);
+ _dbus_win_free_error_string (emsg);
return NULL;
}
-
- if (_dbus_string_ends_with_c_str (&filespec, "/") || _dbus_string_ends_with_c_str (&filespec, "\\") )
- {
- if (!_dbus_string_append (&filespec, "*"))
- {
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
- "Could not append filename wildcard");
- return NULL;
- }
- }
- else if (!_dbus_string_ends_with_c_str (&filespec, "*"))
- {
- if (!_dbus_string_append (&filespec, "\\*"))
- {
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
- "Could not append filename wildcard 2");
- return NULL;
- }
- }
-
iter = dbus_new0 (DBusDirIter, 1);
if (iter == NULL)
{
- _dbus_string_free (&filespec);
+ _dbus_closedir (d);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
"Could not allocate memory for directory iterator");
return NULL;
}
- iter->finished = FALSE;
- iter->offset = 0;
- iter->handle = FindFirstFileA (_dbus_string_get_const_data (&filespec), &(iter->fileinfo));
- if (iter->handle == INVALID_HANDLE_VALUE)
- {
- if (GetLastError () == ERROR_NO_MORE_FILES)
- iter->finished = TRUE;
- else
- {
- char *emsg = _dbus_win_error_string (GetLastError ());
- dbus_set_error (error, _dbus_win_error_from_last_error (),
- "Failed to read directory \"%s\": %s",
- _dbus_string_get_const_data (filename), emsg);
- _dbus_win_free_error_string (emsg);
- dbus_free ( iter );
- _dbus_string_free (&filespec);
- return NULL;
- }
- }
- _dbus_string_free (&filespec);
+ iter->d = d;
+
return iter;
}
@@ -548,6 +623,9 @@
* UNIX. If an error occurs, the contents of "filename" are
* undefined. The error is never set if the function succeeds.
*
+ * @todo for thread safety, I think we have to use
+ * readdir_r(). (GLib has the same issue, should file a bug.)
+ *
* @param iter the iterator
* @param filename string to be set to the next file in the dir
* @param error return location for error
@@ -558,55 +636,40 @@
DBusString *filename,
DBusError *error)
{
- int saved_err = GetLastError();
+ struct dirent *ent;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
again:
SetLastError (0);
-
- if (!iter || iter->finished)
- return FALSE;
-
- if (iter->offset > 0)
+ ent = _dbus_readdir (iter->d);
+ if (ent == NULL)
{
- if (FindNextFileA (iter->handle, &(iter->fileinfo)) == 0)
+ if (GetLastError() != 0)
{
- if (GetLastError() == ERROR_NO_MORE_FILES)
- {
- SetLastError(saved_err);
- iter->finished = 1;
- }
- else
- {
- char *emsg = _dbus_win_error_string (GetLastError ());
- dbus_set_error (error, _dbus_win_error_from_last_error (),
- "Failed to get next in directory: %s", emsg);
- _dbus_win_free_error_string (emsg);
- return FALSE;
- }
+ char *emsg = _dbus_win_error_string (GetLastError ());
+ dbus_set_error (error, _dbus_win_error_from_last_error (),
+ "Failed to get next in directory: %s", emsg);
+ _dbus_win_free_error_string (emsg);
}
- }
-
- iter->offset++;
-
- if (iter->finished)
return FALSE;
-
- if (iter->fileinfo.cFileName[0] == '.' &&
- (iter->fileinfo.cFileName[1] == '\0' ||
- (iter->fileinfo.cFileName[1] == '.' && iter->fileinfo.cFileName[2] == '\0')))
- goto again;
-
- _dbus_string_set_length (filename, 0);
- if (!_dbus_string_append (filename, iter->fileinfo.cFileName))
+ }
+ else if (ent->d_name[0] == '.' &&
+ (ent->d_name[1] == '\0' ||
+ (ent->d_name[1] == '.' && ent->d_name[2] == '\0')))
+ goto again;
+ else
{
- dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
- "No memory to read directory entry");
- return FALSE;
+ _dbus_string_set_length (filename, 0);
+ if (!_dbus_string_append (filename, ent->d_name))
+ {
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "No memory to read directory entry");
+ return FALSE;
+ }
+ else
+ return TRUE;
}
-
- return TRUE;
}
/**
@@ -615,9 +678,7 @@
void
_dbus_directory_close (DBusDirIter *iter)
{
- if (!iter)
- return;
- FindClose(iter->handle);
+ _dbus_closedir (iter->d);
dbus_free (iter);
}
@@ -1469,236 +1530,3 @@
// 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))) {
- strncpy (retval, configure_time_path, sizeof (retval) - 1);
- /* strncpy does not guarantee to 0-terminate the string */
- retval[sizeof (retval) - 1] = '\0';
- } else {
- size_t remaining;
-
- strncpy (retval, runtime_prefix, sizeof (retval) - 1);
- retval[sizeof (retval) - 1] = '\0';
- remaining = sizeof (retval) - 1 - strlen (retval);
- strncat (retval,
- configure_time_path + strlen (DBUS_PREFIX) + 1,
- remaining);
- }
-
- /* 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;
-}
-
-static dbus_bool_t
-_dbus_get_config_file_name (DBusString *str,
- const char *basename)
-{
- DBusString tmp;
-
- if (!_dbus_string_append (str, _dbus_windows_get_datadir ()))
- return FALSE;
-
- _dbus_string_init_const (&tmp, "dbus-1");
-
- if (!_dbus_concat_dir_and_file (str, &tmp))
- return FALSE;
-
- _dbus_string_init_const (&tmp, basename);
-
- if (!_dbus_concat_dir_and_file (str, &tmp))
- return FALSE;
-
- 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 6b361ef..4b3d16f 100644
--- a/dbus/dbus-sysdeps-util.c
+++ b/dbus/dbus-sysdeps-util.c
@@ -80,7 +80,7 @@
return environment;
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static void
check_dirname (const char *filename,
const char *dirname)
@@ -196,4 +196,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c
index d19267e..bc4951b 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-2013 Ralf Habacker <ralf.habacker@freenet.de>
+ * Copyright (C) 2006-2010 Ralf Habacker <ralf.habacker@freenet.de>
*
* Licensed under the Academic Free License version 2.1
*
@@ -52,15 +52,14 @@
#include "dbus-credentials.h"
#include <windows.h>
+#include <ws2tcpip.h>
#include <wincrypt.h>
-#include <iphlpapi.h>
-/* Declarations missing in mingw's and windows sdk 7.0 headers */
+/* Declarations missing in mingw's 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
@@ -77,15 +76,20 @@
#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;
@@ -99,203 +103,6 @@
#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 = 0, 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 peer's pid\n");
-
- 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*
@@ -375,7 +182,7 @@
*/
int
-_dbus_read_socket (DBusSocket fd,
+_dbus_read_socket (int fd,
DBusString *buffer,
int count)
{
@@ -397,8 +204,8 @@
again:
- _dbus_verbose ("recv: count=%d fd=%Iu\n", count, fd.sock);
- bytes_read = recv (fd.sock, data, count, 0);
+ _dbus_verbose ("recv: count=%d fd=%d\n", count, fd);
+ bytes_read = recv (fd, data, count, 0);
if (bytes_read == SOCKET_ERROR)
{
@@ -445,7 +252,7 @@
* @returns the number of bytes written or -1 on error
*/
int
-_dbus_write_socket (DBusSocket fd,
+_dbus_write_socket (int fd,
const DBusString *buffer,
int start,
int len)
@@ -457,8 +264,8 @@
again:
- _dbus_verbose ("send: len=%d fd=%Iu\n", len, fd.sock);
- bytes_written = send (fd.sock, data, len, 0);
+ _dbus_verbose ("send: len=%d fd=%d\n", len, fd);
+ bytes_written = send (fd, data, len, 0);
if (bytes_written == SOCKET_ERROR)
{
@@ -489,13 +296,13 @@
* @returns #FALSE if error set
*/
dbus_bool_t
-_dbus_close_socket (DBusSocket fd,
+_dbus_close_socket (int fd,
DBusError *error)
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
again:
- if (closesocket (fd.sock) == SOCKET_ERROR)
+ if (closesocket (fd) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
@@ -503,11 +310,11 @@
goto again;
dbus_set_error (error, _dbus_error_from_errno (errno),
- "Could not close socket: socket=%Iu, , %s",
- fd.sock, _dbus_strerror_from_errno ());
+ "Could not close socket: socket=%d, , %s",
+ fd, _dbus_strerror_from_errno ());
return FALSE;
}
- _dbus_verbose ("_dbus_close_socket: socket=%Iu, \n", fd.sock);
+ _dbus_verbose ("_dbus_close_socket: socket=%d, \n", fd);
return TRUE;
}
@@ -517,10 +324,10 @@
* on exec. Should be called for all file
* descriptors in D-Bus code.
*
- * @param handle the Windows HANDLE (a SOCKET is also OK)
+ * @param fd the file descriptor
*/
-static void
-_dbus_win_handle_set_close_on_exec (HANDLE handle)
+void
+_dbus_fd_set_close_on_exec (intptr_t handle)
{
if ( !SetHandleInformation( (HANDLE) handle,
HANDLE_FLAG_INHERIT | HANDLE_FLAG_PROTECT_FROM_CLOSE,
@@ -533,24 +340,24 @@
/**
* Sets a file descriptor to be nonblocking.
*
- * @param handle the file descriptor.
+ * @param fd the file descriptor.
* @param error address of error location.
* @returns #TRUE on success.
*/
dbus_bool_t
-_dbus_set_socket_nonblocking (DBusSocket handle,
- DBusError *error)
+_dbus_set_fd_nonblocking (int handle,
+ DBusError *error)
{
u_long one = 1;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (ioctlsocket (handle.sock, FIONBIO, &one) == SOCKET_ERROR)
+ if (ioctlsocket (handle, FIONBIO, &one) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to set socket %Iu to nonblocking: %s",
- handle.sock, _dbus_strerror_from_errno ());
+ "Failed to set socket %d:%d to nonblocking: %s", handle,
+ _dbus_strerror_from_errno ());
return FALSE;
}
@@ -579,7 +386,7 @@
* @returns total bytes written from both buffers, or -1 on error
*/
int
-_dbus_write_socket_two (DBusSocket fd,
+_dbus_write_socket_two (int fd,
const DBusString *buffer1,
int start1,
int len1,
@@ -618,8 +425,8 @@
again:
- _dbus_verbose ("WSASend: len1+2=%d+%d fd=%Iu\n", len1, len2, fd.sock);
- rc = WSASend (fd.sock,
+ _dbus_verbose ("WSASend: len1+2=%d+%d fd=%d\n", len1, len2, fd);
+ rc = WSASend (fd,
vectors,
data2 ? 2 : 1,
&bytes_written,
@@ -642,6 +449,12 @@
return bytes_written;
}
+dbus_bool_t
+_dbus_socket_is_invalid (int fd)
+{
+ return fd == INVALID_SOCKET ? TRUE : FALSE;
+}
+
#if 0
/**
@@ -661,26 +474,21 @@
#endif
-/**
- * @returns #FALSE if no memory
- */
-dbus_bool_t
+
+
+void
_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)
- goto out;
+ return;
wVersionRequested = MAKEWORD (2, 0);
@@ -704,10 +512,6 @@
}
beenhere = TRUE;
-
-out:
- _DBUS_UNLOCK (sysdeps);
- return TRUE;
}
@@ -734,12 +538,9 @@
char buf[1024];
int bufsize;
int len;
- va_list args_copy;
bufsize = sizeof (buf);
- DBUS_VA_COPY (args_copy, args);
- len = _vsnprintf (buf, bufsize - 1, format, args_copy);
- va_end (args_copy);
+ len = _vsnprintf (buf, bufsize - 1, format, args);
while (len == -1) /* try again */
{
@@ -752,9 +553,7 @@
if (p == NULL)
return -1;
- DBUS_VA_COPY (args_copy, args);
- len = _vsnprintf (p, bufsize - 1, format, args_copy);
- va_end (args_copy);
+ len = _vsnprintf (p, bufsize - 1, format, args);
free (p);
}
@@ -939,62 +738,22 @@
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 sid points to sid buffer, need to be freed with LocalFree()
- * @param process_id the process id for which the sid should be returned (use 0 for current process)
+ * @param points to sid buffer, need to be freed with LocalFree()
* @returns process sid
*/
-dbus_bool_t
-_dbus_getsid(char **sid, dbus_pid_t process_id)
+static dbus_bool_t
+_dbus_getsid(char **sid)
{
HANDLE process_token = INVALID_HANDLE_VALUE;
TOKEN_USER *token_user = NULL;
DWORD n;
PSID psid;
int retval = FALSE;
-
- HANDLE process_handle;
- if (process_id == 0)
- process_handle = GetCurrentProcess();
- else if (is_winxp_sp3_or_lower())
- process_handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, process_id);
- else
- process_handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id);
-
- if (!OpenProcessToken (process_handle, TOKEN_QUERY, &process_token))
+
+ if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &process_token))
{
_dbus_win_warn_win_error ("OpenProcessToken failed", GetLastError ());
goto failed;
@@ -1022,11 +781,10 @@
retval = TRUE;
failed:
- CloseHandle (process_handle);
if (process_token != INVALID_HANDLE_VALUE)
CloseHandle (process_token);
- _dbus_verbose("_dbus_getsid() got '%s' and returns %d\n", *sid, retval);
+ _dbus_verbose("_dbus_getsid() returns %d\n",retval);
return retval;
}
#endif
@@ -1038,33 +796,27 @@
************************************************************************/
/**
- * Creates pair of connect sockets (as in socketpair()).
- * Sets both ends of the pair nonblocking.
- *
- * Marks both file descriptors as close-on-exec
+ * Creates a full-duplex pipe (as in socketpair()).
+ * Sets both ends of the pipe nonblocking.
*
* @param fd1 return location for one end
* @param fd2 return location for the other end
- * @param blocking #TRUE if pair should be blocking
+ * @param blocking #TRUE if pipe should be blocking
* @param error error return
* @returns #FALSE on failure (if error is set)
*/
dbus_bool_t
-_dbus_socketpair (DBusSocket *fd1,
- DBusSocket *fd2,
- dbus_bool_t blocking,
- DBusError *error)
+_dbus_full_duplex_pipe (int *fd1,
+ int *fd2,
+ dbus_bool_t blocking,
+ DBusError *error)
{
SOCKET temp, socket1 = -1, socket2 = -1;
struct sockaddr_in saddr;
int len;
u_long arg;
- if (!_dbus_win_startup_winsock ())
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
+ _dbus_win_startup_winsock ();
temp = socket (AF_INET, SOCK_STREAM, 0);
if (temp == INVALID_SOCKET)
@@ -1134,11 +886,11 @@
}
}
- fd1->sock = socket1;
- fd2->sock = socket2;
+ *fd1 = socket1;
+ *fd2 = socket2;
- _dbus_verbose ("full-duplex pipe %Iu:%Iu <-> %Iu:%Iu\n",
- fd1->sock, socket1, fd2->sock, socket2);
+ _dbus_verbose ("full-duplex pipe %d:%d <-> %d:%d\n",
+ *fd1, socket1, *fd2, socket2);
closesocket (temp);
@@ -1202,12 +954,12 @@
if (fdp->events & _DBUS_POLLIN)
- msgp += sprintf (msgp, "R:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "R:%d ", fdp->fd);
if (fdp->events & _DBUS_POLLOUT)
- msgp += sprintf (msgp, "W:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "W:%d ", fdp->fd);
- msgp += sprintf (msgp, "E:%Iu\n\t", fdp->fd.sock);
+ msgp += sprintf (msgp, "E:%d\n\t", fdp->fd);
// FIXME: more robust code for long msg
// create on heap when msg[] becomes too small
@@ -1234,7 +986,7 @@
if (fdp->events & _DBUS_POLLOUT)
lNetworkEvents |= FD_WRITE | FD_CONNECT;
- WSAEventSelect(fdp->fd.sock, ev, lNetworkEvents);
+ WSAEventSelect(fdp->fd, ev, lNetworkEvents);
pEvents[i] = ev;
}
@@ -1266,7 +1018,7 @@
fdp->revents = 0;
- WSAEnumNetworkEvents(fdp->fd.sock, pEvents[i], &ne);
+ WSAEnumNetworkEvents(fdp->fd, pEvents[i], &ne);
if (ne.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
fdp->revents |= _DBUS_POLLIN;
@@ -1278,20 +1030,20 @@
fdp->revents |= _DBUS_POLLERR;
if (ne.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
- msgp += sprintf (msgp, "R:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "R:%d ", fdp->fd);
if (ne.lNetworkEvents & (FD_WRITE | FD_CONNECT))
- msgp += sprintf (msgp, "W:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "W:%d ", fdp->fd);
if (ne.lNetworkEvents & (FD_OOB))
- msgp += sprintf (msgp, "E:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "E:%d ", fdp->fd);
msgp += sprintf (msgp, "lNetworkEvents:%d ", ne.lNetworkEvents);
if(ne.lNetworkEvents)
ret++;
- WSAEventSelect(fdp->fd.sock, pEvents[i], 0);
+ WSAEventSelect(fdp->fd, pEvents[i], 0);
}
msgp += sprintf (msgp, "\n");
@@ -1320,7 +1072,7 @@
char *msgp;
fd_set read_set, write_set, err_set;
- SOCKET max_fd = 0;
+ int max_fd = 0;
int i;
struct timeval tv;
int ready;
@@ -1339,12 +1091,12 @@
if (fdp->events & _DBUS_POLLIN)
- msgp += sprintf (msgp, "R:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "R:%d ", fdp->fd);
if (fdp->events & _DBUS_POLLOUT)
- msgp += sprintf (msgp, "W:%Iu ", fdp->fd.sock);
+ msgp += sprintf (msgp, "W:%d ", fdp->fd);
- msgp += sprintf (msgp, "E:%Iu\n\t", fdp->fd.sock);
+ msgp += sprintf (msgp, "E:%d\n\t", fdp->fd);
// FIXME: more robust code for long msg
// create on heap when msg[] becomes too small
@@ -1362,14 +1114,14 @@
DBusPollFD *fdp = &fds[i];
if (fdp->events & _DBUS_POLLIN)
- FD_SET (fdp->fd.sock, &read_set);
+ FD_SET (fdp->fd, &read_set);
if (fdp->events & _DBUS_POLLOUT)
- FD_SET (fdp->fd.sock, &write_set);
+ FD_SET (fdp->fd, &write_set);
- FD_SET (fdp->fd.sock, &err_set);
+ FD_SET (fdp->fd, &err_set);
- max_fd = MAX (max_fd, fdp->fd.sock);
+ max_fd = MAX (max_fd, fdp->fd);
}
// Avoid random lockups with send(), for lack of a better solution so far
@@ -1397,14 +1149,14 @@
{
DBusPollFD *fdp = &fds[i];
- if (FD_ISSET (fdp->fd.sock, &read_set))
- msgp += sprintf (msgp, "R:%Iu ", fdp->fd.sock);
+ if (FD_ISSET (fdp->fd, &read_set))
+ msgp += sprintf (msgp, "R:%d ", fdp->fd);
- if (FD_ISSET (fdp->fd.sock, &write_set))
- msgp += sprintf (msgp, "W:%Iu ", fdp->fd.sock);
+ if (FD_ISSET (fdp->fd, &write_set))
+ msgp += sprintf (msgp, "W:%d ", fdp->fd);
- if (FD_ISSET (fdp->fd.sock, &err_set))
- msgp += sprintf (msgp, "E:%Iu\n\t", fdp->fd.sock);
+ if (FD_ISSET (fdp->fd, &err_set))
+ msgp += sprintf (msgp, "E:%d\n\t", fdp->fd);
}
msgp += sprintf (msgp, "\n");
_dbus_verbose ("%s",msg);
@@ -1416,13 +1168,13 @@
fdp->revents = 0;
- if (FD_ISSET (fdp->fd.sock, &read_set))
+ if (FD_ISSET (fdp->fd, &read_set))
fdp->revents |= _DBUS_POLLIN;
- if (FD_ISSET (fdp->fd.sock, &write_set))
+ if (FD_ISSET (fdp->fd, &write_set))
fdp->revents |= _DBUS_POLLOUT;
- if (FD_ISSET (fdp->fd.sock, &err_set))
+ if (FD_ISSET (fdp->fd, &err_set))
fdp->revents |= _DBUS_POLLERR;
}
}
@@ -1486,7 +1238,7 @@
* @param error return location for error code
* @returns connection file descriptor or -1 on error
*/
-DBusSocket
+int
_dbus_connect_tcp_socket (const char *host,
const char *port,
const char *family,
@@ -1495,25 +1247,20 @@
return _dbus_connect_tcp_socket_with_nonce (host, port, family, (const char*)NULL, error);
}
-DBusSocket
+int
_dbus_connect_tcp_socket_with_nonce (const char *host,
const char *port,
const char *family,
const char *noncefile,
DBusError *error)
{
- DBusSocket fd = DBUS_SOCKET_INIT;
- int res;
+ int fd = -1, res;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!_dbus_win_startup_winsock ())
- {
- _DBUS_SET_OOM (error);
- return _dbus_socket_get_invalid ();
- }
+ _dbus_win_startup_winsock ();
_DBUS_ZERO (hints);
@@ -1528,7 +1275,7 @@
dbus_set_error (error,
DBUS_ERROR_INVALID_ARGS,
"Unknown address family %s", family);
- return _dbus_socket_get_invalid ();
+ return -1;
}
hints.ai_protocol = IPPROTO_TCP;
hints.ai_socktype = SOCK_STREAM;
@@ -1544,13 +1291,13 @@
_dbus_error_from_errno (res),
"Failed to lookup host/port: \"%s:%s\": %s (%d)",
host, port, _dbus_strerror(res), res);
- return _dbus_socket_get_invalid ();
+ return -1;
}
tmp = ai;
while (tmp)
{
- if ((fd.sock = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error,
@@ -1558,15 +1305,15 @@
"Failed to open socket: %s",
_dbus_strerror_from_errno ());
freeaddrinfo(ai);
- return _dbus_socket_get_invalid ();
+ return -1;
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- if (connect (fd.sock, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
+ if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
- closesocket(fd.sock);
- fd.sock = INVALID_SOCKET;
+ closesocket(fd);
+ fd = -1;
tmp = tmp->ai_next;
continue;
}
@@ -1575,13 +1322,13 @@
}
freeaddrinfo(ai);
- if (!_dbus_socket_is_valid (fd))
+ if (fd == -1)
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
"Failed to connect to socket \"%s:%s\" %s",
host, port, _dbus_strerror_from_errno ());
- return _dbus_socket_get_invalid ();
+ return -1;
}
if (noncefile != NULL)
@@ -1591,9 +1338,9 @@
if (!_dbus_string_init (&noncefileStr) ||
!_dbus_string_append(&noncefileStr, noncefile))
{
- closesocket (fd.sock);
+ closesocket (fd);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
- return _dbus_socket_get_invalid ();
+ return -1;
}
ret = _dbus_send_nonce (fd, &noncefileStr, error);
@@ -1602,18 +1349,17 @@
if (!ret)
{
- closesocket (fd.sock);
- return _dbus_socket_get_invalid ();
+ closesocket (fd);
+ return -1;
}
}
- /* Every SOCKET is also a HANDLE. */
- _dbus_win_handle_set_close_on_exec ((HANDLE) fd.sock);
+ _dbus_fd_set_close_on_exec (fd);
- if (!_dbus_set_socket_nonblocking (fd, error))
+ if (!_dbus_set_fd_nonblocking (fd, error))
{
- closesocket (fd.sock);
- return _dbus_socket_get_invalid ();
+ closesocket (fd);
+ return -1;
}
return fd;
@@ -1639,11 +1385,10 @@
const char *port,
const char *family,
DBusString *retport,
- DBusSocket **fds_p,
+ int **fds_p,
DBusError *error)
{
- DBusSocket *listen_fd = NULL;
- int nlisten_fd = 0, res, i, port_num = -1;
+ int nlisten_fd = 0, *listen_fd = NULL, res, i, port_num = -1;
struct addrinfo hints;
struct addrinfo *ai, *tmp;
@@ -1660,16 +1405,12 @@
*fds_p = NULL;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
- if (!_dbus_win_startup_winsock ())
- {
- _DBUS_SET_OOM (error);
- return -1;
- }
+ _dbus_win_startup_winsock ();
_DBUS_ZERO (hints);
if (!family)
- hints.ai_family = AF_INET;
+ hints.ai_family = AF_UNSPEC;
else if (!strcmp(family, "ipv4"))
hints.ai_family = AF_INET;
else if (!strcmp(family, "ipv6"))
@@ -1703,8 +1444,8 @@
tmp = ai;
while (tmp)
{
- DBusSocket fd = DBUS_SOCKET_INIT, *newlisten_fd;
- if ((fd.sock = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ int fd = -1, *newlisten_fd;
+ if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error,
@@ -1715,39 +1456,30 @@
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- if (bind (fd.sock, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
+ if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
- closesocket (fd.sock);
- if (errno == WSAEADDRINUSE)
- {
- /* Calling this function with port=0 tries to
- * bind the same port twice, so we should
- * ignore the second bind.
- */
- tmp = tmp->ai_next;
- continue;
- }
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to bind socket \"%s:%s\": %s",
host ? host : "*", port, _dbus_strerror_from_errno ());
+ closesocket (fd);
goto failed;
}
- if (listen (fd.sock, 30 /* backlog */) == SOCKET_ERROR)
+ if (listen (fd, 30 /* backlog */) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to listen on socket \"%s:%s\": %s",
host ? host : "*", port, _dbus_strerror_from_errno ());
- closesocket (fd.sock);
+ closesocket (fd);
goto failed;
}
- newlisten_fd = dbus_realloc(listen_fd, sizeof(DBusSocket)*(nlisten_fd+1));
+ newlisten_fd = dbus_realloc(listen_fd, sizeof(int)*(nlisten_fd+1));
if (!newlisten_fd)
{
- closesocket (fd.sock);
+ closesocket (fd);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
"Failed to allocate file handle array");
goto failed;
@@ -1766,12 +1498,9 @@
{
mysockaddr_gen addr;
socklen_t addrlen = sizeof(addr);
- char portbuf[NI_MAXSERV];
+ char portbuf[10];
- if (getsockname(fd.sock, &addr.Address, &addrlen) == SOCKET_ERROR ||
- (res = getnameinfo (&addr.Address, addrlen, NULL, 0,
- portbuf, sizeof(portbuf),
- NI_NUMERICSERV)) != 0)
+ if (getsockname(fd, &addr.Address, &addrlen) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
@@ -1779,6 +1508,7 @@
host ? host : "*", port, _dbus_strerror_from_errno());
goto failed;
}
+ snprintf( portbuf, sizeof( portbuf ) - 1, "%d", addr.AddressIn.sin_port );
if (!_dbus_string_append(retport, portbuf))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
@@ -1818,8 +1548,8 @@
for (i = 0 ; i < nlisten_fd ; i++)
{
- _dbus_win_handle_set_close_on_exec ((HANDLE) listen_fd[i].sock);
- if (!_dbus_set_socket_nonblocking (listen_fd[i], error))
+ _dbus_fd_set_close_on_exec (listen_fd[i]);
+ if (!_dbus_set_fd_nonblocking (listen_fd[i], error))
{
goto failed;
}
@@ -1833,7 +1563,7 @@
if (ai)
freeaddrinfo(ai);
for (i = 0 ; i < nlisten_fd ; i++)
- closesocket (listen_fd[i].sock);
+ closesocket (listen_fd[i]);
dbus_free(listen_fd);
return -1;
}
@@ -1846,22 +1576,22 @@
* @param listen_fd the listen file descriptor
* @returns the connection fd of the client, or -1 on error
*/
-DBusSocket
-_dbus_accept (DBusSocket listen_fd)
+int
+_dbus_accept (int listen_fd)
{
- DBusSocket client_fd;
+ int client_fd;
retry:
- client_fd.sock = accept (listen_fd.sock, NULL, NULL);
+ client_fd = accept (listen_fd, NULL, NULL);
- if (!_dbus_socket_is_valid (client_fd))
+ if (DBUS_SOCKET_IS_INVALID (client_fd))
{
DBUS_SOCKET_SET_ERRNO ();
if (errno == EINTR)
goto retry;
}
- _dbus_verbose ("client fd %Iu accepted\n", client_fd.sock);
+ _dbus_verbose ("client fd %d accepted\n", client_fd);
return client_fd;
}
@@ -1870,8 +1600,8 @@
dbus_bool_t
-_dbus_send_credentials_socket (DBusSocket handle,
- DBusError *error)
+_dbus_send_credentials_socket (int handle,
+ DBusError *error)
{
/* FIXME: for the session bus credentials shouldn't matter (?), but
* for the system bus they are presumably essential. A rough outline
@@ -1935,59 +1665,40 @@
* 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 handle the client file descriptor
+ * @param client_fd the client file descriptor
* @param credentials struct to fill with credentials of client
* @param error location to store error code
* @returns #TRUE on success
*/
dbus_bool_t
-_dbus_read_credentials_socket (DBusSocket handle,
+_dbus_read_credentials_socket (int handle,
DBusCredentials *credentials,
DBusError *error)
{
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\n");
+ _dbus_verbose("got one zero byte from server");
- _dbus_string_free (&buf);
+ _dbus_string_free(&buf);
}
- pid = _dbus_get_peer_pid_from_tcp_handle (handle.sock);
- if (pid == 0)
- return TRUE;
+ _dbus_credentials_add_from_current_process (credentials);
+ _dbus_verbose("FIXME: get faked credentials from current process");
- _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;
+ return TRUE;
}
/**
@@ -2081,10 +1792,10 @@
dbus_bool_t retval = FALSE;
char *sid = NULL;
- if (!_dbus_getsid(&sid, _dbus_getpid()))
+ if (!_dbus_getsid(&sid))
goto failed;
- if (!_dbus_credentials_add_pid (credentials, _dbus_getpid()))
+ if (!_dbus_credentials_add_unix_pid(credentials, _dbus_getpid()))
goto failed;
if (!_dbus_credentials_add_windows_sid (credentials,sid))
@@ -2119,7 +1830,7 @@
dbus_bool_t retval = FALSE;
char *sid = NULL;
- if (!_dbus_getsid(&sid, _dbus_getpid()))
+ if (!_dbus_getsid(&sid))
return FALSE;
retval = _dbus_string_append (str,sid);
@@ -2138,15 +1849,6 @@
return GetCurrentProcessId ();
}
-/** Gets our Unix UID
- * @returns on Windows, just DBUS_UID_UNSET
- */
-dbus_uid_t
-_dbus_getuid (void)
-{
- return DBUS_UID_UNSET;
-}
-
/** nanoseconds in a second */
#define NANOSECONDS_PER_SECOND 1000000000
/** microseconds in a second */
@@ -2262,13 +1964,11 @@
*
* @param str the string
* @param n_bytes the number of random bytes to append to string
- * @param error location to store reason for failure
- * @returns #TRUE on success
+ * @returns #TRUE on success, #FALSE if no memory
*/
dbus_bool_t
_dbus_generate_random_bytes (DBusString *str,
- int n_bytes,
- DBusError *error)
+ int n_bytes)
{
int old_len;
char *p;
@@ -2277,22 +1977,15 @@
old_len = _dbus_string_get_length (str);
if (!_dbus_string_lengthen (str, n_bytes))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
+ return FALSE;
p = _dbus_string_get_data_len (str, old_len, n_bytes);
if (!CryptAcquireContext (&hprov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
+ return FALSE;
if (!CryptGenRandom (hprov, n_bytes, p))
{
- _DBUS_SET_OOM (error);
CryptReleaseContext (hprov, 0);
return FALSE;
}
@@ -2306,18 +1999,14 @@
* 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, or #NULL if no memory for locking
+ * @returns location of temp directory
*/
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;
@@ -2339,8 +2028,6 @@
tmpdir = buf;
}
- _DBUS_UNLOCK (sysdeps);
-
_dbus_assert(tmpdir != NULL);
return tmpdir;
@@ -2376,7 +2063,51 @@
return TRUE;
}
-#if !defined (DBUS_DISABLE_ASSERT) || defined(DBUS_ENABLE_EMBEDDED_TESTS)
+/*
+ * 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(_MSC_VER) || defined(DBUS_WINCE)
# ifdef BACKTRACES
@@ -2412,7 +2143,7 @@
#include <imagehlp.h>
#include <stdio.h>
-#define DPRINTF(fmt, ...) fprintf (stderr, fmt, ##__VA_ARGS__)
+#define DPRINTF _dbus_warn
#ifdef _MSC_VER
#define BOOL int
@@ -2944,7 +2675,6 @@
char *shared_addr = NULL;
DBusString shm_name;
DBusString mutex_name;
- dbus_uint64_t len;
_dbus_assert (address);
@@ -2979,11 +2709,8 @@
}
// create shm
- len = strlen (address) + 1;
-
hDBusSharedMem = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
- len >> 32, len & 0xffffffffu,
- _dbus_string_get_const_data(&shm_name) );
+ 0, strlen( address ) + 1, _dbus_string_get_const_data(&shm_name) );
_dbus_assert( hDBusSharedMem );
shared_addr = MapViewOfFile( hDBusSharedMem, FILE_MAP_WRITE, 0, 0, 0 );
@@ -3127,8 +2854,8 @@
if (_dbus_daemon_already_runs(address,&shm_name,scope))
{
- _dbus_verbose( "found running dbus daemon for scope '%s' at %s\n",
- scope ? scope : "", _dbus_string_get_const_data (&shm_name) );
+ _dbus_verbose( "found running dbus daemon at %s\n",
+ _dbus_string_get_const_data (&shm_name) );
retval = TRUE;
goto out;
}
@@ -3199,7 +2926,6 @@
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_global_unlock (mutex);
- _dbus_string_free (&shm_name);
return retval;
}
@@ -3220,6 +2946,142 @@
}
/**
+ * 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
@@ -3259,18 +3121,8 @@
dbus_int32_t
_dbus_atomic_get (DBusAtomic *atomic)
{
- /* 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);
-
+ /* this is what GLib does, hopefully it's right... */
+ MemoryBarrier ();
return atomic->value;
}
@@ -3290,18 +3142,18 @@
* See if errno is EAGAIN or EWOULDBLOCK (this has to be done differently
* for Winsock so is abstracted)
*
- * @returns #TRUE if e == EAGAIN or e == EWOULDBLOCK
+ * @returns #TRUE if errno == EAGAIN or errno == EWOULDBLOCK
*/
dbus_bool_t
-_dbus_get_is_errno_eagain_or_ewouldblock (int e)
+_dbus_get_is_errno_eagain_or_ewouldblock (void)
{
- return e == WSAEWOULDBLOCK;
+ return errno == WSAEWOULDBLOCK;
}
/**
* return the absolute path of the dbus installation
*
- * @param prefix buffer for installation path
+ * @param s buffer for installation path
* @param len length of buffer
* @returns #FALSE on failure
*/
@@ -3341,6 +3193,97 @@
return TRUE;
}
+/**
+ find config file either from installation or build root according to
+ the following path layout
+ install-root/
+ bin/dbus-daemon[d].exe
+ etc/<config-file>.conf *or* etc/dbus-1/<config-file>.conf
+ (the former above is what dbus4win uses, the latter above is
+ what a "normal" Unix-style "make install" uses)
+
+ build-root/
+ bin/dbus-daemon[d].exe
+ bus/<config-file>.conf
+*/
+dbus_bool_t
+_dbus_get_config_file_name(DBusString *config_file, char *s)
+{
+ char path[MAX_PATH*2];
+ int path_size = sizeof(path);
+
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+
+ if(strlen(s) + 4 + strlen(path) > sizeof(path)-2)
+ return FALSE;
+ strcat(path,"etc\\");
+ strcat(path,s);
+ if (_dbus_file_exists(path))
+ {
+ // find path from executable
+ if (!_dbus_string_append (config_file, path))
+ return FALSE;
+ }
+ else
+ {
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+ if(strlen(s) + 11 + strlen(path) > sizeof(path)-2)
+ return FALSE;
+ strcat(path,"etc\\dbus-1\\");
+ strcat(path,s);
+
+ if (_dbus_file_exists(path))
+ {
+ if (!_dbus_string_append (config_file, path))
+ return FALSE;
+ }
+ else
+ {
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+ if(strlen(s) + 4 + strlen(path) > sizeof(path)-2)
+ return FALSE;
+ strcat(path,"bus\\");
+ strcat(path,s);
+
+ if (_dbus_file_exists(path))
+ {
+ if (!_dbus_string_append (config_file, path))
+ return FALSE;
+ }
+ }
+ }
+ 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,
@@ -3392,7 +3335,7 @@
_dbus_string_append(&homedir,homepath);
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
{
const char *override;
@@ -3408,8 +3351,6 @@
}
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)
{
@@ -3620,8 +3561,13 @@
(LPSTR) &msg, 0, NULL);
if (msg)
{
- dbus_set_error (error, "win32.error", "%s", msg);
+ char *msg_copy;
+
+ msg_copy = dbus_malloc (strlen (msg));
+ strcpy (msg_copy, msg);
LocalFree (msg);
+
+ dbus_set_error (error, "win32.error", "%s", msg_copy);
}
else
dbus_set_error (error, "win32.error", "Unknown error code %d or FormatMessage failed", code);
@@ -3629,7 +3575,7 @@
void
_dbus_win_warn_win_error (const char *message,
- unsigned long code)
+ int code)
{
DBusError error;
@@ -3692,18 +3638,6 @@
return FALSE;
}
-int
-_dbus_save_socket_errno (void)
-{
- return errno;
-}
-
-void
-_dbus_restore_socket_errno (int saved_errno)
-{
- _dbus_win_set_errno (saved_errno);
-}
-
/** @} 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 e9b30d7..74624b7 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 WIN32_LEAN_AND_MEAN
+#define _WINSOCKAPI_
#include "dbus-hash.h"
#include "dbus-string.h"
@@ -40,16 +40,13 @@
void _dbus_win_set_errno (int err);
-DBUS_PRIVATE_EXPORT
const char* _dbus_win_error_from_last_error (void);
-dbus_bool_t _dbus_win_startup_winsock (void);
+void _dbus_win_startup_winsock (void);
void _dbus_win_warn_win_error (const char *message,
- unsigned long code);
+ int code);
-DBUS_PRIVATE_EXPORT
char * _dbus_win_error_string (int error_number);
-DBUS_PRIVATE_EXPORT
void _dbus_win_free_error_string (char *string);
extern const char* _dbus_lm_strerror (int error_number);
@@ -73,7 +70,6 @@
char *_dbus_win_utf16_to_utf8 (const wchar_t *str,
DBusError *error);
-DBUS_PRIVATE_EXPORT
void _dbus_win_set_error_from_win_error (DBusError *error, int code);
dbus_bool_t
@@ -84,14 +80,11 @@
dbus_bool_t _dbus_file_exists (const char *filename);
-DBUS_PRIVATE_EXPORT
+dbus_bool_t _dbus_get_config_file_name(DBusString *config_file,
+ char *s);
+
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);
-
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_getsid(char **sid, dbus_pid_t process_id);
#endif
/** @} end of sysdeps-win.h */
diff --git a/dbus/dbus-sysdeps-wince-glue.c b/dbus/dbus-sysdeps-wince-glue.c
index e276f04..74b1371 100644
--- a/dbus/dbus-sysdeps-wince-glue.c
+++ b/dbus/dbus-sysdeps-wince-glue.c
@@ -491,7 +491,7 @@
/** Gets our SID
- * @param sid points to sid buffer, need to be freed with LocalFree()
+ * @param 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 8b986d5..04fb8d7 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -29,7 +29,6 @@
#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.
@@ -47,6 +46,10 @@
#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__)
@@ -93,8 +96,6 @@
}
/**
- * @ingroup DBusMisc
- *
* Wrapper for setenv(). If the value is #NULL, unsets
* the environment variable.
*
@@ -103,16 +104,13 @@
* 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, or #NULL to unset
- * @returns #TRUE on success, #FALSE if not enough memory.
+ * @param value value of environment variable
+ * @returns #TRUE on success.
*/
dbus_bool_t
-dbus_setenv (const char *varname,
- const char *value)
+_dbus_setenv (const char *varname,
+ const char *value)
{
_dbus_assert (varname != NULL);
@@ -504,37 +502,63 @@
* @{
*/
+void
+_dbus_generate_pseudorandom_bytes_buffer (char *buffer,
+ int n_bytes)
+{
+ long tv_usec;
+ int i;
+
+ /* fall back to pseudorandom */
+ _dbus_verbose ("Falling back to pseudorandom for %d bytes\n",
+ n_bytes);
+
+ _dbus_get_real_time (NULL, &tv_usec);
+ srand (tv_usec);
+
+ i = 0;
+ while (i < n_bytes)
+ {
+ double r;
+ unsigned int b;
+
+ r = rand ();
+ b = (r / (double) RAND_MAX) * 255.0;
+
+ buffer[i] = b;
+
+ ++i;
+ }
+}
+
/**
* Fills n_bytes of the given buffer with random bytes.
*
* @param buffer an allocated buffer
* @param n_bytes the number of bytes in buffer to write to
- * @param error location to store reason for failure
- * @returns #TRUE on success
*/
-dbus_bool_t
-_dbus_generate_random_bytes_buffer (char *buffer,
- int n_bytes,
- DBusError *error)
+void
+_dbus_generate_random_bytes_buffer (char *buffer,
+ int n_bytes)
{
DBusString str;
if (!_dbus_string_init (&str))
{
- _DBUS_SET_OOM (error);
- return FALSE;
+ _dbus_generate_pseudorandom_bytes_buffer (buffer, n_bytes);
+ return;
}
- if (!_dbus_generate_random_bytes (&str, n_bytes, error))
+ if (!_dbus_generate_random_bytes (&str, n_bytes))
{
_dbus_string_free (&str);
- return FALSE;
+ _dbus_generate_pseudorandom_bytes_buffer (buffer, n_bytes);
+ return;
}
_dbus_string_copy_to_buffer (&str, buffer, n_bytes);
_dbus_string_free (&str);
- return TRUE;
}
/**
@@ -543,20 +567,18 @@
*
* @param str the string
* @param n_bytes the number of random ASCII bytes to append to string
- * @param error location to store reason for failure
* @returns #TRUE on success, #FALSE if no memory or other failure
*/
dbus_bool_t
_dbus_generate_random_ascii (DBusString *str,
- int n_bytes,
- DBusError *error)
+ int n_bytes)
{
static const char letters[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
int i;
int len;
- if (!_dbus_generate_random_bytes (str, n_bytes, error))
+ if (!_dbus_generate_random_bytes (str, n_bytes))
return FALSE;
len = _dbus_string_get_length (str);
@@ -698,23 +720,33 @@
}
/**
- * See if errno is ENOMEM
- * @returns #TRUE if e == ENOMEM
+ * See if errno is set
+ * @returns #TRUE if errno is not 0
*/
dbus_bool_t
-_dbus_get_is_errno_enomem (int e)
+_dbus_get_is_errno_nonzero (void)
{
- return e == ENOMEM;
+ return errno != 0;
+}
+
+/**
+ * See if errno is ENOMEM
+ * @returns #TRUE if errno == ENOMEM
+ */
+dbus_bool_t
+_dbus_get_is_errno_enomem (void)
+{
+ return errno == ENOMEM;
}
/**
* See if errno is EINTR
- * @returns #TRUE if e == EINTR
+ * @returns #TRUE if errno == EINTR
*/
dbus_bool_t
-_dbus_get_is_errno_eintr (int e)
+_dbus_get_is_errno_eintr (void)
{
- return e == EINTR;
+ return errno == EINTR;
}
/**
@@ -722,23 +754,9 @@
* @returns #TRUE if errno == EPIPE
*/
dbus_bool_t
-_dbus_get_is_errno_epipe (int e)
+_dbus_get_is_errno_epipe (void)
{
- return e == EPIPE;
-}
-
-/**
- * See if errno is ETOOMANYREFS
- * @returns #TRUE if errno == ETOOMANYREFS
- */
-dbus_bool_t
-_dbus_get_is_errno_etoomanyrefs (int e)
-{
-#ifdef ETOOMANYREFS
- return e == ETOOMANYREFS;
-#else
- return FALSE;
-#endif
+ return errno == EPIPE;
}
/**
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 2d152b8..eee9160 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -25,10 +25,7 @@
#ifndef DBUS_SYSDEPS_H
#define DBUS_SYSDEPS_H
-#ifndef VERSION
-#warning Please include config.h before dbus-sysdeps.h
#include "config.h"
-#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
@@ -62,10 +59,6 @@
#include "dbus-sysdeps-wince-glue.h"
#endif
-#ifdef DBUS_WIN
-#include <ws2tcpip.h>
-#endif
-
DBUS_BEGIN_DECLS
#ifdef DBUS_WIN
@@ -95,9 +88,9 @@
void _dbus_abort (void) _DBUS_GNUC_NORETURN;
dbus_bool_t _dbus_check_setuid (void);
-DBUS_PRIVATE_EXPORT
const char* _dbus_getenv (const char *varname);
-DBUS_PRIVATE_EXPORT
+dbus_bool_t _dbus_setenv (const char *varname,
+ const char *value);
dbus_bool_t _dbus_clearenv (void);
char ** _dbus_get_environment (void);
@@ -122,71 +115,27 @@
/** an appropriate printf format for dbus_gid_t */
#define DBUS_GID_FORMAT "%lu"
+
/**
* Socket interface
+ *
+ * @todo Use for the file descriptors a struct
+ * - struct DBusSocket{ int d; }; -
+ * instead of int to get type-safety which
+ * will be checked by the compiler.
+ *
*/
-#ifdef DBUS_WIN
-typedef struct { SOCKET sock; } DBusSocket;
-# define DBUS_SOCKET_FORMAT "Iu"
-# define DBUS_SOCKET_INIT { INVALID_SOCKET }
-
-static inline SOCKET
-_dbus_socket_printable (DBusSocket s) { return s.sock; }
-
-static inline dbus_bool_t
-_dbus_socket_is_valid (DBusSocket s) { return s.sock != INVALID_SOCKET; }
-
-static inline void
-_dbus_socket_invalidate (DBusSocket *s) { s->sock = INVALID_SOCKET; }
-
-static inline int
-_dbus_socket_get_int (DBusSocket s) { return (int)s.sock; }
-
-#else /* not DBUS_WIN */
-
-typedef struct { int fd; } DBusSocket;
-# define DBUS_SOCKET_FORMAT "d"
-# define DBUS_SOCKET_INIT { -1 }
-
-static inline int
-_dbus_socket_printable (DBusSocket s) { return s.fd; }
-
-static inline dbus_bool_t
-_dbus_socket_is_valid (DBusSocket s) { return s.fd >= 0; }
-
-static inline void
-_dbus_socket_invalidate (DBusSocket *s) { s->fd = -1; }
-
-static inline int
-_dbus_socket_get_int (DBusSocket s) { return s.fd; }
-
-#endif /* not DBUS_WIN */
-
-static inline DBusSocket
-_dbus_socket_get_invalid (void)
-{
- DBusSocket s = DBUS_SOCKET_INIT;
-
- return s;
-}
-
-dbus_bool_t _dbus_set_socket_nonblocking (DBusSocket fd,
- DBusError *error);
-
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_close_socket (DBusSocket fd,
+dbus_bool_t _dbus_close_socket (int fd,
DBusError *error);
-DBUS_PRIVATE_EXPORT
-int _dbus_read_socket (DBusSocket fd,
+int _dbus_read_socket (int fd,
DBusString *buffer,
int count);
-DBUS_PRIVATE_EXPORT
-int _dbus_write_socket (DBusSocket fd,
+int _dbus_write_socket (int fd,
const DBusString *buffer,
int start,
int len);
-int _dbus_write_socket_two (DBusSocket fd,
+int _dbus_write_socket_two (int fd,
const DBusString *buffer1,
int start1,
int len1,
@@ -194,19 +143,18 @@
int start2,
int len2);
-int _dbus_read_socket_with_unix_fds (DBusSocket fd,
+int _dbus_read_socket_with_unix_fds (int fd,
DBusString *buffer,
int count,
int *fds,
int *n_fds);
-DBUS_PRIVATE_EXPORT
-int _dbus_write_socket_with_unix_fds (DBusSocket fd,
+int _dbus_write_socket_with_unix_fds (int fd,
const DBusString *buffer,
int start,
int len,
const int *fds,
int n_fds);
-int _dbus_write_socket_with_unix_fds_two (DBusSocket fd,
+int _dbus_write_socket_with_unix_fds_two (int fd,
const DBusString *buffer1,
int start1,
int len1,
@@ -216,33 +164,35 @@
const int *fds,
int n_fds);
-DBusSocket _dbus_connect_tcp_socket (const char *host,
- const char *port,
- const char *family,
- DBusError *error);
-DBusSocket _dbus_connect_tcp_socket_with_nonce (const char *host,
- const char *port,
- const char *family,
- const char *noncefile,
- DBusError *error);
+dbus_bool_t _dbus_socket_is_invalid (int fd);
+
+int _dbus_connect_tcp_socket (const char *host,
+ const char *port,
+ const char *family,
+ DBusError *error);
+int _dbus_connect_tcp_socket_with_nonce (const char *host,
+ const char *port,
+ const char *family,
+ const char *noncefile,
+ DBusError *error);
int _dbus_listen_tcp_socket (const char *host,
const char *port,
const char *family,
DBusString *retport,
- DBusSocket **fds_p,
+ int **fds_p,
DBusError *error);
-DBusSocket _dbus_accept (DBusSocket listen_fd);
+int _dbus_accept (int listen_fd);
-dbus_bool_t _dbus_read_credentials_socket (DBusSocket client_fd,
+
+dbus_bool_t _dbus_read_credentials_socket (int client_fd,
DBusCredentials *credentials,
DBusError *error);
-dbus_bool_t _dbus_send_credentials_socket (DBusSocket server_fd,
+dbus_bool_t _dbus_send_credentials_socket (int server_fd,
DBusError *error);
dbus_bool_t _dbus_credentials_add_from_user (DBusCredentials *credentials,
const DBusString *username);
dbus_bool_t _dbus_credentials_add_from_current_process (DBusCredentials *credentials);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_append_user_from_current_process (DBusString *str);
dbus_bool_t _dbus_parse_unix_user_from_config (const DBusString *username,
@@ -266,7 +216,7 @@
void _dbus_daemon_unpublish_session_bus_address (void);
-dbus_bool_t _dbus_socket_can_pass_unix_fd(DBusSocket fd);
+dbus_bool_t _dbus_socket_can_pass_unix_fd(int fd);
/** Opaque type representing an atomically-modifiable integer
* that can be used from multiple threads.
@@ -295,95 +245,40 @@
# undef DBUS_HAVE_ATOMIC_INT
#endif
-DBUS_PRIVATE_EXPORT
dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
-DBUS_PRIVATE_EXPORT
dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
-DBUS_PRIVATE_EXPORT
dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
-#ifdef DBUS_WIN
-/* On Windows, you can only poll sockets. We emulate Unix poll() using
- * select(), so it doesn't matter what precise type we put in DBusPollFD;
- * use DBusSocket so that the compiler can check we are doing it right.
- */
-typedef DBusSocket DBusPollable;
-# define DBUS_POLLABLE_FORMAT "Iu"
+/* AIX uses different values for poll */
-static inline DBusPollable
-_dbus_socket_get_pollable (DBusSocket s) { return s; }
-
-static inline SOCKET
-_dbus_pollable_printable (DBusPollable p) { return p.sock; }
-
-static inline dbus_bool_t
-_dbus_pollable_is_valid (DBusPollable p) { return _dbus_socket_is_valid (p); }
-
-static inline void
-_dbus_pollable_invalidate (DBusPollable *p) { _dbus_socket_invalidate (p); }
-
-static inline dbus_bool_t
-_dbus_pollable_equals (DBusPollable a, DBusPollable b) { return a.sock == b.sock; }
-
-#else /* !DBUS_WIN */
-
-/* On Unix, you can poll sockets, pipes, etc., and we must put exactly
- * "int" in DBusPollFD because we're relying on its layout exactly matching
- * struct pollfd. (This is silly, and one day we should use a better
- * abstraction.)
- */
-typedef int DBusPollable;
-# define DBUS_POLLABLE_FORMAT "d"
-
-static inline DBusPollable
-_dbus_socket_get_pollable (DBusSocket s) { return s.fd; }
-
-static inline int
-_dbus_pollable_printable (DBusPollable p) { return p; }
-
-static inline dbus_bool_t
-_dbus_pollable_is_valid (DBusPollable p) { return p >= 0; }
-
-static inline void
-_dbus_pollable_invalidate (DBusPollable *p) { *p = -1; }
-
-static inline dbus_bool_t
-_dbus_pollable_equals (DBusPollable a, DBusPollable b) { return a == b; }
-
-#endif /* !DBUS_WIN */
-
-#if defined(HAVE_POLL) && !defined(BROKEN_POLL)
-/**
- * A portable struct pollfd wrapper, or an emulation of struct pollfd
- * on platforms where poll() is missing or broken.
- */
-typedef struct pollfd DBusPollFD;
-
+#ifdef _AIX
/** There is data to read */
-#define _DBUS_POLLIN POLLIN
+#define _DBUS_POLLIN 0x0001
/** There is urgent data to read */
-#define _DBUS_POLLPRI POLLPRI
+#define _DBUS_POLLPRI 0x0004
/** Writing now will not block */
-#define _DBUS_POLLOUT POLLOUT
+#define _DBUS_POLLOUT 0x0002
/** Error condition */
-#define _DBUS_POLLERR POLLERR
+#define _DBUS_POLLERR 0x4000
/** Hung up */
-#define _DBUS_POLLHUP POLLHUP
+#define _DBUS_POLLHUP 0x2000
/** Invalid request: fd not open */
-#define _DBUS_POLLNVAL POLLNVAL
+#define _DBUS_POLLNVAL 0x8000
+#elif defined(__HAIKU__)
+/** There is data to read */
+#define _DBUS_POLLIN 0x0001
+/** Writing now will not block */
+#define _DBUS_POLLOUT 0x0002
+/** Error condition */
+#define _DBUS_POLLERR 0x0004
+/** There is urgent data to read */
+#define _DBUS_POLLPRI 0x0020
+/** Hung up */
+#define _DBUS_POLLHUP 0x0080
+/** Invalid request: fd not open */
+#define _DBUS_POLLNVAL 0x1000
#else
-/* Emulate poll() via select(). Because we aren't really going to call
- * poll(), any similarly-shaped struct is acceptable, and any power of 2
- * will do for the events/revents; these values happen to match Linux
- * and *BSD. */
-typedef struct
-{
- DBusPollable fd; /**< File descriptor */
- short events; /**< Events to poll for */
- short revents; /**< Events that occurred */
-} DBusPollFD;
-
/** There is data to read */
#define _DBUS_POLLIN 0x0001
/** There is urgent data to read */
@@ -398,38 +293,40 @@
#define _DBUS_POLLNVAL 0x0020
#endif
-DBUS_PRIVATE_EXPORT
+/**
+ * A portable struct pollfd wrapper.
+ */
+typedef struct
+{
+ int fd; /**< File descriptor */
+ short events; /**< Events to poll for */
+ short revents; /**< Events that occurred */
+} DBusPollFD;
+
int _dbus_poll (DBusPollFD *fds,
int n_fds,
int timeout_milliseconds);
-DBUS_PRIVATE_EXPORT
void _dbus_sleep_milliseconds (int milliseconds);
-DBUS_PRIVATE_EXPORT
void _dbus_get_monotonic_time (long *tv_sec,
long *tv_usec);
-DBUS_PRIVATE_EXPORT
void _dbus_get_real_time (long *tv_sec,
long *tv_usec);
/**
* directory interface
*/
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_create_directory (const DBusString *filename,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_delete_directory (const DBusString *filename,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_concat_dir_and_file (DBusString *dir,
const DBusString *next_component);
dbus_bool_t _dbus_string_get_dirname (const DBusString *filename,
DBusString *dirname);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_path_is_absolute (const DBusString *filename);
dbus_bool_t _dbus_get_standard_session_servicedirs (DBusList **dirs);
@@ -451,46 +348,38 @@
dbus_bool_t _dbus_check_dir_is_private_to_user (DBusString *dir,
DBusError *error);
-DBUS_PRIVATE_EXPORT
+void _dbus_fd_set_close_on_exec (intptr_t fd);
+
const char* _dbus_get_tmpdir (void);
/**
* Random numbers
*/
-_DBUS_GNUC_WARN_UNUSED_RESULT
-dbus_bool_t _dbus_generate_random_bytes_buffer (char *buffer,
- int n_bytes,
- DBusError *error);
+void _dbus_generate_pseudorandom_bytes_buffer (char *buffer,
+ int n_bytes);
+void _dbus_generate_random_bytes_buffer (char *buffer,
+ int n_bytes);
dbus_bool_t _dbus_generate_random_bytes (DBusString *str,
- int n_bytes,
- DBusError *error);
-DBUS_PRIVATE_EXPORT
+ int n_bytes);
dbus_bool_t _dbus_generate_random_ascii (DBusString *str,
- int n_bytes,
- DBusError *error);
+ int n_bytes);
-DBUS_PRIVATE_EXPORT
const char* _dbus_error_from_errno (int error_number);
-DBUS_PRIVATE_EXPORT
const char* _dbus_error_from_system_errno (void);
-int _dbus_save_socket_errno (void);
-void _dbus_restore_socket_errno (int saved_errno);
void _dbus_set_errno_to_zero (void);
-dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (int e);
-dbus_bool_t _dbus_get_is_errno_enomem (int e);
-dbus_bool_t _dbus_get_is_errno_eintr (int e);
-dbus_bool_t _dbus_get_is_errno_epipe (int e);
-dbus_bool_t _dbus_get_is_errno_etoomanyrefs (int e);
-DBUS_PRIVATE_EXPORT
+dbus_bool_t _dbus_get_is_errno_nonzero (void);
+dbus_bool_t _dbus_get_is_errno_eagain_or_ewouldblock (void);
+dbus_bool_t _dbus_get_is_errno_enomem (void);
+dbus_bool_t _dbus_get_is_errno_eintr (void);
+dbus_bool_t _dbus_get_is_errno_epipe (void);
const char* _dbus_strerror_from_errno (void);
void _dbus_disable_sigpipe (void);
-DBUS_PRIVATE_EXPORT
+
void _dbus_exit (int code) _DBUS_GNUC_NORETURN;
-DBUS_PRIVATE_EXPORT
int _dbus_printf_string_upper_bound (const char *format,
va_list args);
@@ -513,11 +402,10 @@
dbus_bool_t _dbus_stat (const DBusString *filename,
DBusStat *statbuf,
DBusError *error);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_socketpair (DBusSocket *fd1,
- DBusSocket *fd2,
- dbus_bool_t blocking,
- DBusError *error);
+dbus_bool_t _dbus_full_duplex_pipe (int *fd1,
+ int *fd2,
+ dbus_bool_t blocking,
+ DBusError *error);
void _dbus_print_backtrace (void);
@@ -549,11 +437,10 @@
dbus_bool_t _dbus_user_at_console (const char *username,
DBusError *error);
-void _dbus_init_system_log (dbus_bool_t is_daemon);
+void _dbus_init_system_log (void);
typedef enum {
DBUS_SYSTEM_LOG_INFO,
- DBUS_SYSTEM_LOG_WARNING,
DBUS_SYSTEM_LOG_SECURITY,
DBUS_SYSTEM_LOG_FATAL
} DBusSystemLogSeverity;
@@ -620,17 +507,6 @@
*/
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_PRIVATE_EXPORT
dbus_bool_t _dbus_split_paths_and_append (DBusString *dirs,
const char *suffix,
DBusList **dir_list);
@@ -641,18 +517,15 @@
* the PID file handling just needs a little more abstraction
* in the bus daemon first.
*/
-DBUS_PRIVATE_EXPORT
dbus_pid_t _dbus_getpid (void);
-DBUS_PRIVATE_EXPORT
-dbus_uid_t _dbus_getuid (void);
-
dbus_bool_t _dbus_change_to_daemon_user (const char *user,
DBusError *error);
-DBUS_PRIVATE_EXPORT
void _dbus_flush_caches (void);
+void _dbus_request_file_descriptor_limit (unsigned int limit);
+
/*
* replaces the term DBUS_PREFIX in configure_time_path by the
* current dbus installation directory. On unix this function is a noop
@@ -663,23 +536,6 @@
const char *
_dbus_replace_install_prefix (const char *configure_time_path);
-/* Do not set this too high: it is a denial-of-service risk.
- * See <https://bugs.freedesktop.org/show_bug.cgi?id=82820>
- *
- * (This needs to be in the non-Unix-specific header so that
- * the config-parser can use it.)
- */
-#define DBUS_DEFAULT_MESSAGE_UNIX_FDS 16
-
-typedef struct DBusRLimit DBusRLimit;
-
-DBusRLimit *_dbus_rlimit_save_fd_limit (DBusError *error);
-dbus_bool_t _dbus_rlimit_raise_fd_limit_if_privileged (unsigned int desired,
- DBusError *error);
-dbus_bool_t _dbus_rlimit_restore_fd_limit (DBusRLimit *saved,
- DBusError *error);
-void _dbus_rlimit_free (DBusRLimit *lim);
-
/** @} */
DBUS_END_DECLS
diff --git a/dbus/dbus-test-main.c b/dbus/dbus-test-main.c
index 08e402b..f6ef782 100644
--- a/dbus/dbus-test-main.c
+++ b/dbus/dbus-test-main.c
@@ -31,10 +31,6 @@
#include <locale.h>
#endif
-#ifdef DBUS_UNIX
-# include <dbus/dbus-sysdeps-unix.h>
-#endif
-
int
main (int argc,
char **argv)
@@ -42,16 +38,11 @@
const char *test_data_dir;
const char *specific_test;
-#ifdef DBUS_UNIX
- /* close any inherited fds so dbus-spawn's check for close-on-exec works */
- _dbus_close_all ();
-#endif
-
#if HAVE_SETLOCALE
setlocale(LC_ALL, "");
#endif
- if (argc > 1 && strcmp (argv[1], "--tap") != 0)
+ if (argc > 1)
test_data_dir = argv[1];
else
test_data_dir = NULL;
diff --git a/dbus/dbus-test.c b/dbus/dbus-test.c
index 5990d6e..224a6c8 100644
--- a/dbus/dbus-test.c
+++ b/dbus/dbus-test.c
@@ -28,7 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
static void
die (const char *failure)
{
@@ -41,7 +41,7 @@
{
dbus_shutdown ();
- printf ("%s: checking for memleaks\n", "test-dbus");
+ printf ("%s: checking for memleaks\n", "dbus-test");
if (_dbus_get_malloc_blocks_outstanding () != 0)
{
_dbus_warn ("%d dbus_malloc blocks were not freed\n",
@@ -60,7 +60,7 @@
{
if (!specific_test || strcmp (specific_test, test_name) == 0)
{
- printf ("%s: running %s tests\n", "test-dbus", test_name);
+ printf ("%s: running %s tests\n", "dbus-test", test_name);
if (!test ())
die (test_name);
@@ -76,7 +76,7 @@
{
if (!specific_test || strcmp (specific_test, test_name) == 0)
{
- printf ("%s: running %s tests\n", "test-dbus", test_name);
+ printf ("%s: running %s tests\n", "dbus-test", test_name);
if (!test (test_data_dir))
die (test_name);
@@ -84,7 +84,7 @@
}
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
/**
* An exported symbol to be run in order to execute
@@ -94,12 +94,11 @@
* (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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
if (!_dbus_threads_init_debug ())
die ("debug threads init");
@@ -165,7 +164,7 @@
run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
- printf ("%s: completed successfully\n", "test-dbus");
+ printf ("%s: completed successfully\n", "dbus-test");
#else
printf ("Not compiled with unit tests, not running any\n");
#endif
diff --git a/dbus/dbus-test.h b/dbus/dbus-test.h
index 71876a1..f254388 100644
--- a/dbus/dbus-test.h
+++ b/dbus/dbus-test.h
@@ -28,72 +28,29 @@
#include <dbus/dbus-string.h>
#include <dbus/dbus-marshal-validate.h>
-/* Only things that are in libdbus-1.la and used from libdbus-internal.la
- * need to have DBUS_PRIVATE_EXPORT. If you get
- *
- * warning: 'foo' redeclared without dllimport attribute: previous
- * dllimport ignored [-Wattributes]
- *
- * then you have added too many.
- */
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_hash_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_marshal_test (void);
-
dbus_bool_t _dbus_marshal_recursive_test (void);
dbus_bool_t _dbus_marshal_byteswap_test (void);
dbus_bool_t _dbus_marshal_validate_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_misc_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_signature_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_mem_pool_test (void);
-
dbus_bool_t _dbus_string_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_address_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_server_test (void);
-
dbus_bool_t _dbus_message_test (const char *test_data_dir);
dbus_bool_t _dbus_auth_test (const char *test_data_dir);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_sha_test (const char *test_data_dir);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_keyring_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_data_slot_test (void);
-
dbus_bool_t _dbus_sysdeps_test (void);
dbus_bool_t _dbus_spawn_test (const char *test_data_dir);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_userdb_test (const char *test_data_dir);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_transport_unix_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_memory_test (void);
-
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_object_tree_test (void);
-
dbus_bool_t _dbus_credentials_test (const char *test_data_dir);
void dbus_internal_do_not_use_run_tests (const char *test_data_dir,
diff --git a/dbus/dbus-threads-internal.h b/dbus/dbus-threads-internal.h
index 076acd2..64e8bac 100644
--- a/dbus/dbus-threads-internal.h
+++ b/dbus/dbus-threads-internal.h
@@ -48,9 +48,7 @@
DBUS_BEGIN_DECLS
-DBUS_PRIVATE_EXPORT
void _dbus_rmutex_lock (DBusRMutex *mutex);
-DBUS_PRIVATE_EXPORT
void _dbus_rmutex_unlock (DBusRMutex *mutex);
void _dbus_rmutex_new_at_location (DBusRMutex **location_p);
void _dbus_rmutex_free_at_location (DBusRMutex **location_p);
diff --git a/dbus/dbus-threads.c b/dbus/dbus-threads.c
index 12d4049..bb1169d 100644
--- a/dbus/dbus-threads.c
+++ b/dbus/dbus-threads.c
@@ -27,6 +27,18 @@
#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
@@ -47,6 +59,11 @@
* 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
@@ -54,13 +71,17 @@
{
_dbus_assert (location_p != NULL);
- if (!dbus_threads_init_default ())
+ if (thread_init_generation == _dbus_current_generation)
{
- *location_p = NULL;
- return;
+ *location_p = _dbus_platform_rmutex_new ();
}
+ else
+ {
+ *location_p = _DBUS_DUMMY_RMUTEX;
- *location_p = _dbus_platform_rmutex_new ();
+ if (!_dbus_list_append (&uninitialized_rmutex_list, location_p))
+ *location_p = NULL;
+ }
}
/**
@@ -71,6 +92,11 @@
*
* 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
@@ -78,17 +104,22 @@
{
_dbus_assert (location_p != NULL);
- if (!dbus_threads_init_default ())
+ if (thread_init_generation == _dbus_current_generation)
{
- *location_p = NULL;
- return;
+ *location_p = _dbus_platform_cmutex_new ();
}
+ else
+ {
+ *location_p = _DBUS_DUMMY_CMUTEX;
- *location_p = _dbus_platform_cmutex_new ();
+ if (!_dbus_list_append (&uninitialized_cmutex_list, location_p))
+ *location_p = NULL;
+ }
}
/**
- * Frees a DBusRMutex; does nothing if passed a #NULL pointer.
+ * Frees a DBusRMutex or removes it from the uninitialized mutex list;
+ * does nothing if passed a #NULL pointer.
*/
void
_dbus_rmutex_free_at_location (DBusRMutex **location_p)
@@ -96,12 +127,23 @@
if (location_p == NULL)
return;
- if (*location_p != NULL)
- _dbus_platform_rmutex_free (*location_p);
+ 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);
+ }
}
/**
- * Frees a DBusCMutex; does nothing if passed a #NULL pointer.
+ * Frees a DBusCMutex and removes it from the
+ * uninitialized mutex list;
+ * does nothing if passed a #NULL pointer.
*/
void
_dbus_cmutex_free_at_location (DBusCMutex **location_p)
@@ -109,8 +151,17 @@
if (location_p == NULL)
return;
- if (*location_p != NULL)
- _dbus_platform_cmutex_free (*location_p);
+ 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);
+ }
}
/**
@@ -121,10 +172,8 @@
void
_dbus_rmutex_lock (DBusRMutex *mutex)
{
- if (mutex == NULL)
- return;
-
- _dbus_platform_rmutex_lock (mutex);
+ if (mutex && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_rmutex_lock (mutex);
}
/**
@@ -135,10 +184,8 @@
void
_dbus_cmutex_lock (DBusCMutex *mutex)
{
- if (mutex == NULL)
- return;
-
- _dbus_platform_cmutex_lock (mutex);
+ if (mutex && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_cmutex_lock (mutex);
}
/**
@@ -149,10 +196,8 @@
void
_dbus_rmutex_unlock (DBusRMutex *mutex)
{
- if (mutex == NULL)
- return;
-
- _dbus_platform_rmutex_unlock (mutex);
+ if (mutex && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_rmutex_unlock (mutex);
}
/**
@@ -163,10 +208,8 @@
void
_dbus_cmutex_unlock (DBusCMutex *mutex)
{
- if (mutex == NULL)
- return;
-
- _dbus_platform_cmutex_unlock (mutex);
+ if (mutex && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_cmutex_unlock (mutex);
}
/**
@@ -180,17 +223,19 @@
DBusCondVar *
_dbus_condvar_new (void)
{
- if (!dbus_threads_init_default ())
- return NULL;
-
- return _dbus_platform_condvar_new ();
+ if (thread_init_generation == _dbus_current_generation)
+ return _dbus_platform_condvar_new ();
+ else
+ return _DBUS_DUMMY_CONDVAR;
}
/**
* 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 used to be useful.
+ * 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.
*
* @returns the location of a new condvar or #NULL on OOM
*/
@@ -200,7 +245,17 @@
{
_dbus_assert (location_p != NULL);
- *location_p = _dbus_condvar_new();
+ 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;
+ }
}
@@ -211,14 +266,14 @@
void
_dbus_condvar_free (DBusCondVar *cond)
{
- if (cond == NULL)
- return;
-
- _dbus_platform_condvar_free (cond);
+ if (cond && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_condvar_free (cond);
}
/**
- * Frees a condition variable; does nothing if passed a #NULL pointer.
+ * Frees a conditional variable and removes it from the
+ * uninitialized_condvar_list;
+ * does nothing if passed a #NULL pointer.
*/
void
_dbus_condvar_free_at_location (DBusCondVar **location_p)
@@ -226,8 +281,17 @@
if (location_p == NULL)
return;
- if (*location_p != NULL)
- _dbus_platform_condvar_free (*location_p);
+ 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);
+ }
}
/**
@@ -240,10 +304,8 @@
_dbus_condvar_wait (DBusCondVar *cond,
DBusCMutex *mutex)
{
- if (cond == NULL || mutex == NULL)
- return;
-
- _dbus_platform_condvar_wait (cond, mutex);
+ if (cond && mutex && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_condvar_wait (cond, mutex);
}
/**
@@ -262,11 +324,11 @@
DBusCMutex *mutex,
int timeout_milliseconds)
{
- if (cond == NULL || mutex == NULL)
+ if (cond && mutex && thread_init_generation == _dbus_current_generation)
+ return _dbus_platform_condvar_wait_timeout (cond, mutex,
+ timeout_milliseconds);
+ else
return TRUE;
-
- return _dbus_platform_condvar_wait_timeout (cond, mutex,
- timeout_milliseconds);
}
/**
@@ -277,83 +339,215 @@
void
_dbus_condvar_wake_one (DBusCondVar *cond)
{
- if (cond == NULL)
- return;
-
- _dbus_platform_condvar_wake_one (cond);
+ if (cond && thread_init_generation == _dbus_current_generation)
+ _dbus_platform_condvar_wake_one (cond);
}
-static DBusRMutex *global_locks[_DBUS_N_GLOBAL_LOCKS] = { NULL };
-
static void
-shutdown_global_locks (void *nil)
+shutdown_global_locks (void *data)
{
+ DBusRMutex ***locks = data;
int i;
- for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
+ i = 0;
+ while (i < _DBUS_N_GLOBAL_LOCKS)
{
- _dbus_assert (global_locks[i] != NULL);
- _dbus_platform_rmutex_free (global_locks[i]);
- global_locks[i] = NULL;
+ if (*(locks[i]) != NULL)
+ _dbus_platform_rmutex_free (*(locks[i]));
+
+ *(locks[i]) = NULL;
+ ++i;
}
+
+ 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_global_locks (void)
+init_uninitialized_locks (void)
{
- int i;
- dbus_bool_t ok;
+ DBusList *link;
- for (i = 0; i < _DBUS_N_GLOBAL_LOCKS; i++)
+ _dbus_assert (thread_init_generation != _dbus_current_generation);
+
+ link = uninitialized_rmutex_list;
+ while (link != NULL)
{
- _dbus_assert (global_locks[i] == NULL);
+ DBusRMutex **mp;
- global_locks[i] = _dbus_platform_rmutex_new ();
+ mp = link->data;
+ _dbus_assert (*mp == _DBUS_DUMMY_RMUTEX);
- if (global_locks[i] == NULL)
- goto failed;
+ *mp = _dbus_platform_rmutex_new ();
+ if (*mp == NULL)
+ goto fail_mutex;
+
+ link = _dbus_list_get_next_link (&uninitialized_rmutex_list, link);
}
- _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]);
+ link = uninitialized_cmutex_list;
+ while (link != NULL)
+ {
+ DBusCMutex **mp;
- if (!ok)
- goto failed;
+ 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);
+ }
+
+ link = uninitialized_condvar_list;
+ while (link != NULL)
+ {
+ DBusCondVar **cp;
+
+ cp = (DBusCondVar **)link->data;
+ _dbus_assert (*cp == _DBUS_DUMMY_CONDVAR);
+
+ *cp = _dbus_platform_condvar_new ();
+ if (*cp == NULL)
+ goto fail_condvar;
+
+ link = _dbus_list_get_next_link (&uninitialized_condvar_list, link);
+ }
+
+ _dbus_list_clear (&uninitialized_rmutex_list);
+ _dbus_list_clear (&uninitialized_cmutex_list);
+ _dbus_list_clear (&uninitialized_condvar_list);
+
+ if (!_dbus_register_shutdown_func (shutdown_uninitialized_locks,
+ NULL))
+ goto fail_condvar;
return TRUE;
- failed:
- for (i = i - 1; i >= 0; i--)
+ fail_condvar:
+ link = uninitialized_condvar_list;
+ while (link != NULL)
{
- _dbus_platform_rmutex_free (global_locks[i]);
- global_locks[i] = 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)
+ {
+ 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);
}
return FALSE;
}
-dbus_bool_t
-_dbus_lock (DBusGlobalLock lock)
+static dbus_bool_t
+init_locks (void)
{
- _dbus_assert (lock >= 0);
- _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS);
+ 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
+ };
- if (thread_init_generation != _dbus_current_generation &&
- !dbus_threads_init_default ())
- return FALSE;
+ _dbus_assert (_DBUS_N_ELEMENTS (global_locks) ==
+ _DBUS_N_GLOBAL_LOCKS);
- _dbus_platform_rmutex_lock (global_locks[lock]);
+ 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;
+
+ dynamic_global_locks[i] = global_locks[i];
+
+ ++i;
+ }
+
+ if (!_dbus_register_shutdown_func (shutdown_global_locks,
+ dynamic_global_locks))
+ goto failed;
+
+ if (!init_uninitialized_locks ())
+ goto failed;
+
return TRUE;
-}
-void
-_dbus_unlock (DBusGlobalLock lock)
-{
- _dbus_assert (lock >= 0);
- _dbus_assert (lock < _DBUS_N_GLOBAL_LOCKS);
-
- _dbus_platform_rmutex_unlock (global_locks[lock]);
+ 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;
}
/** @} */ /* end of internals */
@@ -390,24 +584,14 @@
dbus_bool_t
dbus_threads_init (const DBusThreadFunctions *functions)
{
- _dbus_threads_lock_platform_specific ();
-
if (thread_init_generation == _dbus_current_generation)
- {
- _dbus_threads_unlock_platform_specific ();
- return TRUE;
- }
+ return TRUE;
- if (!_dbus_threads_init_platform_specific() ||
- !init_global_locks ())
- {
- _dbus_threads_unlock_platform_specific ();
- return FALSE;
- }
+ if (!init_locks ())
+ return FALSE;
thread_init_generation = _dbus_current_generation;
-
- _dbus_threads_unlock_platform_specific ();
+
return TRUE;
}
@@ -418,16 +602,11 @@
/**
* 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.
+ * will do locking, at some cost in efficiency. Note that this
+ * function must be called BEFORE the second thread is started.
*
- * 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).
- *
- * 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.
+ * It's safe to call dbus_threads_init_default() as many times as you
+ * want, but only the first time will have an effect.
*
* dbus_shutdown() reverses the effects of this function when it
* resets all global state in libdbus.
@@ -437,18 +616,18 @@
dbus_bool_t
dbus_threads_init_default (void)
{
- return dbus_threads_init (NULL);
+ return _dbus_threads_init_platform_specific ();
}
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
dbus_bool_t
_dbus_threads_init_debug (void)
{
- return dbus_threads_init (NULL);
+ return _dbus_threads_init_platform_specific();
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-timeout.h b/dbus/dbus-timeout.h
index c652bb7..d0a8af4 100644
--- a/dbus/dbus-timeout.h
+++ b/dbus/dbus-timeout.h
@@ -40,18 +40,14 @@
/** function to run when the timeout is handled */
typedef dbus_bool_t (* DBusTimeoutHandler) (void *data);
-DBUS_PRIVATE_EXPORT
DBusTimeout* _dbus_timeout_new (int interval,
DBusTimeoutHandler handler,
void *data,
DBusFreeFunction free_data_function);
DBusTimeout* _dbus_timeout_ref (DBusTimeout *timeout);
-DBUS_PRIVATE_EXPORT
void _dbus_timeout_unref (DBusTimeout *timeout);
-DBUS_PRIVATE_EXPORT
void _dbus_timeout_set_interval (DBusTimeout *timeout,
int interval);
-DBUS_PRIVATE_EXPORT
void _dbus_timeout_set_enabled (DBusTimeout *timeout,
dbus_bool_t enabled);
diff --git a/dbus/dbus-transport-protected.h b/dbus/dbus-transport-protected.h
index ee627a3..44b9d78 100644
--- a/dbus/dbus-transport-protected.h
+++ b/dbus/dbus-transport-protected.h
@@ -67,7 +67,7 @@
/**< Outstanding messages counter changed */
dbus_bool_t (* get_socket_fd) (DBusTransport *transport,
- DBusSocket *fd_p);
+ int *fd_p);
/**< Get socket file descriptor */
};
@@ -111,7 +111,7 @@
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_peek_is_authenticated() to query value */
+ unsigned int authenticated : 1; /**< Cache of auth state; use _dbus_transport_get_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 35c3cbf..544d00a 100644
--- a/dbus/dbus-transport-socket.c
+++ b/dbus/dbus-transport-socket.c
@@ -49,7 +49,7 @@
struct DBusTransportSocket
{
DBusTransport base; /**< Parent instance */
- DBusSocket fd; /**< File descriptor. */
+ int fd; /**< File descriptor. */
DBusWatch *read_watch; /**< Watch for readability. */
DBusWatch *write_watch; /**< Watch for writability. */
@@ -135,7 +135,7 @@
_dbus_transport_ref (transport);
- if (_dbus_transport_try_to_authenticate (transport))
+ if (_dbus_transport_get_is_authenticated (transport))
needed = _dbus_connection_has_messages_to_send_unlocked (transport->connection);
else
{
@@ -159,9 +159,9 @@
}
}
- _dbus_verbose ("check_write_watch(): needed = %d on connection %p watch %p fd = %" DBUS_SOCKET_FORMAT " outgoing messages exist %d\n",
+ _dbus_verbose ("check_write_watch(): needed = %d on connection %p watch %p fd = %d outgoing messages exist %d\n",
needed, transport->connection, socket_transport->write_watch,
- _dbus_socket_printable (socket_transport->fd),
+ socket_transport->fd,
_dbus_connection_has_messages_to_send_unlocked (transport->connection));
_dbus_connection_toggle_watch_unlocked (transport->connection,
@@ -177,8 +177,7 @@
DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
dbus_bool_t need_read_watch;
- _dbus_verbose ("fd = %" DBUS_SOCKET_FORMAT "\n",
- _dbus_socket_printable (socket_transport->fd));
+ _dbus_verbose ("fd = %d\n",socket_transport->fd);
if (transport->connection == NULL)
return;
@@ -191,7 +190,7 @@
_dbus_transport_ref (transport);
- if (_dbus_transport_try_to_authenticate (transport))
+ if (_dbus_transport_get_is_authenticated (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);
@@ -248,17 +247,16 @@
DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
DBusString *buffer;
int bytes_read;
- int saved_errno;
-
+
*oom = FALSE;
_dbus_auth_get_buffer (transport->auth, &buffer);
bytes_read = _dbus_read_socket (socket_transport->fd,
buffer, socket_transport->max_bytes_read_per_iteration);
- saved_errno = _dbus_save_socket_errno ();
- _dbus_auth_return_buffer (transport->auth, buffer);
+ _dbus_auth_return_buffer (transport->auth, buffer,
+ bytes_read > 0 ? bytes_read : 0);
if (bytes_read > 0)
{
@@ -270,16 +268,16 @@
{
/* EINTR already handled for us */
- if (_dbus_get_is_errno_enomem (saved_errno))
+ if (_dbus_get_is_errno_enomem ())
{
*oom = TRUE;
}
- else if (_dbus_get_is_errno_eagain_or_ewouldblock (saved_errno))
+ else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
; /* do nothing, just return FALSE below */
else
{
_dbus_verbose ("Error reading from remote app: %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
do_io_error (transport);
}
@@ -302,7 +300,6 @@
{
DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
int bytes_written;
- int saved_errno;
const DBusString *buffer;
if (!_dbus_auth_get_bytes_to_send (transport->auth,
@@ -312,7 +309,6 @@
bytes_written = _dbus_write_socket (socket_transport->fd,
buffer,
0, _dbus_string_get_length (buffer));
- saved_errno = _dbus_save_socket_errno ();
if (bytes_written > 0)
{
@@ -323,12 +319,12 @@
{
/* EINTR already handled for us */
- if (_dbus_get_is_errno_eagain_or_ewouldblock (saved_errno))
+ if (_dbus_get_is_errno_eagain_or_ewouldblock ())
;
else
{
_dbus_verbose ("Error writing to remote app: %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
do_io_error (transport);
}
}
@@ -408,7 +404,7 @@
oom = FALSE;
- orig_auth_state = _dbus_transport_try_to_authenticate (transport);
+ orig_auth_state = _dbus_transport_get_is_authenticated (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
@@ -423,7 +419,7 @@
_dbus_transport_ref (transport);
- while (!_dbus_transport_try_to_authenticate (transport) &&
+ while (!_dbus_transport_get_is_authenticated (transport) &&
_dbus_transport_get_is_connected (transport))
{
if (!exchange_credentials (transport, do_reading, do_writing))
@@ -481,7 +477,7 @@
out:
if (auth_completed)
- *auth_completed = (orig_auth_state != _dbus_transport_try_to_authenticate (transport));
+ *auth_completed = (orig_auth_state != _dbus_transport_get_is_authenticated (transport));
check_read_watch (transport);
check_write_watch (transport);
@@ -502,7 +498,7 @@
dbus_bool_t oom;
/* No messages without authentication! */
- if (!_dbus_transport_try_to_authenticate (transport))
+ if (!_dbus_transport_get_is_authenticated (transport))
{
_dbus_verbose ("Not authenticated, not writing anything\n");
return TRUE;
@@ -515,9 +511,9 @@
}
#if 1
- _dbus_verbose ("do_writing(), have_messages = %d, fd = %" DBUS_SOCKET_FORMAT "\n",
+ _dbus_verbose ("do_writing(), have_messages = %d, fd = %d\n",
_dbus_connection_has_messages_to_send_unlocked (transport->connection),
- _dbus_socket_printable (socket_transport->fd));
+ socket_transport->fd);
#endif
oom = FALSE;
@@ -532,7 +528,6 @@
const DBusString *body;
int header_len, body_len;
int total_bytes_to_write;
- int saved_errno;
if (total > socket_transport->max_bytes_written_per_iteration)
{
@@ -590,7 +585,6 @@
&socket_transport->encoded_outgoing,
socket_transport->message_bytes_written,
total_bytes_to_write - socket_transport->message_bytes_written);
- saved_errno = _dbus_save_socket_errno ();
}
else
{
@@ -619,7 +613,6 @@
0, body_len,
unix_fds,
n);
- saved_errno = _dbus_save_socket_errno ();
if (bytes_written > 0 && n > 0)
_dbus_verbose("Wrote %i unix fds\n", n);
@@ -646,8 +639,6 @@
body_len -
(socket_transport->message_bytes_written - header_len));
}
-
- saved_errno = _dbus_save_socket_errno ();
}
}
@@ -655,48 +646,16 @@
{
/* EINTR already handled for us */
- /* If the other end closed the socket with close() or shutdown(), we
- * receive EPIPE here but we must not close the socket yet: there
- * might still be some data to read. See:
+ /* For some discussion of why we also ignore EPIPE here, see
* http://lists.freedesktop.org/archives/dbus/2008-March/009526.html
*/
- if (_dbus_get_is_errno_eagain_or_ewouldblock (saved_errno) || _dbus_get_is_errno_epipe (saved_errno))
+ if (_dbus_get_is_errno_eagain_or_ewouldblock () || _dbus_get_is_errno_epipe ())
goto out;
-
- /* Since Linux commit 25888e (from 2.6.37-rc4, Nov 2010), sendmsg()
- * on Unix sockets returns -1 errno=ETOOMANYREFS when the passfd
- * mechanism (SCM_RIGHTS) is used recursively with a recursion level
- * of maximum 4. The kernel does not have an API to check whether
- * the passed fds can be forwarded and it can change asynchronously.
- * See:
- * https://bugs.freedesktop.org/show_bug.cgi?id=80163
- */
-
- else if (_dbus_get_is_errno_etoomanyrefs (saved_errno))
- {
- /* We only send fds in the first byte of the message.
- * ETOOMANYREFS cannot happen after.
- */
- _dbus_assert (socket_transport->message_bytes_written == 0);
-
- _dbus_verbose (" discard message of %d bytes due to ETOOMANYREFS\n",
- total_bytes_to_write);
-
- socket_transport->message_bytes_written = 0;
- _dbus_string_set_length (&socket_transport->encoded_outgoing, 0);
- _dbus_string_compact (&socket_transport->encoded_outgoing, 2048);
-
- /* The message was not actually sent but it needs to be removed
- * from the outgoing queue
- */
- _dbus_connection_message_sent_unlocked (transport->connection,
- message);
- }
else
{
_dbus_verbose ("Error writing to remote app: %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
do_io_error (transport);
goto out;
}
@@ -740,13 +699,11 @@
int bytes_read;
int total;
dbus_bool_t oom;
- int saved_errno;
- _dbus_verbose ("fd = %" DBUS_SOCKET_FORMAT "\n",
- _dbus_socket_printable (socket_transport->fd));
+ _dbus_verbose ("fd = %d\n",socket_transport->fd);
/* No messages without authentication! */
- if (!_dbus_transport_try_to_authenticate (transport))
+ if (!_dbus_transport_get_is_authenticated (transport))
return TRUE;
oom = FALSE;
@@ -786,30 +743,34 @@
&socket_transport->encoded_incoming,
socket_transport->max_bytes_read_per_iteration);
- saved_errno = _dbus_save_socket_errno ();
-
_dbus_assert (_dbus_string_get_length (&socket_transport->encoded_incoming) ==
bytes_read);
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);
+ buffer,
+ _dbus_string_get_length (buffer) - orig_len);
oom = TRUE;
goto out;
}
_dbus_message_loader_return_buffer (transport->loader,
- buffer);
+ buffer,
+ _dbus_string_get_length (buffer) - orig_len);
_dbus_string_set_length (&socket_transport->encoded_incoming, 0);
_dbus_string_compact (&socket_transport->encoded_incoming, 2048);
@@ -828,7 +789,7 @@
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);
+ _dbus_message_loader_return_buffer (transport->loader, buffer, 0);
oom = TRUE;
goto out;
}
@@ -837,7 +798,6 @@
buffer,
socket_transport->max_bytes_read_per_iteration,
fds, &n_fds);
- saved_errno = _dbus_save_socket_errno ();
if (bytes_read >= 0 && n_fds > 0)
_dbus_verbose("Read %i unix fds\n", n_fds);
@@ -849,29 +809,29 @@
{
bytes_read = _dbus_read_socket (socket_transport->fd,
buffer, socket_transport->max_bytes_read_per_iteration);
- saved_errno = _dbus_save_socket_errno ();
}
_dbus_message_loader_return_buffer (transport->loader,
- buffer);
+ buffer,
+ bytes_read < 0 ? 0 : bytes_read);
}
-
+
if (bytes_read < 0)
{
/* EINTR already handled for us */
- if (_dbus_get_is_errno_enomem (saved_errno))
+ if (_dbus_get_is_errno_enomem ())
{
_dbus_verbose ("Out of memory in read()/do_reading()\n");
oom = TRUE;
goto out;
}
- else if (_dbus_get_is_errno_eagain_or_ewouldblock (saved_errno))
+ else if (_dbus_get_is_errno_eagain_or_ewouldblock ())
goto out;
else
{
_dbus_verbose ("Error reading from remote app: %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
do_io_error (transport);
goto out;
}
@@ -1009,7 +969,7 @@
_dbus_verbose ("asked to handle write watch with non-write condition 0x%x\n",
flags);
else
- _dbus_verbose ("asked to handle watch %p on fd %" DBUS_SOCKET_FORMAT " that we don't recognize\n",
+ _dbus_verbose ("asked to handle watch %p on fd %d that we don't recognize\n",
watch, dbus_watch_get_socket (watch));
}
#endif /* DBUS_ENABLE_VERBOSE_MODE */
@@ -1027,7 +987,7 @@
free_watches (transport);
_dbus_close_socket (socket_transport->fd, NULL);
- _dbus_socket_invalidate (&socket_transport->fd);
+ socket_transport->fd = -1;
}
static dbus_bool_t
@@ -1078,13 +1038,13 @@
int poll_res;
int poll_timeout;
- _dbus_verbose (" iteration flags = %s%s timeout = %d read_watch = %p write_watch = %p fd = %" DBUS_SOCKET_FORMAT "\n",
+ _dbus_verbose (" iteration flags = %s%s timeout = %d read_watch = %p write_watch = %p fd = %d\n",
flags & DBUS_ITERATION_DO_READING ? "read" : "",
flags & DBUS_ITERATION_DO_WRITING ? "write" : "",
timeout_milliseconds,
socket_transport->read_watch,
socket_transport->write_watch,
- _dbus_socket_printable (socket_transport->fd));
+ socket_transport->fd);
/* the passed in DO_READING/DO_WRITING flags indicate whether to
* read/write messages, but regardless of those we may need to block
@@ -1092,10 +1052,10 @@
* we don't want to read any messages yet if not given DO_READING.
*/
- poll_fd.fd = _dbus_socket_get_pollable (socket_transport->fd);
+ poll_fd.fd = socket_transport->fd;
poll_fd.events = 0;
- if (_dbus_transport_try_to_authenticate (transport))
+ if (_dbus_transport_get_is_authenticated (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
@@ -1145,8 +1105,6 @@
if (poll_fd.events)
{
- int saved_errno;
-
if (flags & DBUS_ITERATION_BLOCK)
poll_timeout = timeout_milliseconds;
else
@@ -1165,9 +1123,8 @@
again:
poll_res = _dbus_poll (&poll_fd, 1, poll_timeout);
- saved_errno = _dbus_save_socket_errno ();
- if (poll_res < 0 && _dbus_get_is_errno_eintr (saved_errno))
+ if (poll_res < 0 && _dbus_get_is_errno_eintr ())
goto again;
if (flags & DBUS_ITERATION_BLOCK)
@@ -1210,7 +1167,7 @@
else
{
_dbus_verbose ("Error from _dbus_poll(): %s\n",
- _dbus_strerror (saved_errno));
+ _dbus_strerror_from_errno ());
}
}
@@ -1241,7 +1198,7 @@
static dbus_bool_t
socket_get_socket_fd (DBusTransport *transport,
- DBusSocket *fd_p)
+ int *fd_p)
{
DBusTransportSocket *socket_transport = (DBusTransportSocket*) transport;
@@ -1272,7 +1229,7 @@
* @returns the new transport, or #NULL if no memory.
*/
DBusTransport*
-_dbus_transport_new_for_socket (DBusSocket fd,
+_dbus_transport_new_for_socket (int fd,
const DBusString *server_guid,
const DBusString *address)
{
@@ -1288,14 +1245,14 @@
if (!_dbus_string_init (&socket_transport->encoded_incoming))
goto failed_1;
- socket_transport->write_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
+ socket_transport->write_watch = _dbus_watch_new (fd,
DBUS_WATCH_WRITABLE,
FALSE,
NULL, NULL, NULL);
if (socket_transport->write_watch == NULL)
goto failed_2;
- socket_transport->read_watch = _dbus_watch_new (_dbus_socket_get_pollable (fd),
+ socket_transport->read_watch = _dbus_watch_new (fd,
DBUS_WATCH_READABLE,
FALSE,
NULL, NULL, NULL);
@@ -1342,7 +1299,7 @@
* @param host the host to connect to
* @param port the port to connect to
* @param family the address family to connect to
- * @param noncefile path to nonce file
+ * @param path to nonce file
* @param error location to store reason for failure.
* @returns a new transport, or #NULL on failure.
*/
@@ -1353,7 +1310,7 @@
const char *noncefile,
DBusError *error)
{
- DBusSocket fd;
+ int fd;
DBusTransport *transport;
DBusString address;
@@ -1390,7 +1347,7 @@
goto error;
fd = _dbus_connect_tcp_socket_with_nonce (host, port, family, noncefile, error);
- if (!_dbus_socket_is_valid (fd))
+ if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
_dbus_string_free (&address);
@@ -1406,7 +1363,7 @@
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
_dbus_close_socket (fd, NULL);
- _dbus_socket_invalidate (&fd);
+ fd = -1;
}
return transport;
diff --git a/dbus/dbus-transport-socket.h b/dbus/dbus-transport-socket.h
index b8267ff..8aefae3 100644
--- a/dbus/dbus-transport-socket.h
+++ b/dbus/dbus-transport-socket.h
@@ -27,7 +27,7 @@
DBUS_BEGIN_DECLS
-DBusTransport* _dbus_transport_new_for_socket (DBusSocket fd,
+DBusTransport* _dbus_transport_new_for_socket (int fd,
const DBusString *server_guid,
const DBusString *address);
DBusTransport* _dbus_transport_new_for_tcp_socket (const char *host,
diff --git a/dbus/dbus-transport-unix.c b/dbus/dbus-transport-unix.c
index f2b1f09..6ba5c0b 100644
--- a/dbus/dbus-transport-unix.c
+++ b/dbus/dbus-transport-unix.c
@@ -59,7 +59,7 @@
dbus_bool_t abstract,
DBusError *error)
{
- DBusSocket fd = DBUS_SOCKET_INIT;
+ int fd;
DBusTransport *transport;
DBusString address;
@@ -71,6 +71,8 @@
return NULL;
}
+ fd = -1;
+
if ((abstract &&
!_dbus_string_append (&address, "unix:abstract=")) ||
(!abstract &&
@@ -81,8 +83,8 @@
goto failed_0;
}
- fd.fd = _dbus_connect_unix_socket (path, abstract, error);
- if (fd.fd < 0)
+ fd = _dbus_connect_unix_socket (path, abstract, error);
+ if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed_0;
@@ -125,7 +127,7 @@
char *const argv[],
DBusError *error)
{
- DBusSocket fd = DBUS_SOCKET_INIT;
+ int fd;
DBusTransport *transport;
DBusString address;
unsigned i;
@@ -139,6 +141,8 @@
return NULL;
}
+ fd = -1;
+
escaped = dbus_address_escape_value (path);
if (!escaped)
{
@@ -180,8 +184,8 @@
}
}
- fd.fd = _dbus_connect_exec (path, argv, error);
- if (fd.fd < 0)
+ fd = _dbus_connect_exec (path, argv, error);
+ if (fd < 0)
{
_DBUS_ASSERT_ERROR_IS_SET (error);
goto failed;
@@ -202,7 +206,7 @@
return transport;
failed:
- if (fd.fd >= 0)
+ if (fd >= 0)
_dbus_close_socket (fd, NULL);
_dbus_string_free (&address);
@@ -408,7 +412,7 @@
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
dbus_bool_t
_dbus_transport_unix_test (void)
diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c
index 31586b1..6b58fda 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_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include "dbus-server-debug-pipe.h"
#endif
@@ -63,7 +63,6 @@
{
DBusTransport *transport = user_data;
- _dbus_connection_lock (transport->connection);
_dbus_transport_ref (transport);
#if 0
@@ -78,11 +77,12 @@
*/
if (transport->vtable->live_messages_changed)
{
+ _dbus_connection_lock (transport->connection);
(* transport->vtable->live_messages_changed) (transport);
+ _dbus_connection_unlock (transport->connection);
}
_dbus_transport_unref (transport);
- _dbus_connection_unlock (transport->connection);
}
/**
@@ -242,7 +242,6 @@
* 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.
*/
@@ -273,7 +272,6 @@
* 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.
*/
@@ -350,7 +348,7 @@
{ _dbus_transport_open_socket },
{ _dbus_transport_open_platform_specific },
{ _dbus_transport_open_autolaunch }
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
, { _dbus_transport_open_debug_pipe }
#endif
};
@@ -686,33 +684,10 @@
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. 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.
+ * Returns #TRUE if we have been authenticated. Will return #TRUE
+ * even if the transport is disconnected.
*
* @todo we drop connection->mutex when calling the unix_user_function,
* and windows_user_function, which may not be safe really.
@@ -721,7 +696,7 @@
* @returns whether we're authenticated
*/
dbus_bool_t
-_dbus_transport_try_to_authenticate (DBusTransport *transport)
+_dbus_transport_get_is_authenticated (DBusTransport *transport)
{
if (transport->authenticated)
return TRUE;
@@ -949,7 +924,7 @@
*/
dbus_bool_t
_dbus_transport_get_socket_fd (DBusTransport *transport,
- DBusSocket *fd_p)
+ int *fd_p)
{
dbus_bool_t retval;
@@ -1045,7 +1020,9 @@
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
- buffer);
+ buffer,
+ _dbus_string_get_length (buffer) -
+ orig_len);
_dbus_auth_delete_unused_bytes (transport->auth);
@@ -1075,7 +1052,9 @@
orig_len);
_dbus_message_loader_return_buffer (transport->loader,
- buffer);
+ buffer,
+ _dbus_string_get_length (buffer) -
+ orig_len);
if (succeeded)
_dbus_auth_delete_unused_bytes (transport->auth);
@@ -1104,12 +1083,12 @@
_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_try_to_authenticate (transport))
+ if (!_dbus_transport_get_is_authenticated (transport))
{
if (_dbus_auth_do_work (transport->auth) ==
DBUS_AUTH_STATE_WAITING_FOR_MEMORY)
return DBUS_DISPATCH_NEED_MEMORY;
- else if (!_dbus_transport_try_to_authenticate (transport))
+ else if (!_dbus_transport_get_is_authenticated (transport))
return DBUS_DISPATCH_COMPLETE;
}
@@ -1358,7 +1337,7 @@
if (_dbus_credentials_include (auth_identity,
DBUS_CREDENTIAL_UNIX_PROCESS_ID))
{
- *pid = _dbus_credentials_get_pid (auth_identity);
+ *pid = _dbus_credentials_get_unix_pid (auth_identity);
return TRUE;
}
else
@@ -1425,33 +1404,6 @@
transport->free_unix_user_data = free_data_function;
}
-dbus_bool_t
-_dbus_transport_get_linux_security_label (DBusTransport *transport,
- char **label_p)
-{
- DBusCredentials *auth_identity;
-
- *label_p = NULL;
-
- if (!transport->authenticated)
- return FALSE;
-
- auth_identity = _dbus_auth_get_identity (transport->auth);
-
- if (_dbus_credentials_include (auth_identity,
- DBUS_CREDENTIAL_LINUX_SECURITY_LABEL))
- {
- /* If no memory, we are supposed to return TRUE and set NULL */
- *label_p = _dbus_strdup (_dbus_credentials_get_linux_security_label (auth_identity));
-
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
/**
* See dbus_connection_get_windows_user().
*
@@ -1539,33 +1491,6 @@
transport->allow_anonymous = value != FALSE;
}
-/**
- * Return how many file descriptors are pending in the loader
- *
- * @param transport the transport
- */
-int
-_dbus_transport_get_pending_fds_count (DBusTransport *transport)
-{
- return _dbus_message_loader_get_pending_fds_count (transport->loader);
-}
-
-/**
- * Register a function to be called whenever the number of pending file
- * descriptors in the loader change.
- *
- * @param transport the transport
- * @param callback the callback
- */
-void
-_dbus_transport_set_pending_fds_function (DBusTransport *transport,
- void (* callback) (void *),
- void *data)
-{
- _dbus_message_loader_set_pending_fds_function (transport->loader,
- callback, data);
-}
-
#ifdef DBUS_ENABLE_STATS
void
_dbus_transport_get_stats (DBusTransport *transport,
diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h
index 9e3787d..4b82151 100644
--- a/dbus/dbus-transport.h
+++ b/dbus/dbus-transport.h
@@ -38,8 +38,7 @@
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_peek_is_authenticated (DBusTransport *transport);
-dbus_bool_t _dbus_transport_try_to_authenticate (DBusTransport *transport);
+dbus_bool_t _dbus_transport_get_is_authenticated (DBusTransport *transport);
dbus_bool_t _dbus_transport_get_is_anonymous (DBusTransport *transport);
dbus_bool_t _dbus_transport_can_pass_unix_fd (DBusTransport *transport);
@@ -71,7 +70,7 @@
long _dbus_transport_get_max_received_unix_fds(DBusTransport *transport);
dbus_bool_t _dbus_transport_get_socket_fd (DBusTransport *transport,
- DBusSocket *fd_p);
+ int *fd_p);
dbus_bool_t _dbus_transport_get_unix_user (DBusTransport *transport,
unsigned long *uid);
dbus_bool_t _dbus_transport_get_unix_process_id (DBusTransport *transport,
@@ -87,9 +86,6 @@
DBusFreeFunction *old_free_data_function);
dbus_bool_t _dbus_transport_get_windows_user (DBusTransport *transport,
char **windows_sid_p);
-dbus_bool_t _dbus_transport_get_linux_security_label (DBusTransport *transport,
- char **label_p);
-
void _dbus_transport_set_windows_user_function (DBusTransport *transport,
DBusAllowWindowsUserFunction function,
void *data,
@@ -100,10 +96,6 @@
const char **mechanisms);
void _dbus_transport_set_allow_anonymous (DBusTransport *transport,
dbus_bool_t value);
-int _dbus_transport_get_pending_fds_count (DBusTransport *transport);
-void _dbus_transport_set_pending_fds_function (DBusTransport *transport,
- void (* callback) (void *),
- void *data);
/* if DBUS_ENABLE_STATS */
void _dbus_transport_get_stats (DBusTransport *transport,
diff --git a/dbus/dbus-types.h b/dbus/dbus-types.h
index 021a55a..57fc586 100644
--- a/dbus/dbus-types.h
+++ b/dbus/dbus-types.h
@@ -79,23 +79,43 @@
/**
* @typedef dbus_uint64_t
*
- * A 64-bit unsigned integer.
+ * 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.
*/
/**
* @typedef dbus_int64_t
*
- * A 64-bit signed integer.
+ * 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.
*/
/**
* @def DBUS_HAVE_INT64
*
- * Always defined.
+ * 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.
*
- * 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.
+ * 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.
+ *
*/
/**
@@ -116,7 +136,7 @@
/**
* An 8-byte struct you could use to access int64 without having
- * int64 support. Use #dbus_int64_t or #dbus_uint64_t instead.
+ * int64 support
*/
typedef struct
{
@@ -142,8 +162,10 @@
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 888a23e..16bf229 100644
--- a/dbus/dbus-userdb-util.c
+++ b/dbus/dbus-userdb-util.c
@@ -21,7 +21,6 @@
*
*/
#include <config.h>
-#include <unistd.h>
#define DBUS_USERDB_INCLUDES_PRIVATE 1
#include "dbus-userdb.h"
#include "dbus-test.h"
@@ -30,6 +29,7 @@
#include <string.h>
#if HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
#endif
@@ -55,8 +55,7 @@
dbus_bool_t result = FALSE;
#ifdef HAVE_SYSTEMD
- /* check if we have logind */
- if (access ("/run/systemd/seats/", F_OK) >= 0)
+ if (sd_booted () > 0)
{
int r;
@@ -104,11 +103,7 @@
#endif /* HAVE_CONSOLE_OWNER_FILE */
- if (!_dbus_user_database_lock_system ())
- {
- _DBUS_SET_OOM (error);
- return FALSE;
- }
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -162,10 +157,7 @@
{
DBusUserDatabase *db;
const DBusGroupInfo *info;
-
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -202,10 +194,7 @@
{
DBusUserDatabase *db;
const DBusUserInfo *info;
-
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -261,6 +250,7 @@
gid = n;
}
+#ifdef DBUS_ENABLE_USERDB_CACHE
if (gid != DBUS_GID_UNSET)
info = _dbus_hash_table_lookup_uintptr (db->groups, gid);
else
@@ -273,6 +263,9 @@
return info;
}
else
+#else
+ if (1)
+#endif
{
if (gid != DBUS_GID_UNSET)
_dbus_verbose ("No cache for GID "DBUS_GID_FORMAT"\n",
@@ -394,9 +387,7 @@
*group_ids = NULL;
*n_group_ids = 0;
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -433,7 +424,7 @@
}
/** @} */
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
#include <stdio.h>
/**
@@ -486,4 +477,4 @@
return TRUE;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
diff --git a/dbus/dbus-userdb.c b/dbus/dbus-userdb.c
index 52f927a..4e8b39a 100644
--- a/dbus/dbus-userdb.c
+++ b/dbus/dbus-userdb.c
@@ -144,6 +144,7 @@
uid = n;
}
+#ifdef DBUS_ENABLE_USERDB_CACHE
if (uid != DBUS_UID_UNSET)
info = _dbus_hash_table_lookup_uintptr (db->users, uid);
else
@@ -156,6 +157,9 @@
return info;
}
else
+#else
+ if (1)
+#endif
{
if (uid != DBUS_UID_UNSET)
_dbus_verbose ("No cache for UID "DBUS_UID_FORMAT"\n",
@@ -302,18 +306,11 @@
/**
* Locks global system user database.
*/
-dbus_bool_t
+void
_dbus_user_database_lock_system (void)
{
- if (_DBUS_LOCK (system_users))
- {
- database_locked = TRUE;
- return TRUE;
- }
- else
- {
- return FALSE;
- }
+ _DBUS_LOCK (system_users);
+ database_locked = TRUE;
}
/**
@@ -348,12 +345,8 @@
void
_dbus_user_database_flush_system (void)
{
- if (!_dbus_user_database_lock_system ())
- {
- /* nothing to flush */
- return;
- }
-
+ _dbus_user_database_lock_system ();
+
if (system_db != NULL)
_dbus_user_database_flush (system_db);
@@ -370,9 +363,7 @@
dbus_bool_t
_dbus_username_from_current_process (const DBusString **username)
{
- if (!_dbus_user_database_lock_system ())
- return FALSE;
-
+ _dbus_user_database_lock_system ();
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@ -394,9 +385,7 @@
dbus_bool_t
_dbus_homedir_from_current_process (const DBusString **homedir)
{
- if (!_dbus_user_database_lock_system ())
- return FALSE;
-
+ _dbus_user_database_lock_system ();
if (!init_system_db ())
{
_dbus_user_database_unlock_system ();
@@ -421,10 +410,7 @@
{
DBusUserDatabase *db;
const DBusUserInfo *info;
-
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -463,10 +449,7 @@
{
DBusUserDatabase *db;
const DBusUserInfo *info;
-
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -513,9 +496,7 @@
DBusUserDatabase *db;
const DBusUserInfo *info;
- /* FIXME: this can't distinguish ENOMEM from other errors */
- if (!_dbus_user_database_lock_system ())
- return FALSE;
+ _dbus_user_database_lock_system ();
db = _dbus_user_database_get_system ();
if (db == NULL)
@@ -598,7 +579,7 @@
_dbus_hash_table_remove_all(db->groups);
}
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+#ifdef DBUS_BUILD_TESTS
/**
* Increments refcount of user database.
* @param db the database
@@ -613,7 +594,7 @@
return db;
}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
+#endif /* DBUS_BUILD_TESTS */
/**
* Decrements refcount of user database.
diff --git a/dbus/dbus-userdb.h b/dbus/dbus-userdb.h
index 53fc90b..cb49d9e 100644
--- a/dbus/dbus-userdb.h
+++ b/dbus/dbus-userdb.h
@@ -56,7 +56,6 @@
DBusUserDatabase* _dbus_user_database_ref (DBusUserDatabase *db);
void _dbus_user_database_flush (DBusUserDatabase *db);
void _dbus_user_database_unref (DBusUserDatabase *db);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_user_database_get_uid (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusUserInfo **info,
@@ -65,7 +64,6 @@
dbus_gid_t gid,
const DBusGroupInfo **info,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_user_database_get_username (DBusUserDatabase *db,
const DBusString *username,
const DBusUserInfo **info,
@@ -75,27 +73,20 @@
const DBusGroupInfo **info,
DBusError *error);
-DBUS_PRIVATE_EXPORT
DBusUserInfo* _dbus_user_database_lookup (DBusUserDatabase *db,
dbus_uid_t uid,
const DBusString *username,
DBusError *error);
-DBUS_PRIVATE_EXPORT
DBusGroupInfo* _dbus_user_database_lookup_group (DBusUserDatabase *db,
dbus_gid_t gid,
const DBusString *groupname,
DBusError *error);
-DBUS_PRIVATE_EXPORT
void _dbus_user_info_free_allocated (DBusUserInfo *info);
-DBUS_PRIVATE_EXPORT
void _dbus_group_info_free_allocated (DBusGroupInfo *info);
#endif /* DBUS_USERDB_INCLUDES_PRIVATE */
-DBUS_PRIVATE_EXPORT
DBusUserDatabase* _dbus_user_database_get_system (void);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_user_database_lock_system (void) _DBUS_GNUC_WARN_UNUSED_RESULT;
-DBUS_PRIVATE_EXPORT
+void _dbus_user_database_lock_system (void);
void _dbus_user_database_unlock_system (void);
void _dbus_user_database_flush_system (void);
@@ -103,7 +94,6 @@
dbus_uid_t *uid);
dbus_bool_t _dbus_get_group_id (const DBusString *group_name,
dbus_gid_t *gid);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_get_user_id_and_primary_group (const DBusString *username,
dbus_uid_t *uid_p,
dbus_gid_t *gid_p);
@@ -112,17 +102,13 @@
dbus_bool_t _dbus_groups_from_uid (dbus_uid_t uid,
dbus_gid_t **group_ids,
int *n_group_ids);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_is_console_user (dbus_uid_t uid,
DBusError *error);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_is_a_number (const DBusString *str,
unsigned long *num);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_username_from_current_process (const DBusString **username);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_homedir_from_current_process (const DBusString **homedir);
dbus_bool_t _dbus_homedir_from_username (const DBusString *username,
DBusString *homedir);
diff --git a/dbus/dbus-uuidgen.c b/dbus/dbus-uuidgen.c
index b404163..6d7c0ae 100644
--- a/dbus/dbus-uuidgen.c
+++ b/dbus/dbus-uuidgen.c
@@ -111,20 +111,20 @@
}
/**
+ * For use by the dbus-uuidgen binary ONLY, do not call this.
+ * We can and will change this function without modifying
+ * the libdbus soname.
+ *
* @param uuid_p out param to return the uuid
- * @param error location to store reason for failure
- * @returns #TRUE on success
+ * @returns #FALSE if no memory
*/
dbus_bool_t
-_dbus_create_uuid (char **uuid_p,
- DBusError *error)
+dbus_internal_do_not_use_create_uuid (char **uuid_p)
{
DBusGUID uuid;
- if (!_dbus_generate_uuid (&uuid, error))
- return FALSE;
-
- return return_uuid (&uuid, uuid_p, error);
+ _dbus_generate_uuid (&uuid);
+ return return_uuid (&uuid, uuid_p, NULL);
}
/** @} */
diff --git a/dbus/dbus-uuidgen.h b/dbus/dbus-uuidgen.h
index 5e4a948..9c1b859 100644
--- a/dbus/dbus-uuidgen.h
+++ b/dbus/dbus-uuidgen.h
@@ -32,7 +32,6 @@
DBUS_BEGIN_DECLS
-DBUS_PRIVATE_EXPORT
dbus_bool_t dbus_internal_do_not_use_get_uuid (const char *filename,
char **uuid_p,
dbus_bool_t create_if_not_found,
@@ -40,9 +39,8 @@
dbus_bool_t dbus_internal_do_not_use_ensure_uuid (const char *filename,
char **uuid_p,
DBusError *error);
-DBUS_PRIVATE_EXPORT
-dbus_bool_t _dbus_create_uuid (char **uuid_p,
- DBusError *error);
+dbus_bool_t dbus_internal_do_not_use_create_uuid (char **uuid_p);
+
DBUS_END_DECLS
diff --git a/dbus/dbus-valgrind-internal.h b/dbus/dbus-valgrind-internal.h
index 6760b40..55566ec 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) 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)
+# 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 */
/* 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 093f193..b9f4ac2 100644
--- a/dbus/dbus-watch.c
+++ b/dbus/dbus-watch.c
@@ -40,7 +40,7 @@
struct DBusWatch
{
int refcount; /**< Reference count */
- DBusPollable fd; /**< File descriptor. */
+ int fd; /**< File descriptor. */
unsigned int flags; /**< Conditions to watch. */
DBusWatchHandler handler; /**< Watch handler. */
@@ -85,7 +85,7 @@
* @returns the new DBusWatch object.
*/
DBusWatch*
-_dbus_watch_new (DBusPollable fd,
+_dbus_watch_new (int fd,
unsigned int flags,
dbus_bool_t enabled,
DBusWatchHandler handler,
@@ -143,7 +143,7 @@
watch->refcount -= 1;
if (watch->refcount == 0)
{
- if (_dbus_pollable_is_valid (watch->fd))
+ if (watch->fd != -1)
_dbus_warn ("this watch should have been invalidated");
dbus_watch_set_data (watch, NULL, NULL); /* call free_data_function */
@@ -168,7 +168,7 @@
void
_dbus_watch_invalidate (DBusWatch *watch)
{
- _dbus_pollable_invalidate (&watch->fd);
+ watch->fd = -1;
watch->flags = 0;
}
@@ -259,25 +259,6 @@
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
@@ -310,13 +291,28 @@
{
DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
link);
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- DBusWatch *watch = link->data;
- _dbus_verbose ("Adding a %s watch on fd %" DBUS_POLLABLE_FORMAT " using newly-set add watch function\n",
- watch_flags_to_string (dbus_watch_get_flags (link->data)),
- _dbus_pollable_printable (watch->fd));
-#endif
+#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 */
if (!(* add_function) (link->data, data))
{
@@ -328,12 +324,9 @@
{
DBusList *next = _dbus_list_get_next_link (&watch_list->watches,
link2);
-#ifdef DBUS_ENABLE_VERBOSE_MODE
- DBusWatch *watch2 = link2->data;
- _dbus_verbose ("Removing watch on fd %" DBUS_POLLABLE_FORMAT " using newly-set remove function because initial add failed\n",
- _dbus_pollable_printable (watch2->fd));
-#endif
+ _dbus_verbose ("Removing watch on fd %d using newly-set remove function because initial add failed\n",
+ dbus_watch_get_socket (link2->data));
(* remove_function) (link2->data, data);
@@ -389,8 +382,8 @@
if (watch_list->add_watch_function != NULL)
{
- _dbus_verbose ("Adding watch on fd %" DBUS_POLLABLE_FORMAT "\n",
- _dbus_pollable_printable (watch->fd));
+ _dbus_verbose ("Adding watch on fd %d\n",
+ dbus_watch_get_socket (watch));
if (!(* watch_list->add_watch_function) (watch,
watch_list->watch_data))
@@ -420,8 +413,8 @@
if (watch_list->remove_watch_function != NULL)
{
- _dbus_verbose ("Removing watch on fd %" DBUS_POLLABLE_FORMAT "\n",
- _dbus_pollable_printable (watch->fd));
+ _dbus_verbose ("Removing watch on fd %d\n",
+ dbus_watch_get_socket (watch));
(* watch_list->remove_watch_function) (watch,
watch_list->watch_data);
@@ -452,10 +445,8 @@
if (watch_list->watch_toggled_function != NULL)
{
- _dbus_verbose ("Toggling watch %p on fd %" DBUS_POLLABLE_FORMAT " to %d\n",
- watch,
- _dbus_pollable_printable (watch->fd),
- watch->enabled);
+ _dbus_verbose ("Toggling watch %p on fd %d to %d\n",
+ watch, dbus_watch_get_socket (watch), watch->enabled);
(* watch_list->watch_toggled_function) (watch,
watch_list->watch_data);
@@ -463,27 +454,6 @@
}
/**
- * Sets all watches to the given enabled state, invoking the
- * application's DBusWatchToggledFunction if appropriate.
- *
- * @param watch_list the watch list.
- * @param enabled #TRUE to enable
- */
-void
-_dbus_watch_list_toggle_all_watches (DBusWatchList *watch_list,
- dbus_bool_t enabled)
-{
- DBusList *link;
-
- for (link = _dbus_list_get_first_link (&watch_list->watches);
- link != NULL;
- link = _dbus_list_get_next_link (&watch_list->watches, link))
- {
- _dbus_watch_list_toggle_watch (watch_list, link->data, enabled);
- }
-}
-
-/**
* Sets the handler for the watch.
*
* @todo this function only exists because of the weird
@@ -595,34 +565,6 @@
{
_dbus_return_val_if_fail (watch != NULL, -1);
-#ifdef DBUS_UNIX
- return watch->fd;
-#else
- return _dbus_socket_get_int (watch->fd);
-#endif
-}
-
-DBusSocket
-_dbus_watch_get_socket (DBusWatch *watch)
-{
- DBusSocket s;
-
- _dbus_assert (watch != NULL);
-
-#ifdef DBUS_UNIX
- s.fd = watch->fd;
-#else
- s = watch->fd;
-#endif
-
- return s;
-}
-
-DBusPollable
-_dbus_watch_get_pollable (DBusWatch *watch)
-{
- _dbus_assert (watch != NULL);
-
return watch->fd;
}
@@ -681,8 +623,8 @@
{
_dbus_return_if_fail (watch != NULL);
- _dbus_verbose ("Setting watch fd %" DBUS_POLLABLE_FORMAT " data to data = %p function = %p from data = %p function = %p\n",
- _dbus_pollable_printable (watch->fd),
+ _dbus_verbose ("Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n",
+ dbus_watch_get_socket (watch),
data, free_data_function, watch->data, watch->free_data_function);
if (watch->free_data_function != NULL)
@@ -737,21 +679,21 @@
_dbus_return_val_if_fail (watch != NULL, FALSE);
#ifndef DBUS_DISABLE_CHECKS
- if (!_dbus_pollable_is_valid (watch->fd) || watch->flags == 0)
+ if (watch->fd < 0 || watch->flags == 0)
{
_dbus_warn_check_failed ("Watch is invalid, it should have been removed\n");
return TRUE;
}
#endif
- _dbus_return_val_if_fail (_dbus_pollable_is_valid (watch->fd) /* fails if watch was removed */, TRUE);
+ _dbus_return_val_if_fail (watch->fd >= 0 /* fails if watch was removed */, TRUE);
_dbus_watch_sanitize_condition (watch, &flags);
if (flags == 0)
{
- _dbus_verbose ("After sanitization, watch flags on fd %" DBUS_POLLABLE_FORMAT " were 0\n",
- _dbus_pollable_printable (watch->fd));
+ _dbus_verbose ("After sanitization, watch flags on fd %d were 0\n",
+ watch->fd);
return TRUE;
}
else
diff --git a/dbus/dbus-watch.h b/dbus/dbus-watch.h
index 8d8bbf2..c583214 100644
--- a/dbus/dbus-watch.h
+++ b/dbus/dbus-watch.h
@@ -44,18 +44,14 @@
unsigned int flags,
void *data);
-DBUS_PRIVATE_EXPORT
-DBusWatch* _dbus_watch_new (DBusPollable fd,
+DBusWatch* _dbus_watch_new (int fd,
unsigned int flags,
dbus_bool_t enabled,
DBusWatchHandler handler,
void *data,
DBusFreeFunction free_data_function);
-DBUS_PRIVATE_EXPORT
DBusWatch* _dbus_watch_ref (DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
void _dbus_watch_unref (DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
void _dbus_watch_invalidate (DBusWatch *watch);
void _dbus_watch_sanitize_condition (DBusWatch *watch,
unsigned int *condition);
@@ -65,40 +61,27 @@
DBusFreeFunction free_data_function);
-DBUS_PRIVATE_EXPORT
DBusWatchList* _dbus_watch_list_new (void);
-DBUS_PRIVATE_EXPORT
void _dbus_watch_list_free (DBusWatchList *watch_list);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_watch_list_set_functions (DBusWatchList *watch_list,
DBusAddWatchFunction add_function,
DBusRemoveWatchFunction remove_function,
DBusWatchToggledFunction toggled_function,
void *data,
DBusFreeFunction free_data_function);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_watch_list_add_watch (DBusWatchList *watch_list,
DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
void _dbus_watch_list_remove_watch (DBusWatchList *watch_list,
DBusWatch *watch);
void _dbus_watch_list_toggle_watch (DBusWatchList *watch_list,
DBusWatch *watch,
dbus_bool_t enabled);
-void _dbus_watch_list_toggle_all_watches (DBusWatchList *watch_list,
- dbus_bool_t enabled);
dbus_bool_t _dbus_watch_get_enabled (DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_watch_get_oom_last_time (DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
void _dbus_watch_set_oom_last_time (DBusWatch *watch,
dbus_bool_t oom);
-DBusSocket _dbus_watch_get_socket (DBusWatch *watch);
-DBUS_PRIVATE_EXPORT
-DBusPollable _dbus_watch_get_pollable (DBusWatch *watch);
-
/** @} */
DBUS_END_DECLS
diff --git a/dbus/sd-daemon.c b/dbus/sd-daemon.c
new file mode 100644
index 0000000..9c23b91
--- /dev/null
+++ b/dbus/sd-daemon.c
@@ -0,0 +1,435 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ Copyright 2010 Lennart Poettering
+
+ 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.
+***/
+
+#ifndef _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 <netinet/in.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "sd-daemon.h"
+
+int sd_listen_fds(int unset_environment) {
+
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
+ return 0;
+#else
+ int r, fd;
+ const char *e;
+ char *p = NULL;
+ unsigned long l;
+
+ if (!(e = getenv("LISTEN_PID"))) {
+ r = 0;
+ goto finish;
+ }
+
+ errno = 0;
+ l = strtoul(e, &p, 10);
+
+ if (errno != 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ if (!p || *p || l <= 0) {
+ r = -EINVAL;
+ goto finish;
+ }
+
+ /* Is this for us? */
+ if (getpid() != (pid_t) l) {
+ r = 0;
+ goto finish;
+ }
+
+ if (!(e = getenv("LISTEN_FDS"))) {
+ r = 0;
+ goto finish;
+ }
+
+ errno = 0;
+ l = strtoul(e, &p, 10);
+
+ if (errno != 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ if (!p || *p) {
+ r = -EINVAL;
+ goto finish;
+ }
+
+ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ if (flags & FD_CLOEXEC)
+ continue;
+
+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
+ r = -errno;
+ goto finish;
+ }
+ }
+
+ r = (int) l;
+
+finish:
+ if (unset_environment) {
+ unsetenv("LISTEN_PID");
+ unsetenv("LISTEN_FDS");
+ }
+
+ return r;
+#endif
+}
+
+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;
+
+ if (!S_ISFIFO(st_fd.st_mode))
+ return 0;
+
+ if (path) {
+ struct stat st_path;
+
+ memset(&st_path, 0, sizeof(st_path));
+ if (stat(path, &st_path) < 0) {
+
+ if (errno == ENOENT || errno == ENOTDIR)
+ return 0;
+
+ return -errno;
+ }
+
+ return
+ st_path.st_dev == st_fd.st_dev &&
+ st_path.st_ino == st_fd.st_ino;
+ }
+
+ return 1;
+}
+
+static int sd_is_socket_internal(int fd, int type, int listening) {
+ struct stat st_fd;
+
+ if (fd < 0 || type < 0)
+ return -EINVAL;
+
+ if (fstat(fd, &st_fd) < 0)
+ return -errno;
+
+ if (!S_ISSOCK(st_fd.st_mode))
+ return 0;
+
+ if (type != 0) {
+ int other_type = 0;
+ socklen_t l = sizeof(other_type);
+
+ if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
+ return -errno;
+
+ if (l != sizeof(other_type))
+ return -EINVAL;
+
+ if (other_type != type)
+ return 0;
+ }
+
+ if (listening >= 0) {
+ int accepting = 0;
+ socklen_t l = sizeof(accepting);
+
+ if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
+ return -errno;
+
+ if (l != sizeof(accepting))
+ return -EINVAL;
+
+ if (!accepting != !listening)
+ return 0;
+ }
+
+ return 1;
+}
+
+union sockaddr_union {
+ struct sockaddr sa;
+ struct sockaddr_in in4;
+ struct sockaddr_in6 in6;
+ struct sockaddr_un un;
+ struct sockaddr_storage storage;
+};
+
+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)
+ return r;
+
+ if (family > 0) {
+ union sockaddr_union sockaddr;
+ socklen_t l;
+
+ memset(&sockaddr, 0, sizeof(sockaddr));
+ l = sizeof(sockaddr);
+
+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
+ return -errno;
+
+ if (l < sizeof(sa_family_t))
+ return -EINVAL;
+
+ return sockaddr.sa.sa_family == family;
+ }
+
+ 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;
+ int r;
+
+ if (family != 0 && family != AF_INET && family != AF_INET6)
+ return -EINVAL;
+
+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ return r;
+
+ memset(&sockaddr, 0, sizeof(sockaddr));
+ l = sizeof(sockaddr);
+
+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
+ return -errno;
+
+ if (l < sizeof(sa_family_t))
+ return -EINVAL;
+
+ if (sockaddr.sa.sa_family != AF_INET &&
+ sockaddr.sa.sa_family != AF_INET6)
+ return 0;
+
+ if (family > 0)
+ if (sockaddr.sa.sa_family != family)
+ return 0;
+
+ if (port > 0) {
+ if (sockaddr.sa.sa_family == AF_INET) {
+ if (l < sizeof(struct sockaddr_in))
+ return -EINVAL;
+
+ return htons(port) == sockaddr.in4.sin_port;
+ } else {
+ if (l < sizeof(struct sockaddr_in6))
+ return -EINVAL;
+
+ return htons(port) == sockaddr.in6.sin6_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;
+ int r;
+
+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
+ return r;
+
+ memset(&sockaddr, 0, sizeof(sockaddr));
+ l = sizeof(sockaddr);
+
+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
+ return -errno;
+
+ if (l < sizeof(sa_family_t))
+ return -EINVAL;
+
+ if (sockaddr.sa.sa_family != AF_UNIX)
+ return 0;
+
+ if (path) {
+ if (length <= 0)
+ length = strlen(path);
+
+ if (length <= 0)
+ /* Unnamed socket */
+ return l == sizeof(sa_family_t);
+
+ if (path[0])
+ /* Normal path socket */
+ return
+ (l >= sizeof(sa_family_t) + length + 1) &&
+ memcmp(path, sockaddr.un.sun_path, length+1) == 0;
+ else
+ /* Abstract namespace socket */
+ return
+ (l == sizeof(sa_family_t) + length) &&
+ memcmp(path, sockaddr.un.sun_path, length) == 0;
+ }
+
+ return 1;
+}
+
+int sd_notify(int unset_environment, const char *state) {
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
+ return 0;
+#else
+ int fd = -1, r;
+ struct msghdr msghdr;
+ struct iovec iovec;
+ union sockaddr_union sockaddr;
+ const char *e;
+
+ if (!state) {
+ r = -EINVAL;
+ goto finish;
+ }
+
+ if (!(e = getenv("NOTIFY_SOCKET")))
+ return 0;
+
+ /* Must be an abstract socket, or an absolute path */
+ if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
+ r = -EINVAL;
+ goto finish;
+ }
+
+ if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ memset(&sockaddr, 0, sizeof(sockaddr));
+ sockaddr.sa.sa_family = AF_UNIX;
+ strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
+
+ if (sockaddr.un.sun_path[0] == '@')
+ sockaddr.un.sun_path[0] = 0;
+
+ memset(&iovec, 0, sizeof(iovec));
+ iovec.iov_base = (char*) state;
+ iovec.iov_len = strlen(state);
+
+ memset(&msghdr, 0, sizeof(msghdr));
+ msghdr.msg_name = &sockaddr;
+ msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e);
+
+ if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
+
+ msghdr.msg_iov = &iovec;
+ msghdr.msg_iovlen = 1;
+
+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
+ r = 1;
+
+finish:
+ if (unset_environment)
+ unsetenv("NOTIFY_SOCKET");
+
+ if (fd >= 0)
+ close(fd);
+
+ return r;
+#endif
+}
+
+int sd_notifyf(int unset_environment, const char *format, ...) {
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
+ return 0;
+#else
+ va_list ap;
+ char *p = NULL;
+ int r;
+
+ va_start(ap, format);
+ r = vasprintf(&p, format, ap);
+ va_end(ap);
+
+ if (r < 0 || !p)
+ return -ENOMEM;
+
+ r = sd_notify(unset_environment, p);
+ free(p);
+
+ return r;
+#endif
+}
+
+int sd_booted(void) {
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
+ return 0;
+#else
+
+ struct stat a, b;
+
+ /* We simply test whether the systemd cgroup hierarchy is
+ * mounted */
+
+ if (lstat("/sys/fs/cgroup", &a) < 0)
+ return 0;
+
+ if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
+ return 0;
+
+ return a.st_dev != b.st_dev;
+#endif
+}
diff --git a/dbus/sd-daemon.h b/dbus/sd-daemon.h
new file mode 100644
index 0000000..c68c96d
--- /dev/null
+++ b/dbus/sd-daemon.h
@@ -0,0 +1,257 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foosddaemonhfoo
+#define foosddaemonhfoo
+
+/***
+ Copyright 2010 Lennart Poettering
+
+ 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 <sys/types.h>
+#include <inttypes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ Reference implementation of a few systemd related interfaces for
+ writing daemons. These interfaces are trivial to implement. To
+ simplify porting we provide this reference implementation.
+ Applications are welcome to reimplement the algorithms described
+ here if they do not want to include these two source files.
+
+ The following functionality is provided:
+
+ - Support for logging with log levels on stderr
+ - File descriptor passing for socket-based activation
+ - Daemon startup and status notification
+ - Detection of systemd boots
+
+ You may compile this with -DDISABLE_SYSTEMD to disable systemd
+ support. This makes all those calls NOPs that are directly related to
+ systemd (i.e. only sd_is_xxx() will stay useful).
+
+ Since this is drop-in code we don't want any of our symbols to be
+ exported in any case. Hence we declare hidden visibility for all of
+ them.
+
+ 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
+
+ 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.
+*/
+
+#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
+
+/*
+ Log levels for usage on stderr:
+
+ fprintf(stderr, SD_NOTICE "Hello World!\n");
+
+ This is similar to printk() usage in the kernel.
+*/
+#define SD_EMERG "<0>" /* system is unusable */
+#define SD_ALERT "<1>" /* action must be taken immediately */
+#define SD_CRIT "<2>" /* critical conditions */
+#define SD_ERR "<3>" /* error conditions */
+#define SD_WARNING "<4>" /* warning conditions */
+#define SD_NOTICE "<5>" /* normal but significant condition */
+#define SD_INFO "<6>" /* informational */
+#define SD_DEBUG "<7>" /* debug-level messages */
+
+/* The first passed file descriptor is fd 3 */
+#define SD_LISTEN_FDS_START 3
+
+/*
+ Returns how many file descriptors have been passed, or a negative
+ errno code on failure. Optionally, removes the $LISTEN_FDS and
+ $LISTEN_PID file descriptors from the environment (recommended, but
+ problematic in threaded environments). If r is the return value of
+ this function you'll find the file descriptors passed as fds
+ SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
+ errno style error code on failure. This function call ensures that
+ the FD_CLOEXEC flag is set for the passed file descriptors, to make
+ sure they are not passed on to child processes. If FD_CLOEXEC shall
+ not be set, the caller needs to unset it after this call for all file
+ descriptors that are used.
+
+ See sd_listen_fds(3) for more information.
+*/
+int sd_listen_fds(int unset_environment) _sd_hidden_;
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is a FIFO in 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 FIFO. Returns a negative errno style error code on
+ failure.
+
+ See sd_is_fifo(3) for more information.
+*/
+int sd_is_fifo(int fd, const char *path) _sd_hidden_;
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is a socket of the specified family (AF_INET,
+ ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
+ family is 0 a socket family check will not be done. If type is 0 a
+ socket type check will not be done and the call only verifies if
+ the file descriptor refers to a socket. If listening is > 0 it is
+ verified that the socket is in listening mode. (i.e. listen() has
+ been called) If listening is == 0 it is verified that the socket is
+ not in listening mode. If listening is < 0 no listening mode check
+ is done. Returns a negative errno style error code on failure.
+
+ See sd_is_socket(3) for more information.
+*/
+int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is an Internet socket, of the specified family
+ (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
+ SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
+ check is not done. If type is 0 a socket type check will not be
+ done. If port is 0 a socket port check will not be done. The
+ listening flag is used the same way as in sd_is_socket(). Returns a
+ negative errno style error code on failure.
+
+ 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_;
+
+/*
+ Helper call for identifying a passed file descriptor. Returns 1 if
+ the file descriptor is an AF_UNIX socket of the specified type
+ (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
+ a socket type check will not be done. If path is NULL a socket path
+ check will not be done. For normal AF_UNIX sockets set length to
+ 0. For abstract namespace sockets set length to the length of the
+ socket name (including the initial 0 byte), and pass the full
+ socket path in path (including the initial 0 byte). The listening
+ flag is used the same way as in sd_is_socket(). Returns a negative
+ errno style error code on failure.
+
+ 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_;
+
+/*
+ Informs systemd about changed daemon state. This takes a number of
+ newline seperated 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
+ value daemons should send is "READY=1".
+
+ STATUS=... Passes a single-line status string back to systemd
+ that describes the daemon state. This is free-from
+ and can be used for various purposes: general state
+ feedback, fsck-like programs could pass completion
+ percentages and failing programs could pass a human
+ readable error message. Example: "STATUS=Completed
+ 66% of file system check..."
+
+ ERRNO=... If a daemon fails, the errno-style error code,
+ formatted as string. Example: "ERRNO=2" for ENOENT.
+
+ BUSERROR=... If a daemon fails, the D-Bus error-style error
+ code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
+
+ MAINPID=... The main pid of a daemon, in case systemd did not
+ fork off the process itself. Example: "MAINPID=4711"
+
+ Daemons can choose to send additional variables. However, it is
+ recommened 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
+ systemd is not running.
+
+ Example: When a daemon finished starting up, it could issue this
+ call to notify systemd about it:
+
+ sd_notify(0, "READY=1");
+
+ See sd_notifyf() for more complete examples.
+
+ See sd_notify(3) for more information.
+*/
+int sd_notify(int unset_environment, const char *state) _sd_hidden_;
+
+/*
+ Similar to sd_notify() but takes a format string.
+
+ Example 1: A daemon could send the following after initialization:
+
+ sd_notifyf(0, "READY=1\n"
+ "STATUS=Processing requests...\n"
+ "MAINPID=%lu",
+ (unsigned long) getpid());
+
+ Example 2: A daemon could send the following shortly before
+ exiting, on failure:
+
+ sd_notifyf(0, "STATUS=Failed to start up: %s\n"
+ "ERRNO=%i",
+ strerror(errno),
+ errno);
+
+ See sd_notifyf(3) for more information.
+*/
+int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_;
+
+/*
+ Returns > 0 if the system was booted with systemd. Returns < 0 on
+ error. Returns 0 if the system was not booted with systemd. Note
+ that all of the functions above handle non-systemd boots just
+ 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.
+
+ See sd_booted(3) for more information.
+*/
+int sd_booted(void) _sd_hidden_;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 8bc85c5..b265987 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,24 +1,28 @@
apidir = @htmldir@/api
-man_pages = \
+# 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 = \
dbus-cleanup-sockets.1 \
- dbus-daemon.1 \
dbus-launch.1 \
dbus-monitor.1 \
- dbus-run-session.1 \
dbus-send.1 \
- dbus-test-tool.1 \
- dbus-update-activation-environment.1 \
- dbus-uuidgen.1 \
- $(NULL)
+ dbus-uuidgen.1
-MAN_XML_FILES = $(patsubst %.1,%.1.xml,$(man_pages))
+# on the other hand, this one is generated
+man1_MANS = \
+ dbus-daemon.1
-if DBUS_XML_DOCS_ENABLED
-man1_MANS = $(man_pages)
-endif
+MAN_IN_FILES = dbus-daemon.1.in
-MAN_HTML_FILES = $(patsubst %.1,%.1.html,$(man_pages))
+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
DTDS = \
busconfig.dtd \
@@ -32,7 +36,6 @@
dbus-specification.xml \
dbus-test-plan.xml \
dbus-tutorial.xml \
- dbus-api-design.duck \
dcop-howto.txt \
introspect.xsl \
$(DTDS)
@@ -40,7 +43,8 @@
EXTRA_DIST = \
file-boilerplate.c \
doxygen_to_devhelp.xsl \
- $(STATIC_DOCS)
+ $(STATIC_DOCS) \
+ $(MAN_IN_FILES)
html_DATA =
@@ -53,40 +57,29 @@
diagram.svg \
$(NULL)
-# Static HTML helper files generated by yelp-build.
-YELP_STATIC_HTML = \
- yelp.js \
- C.css \
- jquery.js \
- jquery.syntax.js \
- jquery.syntax.brush.html.js \
- jquery.syntax.core.js \
- jquery.syntax.layout.yelp.js \
- $(NULL)
-
dist_html_DATA += $(STATIC_HTML)
-# Content HTML files generated by yelp-build.
-YELP_HTML = \
- dbus-api-design.html \
- $(NULL)
+# we distribute these in the tarball so users don't necessarily need xmlto
+dist_html_DATA += $(XMLTO_OUTPUT)
-XMLTO_HTML = \
+XMLTO_OUTPUT= \
dbus-faq.html \
dbus-specification.html \
dbus-test-plan.html \
- dbus-tutorial.html \
- $(MAN_HTML_FILES) \
- $(NULL)
+ dbus-tutorial.html
if DBUS_XML_DOCS_ENABLED
-html_DATA += $(XMLTO_HTML)
-
-%.html: %.xml
+dbus-specification.html: dbus-specification.xml
$(XMLTO) html-nochunks $<
-%.1: %.1.xml
- $(XMLTO) man $<
+dbus-test-plan.html: dbus-test-plan.xml
+ $(XMLTO) html-nochunks $<
+
+dbus-tutorial.html: dbus-tutorial.xml
+ $(XMLTO) html-nochunks $<
+
+dbus-faq.html: dbus-faq.xml
+ $(XMLTO) html-nochunks $<
endif
if DBUS_DOXYGEN_DOCS_ENABLED
@@ -103,16 +96,6 @@
$(XSLTPROC) -o $@ $< api/xml/index.xml
endif
-if DBUS_DUCKTYPE_DOCS_ENABLED
-html_DATA += $(YELP_HTML) $(YELP_STATIC_HTML)
-
-%.page: %.duck
- $(DUCKTYPE) -o $@ $<
-%.html: %.page
- $(YELP_BUILD) html $<
-$(YELP_STATIC_HTML): $(YELP_HTML)
-endif
-
# this assumes CREATE_SUBDIRS isn't set to YES in Doxyfile
# (which it isn't currently)
install-data-local:: doxygen.stamp
@@ -132,6 +115,13 @@
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 \
@@ -141,17 +131,14 @@
$(top_srcdir)/COPYING \
$(top_srcdir)/ChangeLog
-dbus-docs: $(STATIC_DOCS) $(MAN_XML_FILES) $(dist_doc_DATA) $(dist_html_DATA) $(MAN_HTML_FILES) $(BONUS_FILES) doxygen.stamp $(XMLTO_HTML) $(YELP_HTML) $(YELP_STATIC_HTML)
+dbus-docs: $(STATIC_DOCS) $(dist_doc_DATA) $(dist_html_DATA) $(MAN_HTML_FILES) $(BONUS_FILES) doxygen.stamp
$(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_HTML) @abs_builddir@/$@.tmp
- $(AM_V_at)cp $(YELP_HTML) @abs_builddir@/$@.tmp
- $(AM_V_at)cp $(YELP_STATIC_HTML) @abs_builddir@/$@.tmp
+ $(AM_V_at)cp $(XMLTO_OUTPUT) @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 $@
@@ -173,22 +160,17 @@
else
maintainer-upload-docs:
@echo "Can't upload documentation! Re-run configure with"
- @echo " --enable-doxygen-docs --enable-xml-docs --enable-ducktype-docs"
+ @echo " --enable-doxygen-docs --enable-xml-docs"
@echo "and ensure that man2html is installed."
@false
endif
-CLEANFILES = \
- $(man1_MANS) \
- $(MAN_XML_FILES) \
- $(XMLTO_HTML) \
- $(YELP_HTML) \
- $(YELP_STATIC_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/busconfig.dtd b/doc/busconfig.dtd
index 8c5ac33..0cc519b 100644
--- a/doc/busconfig.dtd
+++ b/doc/busconfig.dtd
@@ -11,8 +11,7 @@
include |
policy |
limit |
- selinux |
- apparmor)*>
+ selinux)*>
<!ELEMENT user (#PCDATA)>
<!ELEMENT listen (#PCDATA)>
@@ -64,7 +63,3 @@
<!ATTLIST associate
own CDATA #REQUIRED
context CDATA #REQUIRED>
-
-<!ELEMENT apparmor EMPTY>
-<!ATTLIST apparmor
- mode (required|enabled|disabled) "enabled">
diff --git a/doc/dbus-api-design.duck b/doc/dbus-api-design.duck
deleted file mode 100644
index be3ea9f..0000000
--- a/doc/dbus-api-design.duck
+++ /dev/null
@@ -1,888 +0,0 @@
-= D-Bus API Design Guidelines
-@link[guide >index]
-@credit[type="author copyright"]
- @name Philip Withnall
- @email philip.withnall@collabora.co.uk
- @years 2015
-@desc Guidelines for writing high quality D-Bus APIs
-@revision[date=2015-02-05 status=draft]
-
-[synopsis]
- [title]
- Summary
-
- The most common use for D-Bus is in implementing a service which will be
- consumed by multiple client programs, and hence all interfaces exported on the
- bus form a public API. Designing a D-Bus API is like designing any other API:
- there is a lot of flexibility, but there are design patterns to follow and
- anti-patterns to avoid.
-
- This guide aims to explain the best practices for writing D-Bus APIs. These
- have been refined over several years of use of D-Bus in many projects.
- Pointers will be given for implementing APIs using common D-Bus
- libraries like
- $link[>>https://developer.gnome.org/gio/stable/gdbus-convenience.html](GDBus),
- but detailed implementation instructions are left to the libraries’
- documentation. Note that you should $em(not) use dbus-glib to implement D-Bus
- services as it is deprecated and unmaintained. Most services should also avoid
- libdbus (dbus-1), which is a low-level library and is awkward to use
- correctly: it is designed to be used via a language binding such as
- $link[>>http://qt-project.org/doc/qt-4.8/qtdbus.html](QtDBus).
-
- For documentation on D-Bus itself, see the
- $link[>>http://dbus.freedesktop.org/doc/dbus-specification.html](D-Bus
- specification).
-
-[links section]
-
-== APIs
- [id="apis"]
-
-A D-Bus API is a specification of one or more interfaces, which will be
-implemented by objects exposed by a service on the bus. Typically an API is
-designed as a set of $link[>#interface-files](interface files), and the
-implementation of the service follows those files. Some projects, however,
-choose to define the API in the code for the service, and to export XML
-interface files from the running service
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable](using
-D-Bus introspection). Both are valid approaches.
-
-For simplicity, this document uses the XML descriptions of D-Bus interfaces as
-the canonical representation.
-
-== Interface files
- [id="interface-files"]
-
-A D-Bus interface file is an XML file which describes one or more D-Bus
-interfaces, and is the best way of describing a D-Bus API in a machine
-readable way. The format is described in the
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format](D-Bus
-specification), and is supported by tools such as $cmd(gdbus-codegen).
-
-Interface files for public API should be installed to
-$code($var($$(datadir$))/dbus-1/interfaces) so that other services can load
-them. Private APIs should not be installed. There should be one file installed
-per D-Bus interface, named after the interface, containing a single top-level
-$code(<node>) element with a single $code(<interface>) beneath it. For example,
-interface $code(com.example.MyService1.Manager) would be described by file
-$file($var($$(datadir$))/dbus-1/interfaces/com.example.MyService1.Manager.xml):
-
-[listing]
- [title]
- Example D-Bus Interface XML
- [desc]
- A brief example interface XML document.
- [code mime="application/xml"]
- <!DOCTYPE node PUBLIC
- "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
- <node xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
- <interface name="com.example.MyService1.InterestingInterface">
- <method name="AddContact">
- <arg name="name" direction="in" type="s">
- <doc:doc><doc:summary>Name of new contact</doc:summary></doc:doc>
- </arg>
- <arg name="email" direction="in" type="s">
- <doc:doc><doc:summary>E-mail address of new contact</doc:summary></doc:doc>
- </arg>
- <arg name="id" direction="out" type="u">
- <doc:doc><doc:summary>ID of newly added contact</doc:summary></doc:doc>
- </arg>
- <doc:doc>
- <doc:description>
- <doc:para>
- Adds a new contact to the address book with their name and
- e-mail address.
- </doc:para>
- </doc:description>
- </doc:doc>
- </method>
- </interface>
- </node>
-
-If an interface defined by service A needs to be used by client B, client B
-should declare a build time dependency on service A, and use the installed copy
-of the interface file for any code generation it has to do. It should $em(not)
-have a local copy of the interface, as that could then go out of sync with the
-canonical copy in service A’s git repository.
-
-== API versioning
- [id="api-versioning"]
-
-$link[>>http://ometer.com/parallel.html](Just like C APIs), D-Bus interfaces
-should be designed to be usable in parallel with API-incompatible versions. This
-is achieved by including a version number in each interface name, service name
-and object path which is incremented on every backwards-incompatible change.
-
-Version numbers should be included in all APIs from the first release, as that
-means moving to a new version is as simple as incrementing the number, rather
-than inserting a number everywhere, which takes more effort.
-
-New API can be added to a D-Bus interface without incrementing the version
-number, as such additions are still backwards-compatible. However, clients
-should gracefully handle the $code(org.freedesktop.DBus.Error.UnknownMethod)
-error reply from all D-Bus method calls if they want to run against older
-versions of the service which don’t implement new methods. (This also prevents
-use of generated bindings; any method which a client wants to gracefully fall
-back from should be called using a generic D-Bus method invocation rather than
-a specific generated binding.)
-
-When API is broken, changed or removed, the service’s version number must be
-bumped; for example, from $code(com.example.MyService1)
-to $code(com.example.MyService2). If backwards compatibility is maintained in
-the service by implementing both the old and new interfaces, the service can
-own $em(both) well-known names and clients can use whichever they support.
-
-As discussed in $link[>#annotations], new or deprecated APIs should be marked in
-the interface XML using annotations.
-
-Note, however, that supporting multiple interface versions simultaneously
-requires that $em(object paths) are versioned as well, so objects $em(must not)
-be put on the bus at the root path (‘/’). This is for technical reasons: signals
-sent from a D-Bus service have the originating service name overwritten by its
-unique name (e.g. $code(com.example.MyService2) is overwritten by $code(:1:15)).
-If object paths are shared between objects implementing two versions of the
-service’s interface, client programs cannot tell which object a signal has come
-from. The solution is to include the version number in all object paths, for
-example $code(/com/example/MyService1/Manager) instead of $code(/) or
-$code(/com/example/MyService/Manager).
-
-In summary, version numbers should be included in all service names, interface
-names and object paths:
-[list]
-* $code(com.example.MyService1)
-* $code(com.example.MyService1.InterestingInterface)
-* $code(com.example.MyService1.OtherInterface)
-* $code(/com/example/MyService1/Manager)
-* $code(/com/example/MyService1/OtherObject)
-
-== API design
- [id="api-design"]
-
-D-Bus API design is broadly the same as C API design, but there are a few
-additional points to bear in mind which arise both from D-Bus’ features
-(explicit errors, signals and properties), and from its implementation as an IPC
-system.
-
-D-Bus method calls are much more expensive than C function calls, typically
-taking on the order of milliseconds to complete a round trip. Therefore, the
-design should minimize the number of method calls needed to perform an
-operation.
-
-The type system is very expressive, especially compared to C’s, and APIs should
-take full advantage of it.
-
-Similarly, its support for signals and properties differentiates it from normal
-C APIs, and well written D-Bus APIs make full use of these features where
-appropriate. They can be coupled with standard interfaces defined in the D-Bus
-specification to allow for consistent access to properties and objects in a
-hierarchy.
-
-=== Minimizing Round Trips
- [id="round-trips"]
-
-Each D-Bus method call is a round trip from a client program to a service and
-back again, which is expensive — taking on the order of a millisecond. One of
-the top priorities in D-Bus API design is to minimize the number of round trips
-needed by clients. This can be achieved by a combination of providing specific
-convenience APIs and designing APIs which operate on large data sets in a single
-call, rather than requiring as many calls as elements in the data set.
-
-Consider an address book API, $code(com.example.MyService1.AddressBook). It
-might have an $code(AddContact(ss$) → (u$)) method to add a contact (taking name
-and e-mail address parameters and returning a unique contact ID), and a
-$code(RemoveContact(u$)) method to remove one by ID. In the normal case of
-operating on single contacts in the address book, these calls are optimal.
-However, if the user wants to import a list of contacts, or delete multiple
-contacts simultaneously, one call has to be made per contact — this could take
-a long time for large contact lists.
-
-Instead of the $code(AddContact) and $code(RemoveContact) methods, the interface
-could have an $code(UpdateContacts(a(ss$)au$) → (au$)) method, which takes an array
-of structs containing the new contacts’ details, and an array of IDs of the
-contacts to delete, and returns an array of IDs for the new contacts. This
-reduces the number of round trips needed to one.
-
-Adding convenience APIs to replace a series of common method calls with a single
-method call specifically for that task is best done after the API has been
-profiled and bottlenecks identified, otherwise it could lead to premature
-optimization. One area where convenience methods can typically be added
-is during initialization of a client, where multiple method calls are needed to
-establish its state with the service.
-
-=== Taking Advantage of the Type System
- [id="type-system"]
-
-D-Bus’ type system is similar to Python’s, but with a terser syntax which may be
-unfamiliar to C developers. The key to using the type system effectively is
-to expose as much structure in types as possible. In particular, sending
-structured strings over D-Bus should be avoided, as they need to be built and
-parsed; both are complex operations which are prone to bugs.
-
-For APIs being used in constrained situations, enumerated values should be
-transmitted as unsigned integers. For APIs which need to be extended by third
-parties or which are used in more loosely coupled systems, enumerated values
-should be strings in some defined format.
-
-Transmitting values as integers means string parsing and matching can be
-avoided, the messages are more compact, and typos can be more easily avoided by
-developers (if, for example, C enums are used in the implementation).
-
-Transmitting values as strings means additional values can be defined by third
-parties without fear of conflicting over integer values; for instance by using
-the same reverse-domain-name namespacing as D-Bus interfaces.
-
-In both cases, the interface documentation should describe the meaning of each
-value. It should state whether the type can be extended in future and, if so,
-how the service and client should handle unrecognized values — typically by
-considering them equal to an ‘unknown’ or ‘failure’ value. Conventionally, zero
-is used as the ‘unknown’ value.
-
-[example]
- For example, instead of:
- [code style="invalid" mime="application/xml"]
- <!--
- Status:
-
- Status of the object.
- Valid statuses: ‘unknown’, ‘ready’, ‘complete’.
- -->
- <property name="Status" type="s" access="read" />
-
- Use:
- [code style="valid" mime="application/xml"]
- <!--
- Status:
-
- Status of the object.
- Valid statuses: 0 = Unknown, 1 = Ready, 2 = Complete.
- Unrecognized statuses should be considered equal to Unknown.
- -->
- <property name="Status" type="u" access="read" />
-
-Similarly, enumerated values should be used instead of booleans, as they allow
-extra values to be added in future, and there is no ambiguity about the sense of
-the boolean value.
-
-[example]
- For example, instead of:
- [code style="invalid" mime="application/xml"]
- <!--
- MoveAddressBook:
- @direction: %TRUE to move it up in the list, %FALSE to move it down
-
- Move this address book up or down in the user’s list of address books.
- Higher address books have their contacts displayed first in search
- results.
- -->
- <method name="MoveAddressBook">
- <arg name="direction" type="b" direction="in" />
- </method>
-
- Be more explicit than a boolean:
- [code style="valid" mime="application/xml"]
- <!--
- MoveAddressBook:
- @direction: 0 = Move it up in the list, 1 = Move it down
-
- Move this address book up or down in the user’s list of address books.
- Higher address books have their contacts displayed first in search
- results.
-
- Unrecognized enum values for @direction will result in the address book
- not moving.
- -->
- <method name="MoveAddressBook">
- <arg name="direction" type="u" direction="in" />
- </method>
-
-Enumerated values should also be used instead of $em(human readable) strings,
-which should not be sent over the bus if possible. The service and client could
-be running in different locales, and hence interpret any human readable strings
-differently, or present them to the user in the wrong language. Transmit an
-enumerated value and convert it to a human readable string in the client.
-
-In situations where a service has received a human readable string from
-somewhere else, it should pass it on unmodified to the client, ideally with its
-locale alongside. Passing human readable information to a client is better than
-passing nothing.
-
-[example]
- For example, instead of:
- [code style="invalid" mime="application/xml"]
- <!--
- ProgressNotification:
- @progress_message: Human readable progress message string.
-
- Emitted whenever significant progress is made with some example
- operation. The @progress_message can be displayed in a UI dialogue to
- please the user.
- -->
- <signal name="ProgressNotification">
- <arg name="progress_message" type="s" />
- </method>
-
- The progress should be reported as an enumerated value:
- [code style="valid" mime="application/xml"]
- <!--
- ProgressNotification:
- @progress_state: 0 = Preparing, 1 = In progress, 2 = Finished
-
- Emitted whenever significant progress is made with some example
- operation. The @progress_state is typically converted to a human readable
- string and presented to the user. Unrecognized @progress_state values
- should be treated as state 1, in progress.
- -->
- <signal name="ProgressNotification">
- <arg name="progress_state" type="u" />
- </method>
-
-D-Bus has none of the problems of signed versus unsigned integers which C has
-(specifically, it does not do implicit sign conversion), so integer types should
-always be chosen to be an appropriate size and signedness for the data they
-could possibly contain. Typically, unsigned values are more frequently needed
-than signed values.
-
-Structures can be used almost anywhere in a D-Bus type, and arrays of structures
-are particularly useful. Structures should be used wherever data fields are
-related. Note, however, that structures are not extensible in future, so always
-consider $link[>#extensibility].
-
-[example]
- For example, instead of several identically-indexed arrays containing
- different properties of the same set of items:
- [code style="invalid" mime="application/xml"]
- <!--
- AddContacts:
- @names: Array of contact names to add.
- @emails: Corresponding array of contact e-mail addresses.
- @ids: Returned array of the IDs of the new contacts. This will be the
- same length as @names.
-
- Add zero or more contacts to the address book, using their names and
- e-mail addresses. @names and @emails must be the same length.
- -->
- <method name="AddContacts">
- <arg name="names" type="as" direction="in" />
- <arg name="emails" type="as" direction="in" />
- <arg name="ids" type="au" direction="out" />
- </method>
-
- The arrays can be combined into a single array of structures:
- [code style="invalid" mime="application/xml"]
- <!--
- AddContacts:
- @details: Array of (contact name, contact e-mail address) to add.
- @ids: Returned array of the IDs of the new contacts. This will be the
- same length as @details.
-
- Add zero or more contacts to the address book, using their names and
- e-mail addresses.
- -->
- <method name="AddContacts">
- <arg name="details" type="a(ss)" direction="in" />
- <arg name="ids" type="au" direction="out" />
- </method>
-
-Note that D-Bus arrays are automatically transmitted with their length, so there
-is no need to null-terminate them or encode their length separately.
-
-[comment]
- FIXME: Mention maybe types and the extended kdbus/GVariant type system once
- that’s stable and round-trip-ability is no longer a concern.
-
-=== Extensibility
- [id="extensibility"]
-
-Some D-Bus APIs have very well-defined use cases, and will never need extension.
-Others are used in more loosely coupled systems which may change over time, and
-hence should be designed to be extensible from the beginning without the need
-to break API in future. This is a trade off between having a more complex API,
-and being able to easily extend it in future.
-
-The key tool for extensibility in D-Bus is $code(a{sv}), the dictionary mapping
-strings to variants. If well-defined namespaced strings are used as the
-dictionary keys, arbitrary D-Bus peers can add whatever information they need
-into the dictionary. Any other peer which understands it can query and retrieve
-the information; other peers will ignore it.
-
-The canonical example of an extensible API using $code(a{sv}) is
-$link[>>http://telepathy.freedesktop.org/spec/](Telepathy). It uses $code(a{sv})
-values as the final element in structures to allow them to be extended in
-future.
-
-A secondary tool is the use of flag fields in method calls. The set of accepted
-flags is entirely under the control of the interface designer and, as with
-enumerated types, can be extended in future without breaking API. Adding more
-flags allows the functionality of the method call to be tweaked.
-
-=== Using Signals, Properties and Errors
- [id="using-the-features"]
-
-D-Bus method calls are explicitly asynchronous due to the latency inherent in
-IPC. This means that peers should not block on receiving a reply from a method
-call; they should schedule other work (in a main loop) and handle the reply when
-it is received. Even though method replies may take a while, the caller is
-$em(guaranteed) to receive exactly one reply eventually. This reply could be the
-return value from the method, an error from the method, or an error from the
-D-Bus daemon indicating the service failed in some way (e.g. due to crashing).
-
-Because of this, service implementations should be careful to always reply
-exactly once to each method call. Replying at the end of a long-running
-operation is correct — the client will patiently wait until the operation has
-finished and the reply is received.
-
-Note that D-Bus client bindings may implement synthetic timeouts of several
-tens of seconds, unless explicitly disabled for a call. For very long-running
-operations, you should disable the client bindings’ timeout and make it clear
-in the client’s UI that the application has not frozen and is simply running a
-long operation.
-
-An anti-pattern to avoid in this situation is to start a long-running operation
-when a method call is received, then to never reply to the method call and
-instead notify the client of completion of the operation via a signal. This
-approach is incorrect as signal emissions do not have a one-to-one relationship
-with method calls — the signal could theoretically be emitted multiple times, or
-never, which the client would not be able to handle.
-
-Similarly, use a D-Bus error reply to signify failure of an operation triggered
-by a method call, rather than using a custom error code in the method’s
-reply. This means that a reply always indicates success, and an error always
-indicates failure — rather than a reply indicating either depending on its
-parameters, and having to return dummy values in the other parameters. Using
-D-Bus error replies also means such failures can be highlighted in debugging
-tools, simplifying debugging.
-
-Clients should handle all possible standard and documented D-Bus errors for each
-method call. IPC inherently has more potential failures than normal C function
-calls, and clients should be prepared to handle all of them gracefully.
-
-=== Using Standard Interfaces
- [id="standard-interfaces"]
-
-Use standard D-Bus interfaces where possible.
-
-==== Properties
- [id="interface-properties"]
-
-The D-Bus specification defines the
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties]($code(org.freedesktop.DBus.Properties))
-interface, which should be used by all objects to notify clients of changes
-to their property values, with the $code(PropertiesChanged) signal. This signal
-eliminates the need for individual $code($var(PropertyName)Changed) signals, and
-allows multiple properties to be notified in a single signal emission, reducing
-IPC round trips. Similarly, the $code(Get) and $code(Set) methods can be used to
-manipulate properties on an object, eliminating redundant
-$code(Get$var(PropertyName)) and $code(Set$var(PropertyName)) methods.
-
-[example]
- For example, consider an object implementing an interface
- $code(com.example.MyService1.SomeInterface) with methods:
- [list]
- * $code(GetName($) → (s$))
- * $code(SetName(s$) → ($))
- * $code(GetStatus($) → (u$))
- * $code(RunOperation(ss$) → (u$))
- and signals:
- [list]
- * $code(NameChanged(u$))
- * $code(StatusChanged(u$))
-
- The interface could be cut down to a single method:
- [list]
- * $code(RunOperation(ss$) → (u$))
- The object could then implement the $code(org.freedesktop.DBus.Properties)
- interface and define properties:
- [list]
- * $code(Name) of type $code(s), read–write
- * $code(Status) of type $code(u), read-only
-
- The $code(NameChanged) and $code(StatusChanged) signals would be replaced by
- $code(org.freedesktop.DBus.Properties.PropertiesChanged).
-
-==== Object Manager
- [id="interface-object-manager"]
-
-The specification also defines the
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager]($code(org.freedesktop.DBus.ObjectManager))
-interface, which should be used whenever a service needs to expose a variable
-number of objects of the same class in a flat or tree-like structure, and
-clients are expected to be interested in most or all of the objects. For
-example, this could be used by an address book service which exposes multiple
-address books, each as a separate object. The $code(GetManagedObjects) method
-allows the full object tree to be queried, returning all the objects’ properties
-too, eliminating the need for further IPC round trips to query the properties.
-
-If clients are not expected to be interested in most of the exposed objects,
-$code(ObjectManager) should $em(not) be used, as it will send all of the objects
-to each client anyway, wasting bus bandwidth. A file manager, therefore, should
-not expose the entire file system hierarchy using $code(ObjectManager).
-
-[example]
- For example, consider an object implementing an interface
- $code(com.example.MyService1.AddressBookManager) with methods:
- [list]
- * $code(GetAddressBooks($) → (ao$))
- and signals:
- [list]
- * $code(AddressBookAdded(o$))
- * $code(AddressBookRemoved(o$))
-
- If the manager object is at path
- $code(/com/example/MyService1/AddressBookManager), each address book is a
- child object, e.g.
- $code(/com/example/MyService1/AddressBookManager/SomeAddressBook).
-
- The interface could be eliminated, and the
- $code(org.freedesktop.DBus.ObjectManager) interface implemented on the manager
- object instead.
-
- Calls to $code(GetAddressBooks) would become calls to $code(GetManagedObjects)
- and emissions of the $code(AddressBookAdded) and $code(AddressBookRemoved)
- signals would become emissions of $code(InterfacesAdded) and
- $code(InterfacesRemoved).
-
-=== Naming Conventions
- [id="naming-conventions"]
-
-All D-Bus names, from service names through to method parameters, follow a set
-of conventions. Following these conventions makes APIs more natural to use and
-consistent with all other services on the system.
-
-Services use reverse-domain-name notation, based on the domain name of the
-project providing the service (all in lower case), plus a unique name for the
-service (in camel case).
-
-[example]
- For example, version 2 of an address book application called $code(ContactDex)
- provided by a software vendor whose website is $code(chocolateteapot.com)
- would use service name $code(com.chocolateteapot.ContactDex2).
-
-Almost all names use camel case with no underscores, as in the examples below.
-Method and signal parameters are an exception, using
-$code(lowercase_with_underscores). Type information is never encoded in the
-parameter name (i.e. $em(not)
-$link[>>http://en.wikipedia.org/wiki/Hungarian_notation](Hungarian notation)).
-
-[example]
- [terms]
- - Service Name
- * $code(com.example.MyService1)
- - Interface Name
- * $code(com.example.MyService1.SomeInterface)
- - Object Path (Root Object)
- * $code(/com/example/MyService1)
- - Object Path (Child Object)
- * $code(/com/example/MyService1/SomeChild)
- - Object Path (Grandchild Object)
- * $code(/com/example/MyService1/AnotherChild/Grandchild1)
- - Method Name
- * $code(com.example.MyService1.SomeInterface.MethodName)
- - Signal Name
- * $code(com.example.MyService1.SomeInterface.SignalName)
- - Property Name
- * $code(com.example.MyService1.SomeInterface.PropertyName)
-
-See also: $link[>#api-versioning].
-
-== Code generation
- [id="code-generation"]
-
-Rather than manually implementing both the server and client sides of a D-Bus
-interface, it is often easier to write the interface XML description and use a
-tool such as
-$link[>>https://developer.gnome.org/gio/stable/gdbus-codegen.html]($cmd(gdbus-codegen))
-to generate type-safe C APIs, then build the implementation using those. This
-avoids the tedious and error-prone process of writing code to build and read
-D-Bus parameter variants for each method call.
-
-Use of code generators is beyond the scope of this guide; for more information,
-see the
-$link[>>https://developer.gnome.org/gio/stable/gdbus-codegen.html]($cmd(gdbus-codegen)
-manual).
-
-== Annotations
- [id="annotations"]
-
-Annotations may be added to the interface XML to expose metadata on the API
-which can be used by documentation or code generation tools to modify their
-output. Some standard annotations are given in the
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format](D-Bus
-specification), but further annotations may be defined by specific tools.
-
-For example, $cmd(gdbus-codegen) defines several useful annotations, listed on
-its man page.
-
-The following annotations are the most useful:
-
-[terms]
-- $code(org.freedesktop.DBus.Deprecated)
-* Mark a symbol as deprecated. This should be used whenever the API is changed,
- specifying the version introducing the deprecation, the reason for
- deprecation, and a replacement symbol to use.
-- $code(org.gtk.GDBus.Since)
-* Mark a symbol as having been added to the API after the initial release. This
- should include the version the symbol was first added in.
-- $code(org.gtk.GDBus.C.Name) and $code(org.freedesktop.DBus.GLib.CSymbol)
-* Both used interchangeably to hint at a C function name to use when generating
- code for a symbol. Use of this annotation can make generated bindings a lot
- more pleasant to use.
-- $code(org.freedesktop.DBus.Property.EmitsChangedSignal)
-* Indicate whether a property is expected to emit change signals. This can
- affect code generation, but is also useful documentation, as client programs
- then know when to expect property change notifications and when they have to
- requery.
-
-== Documentation
- [id="documentation"]
-
-Also just like C APIs, D-Bus APIs must be documented. There are several methods
-for documenting the interfaces, methods, properties and signals in a D-Bus
-interface XML file, each unfortunately with their own downsides. You should
-choose the method which best matches the tooling and workflow you are using.
-
-=== XML Comments
-
-XML comments containing documentation in the
-$link[>>https://developer.gnome.org/gtk-doc-manual/stable/documenting_syntax.html.en](gtk-doc
-format) is the recommended format for use with
-$link[>>https://developer.gnome.org/gio/stable/gdbus-codegen.html]($cmd(gdbus-codegen)).
-Using $cmd(gdbus-codegen), these comments can be extracted, converted to DocBook
-format and included in the project’s API manual. For example:
-
-[listing]
- [title]
- Documentation Comments in D-Bus Interface XML
- [desc]
- Example gtk-doc–style documentation comments in the introspection XML for
- the $code(org.freedesktop.DBus.Properties) interface.
- [code mime="application/xml"]
- <!--
- org.freedesktop.DBus.Properties:
- @short_description: Standard property getter/setter interface
-
- Interface for all objects which expose properties on the bus, allowing
- those properties to be got, set, and signals emitted to notify of changes
- to the property values.
- -->
- <interface name="org.freedesktop.DBus.Properties">
- <!--
- Get:
- @interface_name: Name of the interface the property is defined on.
- @property_name: Name of the property to get.
- @value: Property value, wrapped in a variant.
-
- Retrieves the value of the property at @property_name on
- @interface_name on this object. If @interface_name is an empty string,
- all interfaces will be searched for @property_name; if multiple
- properties match, the result is undefined.
-
- If @interface_name or @property_name do not exist, a
- #org.freedesktop.DBus.Error.InvalidArgs error is returned.
- -->
- <method name="Get">
- <arg type="s" name="interface_name" direction="in"/>
- <arg type="s" name="property_name" direction="in"/>
- <arg type="v" name="value" direction="out"/>
- </method>
-
- <!--
- PropertiesChanged:
- @interface_name: Name of the interface the properties changed on.
- @changed_properties: Map of property name to updated value for the
- changed properties.
- @invalidated_properties: List of names of other properties which have
- changed, but whose updated values are not notified.
-
- Emitted when one or more properties change values on @interface_name.
- A property may be listed in @changed_properties or
- @invalidated_properties depending on whether the service wants to
- broadcast the property’s new value. If a value is large or infrequently
- used, the service might not want to broadcast it, and will wait for
- clients to request it instead.
- -->
- <signal name="PropertiesChanged">
- <arg type="s" name="interface_name"/>
- <arg type="a{sv}" name="changed_properties"/>
- <arg type="as" name="invalidated_properties"/>
- </signal>
- </interface>
-
-[comment]
- FIXME: This is only present to fix
- $link[>>https://github.com/projectmallard/mallard-ducktype/issues/2].
-
-=== XML Annotations
-
-Documentation can also be added as annotation elements in the XML. This format
-is also supported by $cmd(gdbus-codegen), but gtk-doc comments are preferred.
-For example:
-
-[listing]
- [title]
- Documentation Annotations in D-Bus Interface XML
- [desc]
- Example GDBus documentation annotations in the introspection XML for
- the $code(org.freedesktop.DBus.Properties) interface.
- [code mime="application/xml"]
- <interface name="org.freedesktop.DBus.Properties">
- <annotation name="org.gtk.GDBus.DocString" value="Interface for all
- objects which expose properties on the bus, allowing those properties to
- be got, set, and signals emitted to notify of changes to the property
- values."/>
- <annotation name="org.gtk.GDBus.DocString.Short"
- value="Standard property getter/setter interface"/>
-
- <method name="Get">
- <annotation name="org.gtk.GDBus.DocString" value="Retrieves the value of
- the property at @property_name on @interface_name on this object. If
- @interface_name is an empty string, all interfaces will be searched
- for @property_name; if multiple properties match, the result is
- undefined.
-
- If @interface_name or @property_name do not exist, a
- #org.freedesktop.DBus.Error.InvalidArgs error is returned."/>
-
- <arg type="s" name="interface_name" direction="in">
- <annotation name="org.gtk.GDBus.DocString"
- value="Name of the interface the property is defined on."/>
- </arg>
-
- <arg type="s" name="property_name" direction="in">
- <annotation name="org.gtk.GDBus.DocString"
- value="Name of the property to get."/>
- </arg>
-
- <arg type="v" name="value" direction="out">
- <annotation name="org.gtk.GDBus.DocString"
- value="Property value, wrapped in a variant."/>
- </arg>
- </method>
-
- <signal name="PropertiesChanged">
- <annotation name="org.gtk.GDBus.DocString" value="Emitted when one or
- more properties change values on @interface_name. A property may be
- listed in @changed_properties or @invalidated_properties depending on
- whether the service wants to broadcast the property’s new value. If a
- value is large or infrequently used, the service might not want to
- broadcast it, and will wait for clients to request it instead."/>
-
- <arg type="s" name="interface_name">
- <annotation name="org.gtk.GDBus.DocString"
- value="Name of the interface the properties changed on."/>
- </arg>
-
- <arg type="a{sv}" name="changed_properties">
- <annotation name="org.gtk.GDBus.DocString"
- value="Map of property name to updated value for the changed
- properties."/>
- </arg>
-
- <arg type="as" name="invalidated_properties">
- <annotation name="org.gtk.GDBus.DocString"
- value="List of names of other properties which have changed, but
- whose updated values are not notified."/>
- </arg>
- </signal>
- </interface>
-
-[comment]
- FIXME: This is only present to fix
- $link[>>https://github.com/projectmallard/mallard-ducktype/issues/2].
-
-== Service files
- [id="service-files"]
-
-Each D-Bus service must install a $file(.service) file describing its service
-name and the command to run to start the service. This allows for service
-activation (see the
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-starting-services](D-Bus
-specification)).
-
-Service files must be named after the service’s well-known name, for example
-file $file(com.example.MyService1.service) for well-known name
-$code(com.example.MyService1). Files must be installed in
-$file($var($$(datadir$))/dbus-1/services) for the session bus and
-$file($var($$(datadir$))/dbus-1/system-services) for the system bus. Note, however,
-that services on the system bus almost always need a
-$link[>#security-policies](security policy) as well.
-
-== Security Policies
- [id="security-policies"]
-
-At a high level, the D-Bus security model is:
-[list]
-* There is a system bus, and zero or more session buses.
-* Any process may connect to the system bus. The system bus limits which can own
- names or send method calls, and only processes running as privileged users can
- receive unicast messages not addressed to them. Every process may receive
- broadcasts.
-* Each session bus has an owner (a user). Only its owner may connect; on
- general-purpose Linux, a session bus is not treated as a privilege boundary,
- so there is no further privilege separation between processes on it.
-
-Full coverage of securing D-Bus services is beyond the scope of this guide,
-however there are some steps which you can take when designing an API to ease
-security policy implementation.
-
-D-Bus security policies are written as XML files in
-$file($var($$(sysconfdir$)/dbus-1/system.d)) and
-$file($var($$(sysconfdir$)/dbus-1/session.d)) and use an allow/deny model, where
-each message (method call, signal emission, etc.) can be allowed or denied
-according to the sum of all policy rules which match it. Each $code(<allow>) or
-$code(<deny>) rule in the policy should have the $code(own),
-$code(send_destination) or $code(receive_sender) attribute set.
-
-When designing an API, bear in mind the need to write and install such a
-security policy, and consider splitting up methods or providing more restricted
-versions which accept constrained parameters, so that they can be exposed with
-less restrictive security policies if needed by less trusted clients.
-
-Secondly, the default D-Bus security policy for the system bus is restrictive
-enough to allow sensitive data, such as passwords, to be safely sent over the
-bus in unicast messages (including unicast signals); so there is no need to
-complicate APIs by implementing extra security. Note, however, that sensitive
-data must $em(not) be sent in broadcast signals, as they can be seen by all
-peers on the bus. The default policy for the session bus is not restrictive, but
-it is typically not a security boundary.
-
-== Debugging
- [id="debugging"]
-
-Debugging services running on D-Bus can be tricky, especially if they are
-launched via service activation and hence in an environment out of your control.
-
-Three main tools are available: D-Bus Monitor, Bustle and D-Feet.
-
-=== D-Bus Monitor
- [id="dbus-monitor"]
-
-$link[>>http://dbus.freedesktop.org/doc/dbus-monitor.1.html]($cmd(dbus-monitor))
-is a core D-Bus tool, and allows eavesdropping on the session or system bus,
-printing all messages it sees. The messages may be filtered using a standard
-$link[>>http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing-match-rules](D-Bus
-match rule) to make the stream more manageable.
-
-Previous versions of D-Bus have required the security policy for the system bus
-to be manually relaxed to allow eavesdropping on all messages. This meant that
-debugging it was difficult and insecure. The latest versions of D-Bus add
-support for monitor-only connections for the root user, which means that
-$cmd(dbus-monitor) can be run as root to painlessly monitor all messages on the
-system bus without modifying its security policy.
-
-=== Bustle
- [id="bustle"]
-
-$link[>>http://willthompson.co.uk/bustle/](Bustle) is a graphical version of
-$cmd(dbus-monitor), with a UI focused on profiling D-Bus performance by plotting
-messages on a timeline. It is ideal for finding bottlenecks in IPC performance
-between a service and client.
-
-=== D-Feet
- [id="d-feet"]
-
-$link[>>https://wiki.gnome.org/Apps/DFeet](D-Feet) is an introspection tool for
-D-Bus, which displays all peers on the bus graphically, with their objects,
-interfaces, methods, signals and properties listed for examination. It is useful
-for debugging all kinds of issues related to presence of services on the bus
-and the objects they expose.
diff --git a/doc/dbus-cleanup-sockets.1 b/doc/dbus-cleanup-sockets.1
new file mode 100644
index 0000000..a062d49
--- /dev/null
+++ b/doc/dbus-cleanup-sockets.1
@@ -0,0 +1,43 @@
+.\"
+.\" 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
deleted file mode 100644
index 6d98083..0000000
--- a/doc/dbus-cleanup-sockets.1.xml.in
+++ /dev/null
@@ -1,65 +0,0 @@
-<?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\-cleanup\-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
new file mode 100644
index 0000000..53856e9
--- /dev/null
+++ b/doc/dbus-daemon.1.in
@@ -0,0 +1,766 @@
+.\"
+.\" 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/doc/dbus-daemon.1.xml.in b/doc/dbus-daemon.1.xml.in
deleted file mode 100644
index df67a90..0000000
--- a/doc/dbus-daemon.1.xml.in
+++ /dev/null
@@ -1,991 +0,0 @@
-<?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='dbusdaemon1'>
-
-<!-- dbus\-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>
-<refname>dbus-daemon</refname>
-<refpurpose>Message bus daemon</refpurpose>
-</refnamediv>
-<!-- body begins here -->
-<refsynopsisdiv id='synopsis'>
-<cmdsynopsis>
- <command>dbus-daemon</command></cmdsynopsis>
-<cmdsynopsis>
- <command>dbus-daemon</command> <arg choice='opt'>--version </arg>
- <arg choice='opt'>--session </arg>
- <arg choice='opt'>--system </arg>
- <arg choice='opt'>--config-file=<replaceable>FILE</replaceable></arg>
- <arg choice='opt'><arg choice='plain'>--print-address </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
- <arg choice='opt'><arg choice='plain'>--print-pid </arg><arg choice='opt'><replaceable>=DESCRIPTOR</replaceable></arg></arg>
- <arg choice='opt'>--fork </arg>
- <sbr/>
-</cmdsynopsis>
-</refsynopsisdiv>
-
-
-<refsect1 id='description'><title>DESCRIPTION</title>
-<para><command>dbus-daemon</command> is the D-Bus message bus daemon. See
-<ulink url='http://www.freedesktop.org/software/dbus/'>http://www.freedesktop.org/software/dbus/</ulink> for more information about
-the big picture. D-Bus is first a library that provides one-to-one
-communication between any two applications; <command>dbus-daemon</command> 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.</para>
-
-<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
-a different configuration file.</para>
-
-<para>The --session option is equivalent to
-"--config-file=@EXPANDED_DATADIR@/dbus-1/session.conf" and the --system
-option is equivalent to
-"--config-file=@EXPANDED_DATADIR@/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 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
-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
-only take effect if you restart the daemon. Policy changes should take effect
-with SIGHUP.</para>
-
-</refsect1>
-
-<refsect1 id='options'><title>OPTIONS</title>
-<para>The following options are supported:</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><option>--config-file=FILE</option></term>
- <listitem>
-<para>Use the given configuration file.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--fork</option></term>
- <listitem>
-<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. 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
-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
-launch the message bus.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--session</option></term>
- <listitem>
-<para>Use the standard configuration file for the per-login-session message
-bus.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--system</option></term>
- <listitem>
-<para>Use the standard configuration file for the systemwide message bus.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <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>
-</variablelist>
-</refsect1>
-
-<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,
-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 "@EXPANDED_DATADIR@/dbus-1/system.conf" and
-"@EXPANDED_DATADIR@/dbus-1/session.conf". These files normally
-<include> a system-local.conf or session-local.conf in
-@EXPANDED_SYSCONFDIR@/dbus-1; you can put local
-overrides in those files to avoid modifying the primary configuration
-files.</para>
-
-
-<para>The configuration file is an XML document. It must have the following
-doctype declaration:</para>
-<literallayout remap='.nf'>
-
- <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "<ulink url='http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd'>http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd</ulink>">
-
-</literallayout> <!-- .fi -->
-
-
-<para>The following elements may be present in the configuration file.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><busconfig></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>Root element.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><type></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
-<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.</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: <type>session</type></para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><include></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>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.</para>
-
-
-<para><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.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><includedir></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>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.</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
-@EXPANDED_DATADIR@/dbus-1/system.d or
-@EXPANDED_SYSCONFDIR@/dbus-1/system.d that allowed all apps to receive
-this message and allowed the printer daemon user to send it.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><user></emphasis></para></listitem>
-
-
-</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.
-If this element is not present, the daemon will not change or care
-about its UID.</para>
-
-
-<para>The last <user> entry in the file "wins", the others are ignored.</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
-privileges for writing.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><fork></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<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>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><keep_umask></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'><syslog></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>If present, the bus daemon will log to syslog.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><pidfile></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'><allow_anonymous></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'><auth></emphasis> element, described below.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><listen></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
-a transport name plus possible parameters/options.</para>
-
-
-<para>Example: <listen>unix:path=/tmp/foo</listen></para>
-
-
-<para>Example: <listen>tcp:host=localhost,port=1234</listen></para>
-
-
-<para>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.</para>
-
-
-<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: <listen>tcp:host=localhost,port=0,family=ipv4</listen></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: <listen>tcp:host=localhost,port=0</listen></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),
-a DNS name that resolves to one of those IP addresses, '0.0.0.0'
-to listen on all IPv4 interfaces simultaneously, or '::'
-to listen on all IPv4 and IPv6 interfaces simultaneously (if supported
-by the OS). If not specified,
-the default is the same value as "host".</para>
-
-
-<para>Example: <listen>tcp:host=localhost,bind=0.0.0.0,port=0</listen></para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><auth></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
-<auth> elements, all the listed mechanisms are allowed. The order in
-which mechanisms are listed is not meaningful.</para>
-
-
-<para>Example: <auth>EXTERNAL</auth></para>
-
-
-<para>Example: <auth>DBUS_COOKIE_SHA1</auth></para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><servicedir></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>Adds a directory to scan for .service files. Directories are
-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,
-not the systemwide bus.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><standard_session_servicedirs/></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para><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.</para>
-
-
-<para>The "XDG Base Directory Specification" can be found at
-<ulink url='http://freedesktop.org/wiki/Standards/basedir-spec'>http://freedesktop.org/wiki/Standards/basedir-spec</ulink> if it hasn't moved,
-otherwise try your favorite search engine.</para>
-
-
-<para>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.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><standard_system_servicedirs/></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para><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.</para>
-
-
-<para>The <standard_system_servicedirs/> option is only relevant to the
-per-system bus daemon defined in
-@EXPANDED_DATADIR@/dbus-1/system.conf. Putting it in any other
-configuration file would probably be nonsense.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><servicehelper/></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para><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.</para>
-
-
-<para>The <servicehelper/> option is only relevant to the per-system bus daemon
-defined in @EXPANDED_DATADIR@/dbus-1/system.conf. Putting it in any other
-configuration file would probably be nonsense.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><limit></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para><limit> establishes a resource limit. For example:</para>
-<literallayout remap='.nf'>
- <limit name="max_message_size">64</limit>
- <limit name="max_completed_connections">512</limit>
-</literallayout> <!-- .fi -->
-
-
-<para>The name attribute is mandatory.
-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
- "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
- "pending_fd_timeout" : milliseconds (thousandths) a
- fd is given to be transmitted to
- dbus-daemon before disconnecting the
- connection
- "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
-</literallayout> <!-- .fi -->
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>Limits are normally only of interest on the systemwide bus, not the user session
-buses.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><policy></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>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.</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 <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.</para>
-
-
-<para>The <policy> 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>
-<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
-in the config file.</para>
-
-<variablelist remap='TP'>
- <varlistentry>
- <term><emphasis remap='I'><deny></emphasis></term>
- <listitem>
-<para><emphasis remap='I'><allow></emphasis></para>
-
- </listitem>
- </varlistentry>
-</variablelist>
-
-<para>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.</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_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"
-</literallayout> <!-- .fi -->
-
-
-<para>Examples:</para>
-<literallayout remap='.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"/>
-</literallayout> <!-- .fi -->
-
-
-<para>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).</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, 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 <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).</para>
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>user and group denials mean that the given user or group may
-not connect to the message bus.</para>
-
-
-<para>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.</para>
-
-
-<para><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).</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>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"/></para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><selinux></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>The <selinux> element contains settings related to Security Enhanced Linux.
-More details below.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><associate></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>An <associate> element appears below an <selinux> element and
-creates a mapping. Right now only one kind of association is possible:</para>
-<literallayout remap='.nf'>
- <associate own="org.freedesktop.Foobar" context="foo_t"/>
-</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
-short discussion of SELinux below.</para>
-
-
-<para>Note, the context here is the target context when requesting a name,
-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'>
- <associate own="*" context="foo_t"/>
-</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>
-
-
-<para>If two <associate> elements specify the same name, the element
-appearing later in the configuration file will be used.</para>
-
-<itemizedlist remap='TP'>
-
- <listitem><para><emphasis remap='I'><apparmor></emphasis></para></listitem>
-
-
-</itemizedlist>
-
-<para>The <apparmor> element is used to configure AppArmor mediation on
-the bus. It can contain one attribute that specifies the mediation mode:</para>
-
-<literallayout remap='.nf'>
- <apparmor mode="(enabled|disabled|required)"/>
-</literallayout> <!-- .fi -->
-
-<para>The default mode is "enabled". In "enabled" mode, AppArmor mediation
-will be performed if AppArmor support is available in the kernel. If it is not
-available, dbus-daemon will start but AppArmor mediation will not occur. In
-"disabled" mode, AppArmor mediation is disabled. In "required" mode, AppArmor
-mediation will be enabled if AppArmor support is available, otherwise
-dbus-daemon will refuse to start.</para>
-
-<para>The AppArmor mediation mode of the bus cannot be changed after the bus
-starts. Modifying the mode in the configuration file and sending a SIGHUP
-signal to the daemon has no effect on the mediation mode.</para>
-
-</refsect1>
-
-<refsect1 id='selinux'><title>SELinux</title>
-<para>See <ulink url='http://www.nsa.gov/selinux/'>http://www.nsa.gov/selinux/</ulink> for full details on SELinux. Some useful excerpts:</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>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.</para>
-
-
-<para>D-Bus performs SELinux security checks in two places.</para>
-
-
-<para>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".</para>
-
-
-<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
-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
-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".</para>
-
-
-<para>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.</para>
-
-</refsect1>
-
-<refsect1 id='apparmor'><title>AppArmor</title>
-<para>The AppArmor confinement context is stored when applications connect to
-the bus. The confinement context consists of a label and a confinement mode.
-When a security decision is required, the daemon uses the confinement context
-to query the AppArmor policy to determine if the action should be allowed or
-denied and if the action should be audited.</para>
-
-<para>The daemon performs AppArmor security checks in three places.</para>
-
-<para>First, any time a message is routed from one connection to another
-connection, the bus daemon will check permissions with the label of the first
-connection as source, label and/or connection name of the second connection as
-target, along with the bus name, the path name, the interface name, and the
-member name. Reply messages, such as method_return and error messages, are
-implicitly allowed if they are in response to a message that has already been
-allowed.</para>
-
-<para>Second, any time a connection asks to own a name, the bus daemon will
-check permissions with the label of the connection as source, the requested
-name as target, along with the bus name.</para>
-
-<para>Third, any time a connection attempts to eavesdrop, the bus daemon will
-check permissions with the label of the connection as the source, along with
-the bus name.</para>
-
-<para>AppArmor rules for bus mediation are not stored in the bus configuration
-files. They are stored in the application's AppArmor profile. Please see
-<emphasis remap='I'>apparmor.d(5)</emphasis> for more details.</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>
-
-</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-faq.xml b/doc/dbus-faq.xml
index 0d296d9..69ac3f1 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.4//EN"
-"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
[
]>
diff --git a/doc/dbus-run-session.1.xml.in b/doc/dbus-run-session.1.xml.in
deleted file mode 100644
index a7ec28a..0000000
--- a/doc/dbus-run-session.1.xml.in
+++ /dev/null
@@ -1,152 +0,0 @@
-<?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‐mode or SSH session, and have the
-<emphasis remap='B'>dbus-daemon</emphasis>
-terminate automatically on leaving the sub‐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'>
- AM_TESTS_ENVIRONMENT = export MY_DEBUG=all;
- LOG_COMPILER = dbus-run-session
- AM_LOG_FLAGS = --
-</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.xml.in b/doc/dbus-send.1.xml.in
deleted file mode 100644
index 8c1bbea..0000000
--- a/doc/dbus-send.1.xml.in
+++ /dev/null
@@ -1,171 +0,0 @@
-<?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='dbussend1'>
-
-<!-- dbus\-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>
-<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><arg choice='plain'>--address=<replaceable>ADDRESS</replaceable></arg></group>
- <arg choice='opt'>--sender=<replaceable>NAME</replaceable></arg>
- <arg choice='opt'>--dest=<replaceable>NAME</replaceable></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>OBJECT_PATH</replaceable></arg>
- <arg choice='plain'><replaceable>INTERFACE.MEMBER</replaceable></arg>
- <arg choice='opt' rep='repeat'><replaceable>CONTENTS</replaceable></arg>
- <sbr/>
-</cmdsynopsis>
-</refsynopsisdiv>
-
-
-<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
-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
-per-user-login-session message bus (started each time a user logs in).
-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 <option>--dest</option> argument
-which is the name of a connection on the bus to send the message to. If
-<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
-may include containers (arrays, dicts, and variants) as described below.</para>
-
-<literallayout remap='.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
-</literallayout> <!-- .fi -->
-
-<para>D-Bus supports more types than these, but <command>dbus-send</command> currently
-does not. Also, <command>dbus-send</command> does not permit empty containers
-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
-
-</literallayout> <!-- .fi -->
-
-<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>
-
-</refsect1>
-
-<refsect1 id='options'><title>OPTIONS</title>
-<para>The following options are supported:</para>
-<variablelist remap='TP'>
- <varlistentry>
- <term><option>--dest=</option><replaceable>NAME</replaceable></term>
- <listitem>
-<para>Specify the name of the connection to receive the message.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--print-reply</option></term>
- <listitem>
-<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‐defined, typically 25 seconds.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--system</option></term>
- <listitem>
-<para>Send to the system message bus.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--session</option></term>
- <listitem>
-<para>Send to the session message bus. (This is the default.)</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--address=</option><replaceable>ADDRESS</replaceable></term>
- <listitem>
-<para>Send to <replaceable>ADDRESS</replaceable>.</para>
- </listitem>
- </varlistentry>
- <varlistentry>
- <term><option>--sender=</option><replaceable>NAME</replaceable></term>
- <listitem>
-<para>Request ownership of name <replaceable>NAME</replaceable> before sending message.</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>
-</variablelist>
-</refsect1>
-
-<refsect1 id='author'><title>AUTHOR</title>
-<para>dbus-send was written by Philip Blundell.</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-specification.xml b/doc/dbus-specification.xml
index 1e0fe20..d806b8e 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.4//EN"
-"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
[
]>
<article id="index">
<articleinfo>
<title>D-Bus Specification</title>
- <releaseinfo>Version 0.26</releaseinfo>
- <date>2015-02-19</date>
+ <releaseinfo>Version 0.19</releaseinfo>
+ <date>2012-02-21</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>
@@ -63,71 +63,19 @@
<firstname>David</firstname>
<surname>Zeuthen</surname>
<affiliation>
+ <orgname>Red Hat, Inc.</orgname>
<address>
- <email>zeuthen@gmail.com</email>
+ <email>davidz@redhat.com</email>
</address>
</affiliation>
</author>
</authorgroup>
<revhistory>
<revision>
- <revnumber>0.26</revnumber>
- <date>2015-02-19</date>
- <authorinitials>smcv, rh</authorinitials>
- <revremark>
- GetConnectionCredentials can return LinuxSecurityLabel or
- WindowsSID; add privileged BecomeMonitor method
- </revremark>
- </revision>
- <revision>
- <revnumber>0.25</revnumber>
- <date>2014-11-10</date>
- <authorinitials>smcv, lennart</authorinitials>
- <revremark>
- ALLOW_INTERACTIVE_AUTHORIZATION flag, EmitsChangedSignal=const
- </revremark>
- </revision>
- <revision>
- <revnumber>0.24</revnumber>
- <date>2014-10-01</date>
- <authorinitials>SMcV</authorinitials>
- <revremark>
- non-method-calls never expect a reply even without NO_REPLY_EXPECTED;
- document how to quote match rules
- </revremark>
- </revision>
- <revision>
- <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>
+ <revnumber>current</revnumber>
+ <date><ulink url='http://cgit.freedesktop.org/dbus/dbus/log/doc/dbus-specification.xml'>commit log</ulink></date>
<authorinitials></authorinitials>
- <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>
+ <revremark></revremark>
</revision>
<revision>
<revnumber>0.19</revnumber>
@@ -213,18 +161,23 @@
<sect1 id="introduction">
<title>Introduction</title>
<para>
- D-Bus is a system for low-overhead, easy to use
+ D-Bus is a system for low-latency, 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. D-Bus is also designed to
- avoid round trips and allow asynchronous operation, much like
- the X protocol.
+ this is an interesting optimization.
</para>
</listitem>
<listitem>
@@ -339,68 +292,17 @@
it back from the wire format is <firstterm>unmarshaling</firstterm>.
</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 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>
+ <sect2 id="message-protocol-signatures">
+ <title>Type Signatures</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 <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.
+ 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.
</para>
<para>
@@ -417,267 +319,10 @@
</para>
<para>
- 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>
+ 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.
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>.
@@ -733,6 +378,34 @@
</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
@@ -740,14 +413,6 @@
</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
@@ -770,10 +435,6 @@
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.
@@ -781,7 +442,6 @@
<tgroup cols="3">
<thead>
<row>
- <entry>Category</entry>
<entry>Conventional Name</entry>
<entry>Code</entry>
<entry>Description</entry>
@@ -789,77 +449,62 @@
</thead>
<tbody>
<row>
- <entry>reserved</entry>
<entry><literal>INVALID</literal></entry>
<entry>0 (ASCII NUL)</entry>
<entry>Not a valid type code, used to terminate signatures</entry>
</row><row>
- <entry>fixed, basic</entry>
- <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>fixed, basic</entry>
- <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>fixed, basic</entry>
+ <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>
</row><row>
- <entry>fixed, basic</entry>
<entry><literal>UINT16</literal></entry>
<entry>113 (ASCII 'q')</entry>
<entry>16-bit unsigned integer</entry>
- </row><row>
- <entry>fixed, basic</entry>
+ </row><row>
<entry><literal>INT32</literal></entry>
<entry>105 (ASCII 'i')</entry>
<entry>32-bit signed integer</entry>
</row><row>
- <entry>fixed, basic</entry>
<entry><literal>UINT32</literal></entry>
<entry>117 (ASCII 'u')</entry>
<entry>32-bit unsigned integer</entry>
- </row><row>
- <entry>fixed, basic</entry>
+ </row><row>
<entry><literal>INT64</literal></entry>
<entry>120 (ASCII 'x')</entry>
<entry>64-bit signed integer</entry>
</row><row>
- <entry>fixed, basic</entry>
<entry><literal>UINT64</literal></entry>
<entry>116 (ASCII 't')</entry>
<entry>64-bit unsigned integer</entry>
</row><row>
- <entry>fixed, basic</entry>
<entry><literal>DOUBLE</literal></entry>
<entry>100 (ASCII 'd')</entry>
<entry>IEEE 754 double</entry>
</row><row>
- <entry>string-like, basic</entry>
<entry><literal>STRING</literal></entry>
<entry>115 (ASCII 's')</entry>
<entry>UTF-8 string (<emphasis>must</emphasis> be valid UTF-8). Must be nul terminated and contain no other nul bytes.</entry>
</row><row>
- <entry>string-like, basic</entry>
<entry><literal>OBJECT_PATH</literal></entry>
<entry>111 (ASCII 'o')</entry>
<entry>Name of an object instance</entry>
</row><row>
- <entry>string-like, basic</entry>
<entry><literal>SIGNATURE</literal></entry>
<entry>103 (ASCII 'g')</entry>
<entry>A type signature</entry>
</row><row>
- <entry>container</entry>
<entry><literal>ARRAY</literal></entry>
<entry>97 (ASCII 'a')</entry>
<entry>Array</entry>
</row><row>
- <entry>container</entry>
<entry><literal>STRUCT</literal></entry>
<entry>114 (ASCII 'r'), 40 (ASCII '('), 41 (ASCII ')')</entry>
<entry>Struct; type code 114 'r' is reserved for use in
@@ -867,12 +512,10 @@
concept of a struct, and must not appear in signatures
used on D-Bus.</entry>
</row><row>
- <entry>container</entry>
<entry><literal>VARIANT</literal></entry>
<entry>118 (ASCII 'v') </entry>
<entry>Variant type (the type of the value is part of the value itself)</entry>
</row><row>
- <entry>container</entry>
<entry><literal>DICT_ENTRY</literal></entry>
<entry>101 (ASCII 'e'), 123 (ASCII '{'), 125 (ASCII '}') </entry>
<entry>Entry in a dict or map (array of key-value pairs).
@@ -881,13 +524,11 @@
dict or dict-entry, and must not appear in signatures
used on D-Bus.</entry>
</row><row>
- <entry>fixed, basic</entry>
<entry><literal>UNIX_FD</literal></entry>
<entry>104 (ASCII 'h')</entry>
<entry>Unix file descriptor</entry>
</row>
<row>
- <entry>reserved</entry>
<entry>(reserved)</entry>
<entry>109 (ASCII 'm')</entry>
<entry>Reserved for <ulink
@@ -897,7 +538,6 @@
specified here</entry>
</row>
<row>
- <entry>reserved</entry>
<entry>(reserved)</entry>
<entry>42 (ASCII '*')</entry>
<entry>Reserved for use in bindings/implementations to
@@ -905,7 +545,6 @@
and must not appear in signatures used on D-Bus.</entry>
</row>
<row>
- <entry>reserved</entry>
<entry>(reserved)</entry>
<entry>63 (ASCII '?')</entry>
<entry>Reserved for use in bindings/implementations to
@@ -913,7 +552,6 @@
not appear in signatures used on D-Bus.</entry>
</row>
<row>
- <entry>reserved</entry>
<entry>(reserved)</entry>
<entry>64 (ASCII '@'), 38 (ASCII '&'),
94 (ASCII '^')</entry>
@@ -928,21 +566,9 @@
</para>
</sect2>
- </sect1>
- <sect1 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>
+ <sect2 id="message-protocol-marshaling">
+ <title>Marshaling (Wire Format)</title>
<para>
Given a type signature, a block of bytes can be converted into typed
@@ -951,11 +577,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>
@@ -971,95 +597,6 @@
</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 (64 MiB). 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">
@@ -1124,7 +661,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 above).
+ content must be a valid object path (see below).
</entry>
<entry>
4 (for the length)
@@ -1133,7 +670,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 above).
+ and the content must be a valid signature (see below).
</entry>
<entry>
1
@@ -1142,8 +679,14 @@
<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.
+ 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.
</entry>
<entry>
4 (for the length)
@@ -1159,17 +702,22 @@
<entry>
8
</entry>
- </row><row>
+ </row><row>
<entry><literal>VARIANT</literal></entry>
<entry>
- The marshaled <literal>SIGNATURE</literal> of a single
- complete type, followed by a marshaled value with the type
- given in the signature.
+ 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.
</entry>
<entry>
1 (alignment of the signature)
</entry>
- </row><row>
+ </row><row>
<entry><literal>DICT_ENTRY</literal></entry>
<entry>
Identical to STRUCT.
@@ -1186,12 +734,135 @@
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>
@@ -1241,8 +912,8 @@
<para>
The maximum length of a message, including header, header alignment padding,
- and body is 2 to the 27th power or 134217728 (128 MiB).
- Implementations must not send or accept messages exceeding this size.
+ and body is 2 to the 27th power or 134217728. Implementations must not
+ send or accept messages exceeding this size.
</para>
<para>
@@ -1341,8 +1012,7 @@
<row>
<entry><literal>METHOD_CALL</literal></entry>
<entry>1</entry>
- <entry>Method call. This message type may prompt a
- reply.</entry>
+ <entry>Method call.</entry>
</row>
<row>
<entry><literal>METHOD_RETURN</literal></entry>
@@ -1379,26 +1049,11 @@
<row>
<entry><literal>NO_REPLY_EXPECTED</literal></entry>
<entry>0x1</entry>
- <entry>
- <para>
- This message does not expect method return replies or
- error replies, even if it is of a type that can
- have a reply; the reply can be omitted as an
- optimization. It is compliant with this specification
- to return the reply despite this flag, although doing
- so on a bus with a non-trivial security policy
- (such as the well-known system bus) may result in
- access denial messages being logged for the reply.
- </para>
- <para>
- Note that METHOD_CALL is the only message type currently
- defined in this specification that can expect a reply,
- so the presence or absence of this flag in the other
- three message types that are currently
- documented is meaningless: replies to those message
- types should not be sent, whether this flag is present
- or not.
- </para>
+ <entry>This message does not expect method return replies or
+ error replies; the reply can be omitted as an
+ optimization. However, it is compliant with this specification
+ to return the reply despite this flag and the only harm
+ from doing so is extra network traffic.
</entry>
</row>
<row>
@@ -1408,66 +1063,6 @@
for the destination name in response to this message.
</entry>
</row>
- <row>
- <entry><literal>ALLOW_INTERACTIVE_AUTHORIZATION</literal></entry>
- <entry>0x4</entry>
- <entry>
- <para>
- This flag may be set on a method call message to
- inform the receiving side that the caller is prepared
- to wait for interactive authorization, which might
- take a considerable time to complete. For instance,
- if this flag is set, it would be appropriate to
- query the user for passwords or confirmation via
- Polkit or a similar framework.
- </para>
- <para>
- This flag is only useful when
- unprivileged code calls a more privileged method call,
- and an authorization framework is deployed that allows
- possibly interactive authorization. If no such framework
- is deployed it has no effect. This flag should not
- be set by default by client implementations. If it is
- set, the caller should also set a suitably long timeout
- on the method call to make sure the user interaction
- may complete. This flag is only valid for method call
- messages, and shall be ignored otherwise.
- </para>
- <para>
- Interaction that takes place as a part of the
- effect of the method being called is outside the scope
- of this flag, even if it could also be characterized
- as authentication or authorization. For instance, in
- a method call that directs a network management service
- to attempt to connect to a virtual private network,
- this flag should control how the network management
- service makes the decision "is this user allowed to
- change system network configuration?", but it should
- not affect how or whether the network management
- service interacts with the user to obtain the credentials
- that are required for access to the VPN.
- </para>
- <para>
- If a this flag is not set on a method call, and a
- service determines that the requested operation is
- not allowed without interactive authorization, but
- could be allowed after successful interactive
- authorization, it may return the
- <literal>org.freedesktop.DBus.Error.InteractiveAuthorizationRequired</literal>
- error.
- </para>
- <para>
- The absence of this flag does not guarantee that
- interactive authorization will not be applied, since
- existing services that pre-date this flag might
- already use interactive authorization. However,
- existing D-Bus APIs that will use interactive
- authorization should document that the call may take
- longer than usual, and new D-Bus APIs should avoid
- interactive authorization in the absence of this flag.
- </para>
- </entry>
- </row>
</tbody>
</tgroup>
</informaltable>
@@ -1654,12 +1249,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>
@@ -1718,12 +1313,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>
@@ -1761,12 +1356,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>
@@ -1814,25 +1409,12 @@
<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.
- 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.
+ <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.
</para>
<para>
Method call messages also include a <literal>PATH</literal> field
@@ -2110,23 +1692,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 <data in hex encoding></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 <data in hex encoding></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 <space-separated list of mechanism names></para></listitem>
- <listitem><para>OK <GUID in hex></para></listitem>
- <listitem><para>DATA <data in hex encoding></para></listitem>
- <listitem><para>ERROR</para></listitem>
- <listitem><para>AGREE_UNIX_FD</para></listitem>
- </itemizedlist>
+ <listitem><para>REJECTED <space-separated list of mechanism names></para></listitem>
+ <listitem><para>OK <GUID in hex></para></listitem>
+ <listitem><para>DATA <data in hex encoding></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
@@ -2356,18 +1938,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
@@ -2376,20 +1958,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
@@ -2398,10 +1980,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
@@ -2414,10 +1996,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
@@ -2430,10 +2012,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
@@ -2442,10 +2024,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
@@ -2454,7 +2036,7 @@
S: ERROR
C: BEGIN
</programlisting>
- </figure>
+ </figure>
</para>
</sect2>
<sect2 id="auth-states">
@@ -2592,7 +2174,7 @@
</listitem>
<listitem>
<para>
- Receive REJECTED [mechs] → send AUTH [next mech],
+ Receive REJECT [mechs] → send AUTH [next mech],
goto <emphasis>WaitingForData</emphasis> or
<emphasis>WaitingForOK</emphasis>
</para>
@@ -2628,7 +2210,7 @@
<itemizedlist>
<listitem>
<para>
- Receive REJECTED [mechs] → send AUTH [next mech],
+ Receive REJECT [mechs] → send AUTH [next mech],
goto <emphasis>WaitingForData</emphasis> or
<emphasis>WaitingForOK</emphasis>
</para>
@@ -2670,7 +2252,7 @@
<listitem>
<para>
- REJECTED means that the client failed to authenticate or
+ REJECT means that the client failed to authenticate or
there was an error in RESP.
</para>
</listitem>
@@ -2717,7 +2299,7 @@
</member>
<member>
- MECH(RESP) returns REJECTED → send REJECTED
+ MECH(RESP) returns REJECT → send REJECTED
[mechs], goto
<emphasis>WaitingForAuth</emphasis>
</member>
@@ -2771,7 +2353,7 @@
</member>
<member>
- MECH(RESP) returns REJECTED → send REJECTED
+ MECH(RESP) returns REJECT → send REJECTED
[mechs], goto
<emphasis>WaitingForAuth</emphasis>
</member>
@@ -3077,38 +2659,6 @@
<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>,
- listening on <literal>unix:tmpdir=/tmp</literal>
- might result in the connectable address
- <literal>unix:abstract=/tmp/dbus-U8OSdmf7</literal>, or
- listening on <literal>unix:runtime=yes</literal>
- might result in the connectable address
- <literal>unix:path=/run/user/1234/bus</literal>.
- </para>
</sect1>
<sect1 id="transports">
@@ -3126,31 +2676,21 @@
<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>.
- Similarly, Unix addresses that specify <literal>runtime</literal>
- are only listenable, and the corresponding connectable address
- will specify <literal>path</literal>.
- </para>
<sect3 id="transports-unix-domain-sockets-addresses">
<title>Server Address Format</title>
<para>
@@ -3180,21 +2720,11 @@
<row>
<entry>abstract</entry>
<entry>(string)</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>
- <row>
- <entry>runtime</entry>
- <entry><literal>yes</literal></entry>
- <entry>If given, This key can only be used in server addresses, not in client addresses. If set, its value must be <literal>yes</literal>. This is typically used in an address string like <literal>unix:runtime=yes;unix:tmpdir=/tmp</literal> so that there can be a fallback if <literal>XDG_RUNTIME_DIR</literal> is not set.</entry>
+ <entry>unique string (path) in the abstract namespace. If set, the "path" or "tempdir" key must not be set.</entry>
</row>
</tbody>
</tgroup>
</informaltable>
- <para>
- Exactly one of the keys <literal>path</literal>,
- <literal>abstract</literal>, <literal>runtime</literal> or
- <literal>tmpdir</literal> must be provided.
- </para>
</sect3>
</sect2>
<sect2 id="transports-launchd">
@@ -3218,9 +2748,6 @@
<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>
@@ -3245,9 +2772,6 @@
</tbody>
</tgroup>
</informaltable>
- <para>
- The <literal>env</literal> key is required.
- </para>
</sect3>
</sect2>
<sect2 id="transports-systemd">
@@ -3270,11 +2794,6 @@
<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>
@@ -3287,16 +2806,9 @@
over a network is unsecure.
</para>
<para>
- 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.
+ 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.
</para>
<sect3 id="transports-tcp-sockets-addresses">
<title>Server Address Format</title>
@@ -3317,18 +2829,7 @@
<row>
<entry>host</entry>
<entry>(string)</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>
+ <entry>dns name or ip address</entry>
</row>
<row>
<entry>port</entry>
@@ -3379,12 +2880,6 @@
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>
@@ -3404,13 +2899,7 @@
<row>
<entry>host</entry>
<entry>(string)</entry>
- <entry>DNS name or IP address</entry>
- </row>
- <row>
- <entry>bind</entry>
- <entry>(string)</entry>
- <entry>The same as for tcp: addresses
- </entry>
+ <entry>dns name or ip address</entry>
</row>
<row>
<entry>port</entry>
@@ -3428,10 +2917,7 @@
<row>
<entry>noncefile</entry>
<entry>(path)</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>
+ <entry>file location containing the secret</entry>
</row>
</tbody>
</tgroup>
@@ -3454,10 +2940,6 @@
<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>
@@ -3516,15 +2998,6 @@
<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>
@@ -3915,8 +3388,8 @@
<programlisting>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
- <node name="/com/example/sample_object">
- <interface name="com.example.SampleInterface">
+ <node name="/org/freedesktop/sample_object">
+ <interface name="org.freedesktop.SampleInterface">
<method name="Frobate">
<arg name="foo" type="i" direction="in"/>
<arg name="bar" type="s" direction="out"/>
@@ -4000,38 +3473,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,const,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>
@@ -4040,12 +3513,6 @@
guaranteed to be emitted if the property changes.
</para>
<para>
- If set to <literal>const</literal> the property never
- changes value during the lifetime of the object it
- belongs to, and hence the signal is never emitted for
- it.
- </para>
- <para>
If set to <literal>invalidates</literal> the signal
is emitted but the value is not included in the
signal.
@@ -4061,20 +3528,9 @@
defaults to the value specified in the enclosing
interface element.
</para>
- <para>
- This annotation is intended to be used by code
- generators to implement client-side caching of
- property values. For all properties for which the
- annotation is set to <literal>const</literal>,
- <literal>invalidates</literal> or
- <literal>true</literal> the client may
- unconditionally cache the values as the properties
- don't change or notifications are generated for them
- if they do.
- </para>
</entry>
- </row>
- </tbody>
+ </row>
+ </tbody>
</tgroup>
</informaltable>
</sect1>
@@ -4093,17 +3549,14 @@
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
- "com.example.TextEditor". When a name is bound to a connection,
+ "org.freedesktop.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>, 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.
+ 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.
</para>
<para>
Each name may have <firstterm>queued owners</firstterm>. When an
@@ -4115,7 +3568,7 @@
<para>
This feature causes the right thing to happen if you start two text
- editors for example; the first one may request "com.example.TextEditor",
+ editors for example; the first one may request "org.freedesktop.TextEditor",
and the second will be queued as a possible owner of that name. When
the first exits, the second will take over.
</para>
@@ -4187,11 +3640,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>
@@ -4302,10 +3755,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
@@ -4319,11 +3772,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
@@ -4332,11 +3785,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
@@ -4349,10 +3802,10 @@
became the name owner.
</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
The return code can be one of the following values:
@@ -4366,41 +3819,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>
@@ -4473,7 +3926,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
@@ -4481,21 +3934,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>
@@ -4576,9 +4029,7 @@
<literal>DESTINATION</literal> field is absent, it is considered to
be a <firstterm>broadcast signal</firstterm>, and is sent to all
applications with <firstterm>message matching rules</firstterm> that
- match the message. Most signal messages are broadcasts, and
- no other message types currently defined in this specification
- may be broadcast.
+ match the message. Most signal messages are broadcasts.
</para>
<para>
@@ -4618,7 +4069,7 @@
<para>
Message bus implementations may impose a security policy which
prevents certain messages from being sent or received.
- When a method call message cannot be sent or received due to a security
+ When a message cannot be sent or received due to a security
policy, the message bus should send an error reply, unless the
original message had the <literal>NO_REPLY</literal> flag.
</para>
@@ -4654,19 +4105,12 @@
adding the same rule with the <literal>eavesdrop</literal> match
omitted.
</para>
-
- <para>
- Eavesdropping interacts poorly with buses with non-trivial
- access control restrictions. The
- <xref linkend="bus-messages-become-monitor"/> method provides
- an alternative way to monitor buses.
- </para>
</sect3>
<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
@@ -4695,34 +4139,9 @@
"type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='Foo',path='/bar/foo',destination=':452345.34',arg2='bar'"
</para>
<para>
- Within single quotes (ASCII apostrophe, U+0027), a backslash
- (U+005C) represents itself, and an apostrophe ends the quoted
- section. Outside single quotes, \' (backslash, apostrophe)
- represents an apostrophe, and any backslash not followed by
- an apostrophe represents itself. For instance, the match rules
- <literal>arg0=''\''',arg1='\',arg2=',',arg3='\\'</literal> and
- <literal>arg0=\',arg1=\,arg2=',',arg3=\\</literal>
- both match messages where the arguments are a 1-character string
- containing an apostrophe, a 1-character string containing a
- backslash, a 1-character string containing a comma, and a
- 2-character string containing two backslashes<footnote>
- <para>
- This idiosyncratic quoting style is based on the rules for
- escaping items to appear inside single-quoted strings
- in POSIX <literal>/bin/sh</literal>, but please
- note that backslashes that are not inside single quotes have
- different behaviour. This syntax does not offer any way to
- represent an apostrophe inside single quotes (it is necessary
- to leave the single-quoted section, backslash-escape the
- apostrophe and re-enter single quotes), or to represent a
- comma outside single quotes (it is necessary to wrap it in
- a single-quoted section).
- </para>
- </footnote>.
- </para>
- <para>
The following table describes the keys that can be used to create
- a match rule.
+ a match rule:
+ The following table summarizes the D-Bus types.
<informaltable>
<tgroup cols="3">
<thead>
@@ -4924,9 +4343,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>com.example.TextEditor</literal>.
- This implies a contract documented along with the name
- <literal>com.example.TextEditor</literal> for which object
+ 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
the owner of that name will provide, and what interfaces those
objects will have.
</para>
@@ -4950,19 +4369,6 @@
</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. ;-)]
@@ -4973,55 +4379,23 @@
<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]
- Name=com.example.ConfigurationDatabase
- Exec=/usr/bin/sample-configd
+ Names=org.freedesktop.ConfigurationDatabase;org.gnome.GConf;
+ Exec=/usr/libexec/gconfd-2
</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.
- </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.
+ 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?]
</para>
<para>
The executable launched will have the environment variable
@@ -5568,16 +4942,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>
@@ -5677,11 +5051,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>
@@ -5719,7 +5093,7 @@
</row>
</thead>
<tbody>
- <row>
+ <row>
<entry>DBUS_START_REPLY_SUCCESS</entry>
<entry>1</entry>
<entry>The service was successfully started.</entry>
@@ -5930,284 +5304,6 @@
</para>
</sect3>
- <sect3 id="bus-messages-get-connection-credentials">
- <title><literal>org.freedesktop.DBus.GetConnectionCredentials</literal></title>
- <para>
- As a method:
- <programlisting>
- DICT<STRING,VARIANT> 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<STRING,VARIANT></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>
- <row>
- <entry>WindowsSID</entry>
- <entry>STRING</entry>
- <entry>The Windows security identifier in its string form,
- e.g. "S-1-5-21-3623811015-3361044348-30300820-1013" for
- a domain or local computer user or "S-1-5-18" for the
- LOCAL_SYSTEM user</entry>
- </row>
-
- <row>
- <entry>LinuxSecurityLabel</entry>
- <entry>ARRAY of BYTE</entry>
- <entry>
- <para>On Linux systems, the security label that would result
- from the SO_PEERSEC getsockopt call. The array contains
- the non-zero bytes of the security label in an unspecified
- ASCII-compatible encoding<footnote>
- <para>It could be ASCII or UTF-8, but could also be
- ISO Latin-1 or any other encoding.</para>
- </footnote>, followed by a single zero byte.</para>
- <para>
- For example, the SELinux context
- <literal>system_u:system_r:init_t:s0</literal>
- (a string of length 27) would be encoded as 28 bytes
- ending with ':', 's', '0', '\x00'.<footnote>
- <para>Note that this is not the same as the older
- GetConnectionSELinuxContext method, which does
- not append the zero byte. Always appending the
- zero byte allows callers to read the string
- from the message payload without copying.</para>
- </footnote>
- </para>
- <para>
- On SELinux systems this is the SELinux context, as output
- by <literal>ps -Z</literal> or <literal>ls -Z</literal>.
- Typical values might include
- <literal>system_u:system_r:init_t:s0</literal>,
- <literal>unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023</literal>,
- or
- <literal>unconfined_u:unconfined_r:chrome_sandbox_t:s0-s0:c0.c1023</literal>.
- </para>
- <para>
- On Smack systems, this is the Smack label.
- Typical values might include
- <literal>_</literal>, <literal>*</literal>,
- <literal>User</literal>, <literal>System</literal>
- or <literal>System::Shared</literal>.
- </para>
- <para>
- On AppArmor systems, this is the AppArmor context,
- a composite string encoding the AppArmor label (one or more
- profiles) and the enforcement mode.
- Typical values might include <literal>unconfined</literal>,
- <literal>/usr/bin/firefox (enforce)</literal> or
- <literal>user1 (complain)</literal>.
- </para>
- </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>
@@ -6235,8 +5331,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">
@@ -6266,8 +5362,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>
@@ -6307,96 +5403,6 @@
</para>
</sect3>
- <sect3 id="bus-messages-become-monitor">
- <title><literal>org.freedesktop.DBus.Monitoring.BecomeMonitor</literal></title>
- <para>
- As a method:
- <programlisting>
- BecomeMonitor (in ARRAY of STRING rule, in UINT32 flags)
- </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>ARRAY of STRING</entry>
- <entry>Match rules to add to the connection</entry>
- </row>
- <row>
- <entry>1</entry>
- <entry>UINT32</entry>
- <entry>Not used, must be 0</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </para>
-
- <para>
- Converts the connection into a <emphasis>monitor
- connection</emphasis> which can be used as a debugging/monitoring
- tool. Only a user who is privileged on this
- bus (by some implementation-specific definition) may create
- monitor connections<footnote>
- <para>
- In the reference implementation,
- the default configuration is that each user (identified by
- numeric user ID) may monitor their own session bus,
- and the root user (user ID zero) may monitor the
- system bus.
- </para>
- </footnote>.
- </para>
-
- <para>
- Monitor connections lose all their bus names, including the unique
- connection name, and all their match rules. Sending messages on a
- monitor connection is not allowed: applications should use a private
- connection for monitoring.
- </para>
-
- <para>
- Monitor connections may receive all messages, even messages that
- should only have gone to some other connection ("eavesdropping").
- The first argument is a list of match rules, which replace any
- match rules that were previously active for this connection.
- These match rules are always treated as if they contained the
- special <literal>eavesdrop='true'</literal> member.
- </para>
-
- <para>
- As a special case, an empty list of match rules (which would
- otherwise match nothing, making the monitor useless) is treated
- as a shorthand for matching all messages.
- </para>
-
- <para>
- The second argument might be used for flags to influence the
- behaviour of the monitor connection in future D-Bus versions.
- </para>
-
- <para>
- Message bus implementations should attempt to minimize the
- side-effects of monitoring — in particular, unlike ordinary
- eavesdropping, monitoring the system bus does not require the
- access control rules to be relaxed, which would change the set
- of messages that can be delivered to their (non-monitor)
- destinations. However, it is unavoidable that monitoring
- will increase the message bus's resource consumption. In
- edge cases where there was barely enough time or memory without
- monitoring, this might result in message deliveries failing
- when they would otherwise have succeeded.
- </para>
- </sect3>
-
</sect2>
</sect1>
@@ -6501,7 +5507,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
@@ -6540,9 +5546,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
- "com.example.Screensaver", have a singleton object
- "/com/example/Application", and that object will implement the
- interface "com.example.Screensaver.Control".
+ "org.freedesktop.Screensaver", have a singleton object
+ "/org/freedesktop/Application", and that object will implement the
+ interface "org.freedesktop.ScreensaverControl".
</para>
</glossdef>
</glossentry>
diff --git a/doc/dbus-test-plan.xml b/doc/dbus-test-plan.xml
index e3efd2c..e6aafb9 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.4//EN"
-"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.1.2/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 test-dbus
+ The tests for the client library consist of the dbus-test
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 test-dbus.
+ a string class. All aspects of those are tested by dbus-test.
</para>
</sect2>
<sect2 id="message-loader">
@@ -104,7 +104,7 @@
the D-Bus Reference Manual.
</para>
<para>
- The message test part of test-dbus is using the message
+ The message test part of dbus-test 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="test-bus">
- <title>The test-bus program</title>
+ <sect2 id="bus-test">
+ <title>The bus-test program</title>
<para>
- The test-bus program is a program that is used to test various
+ The bus-test 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 test-bus program should test all major features of the
+ The bus-test 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-test-tool.1.xml.in b/doc/dbus-test-tool.1.xml.in
deleted file mode 100644
index 5b7c43e..0000000
--- a/doc/dbus-test-tool.1.xml.in
+++ /dev/null
@@ -1,325 +0,0 @@
-<?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="dbus-test-tool.1">
- <refentryinfo>
- <copyright>
- <year>2015</year>
- <holder>Collabora Ltd.</holder>
- </copyright>
- <legalnotice>
- <para>This man page is distributed under the same terms as
- dbus-test-tool (GPL-2+). There is NO WARRANTY, to the extent
- permitted by law.</para>
- </legalnotice>
- </refentryinfo>
-
- <refmeta>
- <refentrytitle>dbus-test-tool</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-test-tool</refname>
- <refpurpose>D-Bus traffic generator and test tool</refpurpose>
- </refnamediv>
-
- <refsynopsisdiv id="synopsis">
- <cmdsynopsis>
- <command>dbus-test-tool</command>
- <arg choice="plain">black-hole</arg>
- <group choice="opt">
- <arg choice="plain">--session</arg>
- <arg choice="plain">--system</arg>
- </group>
- <arg choice="opt">--name=<replaceable>NAME</replaceable></arg>
- <arg choice="opt">--no-read</arg>
- </cmdsynopsis>
-
- <cmdsynopsis>
- <command>dbus-test-tool</command>
- <arg choice="plain">echo</arg>
- <group choice="opt">
- <arg choice="plain">--session</arg>
- <arg choice="plain">--system</arg>
- </group>
- <arg choice="opt">--name=<replaceable>NAME</replaceable></arg>
- <arg choice="opt">--sleep-ms=<replaceable>MS</replaceable></arg>
- </cmdsynopsis>
-
- <cmdsynopsis>
- <command>dbus-test-tool</command>
- <arg choice="plain">spam</arg>
- <group choice="opt">
- <arg choice="plain">--session</arg>
- <arg choice="plain">--system</arg>
- </group>
- <arg choice="opt">--dest=<replaceable>NAME</replaceable></arg>
- <arg choice="opt">--count=<replaceable>N</replaceable></arg>
- <arg choice="opt">--flood</arg>
- <arg choice="opt">--ignore-errors</arg>
- <arg choice="opt">--messages-per-conn=<replaceable>N</replaceable></arg>
- <arg choice="opt">--no-reply</arg>
- <arg choice="opt">--queue=<replaceable>N</replaceable></arg>
- <arg choice="opt">--seed=<replaceable>SEED</replaceable></arg>
- <group choice="opt">
- <arg choice="plain">--string</arg>
- <arg choice="plain">--bytes</arg>
- <arg choice="plain">--empty</arg>
- </group>
- <group choice="opt">
- <arg choice="plain">--payload=<replaceable>S</replaceable></arg>
- <arg choice="plain">--stdin</arg>
- <arg choice="plain">--message-stdin</arg>
- <arg choice="plain">--random-size</arg>
- </group>
- </cmdsynopsis>
- </refsynopsisdiv>
-
- <refsect1 id="description">
- <title>DESCRIPTION</title>
- <para><command>dbus-test-tool</command> is a multi-purpose tool
- for debugging and profiling D-Bus.</para>
-
- <para><command>dbus-test-tool black-hole</command>
- connects to D-Bus, optionally requests a name, then does not
- reply to messages. It normally reads and discards messages from
- its D-Bus socket, but can be configured to sleep forever without
- reading.</para>
-
- <para><command>dbus-test-tool echo</command>
- connects to D-Bus, optionally requests a name, then sends back an
- empty reply to every method call, after an optional delay.</para>
-
- <para><command>dbus-test-tool spam</command>
- connects to D-Bus and makes repeated method calls,
- normally named <literal>com.example.Spam</literal>.</para>
- </refsect1>
-
- <refsect1 id="options">
- <title>OPTIONS</title>
- <refsect2>
- <title>Common options</title>
- <variablelist remap="TP">
-
- <varlistentry>
- <term><option>--session</option></term>
- <listitem>
- <para>Connect to the session bus. This is the default.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--system</option></term>
- <listitem>
- <para>Connect to the system bus.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
- </refsect2>
-
- <refsect2>
- <title>black-hole mode</title>
- <variablelist remap="TP">
-
- <varlistentry>
- <term><option>--name=</option><replaceable>NAME</replaceable></term>
- <listitem>
- <para>Before proceeding, request ownership of the well-known
- bus name <replaceable>NAME</replaceable>, for example
- <literal>com.example.NoReply</literal>. By default,
- no name is requested, and the tool can only be addressed by
- a unique bus name such as <literal>:1.23</literal>.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--no-read</option></term>
- <listitem>
- <para>Do not read from the D-Bus socket.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
- </refsect2>
-
- <refsect2>
- <title>echo mode</title>
- <variablelist remap="TP">
-
- <varlistentry>
- <term><option>--name=</option><replaceable>NAME</replaceable></term>
- <listitem>
- <para>Before proceeding, request ownership of the well-known
- bus name <replaceable>NAME</replaceable>, for example
- <literal>com.example.Echo</literal>. By default,
- no name is requested, and the tool can only be addressed by
- a unique bus name such as <literal>:1.23</literal>.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--sleep-ms=</option><replaceable>MS</replaceable></term>
- <listitem>
- <para>Block for <replaceable>MS</replaceable> milliseconds
- before replying to a method call.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
- </refsect2>
-
- <refsect2>
- <title>spam mode</title>
- <variablelist remap="TP">
-
- <varlistentry>
- <term><option>--dest=</option><replaceable>NAME</replaceable></term>
- <listitem>
- <para>Send method calls to the well-known or unique
- bus name <replaceable>NAME</replaceable>.
- The default is the dbus-daemon,
- <literal>org.freedesktop.DBus</literal>.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--count=</option><replaceable>N</replaceable></term>
- <listitem>
- <para>Send <replaceable>N</replaceable> method calls in total.
- The default is 1.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--queue=</option><replaceable>N</replaceable></term>
- <listitem>
- <para>Send <replaceable>N</replaceable> method calls before
- waiting for any replies, then send one new call per reply
- received, keeping <replaceable>N</replaceable> method calls
- "in flight" at all times until the number of messages specified
- with the <option>--count</option> option have been sent.
- The default is 1, unless <option>--flood</option>
- is used.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--flood</option></term>
- <listitem>
- <para>Send all messages without waiting for a reply,
- equivalent to <option>--queue</option> with an arbitrarily
- large <replaceable>N</replaceable>.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--no-reply</option></term>
- <listitem>
- <para>Set the "no reply desired" flag on the messages.
- This implies <option>--flood</option>, since it disables
- the replies that would be used for a finite
- <option>--queue</option> length.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--messages-per-conn=</option><replaceable>N</replaceable></term>
- <listitem>
- <para>If given, send <replaceable>N</replaceable> method calls
- on the same connection, then disconnect and reconnect.
- The default is to use the same connection for all method
- calls.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--string</option></term>
- <listitem>
- <para>The payload of each message is a UTF-8 string. This is the
- default. The actual string used is given by the
- <option>--payload</option> or <option>--stdin</option>
- option, defaulting to "hello, world!".</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--bytes</option></term>
- <listitem>
- <para>The payload of each message is a byte-array.
- The actual bytes used are given by the
- <option>--payload</option> or <option>--stdin</option>
- option, defaulting to the ASCII encoding of
- "hello, world!".</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--empty</option></term>
- <listitem>
- <para>The messages have no payload.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--payload=</option><replaceable>S</replaceable></term>
- <listitem>
- <para>Use <replaceable>S</replaceable> as the
- <option>--string</option> or <option>--bytes</option>
- in the messages. The default is "hello, world!".</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--stdin</option></term>
- <listitem>
- <para>Read from standard input until end-of-file is reached,
- and use that as the <option>--string</option> or
- <option>--bytes</option> in the messages.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--message-stdin</option></term>
- <listitem>
- <para>Read a complete binary D-Bus method call message from
- standard input, and use that for each method call.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--random-size</option></term>
- <listitem>
- <para>Read whitespace-separated ASCII decimal numbers from
- standard input, choose one at random for each message,
- and send a message whose payload is a string of that
- length.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--seed=</option><replaceable>SEED</replaceable></term>
- <listitem>
- <para>Use <replaceable>SEED</replaceable> as the seed
- for the pseudorandom number generator, to have somewhat
- repeatable sequences of random messages.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
- </refsect2>
- </refsect1>
-
- <refsect1 id="bugs">
- <title>BUGS</title>
- <para>Please send bug reports to the D-Bus bug tracker or mailing list.
- 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-send</refentrytitle><manvolnum>1</manvolnum></citerefentry></para>
- </refsect1>
-</refentry>
diff --git a/doc/dbus-tutorial.xml b/doc/dbus-tutorial.xml
index c4d9504..5c385f0 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.4//EN"
-"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
[
]>
@@ -704,19 +704,939 @@
</sect1>
<sect1 id="glib-client">
- <title>GLib APIs</title>
- <para>
- The recommended GLib API for D-Bus is GDBus, which has been
- distributed with GLib since version 2.26. It is not documented here.
- See <ulink url="https://developer.gnome.org/gio/stable/gdbus-convenience.html">the
- GLib documentation</ulink> for details of how to use GDBus.
- </para>
+ <title>GLib API: Using Remote Objects</title>
<para>
- An older API, dbus-glib, also exists. It is deprecated and should
- not be used in new code. Whenever possible, porting existing code
- from dbus-glib to GDBus is also recommended.
+ The GLib binding is defined in the header file
+ <literal><dbus/dbus-glib.h></literal>.
</para>
+
+ <sect2 id="glib-typemappings">
+ <title>D-Bus - GLib type mappings</title>
+ <para>
+ The heart of the GLib bindings for D-Bus is the mapping it
+ provides between D-Bus "type signatures" and GLib types
+ (<literal>GType</literal>). The D-Bus type system is composed of
+ a number of "basic" types, along with several "container" types.
+ </para>
+ <sect3 id="glib-basic-typemappings">
+ <title>Basic type mappings</title>
+ <para>
+ Below is a list of the basic types, along with their associated
+ mapping to a <literal>GType</literal>.
+ <informaltable>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>D-Bus basic type</entry>
+ <entry>GType</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>BYTE</literal></entry>
+ <entry><literal>G_TYPE_UCHAR</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>BOOLEAN</literal></entry>
+ <entry><literal>G_TYPE_BOOLEAN</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>INT16</literal></entry>
+ <entry><literal>G_TYPE_INT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_INT16</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>UINT16</literal></entry>
+ <entry><literal>G_TYPE_UINT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_UINT16</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>INT32</literal></entry>
+ <entry><literal>G_TYPE_INT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_INT32</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>UINT32</literal></entry>
+ <entry><literal>G_TYPE_UINT</literal></entry>
+ <entry></entry>
+ <entry>Will be changed to a <literal>G_TYPE_UINT32</literal> once GLib has it</entry>
+ </row><row>
+ <entry><literal>INT64</literal></entry>
+ <entry><literal>G_TYPE_GINT64</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>UINT64</literal></entry>
+ <entry><literal>G_TYPE_GUINT64</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>DOUBLE</literal></entry>
+ <entry><literal>G_TYPE_DOUBLE</literal></entry>
+ <entry></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>STRING</literal></entry>
+ <entry><literal>G_TYPE_STRING</literal></entry>
+ <entry><literal>g_free</literal></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>OBJECT_PATH</literal></entry>
+ <entry><literal>DBUS_TYPE_G_PROXY</literal></entry>
+ <entry><literal>g_object_unref</literal></entry>
+ <entry>The returned proxy does not have an interface set; use <literal>dbus_g_proxy_set_interface</literal> to invoke methods</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ As you can see, the basic mapping is fairly straightforward.
+ </para>
+ </sect3>
+ <sect3 id="glib-container-typemappings">
+ <title>Container type mappings</title>
+ <para>
+ The D-Bus type system also has a number of "container"
+ types, such as <literal>DBUS_TYPE_ARRAY</literal> and
+ <literal>DBUS_TYPE_STRUCT</literal>. The D-Bus type system
+ is fully recursive, so one can for example have an array of
+ array of strings (i.e. type signature
+ <literal>aas</literal>).
+ </para>
+ <para>
+ However, not all of these types are in common use; for
+ example, at the time of this writing the author knows of no
+ one using <literal>DBUS_TYPE_STRUCT</literal>, or a
+ <literal>DBUS_TYPE_ARRAY</literal> containing any non-basic
+ type. The approach the GLib bindings take is pragmatic; try
+ to map the most common types in the most obvious way, and
+ let using less common and more complex types be less
+ "natural".
+ </para>
+ <para>
+ First, D-Bus type signatures which have an "obvious"
+ corresponding built-in GLib type are mapped using that type:
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>as</literal></entry>
+ <entry>Array of strings</entry>
+ <entry><literal>G_TYPE_STRV</literal></entry>
+ <entry><literal>char **</literal></entry>
+ <entry><literal>g_strfreev</literal></entry>
+ <entry></entry>
+ </row><row>
+ <entry><literal>v</literal></entry>
+ <entry>Generic value container</entry>
+ <entry><literal>G_TYPE_VALUE</literal></entry>
+ <entry><literal>GValue *</literal></entry>
+ <entry><literal>g_value_unset</literal></entry>
+ <entry>The calling conventions for values expect that method callers have allocated return values; see below.</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ <para>
+ The next most common recursive type signatures are arrays of
+ basic values. The most obvious mapping for arrays of basic
+ types is a <literal>GArray</literal>. Now, GLib does not
+ provide a builtin <literal>GType</literal> for
+ <literal>GArray</literal>. However, we actually need more than
+ that - we need a "parameterized" type which includes the
+ contained type. Why we need this we will see below.
+ </para>
+ <para>
+ The approach taken is to create these types in the D-Bus GLib
+ bindings; however, there is nothing D-Bus specific about them.
+ In the future, we hope to include such "fundamental" types in GLib
+ itself.
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>ay</literal></entry>
+ <entry>Array of bytes</entry>
+ <entry><literal>DBUS_TYPE_G_BYTE_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>au</literal></entry>
+ <entry>Array of uint</entry>
+ <entry><literal>DBUS_TYPE_G_UINT_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ai</literal></entry>
+ <entry>Array of int</entry>
+ <entry><literal>DBUS_TYPE_G_INT_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ax</literal></entry>
+ <entry>Array of int64</entry>
+ <entry><literal>DBUS_TYPE_G_INT64_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>at</literal></entry>
+ <entry>Array of uint64</entry>
+ <entry><literal>DBUS_TYPE_G_UINT64_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ad</literal></entry>
+ <entry>Array of double</entry>
+ <entry><literal>DBUS_TYPE_G_DOUBLE_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><literal>ab</literal></entry>
+ <entry>Array of boolean</entry>
+ <entry><literal>DBUS_TYPE_G_BOOLEAN_ARRAY</literal></entry>
+ <entry><literal>GArray *</literal></entry>
+ <entry>g_array_free</entry>
+ <entry></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ <para>
+ D-Bus also includes a special type DBUS_TYPE_DICT_ENTRY which
+ is only valid in arrays. It's intended to be mapped to a "dictionary"
+ type by bindings. The obvious GLib mapping here is GHashTable. Again,
+ however, there is no builtin <literal>GType</literal> for a GHashTable.
+ Moreover, just like for arrays, we need a parameterized type so that
+ the bindings can communiate which types are contained in the hash table.
+ </para>
+ <para>
+ At present, only strings are supported. Work is in progress to
+ include more types.
+ <informaltable>
+ <tgroup cols="6">
+ <thead>
+ <row>
+ <entry>D-Bus type signature</entry>
+ <entry>Description</entry>
+ <entry>GType</entry>
+ <entry>C typedef</entry>
+ <entry>Free function</entry>
+ <entry>Notes</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry><literal>a{ss}</literal></entry>
+ <entry>Dictionary mapping strings to strings</entry>
+ <entry><literal>DBUS_TYPE_G_STRING_STRING_HASHTABLE</literal></entry>
+ <entry><literal>GHashTable *</literal></entry>
+ <entry>g_hash_table_destroy</entry>
+ <entry></entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </sect3>
+ <sect3 id="glib-generic-typemappings">
+ <title>Arbitrarily recursive type mappings</title>
+ <para>
+ Finally, it is possible users will want to write or invoke D-Bus
+ methods which have arbitrarily complex type signatures not
+ directly supported by these bindings. For this case, we have a
+ <literal>DBusGValue</literal> which acts as a kind of special
+ variant value which may be iterated over manually. The
+ <literal>GType</literal> associated is
+ <literal>DBUS_TYPE_G_VALUE</literal>.
+ </para>
+ <para>
+ TODO insert usage of <literal>DBUS_TYPE_G_VALUE</literal> here.
+ </para>
+ </sect3>
+ </sect2>
+ <sect2 id="sample-program-1">
+ <title>A sample program</title>
+ <para>Here is a D-Bus program using the GLib bindings.
+<programlisting>
+int
+main (int argc, char **argv)
+{
+ DBusGConnection *connection;
+ GError *error;
+ DBusGProxy *proxy;
+ char **name_list;
+ char **name_list_ptr;
+
+ g_type_init ();
+
+ error = NULL;
+ connection = dbus_g_bus_get (DBUS_BUS_SESSION,
+ &error);
+ if (connection == NULL)
+ {
+ g_printerr ("Failed to open connection to bus: %s\n",
+ error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ /* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
+
+ proxy = dbus_g_proxy_new_for_name (connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ /* Call ListNames method, wait for reply */
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID,
+ G_TYPE_STRV, &name_list, G_TYPE_INVALID))
+ {
+ /* Just do demonstrate remote exceptions versus regular GError */
+ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
+ g_printerr ("Caught remote method exception %s: %s",
+ dbus_g_error_get_name (error),
+ error->message);
+ else
+ g_printerr ("Error: %s\n", error->message);
+ g_error_free (error);
+ exit (1);
+ }
+
+ /* Print the results */
+
+ g_print ("Names on the message bus:\n");
+
+ for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++)
+ {
+ g_print (" %s\n", *name_list_ptr);
+ }
+ g_strfreev (name_list);
+
+ g_object_unref (proxy);
+
+ return 0;
+}
+</programlisting>
+ </para>
+ </sect2>
+ <sect2 id="glib-program-setup">
+ <title>Program initalization</title>
+ <para>
+ A connection to the bus is acquired using
+ <literal>dbus_g_bus_get</literal>. Next, a proxy
+ is created for the object "/org/freedesktop/DBus" with
+ interface <literal>org.freedesktop.DBus</literal>
+ on the service <literal>org.freedesktop.DBus</literal>.
+ This is a proxy for the message bus itself.
+ </para>
+ </sect2>
+ <sect2 id="glib-method-invocation">
+ <title>Understanding method invocation</title>
+ <para>
+ You have a number of choices for method invocation. First, as
+ used above, <literal>dbus_g_proxy_call</literal> sends a
+ method call to the remote object, and blocks until a reply is
+ recieved. The outgoing arguments are specified in the varargs
+ array, terminated with <literal>G_TYPE_INVALID</literal>.
+ Next, pointers to return values are specified, followed again
+ by <literal>G_TYPE_INVALID</literal>.
+ </para>
+ <para>
+ To invoke a method asynchronously, use
+ <literal>dbus_g_proxy_begin_call</literal>. This returns a
+ <literal>DBusGPendingCall</literal> object; you may then set a
+ notification function using
+ <literal>dbus_g_pending_call_set_notify</literal>.
+ </para>
+ </sect2>
+ <sect2 id="glib-signal-connection">
+ <title>Connecting to object signals</title>
+ <para>
+ You may connect to signals using
+ <literal>dbus_g_proxy_add_signal</literal> and
+ <literal>dbus_g_proxy_connect_signal</literal>. You must
+ invoke <literal>dbus_g_proxy_add_signal</literal> to specify
+ the signature of your signal handlers; you may then invoke
+ <literal>dbus_g_proxy_connect_signal</literal> multiple times.
+ </para>
+ <para>
+ Note that it will often be the case that there is no builtin
+ marshaller for the type signature of a remote signal. In that
+ case, you must generate a marshaller yourself by using
+ <application>glib-genmarshal</application>, and then register
+ it using <literal>dbus_g_object_register_marshaller</literal>.
+ </para>
+ </sect2>
+ <sect2 id="glib-error-handling">
+ <title>Error handling and remote exceptions</title>
+ <para>
+ All of the GLib binding methods such as
+ <literal>dbus_g_proxy_end_call</literal> return a
+ <literal>GError</literal>. This <literal>GError</literal> can
+ represent two different things:
+ <itemizedlist>
+ <listitem>
+ <para>
+ An internal D-Bus error, such as an out-of-memory
+ condition, an I/O error, or a network timeout. Errors
+ generated by the D-Bus library itself have the domain
+ <literal>DBUS_GERROR</literal>, and a corresponding code
+ such as <literal>DBUS_GERROR_NO_MEMORY</literal>. It will
+ not be typical for applications to handle these errors
+ specifically.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ A remote D-Bus exception, thrown by the peer, bus, or
+ service. D-Bus remote exceptions have both a textual
+ "name" and a "message". The GLib bindings store this
+ information in the <literal>GError</literal>, but some
+ special rules apply.
+ </para>
+ <para>
+ The set error will have the domain
+ <literal>DBUS_GERROR</literal> as above, and will also
+ have the code
+ <literal>DBUS_GERROR_REMOTE_EXCEPTION</literal>. In order
+ to access the remote exception name, you must use a
+ special accessor, such as
+ <literal>dbus_g_error_has_name</literal> or
+ <literal>dbus_g_error_get_name</literal>. The remote
+ exception detailed message is accessible via the regular
+ GError <literal>message</literal> member.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </sect2>
+ <sect2 id="glib-more-examples">
+ <title>More examples of method invocation</title>
+ <sect3 id="glib-sending-stuff">
+ <title>Sending an integer and string, receiving an array of bytes</title>
+ <para>
+<programlisting>
+ GArray *arr;
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "Foobar", &error,
+ G_TYPE_INT, 42, G_TYPE_STRING, "hello",
+ G_TYPE_INVALID,
+ DBUS_TYPE_G_UCHAR_ARRAY, &arr, G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ g_assert (arr != NULL);
+ printf ("got back %u values", arr->len);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-sending-hash">
+ <title>Sending a GHashTable</title>
+ <para>
+<programlisting>
+ GHashTable *hash = g_hash_table_new (g_str_hash, g_str_equal);
+ guint32 ret;
+
+ g_hash_table_insert (hash, "foo", "bar");
+ g_hash_table_insert (hash, "baz", "whee");
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "HashSize", &error,
+ DBUS_TYPE_G_STRING_STRING_HASH, hash, G_TYPE_INVALID,
+ G_TYPE_UINT, &ret, G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ g_assert (ret == 2);
+ g_hash_table_destroy (hash);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-receiving-bool-int">
+ <title>Receiving a boolean and a string</title>
+ <para>
+<programlisting>
+ gboolean boolret;
+ char *strret;
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "GetStuff", &error,
+ G_TYPE_INVALID,
+ G_TYPE_BOOLEAN, &boolret,
+ G_TYPE_STRING, &strret,
+ G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ printf ("%s %s", boolret ? "TRUE" : "FALSE", strret);
+ g_free (strret);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-sending-str-arrays">
+ <title>Sending two arrays of strings</title>
+ <para>
+<programlisting>
+ /* NULL terminate */
+ char *strs_static[] = {"foo", "bar", "baz", NULL};
+ /* Take pointer to array; cannot pass array directly */
+ char **strs_static_p = strs_static;
+ char **strs_dynamic;
+
+ strs_dynamic = g_new (char *, 4);
+ strs_dynamic[0] = g_strdup ("hello");
+ strs_dynamic[1] = g_strdup ("world");
+ strs_dynamic[2] = g_strdup ("!");
+ /* NULL terminate */
+ strs_dynamic[3] = NULL;
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "TwoStrArrays", &error,
+ G_TYPE_STRV, strs_static_p,
+ G_TYPE_STRV, strs_dynamic,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ g_strfreev (strs_dynamic);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-getting-str-array">
+ <title>Sending a boolean, receiving an array of strings</title>
+ <para>
+<programlisting>
+ char **strs;
+ char **strs_p;
+ gboolean blah;
+
+ error = NULL;
+ blah = TRUE;
+ if (!dbus_g_proxy_call (proxy, "GetStrs", &error,
+ G_TYPE_BOOLEAN, blah,
+ G_TYPE_INVALID,
+ G_TYPE_STRV, &strs,
+ G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ for (strs_p = strs; *strs_p; strs_p++)
+ printf ("got string: \"%s\"", *strs_p);
+ g_strfreev (strs);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-sending-variant">
+ <title>Sending a variant</title>
+ <para>
+<programlisting>
+ GValue val = {0, };
+
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, "hello world");
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "SendVariant", &error,
+ G_TYPE_VALUE, &val, G_TYPE_INVALID,
+ G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ g_assert (ret == 2);
+ g_value_unset (&val);
+</programlisting>
+ </para>
+ </sect3>
+ <sect3 id="glib-receiving-variant">
+ <title>Receiving a variant</title>
+ <para>
+<programlisting>
+ GValue val = {0, };
+
+ error = NULL;
+ if (!dbus_g_proxy_call (proxy, "GetVariant", &error, G_TYPE_INVALID,
+ G_TYPE_VALUE, &val, G_TYPE_INVALID))
+ {
+ /* Handle error */
+ }
+ if (G_VALUE_TYPE (&val) == G_TYPE_STRING)
+ printf ("%s\n", g_value_get_string (&val));
+ else if (G_VALUE_TYPE (&val) == G_TYPE_INT)
+ printf ("%d\n", g_value_get_int (&val));
+ else
+ ...
+ g_value_unset (&val);
+</programlisting>
+ </para>
+ </sect3>
+ </sect2>
+
+ <sect2 id="glib-generated-bindings">
+ <title>Generated Bindings</title>
+ <para>
+ By using the Introspection XML files, convenient client-side bindings
+ can be automatically created to ease the use of a remote DBus object.
+ </para>
+ <para>
+ Here is a sample XML file which describes an object that exposes
+ one method, named <literal>ManyArgs</literal>.
+ <programlisting>
+<?xml version="1.0" encoding="UTF-8" ?>
+<node name="/com/example/MyObject">
+ <interface name="com.example.MyObject">
+ <method name="ManyArgs">
+ <arg type="u" name="x" direction="in" />
+ <arg type="s" name="str" direction="in" />
+ <arg type="d" name="trouble" direction="in" />
+ <arg type="d" name="d_ret" direction="out" />
+ <arg type="s" name="str_ret" direction="out" />
+ </method>
+ </interface>
+</node>
+</programlisting>
+ </para>
+ <para>
+ Run <literal>dbus-binding-tool --mode=glib-client
+ <replaceable>FILENAME</replaceable> >
+ <replaceable>HEADER_NAME</replaceable></literal> to generate the header
+ file. For example: <command>dbus-binding-tool --mode=glib-client
+ my-object.xml > my-object-bindings.h</command>. This will generate
+ inline functions with the following prototypes:
+ <programlisting>
+/* This is a blocking call */
+gboolean
+com_example_MyObject_many_args (DBusGProxy *proxy, const guint IN_x,
+ const char * IN_str, const gdouble IN_trouble,
+ gdouble* OUT_d_ret, char ** OUT_str_ret,
+ GError **error);
+
+/* This is a non-blocking call */
+DBusGProxyCall*
+com_example_MyObject_many_args_async (DBusGProxy *proxy, const guint IN_x,
+ const char * IN_str, const gdouble IN_trouble,
+ com_example_MyObject_many_args_reply callback,
+ gpointer userdata);
+
+/* This is the typedef for the non-blocking callback */
+typedef void
+(*com_example_MyObject_many_args_reply)
+(DBusGProxy *proxy, gdouble OUT_d_ret, char * OUT_str_ret,
+ GError *error, gpointer userdata);
+</programlisting>
+ The first argument in all functions is a <literal>DBusGProxy
+ *</literal>, which you should create with the usual
+ <literal>dbus_g_proxy_new_*</literal> functions. Following that are the
+ "in" arguments, and then either the "out" arguments and a
+ <literal>GError *</literal> for the synchronous (blocking) function, or
+ callback and user data arguments for the asynchronous (non-blocking)
+ function. The callback in the asynchronous function passes the
+ <literal>DBusGProxy *</literal>, the returned "out" arguments, an
+ <literal>GError *</literal> which is set if there was an error otherwise
+ <literal>NULL</literal>, and the user data.
+ </para>
+ <para>
+ As with the server-side bindings support (see <xref
+ linkend="glib-server"/>), the exact behaviour of the client-side
+ bindings can be manipulated using "annotations". Currently the only
+ annotation used by the client bindings is
+ <literal>org.freedesktop.DBus.GLib.NoReply</literal>, which sets the
+ flag indicating that the client isn't expecting a reply to the method
+ call, so a reply shouldn't be sent. This is often used to speed up
+ rapid method calls where there are no "out" arguments, and not knowing
+ if the method succeeded is an acceptable compromise to half the traffic
+ on the bus.
+ </para>
+ </sect2>
+ </sect1>
+
+ <sect1 id="glib-server">
+ <title>GLib API: Implementing Objects</title>
+ <para>
+ At the moment, to expose a GObject via D-Bus, you must
+ write XML by hand which describes the methods exported
+ by the object. In the future, this manual step will
+ be obviated by the upcoming GLib introspection support.
+ </para>
+ <para>
+ Here is a sample XML file which describes an object that exposes
+ one method, named <literal>ManyArgs</literal>.
+<programlisting>
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/com/example/MyObject">
+
+ <interface name="com.example.MyObject">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_object"/>
+ <method name="ManyArgs">
+ <!-- This is optional, and in this case is redunundant -->
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="my_object_many_args"/>
+ <arg type="u" name="x" direction="in" />
+ <arg type="s" name="str" direction="in" />
+ <arg type="d" name="trouble" direction="in" />
+ <arg type="d" name="d_ret" direction="out" />
+ <arg type="s" name="str_ret" direction="out" />
+ </method>
+ </interface>
+</node>
+</programlisting>
+ </para>
+ <para>
+ This XML is in the same format as the D-Bus introspection XML
+ format. Except we must include an "annotation" which give the C
+ symbols corresponding to the object implementation prefix
+ (<literal>my_object</literal>). In addition, if particular
+ methods symbol names deviate from C convention
+ (i.e. <literal>ManyArgs</literal> ->
+ <literal>many_args</literal>), you may specify an annotation
+ giving the C symbol.
+ </para>
+ <para>
+ Once you have written this XML, run <literal>dbus-binding-tool --mode=glib-server <replaceable>FILENAME</replaceable> > <replaceable>HEADER_NAME</replaceable>.</literal> to
+ generate a header file. For example: <command>dbus-binding-tool --mode=glib-server my-object.xml > my-object-glue.h</command>.
+ </para>
+ <para>
+ Next, include the generated header in your program, and invoke
+ <literal>dbus_g_object_class_install_info</literal> in the class
+ initializer, passing the object class and "object info" included in the
+ header. For example:
+ <programlisting>
+ dbus_g_object_type_install_info (COM_FOO_TYPE_MY_OBJECT, &com_foo_my_object_info);
+ </programlisting>
+ This should be done exactly once per object class.
+ </para>
+ <para>
+ To actually implement the method, just define a C function named e.g.
+ <literal>my_object_many_args</literal> in the same file as the info
+ header is included. At the moment, it is required that this function
+ conform to the following rules:
+ <itemizedlist>
+ <listitem>
+ <para>
+ The function must return a value of type <literal>gboolean</literal>;
+ <literal>TRUE</literal> on success, and <literal>FALSE</literal>
+ otherwise.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The first parameter is a pointer to an instance of the object.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Following the object instance pointer are the method
+ input values.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Following the input values are pointers to return values.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The final parameter must be a <literal>GError **</literal>.
+ If the function returns <literal>FALSE</literal> for an
+ error, the error parameter must be initalized with
+ <literal>g_set_error</literal>.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ <para>
+ Finally, you can export an object using <literal>dbus_g_connection_register_g_object</literal>. For example:
+ <programlisting>
+ dbus_g_connection_register_g_object (connection,
+ "/com/foo/MyObject",
+ obj);
+ </programlisting>
+ </para>
+
+ <sect2 id="glib-annotations">
+ <title>Server-side Annotations</title>
+ <para>
+ There are several annotations that are used when generating the
+ server-side bindings. The most common annotation is
+ <literal>org.freedesktop.DBus.GLib.CSymbol</literal> but there are other
+ annotations which are often useful.
+ <variablelist>
+ <varlistentry>
+ <term><literal>org.freedesktop.DBus.GLib.CSymbol</literal></term>
+ <listitem>
+ <para>
+ This annotation is used to specify the C symbol names for
+ the various types (interface, method, etc), if it differs from the
+ name DBus generates.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>org.freedesktop.DBus.GLib.Async</literal></term>
+ <listitem>
+ <para>
+ This annotation marks the method implementation as an
+ asynchronous function, which doesn't return a response straight
+ away but will send the response at some later point to complete
+ the call. This is used to implement non-blocking services where
+ method calls can take time.
+ </para>
+ <para>
+ When a method is asynchronous, the function prototype is
+ different. It is required that the function conform to the
+ following rules:
+ <itemizedlist>
+ <listitem>
+ <para>
+ The function must return a value of type <literal>gboolean</literal>;
+ <literal>TRUE</literal> on success, and <literal>FALSE</literal>
+ otherwise. TODO: the return value is currently ignored.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The first parameter is a pointer to an instance of the object.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Following the object instance pointer are the method
+ input values.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ The final parameter must be a
+ <literal>DBusGMethodInvocation *</literal>. This is used
+ when sending the response message back to the client, by
+ calling <literal>dbus_g_method_return</literal> or
+ <literal>dbus_g_method_return_error</literal>.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>org.freedesktop.DBus.GLib.Const</literal></term>
+ <listitem>
+ <para>This attribute can only be applied to "out"
+ <literal><arg></literal> nodes, and specifies that the
+ parameter isn't being copied when returned. For example, this
+ turns a 's' argument from a <literal>char **</literal> to a
+ <literal>const char **</literal>, and results in the argument not
+ being freed by DBus after the message is sent.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><literal>org.freedesktop.DBus.GLib.ReturnVal</literal></term>
+ <listitem>
+ <para>
+ This attribute can only be applied to "out"
+ <literal><arg></literal> nodes, and alters the expected
+ function signature. It currently can be set to two values:
+ <literal>""</literal> or <literal>"error"</literal>. The
+ argument marked with this attribute is not returned via a
+ pointer argument, but by the function's return value. If the
+ attribute's value is the empty string, the <literal>GError
+ *</literal> argument is also omitted so there is no standard way
+ to return an error value. This is very useful for interfacing
+ with existing code, as it is possible to match existing APIs.
+ If the attribute's value is <literal>"error"</literal>, then the
+ final argument is a <literal>GError *</literal> as usual.
+ </para>
+ <para>
+ Some examples to demonstrate the usage. This introspection XML:
+ <programlisting>
+<method name="Increment">
+ <arg type="u" name="x" />
+ <arg type="u" direction="out" />
+</method>
+ </programlisting>
+ Expects the following function declaration:
+ <programlisting>
+gboolean
+my_object_increment (MyObject *obj, gint32 x, gint32 *ret, GError **error);
+ </programlisting>
+ </para>
+ <para>
+ This introspection XML:
+ <programlisting>
+<method name="IncrementRetval">
+ <arg type="u" name="x" />
+ <arg type="u" direction="out" >
+ <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+ </arg>
+</method>
+ </programlisting>
+ Expects the following function declaration:
+ <programlisting>
+gint32
+my_object_increment_retval (MyObject *obj, gint32 x)
+ </programlisting>
+ </para>
+ <para>
+ This introspection XML:
+ <programlisting>
+<method name="IncrementRetvalError">
+ <arg type="u" name="x" />
+ <arg type="u" direction="out" >
+ <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+ </arg>
+</method>
+ </programlisting>
+ Expects the following function declaration:
+ <programlisting>
+gint32
+my_object_increment_retval_error (MyObject *obj, gint32 x, GError **error)
+ </programlisting>
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </para>
+ </sect2>
</sect1>
<sect1 id="python-client">
@@ -730,12 +1650,18 @@
</sect1>
<sect1 id="qt-client">
- <title>Qt API</title>
+ <title>Qt API: Using Remote Objects</title>
<para>
- The Qt binding for libdbus, QtDBus, has been distributed with Qt
- since version 4.2. It is not documented here. See
- <ulink url="http://qt-project.org/doc/qt-5/qtdbus-index.html">the Qt
- documentation</ulink> for details of how to use QtDBus.
+
+ The Qt bindings are not yet documented.
+
+ </para>
+ </sect1>
+
+ <sect1 id="qt-server">
+ <title>Qt API: Implementing Objects</title>
+ <para>
+ The Qt bindings are not yet documented.
</para>
</sect1>
</article>
diff --git a/doc/dbus-update-activation-environment.1.xml.in b/doc/dbus-update-activation-environment.1.xml.in
deleted file mode 100644
index 8a495df..0000000
--- a/doc/dbus-update-activation-environment.1.xml.in
+++ /dev/null
@@ -1,213 +0,0 @@
-<?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="dbus-update-activation-environment.1">
- <refentryinfo>
- <copyright>
- <year>2015</year>
- <holder>Collabora Ltd.</holder>
- </copyright>
- <legalnotice>
- <para>This man page is distributed under the same terms as
- dbus-update-activation-environment (MIT/X11). There is NO WARRANTY,
- to the extent permitted by law.</para>
- </legalnotice>
- </refentryinfo>
-
- <refmeta>
- <refentrytitle>dbus-update-activation-environment</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-update-activation-environment</refname>
- <refpurpose>update environment used for D-Bus session services</refpurpose>
- </refnamediv>
-
- <refsynopsisdiv id="synopsis">
- <cmdsynopsis>
- <command>dbus-update-activation-environment</command>
- <arg choice="opt">--systemd</arg>
- <arg choice="opt">--verbose</arg>
- <group choice="plain">
- <arg choice="plain">--all</arg>
- <arg choice="plain" rep="repeat"><replaceable>VAR</replaceable></arg>
- <arg choice="plain" rep="repeat"><replaceable>VAR</replaceable>=<replaceable>VAL</replaceable></arg>
- </group>
- </cmdsynopsis>
- </refsynopsisdiv>
-
- <refsect1 id="description">
- <title>DESCRIPTION</title>
- <para><command>dbus-update-activation-environment</command>
- updates the list of environment variables used by
- <command>dbus-daemon --session</command>
- when it activates session services without using
- <command>systemd</command>.</para>
-
- <para>With the <option>--systemd</option> option,
- if an instance of <command>systemd --user</command> is
- available on D-Bus, it also updates the list of environment variables
- used by <command>systemd --user</command>
- when it activates user services, including D-Bus session services
- for which <command>dbus-daemon</command> has been configured to
- delegate activation to <command>systemd</command>.
- This is very similar to the <option>import-environment</option>
- command provided by
- <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>).</para>
-
- <para>Variables that are special to <command>dbus-daemon</command>
- or <command>systemd</command> may be set, but their values will
- be overridden when a service is started. For instance, it is
- not useful to add <envar>DBUS_SESSION_BUS_ADDRESS</envar> to
- <command>dbus-daemon</command>'s activation environment,
- although it might still be useful to add it to
- <command>systemd</command>'s activation environment.</para>
- </refsect1>
-
- <refsect1 id="options">
- <title>OPTIONS</title>
- <variablelist remap="TP">
-
- <varlistentry>
- <term><option>--all</option></term>
- <listitem>
- <para>Set all environment variables present in
- the environment used by
- <command>dbus-update-activation-environment</command>.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--systemd</option></term>
- <listitem>
- <para>Set environment variables for systemd user services as well as
- for traditional D-Bus session services.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><option>--verbose</option></term>
- <listitem>
- <para>Output messages to standard error explaining what
- dbus-update-activation-environment is doing.</para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><replaceable>VAR</replaceable></term>
- <listitem>
- <para>If <replaceable>VAR</replaceable> is present in the
- environment of <command>dbus-update-activation-environment</command>,
- set it to the same value for D-Bus services. Its value must be
- UTF-8 (if not, it is skipped with a warning). If
- <replaceable>VAR</replaceable> is not present
- in the environment, this argument is silently ignored.
- </para>
- </listitem>
- </varlistentry>
-
- <varlistentry>
- <term><replaceable>VAR</replaceable>=<replaceable>VAL</replaceable></term>
- <listitem>
- <para>Set <replaceable>VAR</replaceable> to <replaceable>VAL</replaceable>,
- which must be UTF-8.</para>
- </listitem>
- </varlistentry>
-
- </variablelist>
- </refsect1>
-
- <refsect1 id="examples">
- <title>EXAMPLES</title>
- <para>
- <command>dbus-update-activation-environment</command> is
- primarily designed to be used in Linux distributions' X11 session
- startup scripts, in conjunction with the "user bus" design.
- </para>
-
- <para>To propagate <envar>DISPLAY</envar> and <envar>XAUTHORITY</envar>
- to <command>dbus-daemon</command>
- and, if present, <command>systemd</command>,
- and propagate <envar>DBUS_SESSION_BUS_ADDRESS</envar> to
- <command>systemd</command>:
- <programlisting language="sh">
- dbus-update-activation-environment --systemd \
- DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY
- </programlisting>
- </para>
-
- <para>To propagate all environment variables except
- <envar>XDG_SEAT</envar>, <envar>XDG_SESSION_ID</envar>
- and <envar>XDG_VTNR</envar> to <command>dbus-daemon</command>
- (and, if present, <command>systemd</command>) for compatibility
- with legacy X11 session startup scripts:
- <programlisting language="sh">
- # in a subshell so the variables remain set in the
- # parent script
- (
- unset XDG_SEAT
- unset XDG_SESSION_ID
- unset XDG_VTNR
-
- dbus-update-activation-environment --systemd --all
- )
- </programlisting>
- </para>
- </refsect1>
-
- <refsect1 id="exit_status">
- <title>EXIT STATUS</title>
- <para>
- <command>dbus-update-activation-environment</command>
- exits with status 0 on success, EX_USAGE (64) on invalid
- command-line options, EX_OSERR (71) if unable to connect
- to the session bus, or EX_UNAVAILABLE (69) if unable to
- set the environment variables. Other nonzero exit codes might be
- added in future versions.</para>
- </refsect1>
-
- <refsect1 id="environment">
- <title>ENVIRONMENT</title>
- <para><envar>DBUS_SESSION_BUS_ADDRESS</envar>,
- <envar>XDG_RUNTIME_DIR</envar> and/or <envar>DISPLAY</envar>
- are used to find the address of the session bus.</para>
- </refsect1>
-
- <refsect1 id="limitations">
- <title>LIMITATIONS</title>
- <para>
- <command>dbus-daemon</command> does not provide a way to unset
- environment variables after they have been set (although
- <command>systemd</command> does), so
- <command>dbus-update-activation-environment</command> does not
- offer this functionality either.
- </para>
-
- <para>
- POSIX does not specify the encoding of non-ASCII environment variable
- names or values and allows them to contain any non-zero byte, but
- neither <command>dbus-daemon</command> nor <command>systemd</command>
- supports environment variables with non-UTF-8 names or values.
- Accordingly, <command>dbus-update-activation-environment</command>
- assumes that any name or value that appears to be valid UTF-8 is
- intended to be UTF-8, and ignores other names or values with a warning.
- </para>
- </refsect1>
-
- <refsect1 id="bugs">
- <title>BUGS</title>
- <para>Please send bug reports to the D-Bus bug tracker or mailing list.
- 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>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
- the <option>import-environment</option> command of
- <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></para>
- </refsect1>
-</refentry>
diff --git a/doc/dbus-uuidgen.1.xml.in b/doc/dbus-uuidgen.1.xml.in
deleted file mode 100644
index fbd2681..0000000
--- a/doc/dbus-uuidgen.1.xml.in
+++ /dev/null
@@ -1,126 +0,0 @@
-<?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\-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 5a197ad..5aff5d8 100644
--- a/m4/compiler.m4
+++ b/m4/compiler.m4
@@ -63,5 +63,5 @@
if test "x$GCC" = "xyes"; then
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
fi
-fi],[enable_compiler_coverage=no])dnl
+fi])dnl
])# COMPILER_COVERAGE
diff --git a/m4/ld-version-script.m4 b/m4/ld-version-script.m4
deleted file mode 100644
index 228f52f..0000000
--- a/m4/ld-version-script.m4
+++ /dev/null
@@ -1,43 +0,0 @@
-# ld-version-script.m4 serial 1
-dnl Copyright (C) 2008, 2009 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Simon Josefsson
-
-# FIXME: The test below returns a false positive for mingw
-# cross-compiles, 'local:' statements does not reduce number of
-# exported symbols in a DLL. Use --disable-ld-version-script to work
-# around the problem.
-
-# gl_LD_VERSION_SCRIPT
-# --------------------
-# Check if LD supports linker scripts, and define automake conditional
-# HAVE_LD_VERSION_SCRIPT if so.
-AC_DEFUN([gl_LD_VERSION_SCRIPT],
-[
- AC_ARG_ENABLE([ld-version-script],
- AS_HELP_STRING([--enable-ld-version-script],
- [enable linker version script (default is enabled when possible)]),
- [have_ld_version_script=$enableval], [])
- if test -z "$have_ld_version_script"; then
- AC_MSG_CHECKING([if LD -Wl,--version-script works])
- save_LDFLAGS="$LDFLAGS"
- LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
- cat > conftest.map <<EOF
-VERS_1 {
- global: sym;
-};
-
-VERS_2 {
- global: sym;
-} VERS_1;
-EOF
- AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
- [have_ld_version_script=yes], [have_ld_version_script=no])
- rm -f conftest.map
- LDFLAGS="$save_LDFLAGS"
- AC_MSG_RESULT($have_ld_version_script)
- fi
-])
diff --git a/m4/visibility.m4 b/m4/visibility.m4
deleted file mode 100644
index 552e397..0000000
--- a/m4/visibility.m4
+++ /dev/null
@@ -1,77 +0,0 @@
-# visibility.m4 serial 5 (gettext-0.18.2)
-dnl Copyright (C) 2005, 2008, 2010-2014 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-dnl From Bruno Haible.
-
-dnl Tests whether the compiler supports the command-line option
-dnl -fvisibility=hidden and the function and variable attributes
-dnl __attribute__((__visibility__("hidden"))) and
-dnl __attribute__((__visibility__("default"))).
-dnl Does *not* test for __visibility__("protected") - which has tricky
-dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on
-dnl Mac OS X.
-dnl Does *not* test for __visibility__("internal") - which has processor
-dnl dependent semantics.
-dnl Does *not* test for #pragma GCC visibility push(hidden) - which is
-dnl "really only recommended for legacy code".
-dnl Set the variable CFLAG_VISIBILITY.
-dnl Defines and sets the variable HAVE_VISIBILITY.
-
-AC_DEFUN([gl_VISIBILITY],
-[
- AC_REQUIRE([AC_PROG_CC])
- CFLAG_VISIBILITY=
- HAVE_VISIBILITY=0
- if test -n "$GCC"; then
- dnl First, check whether -Werror can be added to the command line, or
- dnl whether it leads to an error because of some other option that the
- dnl user has put into $CC $CFLAGS $CPPFLAGS.
- AC_MSG_CHECKING([whether the -Werror option is usable])
- AC_CACHE_VAL([gl_cv_cc_vis_werror], [
- gl_save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -Werror"
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM([[]], [[]])],
- [gl_cv_cc_vis_werror=yes],
- [gl_cv_cc_vis_werror=no])
- CFLAGS="$gl_save_CFLAGS"])
- AC_MSG_RESULT([$gl_cv_cc_vis_werror])
- dnl Now check whether visibility declarations are supported.
- AC_MSG_CHECKING([for simple visibility declarations])
- AC_CACHE_VAL([gl_cv_cc_visibility], [
- gl_save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -fvisibility=hidden"
- dnl We use the option -Werror and a function dummyfunc, because on some
- dnl platforms (Cygwin 1.7) the use of -fvisibility triggers a warning
- dnl "visibility attribute not supported in this configuration; ignored"
- dnl at the first function definition in every compilation unit, and we
- dnl don't want to use the option in this case.
- if test $gl_cv_cc_vis_werror = yes; then
- CFLAGS="$CFLAGS -Werror"
- fi
- AC_COMPILE_IFELSE(
- [AC_LANG_PROGRAM(
- [[extern __attribute__((__visibility__("hidden"))) int hiddenvar;
- extern __attribute__((__visibility__("default"))) int exportedvar;
- extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void);
- extern __attribute__((__visibility__("default"))) int exportedfunc (void);
- void dummyfunc (void) {}
- ]],
- [[]])],
- [gl_cv_cc_visibility=yes],
- [gl_cv_cc_visibility=no])
- CFLAGS="$gl_save_CFLAGS"])
- AC_MSG_RESULT([$gl_cv_cc_visibility])
- if test $gl_cv_cc_visibility = yes; then
- CFLAG_VISIBILITY="-fvisibility=hidden"
- HAVE_VISIBILITY=1
- fi
- fi
- AC_SUBST([CFLAG_VISIBILITY])
- AC_SUBST([HAVE_VISIBILITY])
- AC_DEFINE_UNQUOTED([HAVE_VISIBILITY], [$HAVE_VISIBILITY],
- [Define to 1 or 0, depending whether the compiler supports simple visibility declarations.])
-])
diff --git a/test/Makefile.am b/test/Makefile.am
index 7f4cdd0..e944899 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,54 +4,40 @@
SUBDIRS= . name-test
DIST_SUBDIRS=name-test
-CLEANFILES =
-EXTRA_DIST =
-
+# CPPFLAGS for binaries that are normally dynamic
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(DBUS_STATIC_BUILD_CPPFLAGS) \
- -DDBUS_COMPILATION \
$(GLIB_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
$(NULL)
# improve backtraces from test stuff
AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
-noinst_LTLIBRARIES = libdbus-testutils.la
+# CPPFLAGS for binaries that are always static
+static_cppflags = \
+ $(AM_CPPFLAGS) \
+ -DDBUS_STATIC_BUILD \
+ $(NULL)
+libdbus_testutils_la_CPPFLAGS = \
+ $(static_cppflags)
libdbus_testutils_la_SOURCES = \
test-utils.c \
test-utils.h \
$(NULL)
-
-if DBUS_WITH_GLIB
-libdbus_testutils_la_SOURCES += \
- test-utils-glib.c \
- test-utils-glib.h \
- $(NULL)
-endif
-
libdbus_testutils_la_LIBADD = \
- $(top_builddir)/dbus/libdbus-1.la \
$(top_builddir)/dbus/libdbus-internal.la \
$(NULL)
-TEST_EXTENSIONS = .sh
+noinst_LTLIBRARIES = libdbus-testutils.la
-LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
-LOG_COMPILER = $(srcdir)/glib-tap-test.sh
-SH_LOG_DRIVER = $(LOG_DRIVER)
-SH_LOG_COMPILER = $(SHELL)
-EXTRA_DIST += glib-tap-test.sh
-EXTRA_DIST += tap-test.sh.in
-
-TESTS =
-
-if DBUS_ENABLE_EMBEDDED_TESTS
+if DBUS_BUILD_TESTS
## break-loader removed for now
## these binaries are used in tests but are not themselves tests
TEST_BINARIES = \
- test-spawn \
+ spawn-test \
test-exit \
test-names \
test-segfault \
@@ -62,255 +48,129 @@
## These are conceptually part of directories that come earlier in SUBDIRS
## order, but we don't want to run them til we arrive in this directory,
-## since they depend on stuff from this directory. We wrap them in a
-## simple shell script to get TAP output.
-
-wrap_bus_tests = test-bus.sh
-wrap_dbus_tests = test-dbus.sh
+## since they depend on stuff from this directory
+TESTS = \
+ ../bus/bus-test$(EXEEXT) \
+ ../bus/bus-test-system$(EXEEXT) \
+ ../dbus/dbus-test$(EXEEXT) \
+ $(NULL)
if DBUS_UNIX
-wrap_bus_tests += test-bus-launch-helper.sh
-wrap_bus_tests += test-bus-system.sh
+TESTS += ../bus/bus-test-launch-helper$(EXEEXT)
endif
-TESTS += $(wrap_bus_tests) $(wrap_dbus_tests)
-CLEANFILES += $(wrap_bus_tests) $(wrap_dbus_tests)
-
-$(wrap_bus_tests): test-bus%.sh: ../bus/test-bus%$(EXEEXT) tap-test.sh.in Makefile
- sed -e 's![@]RUN[@]!$<!' \
- < $(srcdir)/tap-test.sh.in > $@
-
-$(wrap_dbus_tests): test-dbus%.sh: ../dbus/test-dbus%$(EXEEXT) tap-test.sh.in Makefile
- sed -e 's![@]RUN[@]!$<!' \
- < $(srcdir)/tap-test.sh.in > $@
-
-else !DBUS_ENABLE_EMBEDDED_TESTS
+else !DBUS_BUILD_TESTS
TEST_BINARIES=
+TESTS=
-endif !DBUS_ENABLE_EMBEDDED_TESTS
+endif !DBUS_BUILD_TESTS
noinst_PROGRAMS= $(TEST_BINARIES)
+test_service_CPPFLAGS = $(static_cppflags)
test_service_LDADD = libdbus-testutils.la
+test_names_CPPFLAGS = $(static_cppflags)
test_names_LDADD = libdbus-testutils.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
-test_shell_SOURCES = shell-test.c
-test_shell_LDADD = libdbus-testutils.la
-test_spawn_SOURCES = spawn-test.c
-test_spawn_LDADD = $(top_builddir)/dbus/libdbus-internal.la
-
-test_printf_SOURCES = internals/printf.c
-test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.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_refs_SOURCES = internals/refs.c
+test_refs_CPPFLAGS = $(static_cppflags)
test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
test_syslog_SOURCES = internals/syslog.c
+test_syslog_CPPFLAGS = $(static_cppflags)
test_syslog_LDADD = libdbus-testutils.la $(GLIB_LIBS)
-manual_dir_iter_SOURCES = manual-dir-iter.c
-manual_dir_iter_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+EXTRA_DIST = dbus-test-runner
-manual_paths_SOURCES = manual-paths.c
-manual_paths_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+testexecdir = $(libdir)/dbus-1.0/test
-manual_tcp_SOURCES = manual-tcp.c
-manual_tcp_LDADD = $(top_builddir)/dbus/libdbus-internal.la
-
-EXTRA_DIST += dbus-test-runner
-
-testexecdir = $(libexecdir)/installed-tests/dbus
-testmetadir = $(datadir)/installed-tests/dbus
-
-dist_testexec_SCRIPTS =
testexec_PROGRAMS =
-testmeta_DATA =
installable_tests = \
- test-shell \
- test-printf \
+ shell-test \
$(NULL)
-installable_manual_tests = \
- manual-dir-iter \
- manual-tcp \
- $(NULL)
-dist_installable_test_scripts = \
- $(NULL)
-
-if DBUS_WIN
-installable_manual_tests += manual-paths
-endif
if DBUS_WITH_GLIB
installable_tests += \
test-corrupt \
test-dbus-daemon \
test-dbus-daemon-eavesdrop \
- test-fdpass \
- test-monitor \
test-loopback \
test-marshal \
test-refs \
test-relay \
test-syntax \
test-syslog \
- test-uid-permissions \
- $(NULL)
-
-if DBUS_UNIX
-installable_tests += \
- test-sd-activation \
- $(NULL)
-
-dist_installable_test_scripts += \
- test-dbus-daemon-fork.sh \
- $(NULL)
-
-# Testing dbus-launch relies on special code in that binary.
-if DBUS_ENABLE_EMBEDDED_TESTS
-dist_installable_test_scripts += \
- test-dbus-launch-eval.sh \
- test-dbus-launch-x11.sh \
- $(NULL)
-endif DBUS_ENABLE_EMBEDDED_TESTS
-
-endif DBUS_UNIX
-
-installable_manual_tests += \
- manual-authz \
$(NULL)
endif DBUS_WITH_GLIB
-installable_test_meta = \
- $(dist_installable_test_scripts:=.test) \
- $(installable_tests:=.test) \
- $(NULL)
-installable_test_meta_with_config = \
- $(dist_installable_test_scripts:=_with_config.test) \
- $(installable_tests:=_with_config.test) \
- $(NULL)
-
installcheck_tests =
installcheck_environment = \
- export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
- export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \
- export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \
- export DBUS_TEST_DBUS_MONITOR=$(DESTDIR)$(bindir)/dbus-monitor$(EXEEXT); \
- export DBUS_TEST_DBUS_SEND=$(DESTDIR)$(bindir)/dbus-send$(EXEEXT); \
- export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
- export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \
- ${NULL}
+ DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT) \
+ DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \
+ DBUS_TEST_SYSCONFDIR=$(DESTDIR)$(sysconfdir)
-AM_TESTS_ENVIRONMENT = \
- export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
- export DBUS_FATAL_WARNINGS=1; \
- export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
- export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \
- export DBUS_TEST_DBUS_MONITOR=@abs_top_builddir@/tools/dbus-monitor$(EXEEXT); \
- export DBUS_TEST_DBUS_SEND=@abs_top_builddir@/tools/dbus-send$(EXEEXT); \
- export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \
- export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \
+TESTS_ENVIRONMENT = \
+ DBUS_BLOCK_ON_ABORT=1 \
+ 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_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
-
test_corrupt_SOURCES = corrupt.c
-test_corrupt_LDADD = \
- libdbus-testutils.la \
+test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(NULL)
+ $(DBUS_GLIB_LIBS)
test_loopback_SOURCES = loopback.c
-test_loopback_LDADD = \
- libdbus-testutils.la \
+test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(NULL)
+ $(DBUS_GLIB_LIBS)
test_relay_SOURCES = relay.c
-test_relay_LDADD = \
- libdbus-testutils.la \
+test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(NULL)
+ $(DBUS_GLIB_LIBS)
test_dbus_daemon_SOURCES = dbus-daemon.c
-test_dbus_daemon_LDADD = \
- libdbus-testutils.la \
+test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(NULL)
+ $(DBUS_GLIB_LIBS)
test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c
-test_dbus_daemon_eavesdrop_LDADD = \
- libdbus-testutils.la \
+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 \
$(GLIB_LIBS) \
- $(NULL)
-
-if DBUS_UNIX
-test_sd_activation_SOURCES = \
- sd-activation.c \
- $(NULL)
-test_sd_activation_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
-endif
+ $(DBUS_GLIB_LIBS)
test_marshal_SOURCES = marshal.c
-test_marshal_LDADD = \
- libdbus-testutils.la \
+test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
- $(NULL)
-
-test_monitor_SOURCES = \
- monitor.c \
- $(NULL)
-test_monitor_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
+ $(DBUS_GLIB_LIBS)
test_syntax_SOURCES = syntax.c
-test_syntax_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
-
-test_uid_permissions_SOURCES = \
- uid-permissions.c \
- $(NULL)
-test_uid_permissions_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
-
-test_fdpass_SOURCES = \
- fdpass.c \
- $(NULL)
-test_fdpass_LDADD = \
- libdbus-testutils.la \
- $(GLIB_LIBS) \
- $(NULL)
-
-TESTS += $(dist_installable_test_scripts)
-installcheck_tests += $(dist_installable_test_scripts)
+test_syntax_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS)
if DBUS_ENABLE_MODULAR_TESTS
TESTS += $(installable_tests)
installcheck_tests += $(installable_tests)
if DBUS_ENABLE_INSTALLED_TESTS
- testexec_PROGRAMS += $(installable_tests) $(installable_manual_tests)
- dist_testexec_SCRIPTS += $(dist_installable_test_scripts)
-
- testmeta_DATA += $(installable_test_meta)
- testmeta_DATA += $(installable_test_meta_with_config)
+ testexec_PROGRAMS += $(installable_tests)
else !DBUS_ENABLE_INSTALLED_TESTS
- noinst_PROGRAMS += $(installable_tests) $(installable_manual_tests)
+ noinst_PROGRAMS += $(installable_tests)
endif !DBUS_ENABLE_INSTALLED_TESTS
endif DBUS_ENABLE_MODULAR_TESTS
@@ -320,13 +180,13 @@
# do a portable equivalent of setting LD_LIBRARY_PATH.
installcheck-local:
$(MAKE) check-TESTS TESTS='$$(installcheck_tests)' \
- AM_TESTS_ENVIRONMENT='$$(installcheck_environment)'
+ TESTS_ENVIRONMENT='$$(installcheck_environment)'
if DBUS_ENABLE_INSTALLED_TESTS
- test -n "$(DESTDIR)" || { \
+ test -n "$(DESTDIR)" || \
$(installcheck_environment) \
$(srcdir)/dbus-test-runner \
$(testexecdir) \
- $(installable_tests); }
+ $(testexec_PROGRAMS)
endif DBUS_ENABLE_INSTALLED_TESTS
in_data = \
@@ -334,11 +194,6 @@
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/finite-timeout.conf.in \
- data/valid-config-files/forbidding.conf.in \
- data/valid-config-files/incoming-limit.conf.in \
- data/valid-config-files/multi-user.conf.in \
- data/valid-config-files/systemd-activation.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 \
@@ -407,16 +262,12 @@
data/sha-1/bit-messages.sha1 \
data/sha-1/byte-hashes.sha1 \
data/sha-1/byte-messages.sha1 \
- data/systemd-activation/com.example.SystemdActivatable1.service \
- data/systemd-activation/com.example.SystemdActivatable2.service \
- data/systemd-activation/com.example.SystemdActivatable3.service \
- data/systemd-activation/org.freedesktop.systemd1.service \
data/valid-config-files/basic.conf \
data/valid-config-files/basic.d/basic.conf \
data/valid-config-files/entities.conf \
- data/valid-config-files/listen-unix-runtime.conf \
+ data/valid-config-files/incoming-limit.conf \
data/valid-config-files/many-rules.conf \
- data/valid-config-files-system/system.d/test.conf \
+ data/valid-config-files/system.d/test.conf \
data/valid-messages/array-of-array-of-uint32.message \
data/valid-messages/dict-simple.message \
data/valid-messages/dict.message \
@@ -438,116 +289,39 @@
## copy tests to builddir so that generated tests and static tests
## are all in one place.
-all-local: copy-config-local uninstalled-config-local
- @:
-
-copy-config-local:
+all-local:
$(AM_V_at)$(MKDIR_P) data/valid-config-files/session.d
- $(AM_V_GEN)set -e; \
+ $(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 \
- $(MKDIR_P) "$${F%/*}"; \
- rm -f "$$F"; \
- cp $(srcdir)/"$$F" "$$F"; \
+ $(MKDIR_P) $${F%/*}; \
+ rm -f $$F; \
+ cp $(srcdir)/$$F $$F; \
done; \
fi
-uninstalled-config-local:
- $(AM_V_GEN)set -e; \
- for F in $(in_data); do \
- $(MKDIR_P) "$${F%/*}"; \
- sed \
- -e 's,[@]DBUS_TEST_DATA[@],@abs_builddir@/data,' \
- -e 's,[@]DBUS_TEST_EXEC[@],@abs_builddir@,' \
- -e 's,[@]EXEEXT[@],$(EXEEXT),' \
- -e 's,[@]TEST_LAUNCH_HELPER_BINARY[@],@abs_top_builddir@/bus/dbus-daemon-launch-helper-test$(EXEEXT),' \
- -e 's,[@]TEST_LISTEN[@],$(TEST_LISTEN),' \
- < $(srcdir)/"$$F" > "$${F%.in}"; \
- done
-
-installable-config-local:
-if DBUS_ENABLE_INSTALLED_TESTS
- $(AM_V_GEN)set -e; \
- for F in $(in_data); do \
- $(MKDIR_P) "installable/$${F%/*}"; \
- sed \
- -e 's,[@]DBUS_TEST_DATA[@],$(testexecdir)/data,' \
- -e 's,[@]DBUS_TEST_EXEC[@],$(testexecdir),' \
- -e 's,[@]EXEEXT[@],$(EXEEXT),' \
- -e 's,[@]TEST_LAUNCH_HELPER_BINARY[@],/bin/false,' \
- -e 's,[@]TEST_LISTEN[@],$(TEST_LISTEN),' \
- < $(srcdir)/"$$F" > "installable/$${F%.in}"; \
- done
-else
- @:
-endif
-
-
-install-data-local: install-config-local
- @:
-
-install-config-local: installable-config-local
-if DBUS_ENABLE_INSTALLED_TESTS
- $(AM_V_GEN)set -e; \
- for F in $(static_data); do \
- install -d "$(DESTDIR)$(testexecdir)/$${F%/*}"; \
- install -m644 "$(srcdir)/$$F" "$(DESTDIR)$(testexecdir)/$$F"; \
- done; \
- for F in $(in_data); do \
- install -d "$(DESTDIR)$(testexecdir)/$${F%/*}"; \
- install -m644 "installable/$${F%.in}" "$(DESTDIR)$(testexecdir)/$${F%.in}"; \
- done
- ln -nfs $(datadir)/dbus-1/session.conf $(DESTDIR)$(testexecdir)/data/valid-config-files/session.conf
- ln -nfs $(datadir)/dbus-1/system.conf $(DESTDIR)$(testexecdir)/data/valid-config-files-system/system.conf
-else
- @:
-endif
-
## this doesn't clean most copied test data files when srcdir=builddir
clean-local:
$(AM_V_at)if test $(srcdir) = . || test $(srcdir) -ef .; then \
echo '-- No need to clean test data as srcdir = builddir'; \
else \
rm -f $(static_data); \
- for F in $(in_data); do \
- rm -f "$${F%.in}"; \
- done; \
fi
imported_data = \
data/valid-config-files/session.conf \
- data/valid-config-files-system/system.conf \
+ data/valid-config-files/system.conf \
$(NULL)
noinst_DATA = $(imported_data)
-CLEANFILES += \
- $(noinst_DATA) \
- XDG_RUNTIME_DIR \
- installable \
- $(NULL)
+CLEANFILES = $(noinst_DATA)
data/valid-config-files/session.conf: $(top_builddir)/bus/session.conf
$(AM_V_at)$(MKDIR_P) data/valid-config-files
$(AM_V_GEN)cp $< $@
-data/valid-config-files-system/system.conf: $(top_builddir)/bus/system.conf
- $(AM_V_at)$(MKDIR_P) data/valid-config-files-system
+data/valid-config-files/system.conf: $(top_builddir)/bus/system.conf
+ $(AM_V_at)$(MKDIR_P) data/valid-config-files
$(AM_V_GEN)cp $< $@
-
-$(installable_test_meta): %.test: %$(EXEEXT) Makefile
- $(AM_V_GEN) ( \
- echo '[Test]'; \
- echo 'Type=session'; \
- echo 'Output=TAP'; \
- echo 'Exec=env $(testexecdir)/$* --tap'; \
- ) > $@.tmp && mv $@.tmp $@
-
-$(installable_test_meta_with_config): %_with_config.test: %$(EXEEXT) Makefile
- $(AM_V_GEN) ( \
- echo '[Test]'; \
- echo 'Type=session'; \
- echo 'Output=TAP'; \
- echo 'Exec=env DBUS_TEST_DATA=$(testexecdir)/data $(testexecdir)/$* --tap'; \
- ) > $@.tmp && mv $@.tmp $@
diff --git a/test/break-loader.c b/test/break-loader.c
new file mode 100644
index 0000000..e62b8c2
--- /dev/null
+++ b/test/break-loader.c
@@ -0,0 +1,764 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-break-loader.c Program to find byte streams that break the message 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 <dbus/dbus.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#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;
+static int failures_this_iteration;
+
+static int
+random_int_in_range (int start,
+ int end)
+{
+ /* such elegant math */
+ double gap;
+ double v_double;
+ int v;
+
+ if (start == end)
+ return start;
+
+ _dbus_assert (end > start);
+
+ gap = end - start - 1; /* -1 to not include "end" */
+ v_double = ((double)start) + (((double)rand ())/RAND_MAX) * gap;
+ if (v_double < 0.0)
+ v = (v_double - 0.5);
+ else
+ v = (v_double + 0.5);
+
+ if (v < start)
+ {
+ fprintf (stderr, "random_int_in_range() generated %d for range [%d,%d)\n",
+ v, start, end);
+ v = start;
+ }
+ else if (v >= end)
+ {
+ fprintf (stderr, "random_int_in_range() generated %d for range [%d,%d)\n",
+ v, start, end);
+ v = end - 1;
+ }
+
+ /* printf (" %d of [%d,%d)\n", v, start, end); */
+
+ return v;
+}
+
+static dbus_bool_t
+try_mutated_data (const DBusString *data)
+{
+ int pid;
+
+ total_attempts += 1;
+ /* printf (" attempt %d\n", total_attempts); */
+
+ pid = fork ();
+
+ if (pid < 0)
+ {
+ fprintf (stderr, "fork() failed: %s\n",
+ strerror (errno));
+ exit (1);
+ return FALSE;
+ }
+
+ if (pid == 0)
+ {
+ /* Child, try loading the data */
+ if (!dbus_internal_do_not_use_try_message_data (data, _DBUS_MESSAGE_UNKNOWN))
+ exit (1);
+ else
+ exit (0);
+ }
+ else
+ {
+ /* Parent, wait for child */
+ int status;
+ DBusString filename;
+ dbus_bool_t failed;
+
+ if (waitpid (pid, &status, 0) < 0)
+ {
+ fprintf (stderr, "waitpid() failed: %s\n", strerror (errno));
+ exit (1);
+ return FALSE;
+ }
+
+ failed = FALSE;
+
+ if (!_dbus_string_init (&filename) ||
+ !_dbus_string_copy (&failure_dir, 0,
+ &filename, 0) ||
+ !_dbus_string_append_byte (&filename, '/'))
+ {
+ fprintf (stderr, "out of memory\n");
+ exit (1);
+ }
+
+ _dbus_string_append_int (&filename, total_attempts);
+
+ if (WIFEXITED (status))
+ {
+ if (WEXITSTATUS (status) != 0)
+ {
+ _dbus_string_append (&filename, "-exited-");
+ _dbus_string_append_int (&filename, WEXITSTATUS (status));
+ failed = TRUE;
+ }
+ }
+ else if (WIFSIGNALED (status))
+ {
+ _dbus_string_append (&filename, "signaled-");
+ _dbus_string_append_int (&filename, WTERMSIG (status));
+ failed = TRUE;
+ }
+
+ if (failed)
+ {
+ DBusError error;
+
+ _dbus_string_append (&filename, ".message-raw");
+
+ printf ("Child failed, writing %s\n", _dbus_string_get_const_data (&filename));
+
+ dbus_error_init (&error);
+ if (!_dbus_string_save_to_file (data, &filename, FALSE, &error))
+ {
+ fprintf (stderr, "Failed to save failed message data: %s\n",
+ error.message);
+ dbus_error_free (&error);
+ exit (1); /* so we can see the seed that was printed out */
+ }
+
+ failures_this_iteration += 1;
+
+ _dbus_string_free (&filename);
+
+ return FALSE;
+ }
+ else
+ {
+ _dbus_string_free (&filename);
+ return TRUE;
+ }
+ }
+
+ _dbus_assert_not_reached ("should not be reached");
+ return TRUE;
+}
+
+static void
+randomly_shorten_or_lengthen (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int delta;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) == 0)
+ delta = random_int_in_range (0, 10);
+ else
+ delta = random_int_in_range (- _dbus_string_get_length (mutated),
+ _dbus_string_get_length (mutated) * 3);
+
+ if (delta < 0)
+ _dbus_string_shorten (mutated, - delta);
+ else if (delta > 0)
+ {
+ int i = 0;
+
+ i = _dbus_string_get_length (mutated);
+ if (!_dbus_string_lengthen (mutated, delta))
+ _dbus_assert_not_reached ("couldn't lengthen string");
+
+ while (i < _dbus_string_get_length (mutated))
+ {
+ _dbus_string_set_byte (mutated,
+ i,
+ random_int_in_range (0, 256));
+ ++i;
+ }
+ }
+}
+
+static void
+randomly_change_one_byte (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) == 0)
+ return;
+
+ i = random_int_in_range (0, _dbus_string_get_length (mutated));
+
+ _dbus_string_set_byte (mutated, i,
+ random_int_in_range (0, 256));
+}
+
+static void
+randomly_remove_one_byte (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) == 0)
+ return;
+
+ i = random_int_in_range (0, _dbus_string_get_length (mutated));
+
+ _dbus_string_delete (mutated, i, 1);
+}
+
+
+static void
+randomly_add_one_byte (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ i = random_int_in_range (0, _dbus_string_get_length (mutated));
+
+ _dbus_string_insert_bytes (mutated, i, 1,
+ random_int_in_range (0, 256));
+}
+
+static void
+randomly_modify_length (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+ int byte_order;
+ const char *d;
+ dbus_uint32_t orig;
+ int delta;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) < 12)
+ return;
+
+ d = _dbus_string_get_const_data (mutated);
+
+ if (!(*d == DBUS_LITTLE_ENDIAN ||
+ *d == DBUS_BIG_ENDIAN))
+ return;
+
+ byte_order = *d;
+
+ i = random_int_in_range (4, _dbus_string_get_length (mutated) - 8);
+ i = _DBUS_ALIGN_VALUE (i, 4);
+
+ orig = _dbus_demarshal_uint32 (mutated, byte_order, i, NULL);
+
+ delta = random_int_in_range (-10, 10);
+
+ _dbus_marshal_set_uint32 (mutated, byte_order, i,
+ (unsigned) (orig + delta));
+}
+
+static void
+randomly_set_extreme_ints (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+ int byte_order;
+ const char *d;
+ dbus_uint32_t orig;
+ static int which = 0;
+ unsigned int extreme_ints[] = {
+ _DBUS_INT_MAX,
+ _DBUS_UINT_MAX,
+ _DBUS_INT_MAX - 1,
+ _DBUS_UINT_MAX - 1,
+ _DBUS_INT_MAX - 2,
+ _DBUS_UINT_MAX - 2,
+ _DBUS_INT_MAX - 17,
+ _DBUS_UINT_MAX - 17,
+ _DBUS_INT_MAX / 2,
+ _DBUS_INT_MAX / 3,
+ _DBUS_UINT_MAX / 2,
+ _DBUS_UINT_MAX / 3,
+ 0, 1, 2, 3,
+ (unsigned int) -1,
+ (unsigned int) -2,
+ (unsigned int) -3
+ };
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) < 12)
+ return;
+
+ d = _dbus_string_get_const_data (mutated);
+
+ if (!(*d == DBUS_LITTLE_ENDIAN ||
+ *d == DBUS_BIG_ENDIAN))
+ return;
+
+ byte_order = *d;
+
+ i = random_int_in_range (4, _dbus_string_get_length (mutated) - 8);
+ i = _DBUS_ALIGN_VALUE (i, 4);
+
+ orig = _dbus_demarshal_uint32 (mutated, byte_order, i, NULL);
+
+ which = random_int_in_range (0, _DBUS_N_ELEMENTS (extreme_ints));
+
+ _dbus_assert (which >= 0);
+ _dbus_assert (which < _DBUS_N_ELEMENTS (extreme_ints));
+
+ _dbus_marshal_set_uint32 (mutated, byte_order, i,
+ extreme_ints[which]);
+}
+
+static int
+random_type (void)
+{
+ const char types[] = {
+ DBUS_TYPE_INVALID,
+ DBUS_TYPE_NIL,
+ DBUS_TYPE_BYTE,
+ DBUS_TYPE_BOOLEAN,
+ DBUS_TYPE_INT32,
+ DBUS_TYPE_UINT32,
+ DBUS_TYPE_INT64,
+ DBUS_TYPE_UINT64,
+ DBUS_TYPE_DOUBLE,
+ DBUS_TYPE_STRING,
+ DBUS_TYPE_CUSTOM,
+ DBUS_TYPE_ARRAY,
+ DBUS_TYPE_DICT,
+ DBUS_TYPE_OBJECT_PATH
+ };
+
+ _dbus_assert (_DBUS_N_ELEMENTS (types) == DBUS_NUMBER_OF_TYPES + 1);
+
+ return types[ random_int_in_range (0, _DBUS_N_ELEMENTS (types)) ];
+}
+
+static void
+randomly_change_one_type (const DBusString *orig_data,
+ DBusString *mutated)
+{
+ int i;
+ int len;
+
+ if (orig_data != mutated)
+ {
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+ }
+
+ if (_dbus_string_get_length (mutated) == 0)
+ return;
+
+ len = _dbus_string_get_length (mutated);
+ i = random_int_in_range (0, len);
+
+ /* Look for a type starting at a random location,
+ * and replace with a different type
+ */
+ while (i < len)
+ {
+ int b;
+ b = _dbus_string_get_byte (mutated, i);
+ if (dbus_type_is_valid (b))
+ {
+ _dbus_string_set_byte (mutated, i, random_type ());
+ return;
+ }
+ ++i;
+ }
+}
+
+static int times_we_did_each_thing[7] = { 0, };
+
+static void
+randomly_do_n_things (const DBusString *orig_data,
+ DBusString *mutated,
+ int n)
+{
+ int i;
+ void (* functions[]) (const DBusString *orig_data,
+ DBusString *mutated) =
+ {
+ randomly_shorten_or_lengthen,
+ randomly_change_one_byte,
+ randomly_add_one_byte,
+ randomly_remove_one_byte,
+ randomly_modify_length,
+ randomly_set_extreme_ints,
+ randomly_change_one_type
+ };
+
+ _dbus_string_set_length (mutated, 0);
+
+ if (!_dbus_string_copy (orig_data, 0, mutated, 0))
+ _dbus_assert_not_reached ("out of mem");
+
+ i = 0;
+ while (i < n)
+ {
+ int which;
+
+ which = random_int_in_range (0, _DBUS_N_ELEMENTS (functions));
+
+ (* functions[which]) (mutated, mutated);
+ times_we_did_each_thing[which] += 1;
+
+ ++i;
+ }
+}
+
+static dbus_bool_t
+find_breaks_based_on (const DBusString *filename,
+ dbus_bool_t is_raw,
+ DBusMessageValidity expected_validity,
+ void *data)
+{
+ DBusString orig_data;
+ DBusString mutated;
+ const char *filename_c;
+ dbus_bool_t retval;
+ int i;
+
+ filename_c = _dbus_string_get_const_data (filename);
+
+ retval = FALSE;
+
+ if (!_dbus_string_init (&orig_data))
+ _dbus_assert_not_reached ("could not allocate string\n");
+
+ if (!_dbus_string_init (&mutated))
+ _dbus_assert_not_reached ("could not allocate string\n");
+
+ if (!dbus_internal_do_not_use_load_message_file (filename, is_raw,
+ &orig_data))
+ {
+ fprintf (stderr, "could not load file %s\n", filename_c);
+ goto failed;
+ }
+
+ printf (" changing one random byte 100 times\n");
+ i = 0;
+ while (i < 100)
+ {
+ randomly_change_one_byte (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" changing length 50 times\n");
+ i = 0;
+ while (i < 50)
+ {
+ randomly_modify_length (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" removing one byte 50 times\n");
+ i = 0;
+ while (i < 50)
+ {
+ randomly_remove_one_byte (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" adding one byte 50 times\n");
+ i = 0;
+ while (i < 50)
+ {
+ randomly_add_one_byte (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" changing ints to boundary values 50 times\n");
+ i = 0;
+ while (i < 50)
+ {
+ randomly_set_extreme_ints (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" changing typecodes 50 times\n");
+ i = 0;
+ while (i < 50)
+ {
+ randomly_change_one_type (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" changing message length 15 times\n");
+ i = 0;
+ while (i < 15)
+ {
+ randomly_shorten_or_lengthen (&orig_data, &mutated);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" randomly making 2 of above modifications 42 times\n");
+ i = 0;
+ while (i < 42)
+ {
+ randomly_do_n_things (&orig_data, &mutated, 2);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" randomly making 3 of above modifications 42 times\n");
+ i = 0;
+ while (i < 42)
+ {
+ randomly_do_n_things (&orig_data, &mutated, 3);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ printf (" randomly making 4 of above modifications 42 times\n");
+ i = 0;
+ while (i < 42)
+ {
+ randomly_do_n_things (&orig_data, &mutated, 4);
+ try_mutated_data (&mutated);
+
+ ++i;
+ }
+
+ retval = TRUE;
+
+ failed:
+
+ _dbus_string_free (&orig_data);
+ _dbus_string_free (&mutated);
+
+ /* FALSE means end the whole process */
+ return retval;
+}
+
+static unsigned int
+get_random_seed (void)
+{
+ DBusString bytes;
+ unsigned int seed;
+ int fd;
+ const char *s;
+
+ seed = 0;
+
+ if (!_dbus_string_init (&bytes))
+ exit (1);
+
+ fd = open ("/dev/urandom", O_RDONLY);
+ if (fd < 0)
+ goto use_fallback;
+
+ if (_dbus_read (fd, &bytes, 4) != 4)
+ goto use_fallback;
+
+ close (fd);
+
+ s = _dbus_string_get_const_data (&bytes);
+
+ seed = * (unsigned int*) s;
+ goto out;
+
+ use_fallback:
+ {
+ long tv_usec;
+
+ fprintf (stderr, "could not open/read /dev/urandom, using current time for seed\n");
+
+ _dbus_get_monotonic_time (NULL, &tv_usec);
+
+ seed = tv_usec;
+ }
+
+ out:
+ _dbus_string_free (&bytes);
+
+ return seed;
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ const char *test_data_dir;
+ const char *failure_dir_c;
+ int total_failures_found;
+
+ if (argc > 1)
+ test_data_dir = argv[1];
+ else
+ {
+ fprintf (stderr, "Must specify a top_srcdir/test/data directory\n");
+ return 1;
+ }
+
+ total_failures_found = 0;
+ total_attempts = 0;
+
+ if (!_dbus_string_init (&failure_dir))
+ return 1;
+
+ /* so you can leave it overnight safely */
+#define MAX_FAILURES 1000
+
+ while (total_failures_found < MAX_FAILURES)
+ {
+ unsigned int seed;
+
+ failures_this_iteration = 0;
+
+ seed = get_random_seed ();
+
+ _dbus_string_set_length (&failure_dir, 0);
+
+ if (!_dbus_string_append (&failure_dir, "failures-"))
+ return 1;
+
+ if (!_dbus_string_append_uint (&failure_dir, seed))
+ return 1;
+
+ failure_dir_c = _dbus_string_get_const_data (&failure_dir);
+
+ if (mkdir (failure_dir_c, 0700) < 0)
+ {
+ if (errno != EEXIST)
+ fprintf (stderr, "didn't mkdir %s: %s\n",
+ failure_dir_c, strerror (errno));
+ }
+
+ printf ("next seed = %u \ttotal failures %d of %d attempts\n",
+ seed, total_failures_found, total_attempts);
+
+ srand (seed);
+
+ if (!dbus_internal_do_not_use_foreach_message_file (test_data_dir,
+ find_breaks_based_on,
+ NULL))
+ {
+ fprintf (stderr, "fatal error iterating over message files\n");
+ rmdir (failure_dir_c);
+ return 1;
+ }
+
+ printf (" did %d random mutations: %d %d %d %d %d %d %d\n",
+ _DBUS_N_ELEMENTS (times_we_did_each_thing),
+ times_we_did_each_thing[0],
+ times_we_did_each_thing[1],
+ times_we_did_each_thing[2],
+ times_we_did_each_thing[3],
+ times_we_did_each_thing[4],
+ times_we_did_each_thing[5],
+ times_we_did_each_thing[6]);
+
+ printf ("Found %d failures with seed %u stored in %s\n",
+ failures_this_iteration, seed, failure_dir_c);
+
+ total_failures_found += failures_this_iteration;
+
+ rmdir (failure_dir_c); /* does nothing if non-empty */
+ }
+
+ return 0;
+}
diff --git a/test/corrupt.c b/test/corrupt.c
index d106fcc..0249590 100644
--- a/test/corrupt.c
+++ b/test/corrupt.c
@@ -30,12 +30,10 @@
#include <gio/gio.h>
#include <dbus/dbus.h>
-
-#include "test-utils-glib.h"
+#include <dbus/dbus-glib-lowlevel.h>
typedef struct {
DBusError e;
- TestMainContext *ctx;
DBusServer *server;
DBusConnection *server_conn;
@@ -74,14 +72,13 @@
g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn);
- test_connection_setup (f->ctx, server_conn);
+ dbus_connection_setup_with_g_main (server_conn, NULL);
}
static void
setup (Fixture *f,
gconstpointer addr)
{
- f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->client_messages);
@@ -91,7 +88,7 @@
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- test_server_setup (f->ctx, f->server);
+ dbus_server_setup_with_g_main (f->server, NULL);
}
static void
@@ -106,12 +103,12 @@
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
g_assert (f->client_conn != NULL);
- test_connection_setup (f->ctx, f->client_conn);
+ dbus_connection_setup_with_g_main (f->client_conn, NULL);
while (f->server_conn == NULL)
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
have_mem = dbus_connection_add_filter (f->client_conn,
@@ -139,8 +136,8 @@
while (g_queue_is_empty (&f->client_messages))
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1);
@@ -231,8 +228,8 @@
* rubbish, so it should disconnect */
while (g_queue_is_empty (&f->client_messages))
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
incoming = g_queue_pop_head (&f->client_messages);
@@ -249,16 +246,6 @@
"/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);
}
@@ -320,8 +307,8 @@
* message, so it should disconnect */
while (g_queue_is_empty (&f->client_messages))
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
message = g_queue_pop_head (&f->client_messages);
@@ -338,12 +325,6 @@
"/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);
}
@@ -371,15 +352,14 @@
dbus_server_unref (f->server);
f->server = NULL;
}
-
- test_main_context_unref (f->ctx);
}
int
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ g_type_init ();
g_test_add ("/corrupt/tcp", Fixture, "tcp:host=127.0.0.1", setup,
test_corrupt, teardown);
diff --git a/test/data/systemd-activation/com.example.SystemdActivatable1.service b/test/data/systemd-activation/com.example.SystemdActivatable1.service
deleted file mode 100644
index f15f038..0000000
--- a/test/data/systemd-activation/com.example.SystemdActivatable1.service
+++ /dev/null
@@ -1,4 +0,0 @@
-[D-BUS Service]
-Name=com.example.SystemdActivatable1
-Exec=/bin/false 1
-SystemdService=dbus-com.example.SystemdActivatable1.service
diff --git a/test/data/systemd-activation/com.example.SystemdActivatable2.service b/test/data/systemd-activation/com.example.SystemdActivatable2.service
deleted file mode 100644
index dcedd73..0000000
--- a/test/data/systemd-activation/com.example.SystemdActivatable2.service
+++ /dev/null
@@ -1,4 +0,0 @@
-[D-BUS Service]
-Name=com.example.SystemdActivatable2
-Exec=/bin/false 2
-SystemdService=dbus-com.example.SystemdActivatable2.service
diff --git a/test/data/systemd-activation/com.example.SystemdActivatable3.service b/test/data/systemd-activation/com.example.SystemdActivatable3.service
deleted file mode 100644
index f6f0559..0000000
--- a/test/data/systemd-activation/com.example.SystemdActivatable3.service
+++ /dev/null
@@ -1,4 +0,0 @@
-[D-BUS Service]
-Name=com.example.SystemdActivatable3
-Exec=/bin/false 3
-SystemdService=dbus-com.example.SystemdActivatable3.service
diff --git a/test/data/systemd-activation/org.freedesktop.systemd1.service b/test/data/systemd-activation/org.freedesktop.systemd1.service
deleted file mode 100644
index aea9311..0000000
--- a/test/data/systemd-activation/org.freedesktop.systemd1.service
+++ /dev/null
@@ -1,3 +0,0 @@
-[D-BUS Service]
-Name=org.freedesktop.systemd1
-Exec=/bin/false
diff --git a/test/data/valid-config-files/finite-timeout.conf.in b/test/data/valid-config-files/finite-timeout.conf.in
deleted file mode 100644
index 7d26d71..0000000
--- a/test/data/valid-config-files/finite-timeout.conf.in
+++ /dev/null
@@ -1,19 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <!-- Our well-known bus type, don't change this -->
- <type>session</type>
- <listen>@TEST_LISTEN@</listen>
-
- <policy context="default">
- <!-- Allow everything to be sent -->
- <allow send_destination="*" eavesdrop="true"/>
- <!-- Allow everything to be received -->
- <allow eavesdrop="true"/>
- <!-- Allow anyone to own anything -->
- <allow own="*"/>
- </policy>
-
- <!-- Forcibly time out method calls after 100ms -->
- <limit name="reply_timeout">100</limit>
-</busconfig>
diff --git a/test/data/valid-config-files/forbidding.conf.in b/test/data/valid-config-files/forbidding.conf.in
deleted file mode 100644
index 6a674f8..0000000
--- a/test/data/valid-config-files/forbidding.conf.in
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <!-- Our well-known bus type, don't change this -->
- <type>session</type>
- <listen>@TEST_LISTEN@</listen>
-
- <policy context="default">
- <!-- Allow everything -->
- <allow send_destination="*"/>
- <allow receive_sender="*"/>
- <allow own="*"/>
-
- <!-- Exception: some messages are forbidden -->
- <deny send_interface="com.example.CannotSend"/>
- <deny receive_interface="com.example.CannotReceive"/>
- </policy>
-</busconfig>
diff --git a/test/data/valid-config-files/incoming-limit.conf.in b/test/data/valid-config-files/incoming-limit.conf.in
deleted file mode 100644
index 40ff224..0000000
--- a/test/data/valid-config-files/incoming-limit.conf.in
+++ /dev/null
@@ -1,18 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <!-- Our well-known bus type, don't change this -->
- <type>session</type>
- <listen>@TEST_LISTEN@</listen>
-
- <policy context="default">
- <!-- Allow everything to be sent -->
- <allow send_destination="*" eavesdrop="true"/>
- <!-- Allow everything to be received -->
- <allow eavesdrop="true"/>
- <!-- Allow anyone to own anything -->
- <allow own="*"/>
- </policy>
-
- <limit name="max_incoming_bytes">1</limit>
-</busconfig>
diff --git a/test/data/valid-config-files/listen-unix-runtime.conf b/test/data/valid-config-files/listen-unix-runtime.conf
deleted file mode 100644
index 169de2c..0000000
--- a/test/data/valid-config-files/listen-unix-runtime.conf
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <type>session</type>
- <listen>unix:runtime=yes</listen>
- <policy context="default">
- <allow send_destination="*" eavesdrop="true"/>
- <allow eavesdrop="true"/>
- <allow own="*"/>
- </policy>
-</busconfig>
diff --git a/test/data/valid-config-files/many-rules.conf b/test/data/valid-config-files/many-rules.conf
index df9a994..2393162 100644
--- a/test/data/valid-config-files/many-rules.conf
+++ b/test/data/valid-config-files/many-rules.conf
@@ -17,6 +17,8 @@
<deny own_prefix="org.freedesktop.ManySystems"/>
<deny send_destination="org.freedesktop.System"/>
<deny receive_sender="org.freedesktop.System"/>
+ <deny user="root"/>
+ <deny group="bin"/>
<allow send_type="error"/>
<allow send_type="method_call"/>
<allow send_type="method_return"/>
@@ -34,6 +36,8 @@
<deny own_prefix="org.freedesktop.ManySystems"/>
<deny send_destination="org.freedesktop.System"/>
<deny receive_sender="org.freedesktop.System"/>
+ <deny user="root"/>
+ <deny group="bin"/>
<allow send_type="error"/>
<allow send_type="method_call"/>
<allow send_type="method_return"/>
diff --git a/test/data/valid-config-files/multi-user.conf.in b/test/data/valid-config-files/multi-user.conf.in
deleted file mode 100644
index 37a7da6..0000000
--- a/test/data/valid-config-files/multi-user.conf.in
+++ /dev/null
@@ -1,15 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <listen>@TEST_LISTEN@</listen>
-
- <policy context="default">
- <allow send_interface="*"/>
- <allow receive_interface="*"/>
- <allow own="*"/>
- <allow user="*"/>
- </policy>
-
- <!-- avoid allowing service activation since we are allowing everyone in -->
- <servicehelper>/bin/false</servicehelper>
-</busconfig>
diff --git a/test/data/valid-config-files/systemd-activation.conf.in b/test/data/valid-config-files/systemd-activation.conf.in
deleted file mode 100644
index bcd6416..0000000
--- a/test/data/valid-config-files/systemd-activation.conf.in
+++ /dev/null
@@ -1,11 +0,0 @@
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-<busconfig>
- <listen>@TEST_LISTEN@</listen>
- <servicedir>@DBUS_TEST_DATA@/systemd-activation</servicedir>
- <policy context="default">
- <allow send_destination="*"/>
- <allow receive_sender="*"/>
- <allow own="*"/>
- </policy>
-</busconfig>
diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c
index 4198578..0bd923d 100644
--- a/test/dbus-daemon-eavesdrop.c
+++ b/test/dbus-daemon-eavesdrop.c
@@ -27,9 +27,20 @@
#include <config.h>
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
#include <string.h>
-#include "test-utils-glib.h"
+#ifdef DBUS_WIN
+# include <io.h>
+# include <windows.h>
+#else
+# include <signal.h>
+# include <unistd.h>
+#endif
#define SENDER_NAME "test.eavesdrop.sender"
#define SENDER_PATH "/test/eavesdrop/sender"
@@ -60,7 +71,6 @@
} SignalDst;
typedef struct {
- TestMainContext *ctx;
DBusError e;
GError *ge;
@@ -79,6 +89,96 @@
dbus_bool_t politelistener_got_stopper;
} Fixture;
+#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__)
+static void
+_assert_no_error (const DBusError *e,
+ const char *file,
+ int line)
+{
+ if (G_UNLIKELY (dbus_error_is_set (e)))
+ g_error ("%s:%d: expected success but got error: %s: %s",
+ file, line, e->name, e->message);
+}
+
+static gchar *
+spawn_dbus_daemon (gchar *binary,
+ gchar *configuration,
+ GPid *daemon_pid)
+{
+ GError *error = NULL;
+ GString *address;
+ gint address_fd;
+ gchar *argv[] = {
+ binary,
+ configuration,
+ "--nofork",
+ "--print-address=1", /* stdout */
+ NULL
+ };
+
+ g_spawn_async_with_pipes (NULL, /* working directory */
+ argv,
+ NULL, /* envp */
+ G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
+ NULL, /* child_setup */
+ NULL, /* user data */
+ daemon_pid,
+ NULL, /* child's stdin = /dev/null */
+ &address_fd,
+ NULL, /* child's stderr = our stderr */
+ &error);
+ g_assert_no_error (error);
+
+ address = g_string_new (NULL);
+
+ /* polling until the dbus-daemon writes out its address is a bit stupid,
+ * but at least it's simple, unlike dbus-launch... in principle we could
+ * use select() here, but life's too short */
+ while (1)
+ {
+ gssize bytes;
+ gchar buf[4096];
+ gchar *newline;
+
+ bytes = read (address_fd, buf, sizeof (buf));
+
+ if (bytes > 0)
+ g_string_append_len (address, buf, bytes);
+
+ newline = strchr (address->str, '\n');
+
+ if (newline != NULL)
+ {
+ g_string_truncate (address, newline - address->str);
+ break;
+ }
+
+ g_usleep (G_USEC_PER_SEC / 10);
+ }
+
+ return g_string_free (address, FALSE);
+}
+
+static DBusConnection *
+connect_to_bus (const gchar *address)
+{
+ DBusConnection *conn;
+ DBusError error = DBUS_ERROR_INIT;
+ dbus_bool_t ok;
+
+ conn = dbus_connection_open_private (address, &error);
+ assert_no_error (&error);
+ g_assert (conn != NULL);
+
+ ok = dbus_bus_register (conn, &error);
+ assert_no_error (&error);
+ g_assert (ok);
+ g_assert (dbus_bus_get_unique_name (conn) != NULL);
+
+ dbus_connection_setup_with_g_main (conn, NULL);
+ return conn;
+}
+
/* send a unicast signal to <self> to ensure that no other connection
* listening is the actual recipient for the signal */
static DBusHandlerResult
@@ -233,9 +333,9 @@
DBusError e = DBUS_ERROR_INIT;
dbus_bus_add_match (f->receiver, RECEIVER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
dbus_bus_add_match (f->receiver, STOPPER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
if (!dbus_connection_add_filter (f->receiver,
signal_filter, f, NULL))
@@ -248,9 +348,9 @@
DBusError e = DBUS_ERROR_INIT;
dbus_bus_add_match (f->eavesdropper, EAVESDROPPER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
dbus_bus_add_match (f->eavesdropper, STOPPER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
if (!dbus_connection_add_filter (f->eavesdropper,
signal_filter, f, NULL))
@@ -263,9 +363,9 @@
DBusError e = DBUS_ERROR_INIT;
dbus_bus_add_match (f->politelistener, POLITELISTENER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
dbus_bus_add_match (f->politelistener, STOPPER_RULE, &e);
- test_assert_no_error (&e);
+ assert_no_error (&e);
if (!dbus_connection_add_filter (f->politelistener,
signal_filter, f, NULL))
@@ -276,21 +376,45 @@
setup (Fixture *f,
gconstpointer context G_GNUC_UNUSED)
{
+ gchar *dbus_daemon;
+ gchar *config;
gchar *address;
- f->ctx = test_main_context_get ();
-
f->ge = NULL;
dbus_error_init (&f->e);
- address = test_get_dbus_daemon (NULL, TEST_USER_ME, &f->daemon_pid);
+ dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
- f->sender = test_connect_to_bus (f->ctx, address);
+ if (dbus_daemon == NULL)
+ dbus_daemon = g_strdup ("dbus-daemon");
+
+ if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
+ {
+ config = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
+ g_getenv ("DBUS_TEST_SYSCONFDIR"));
+ }
+ else if (g_getenv ("DBUS_TEST_DATA") != NULL)
+ {
+ config = g_strdup_printf (
+ "--config-file=%s/valid-config-files/session.conf",
+ g_getenv ("DBUS_TEST_DATA"));
+ }
+ else
+ {
+ config = g_strdup ("--session");
+ }
+
+ address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+
+ g_free (dbus_daemon);
+ g_free (config);
+
+ f->sender = connect_to_bus (address);
dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE,
&(f->e));
- f->receiver = test_connect_to_bus (f->ctx, address);
- f->eavesdropper = test_connect_to_bus (f->ctx, address);
- f->politelistener = test_connect_to_bus (f->ctx, address);
+ f->receiver = connect_to_bus (address);
+ f->eavesdropper = connect_to_bus (address);
+ f->politelistener = connect_to_bus (address);
add_receiver_filter (f);
add_politelistener_filter (f);
add_eavesdropper_filter (f);
@@ -308,7 +432,7 @@
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
/* all the three connection can receive a broadcast */
g_assert_cmpint (f->receiver_dst, ==, BROADCAST);
@@ -328,7 +452,7 @@
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
/* not directed to it and not broadcasted, they cannot receive it */
g_assert_cmpint (f->receiver_dst, ==, NONE_YET);
@@ -348,7 +472,7 @@
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
/* direct to him */
g_assert_cmpint (f->receiver_dst, ==, TO_ME);
@@ -403,17 +527,21 @@
f->eavesdropper = NULL;
}
- test_kill_pid (f->daemon_pid);
- g_spawn_close_pid (f->daemon_pid);
+#ifdef DBUS_WIN
+ TerminateProcess (f->daemon_pid, 1);
+#else
+ kill (f->daemon_pid, SIGTERM);
+#endif
- test_main_context_unref (f->ctx);
+ g_spawn_close_pid (f->daemon_pid);
}
int
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/eavedrop/match_keyword/broadcast", Fixture, NULL,
setup, test_eavesdrop_broadcast, teardown);
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index 99d2bc6..cc87153 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -2,7 +2,6 @@
*
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2015 Collabora Ltd.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -27,53 +26,24 @@
#include <config.h>
-#include <errno.h>
-#include <string.h>
+#include <glib.h>
#include <dbus/dbus.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include "test-utils-glib.h"
+#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
-#ifdef DBUS_UNIX
+#ifdef DBUS_WIN
+# include <io.h>
+# include <windows.h>
+#else
+# include <signal.h>
# include <unistd.h>
-# include <sys/types.h>
-#endif
-
-/* Platforms where we know that credentials-passing passes both the
- * uid and the pid. Please keep these in alphabetical order.
- *
- * These platforms should #error in _dbus_read_credentials_socket()
- * if we didn't detect their flavour of credentials-passing, since that
- * would be a regression.
- */
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
- defined(__linux__) || \
- defined(__NetBSD__) || \
- defined(__OpenBSD__)
-# define UNIX_USER_SHOULD_WORK
-# define PID_SHOULD_WORK
-#endif
-
-/* Platforms where we know that credentials-passing passes the
- * uid, but not necessarily the pid. Again, alphabetical order please.
- *
- * These platforms should also #error in _dbus_read_credentials_socket()
- * if we didn't detect their flavour of credentials-passing.
- */
-#if 0 /* defined(__your_platform_here__) */
-# define UNIX_USER_SHOULD_WORK
#endif
typedef struct {
gboolean skip;
- TestMainContext *ctx;
-
DBusError e;
GError *ge;
@@ -83,30 +53,108 @@
DBusConnection *right_conn;
gboolean right_conn_echo;
- gboolean wait_forever_called;
-
- gchar *tmp_runtime_dir;
- gchar *saved_runtime_dir;
} Fixture;
+#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__)
+static void
+_assert_no_error (const DBusError *e,
+ const char *file,
+ int line)
+{
+ if (G_UNLIKELY (dbus_error_is_set (e)))
+ g_error ("%s:%d: expected success but got error: %s: %s",
+ file, line, e->name, e->message);
+}
+
+static gchar *
+spawn_dbus_daemon (gchar *binary,
+ gchar *configuration,
+ GPid *daemon_pid)
+{
+ GError *error = NULL;
+ GString *address;
+ gint address_fd;
+ gchar *argv[] = {
+ binary,
+ configuration,
+ "--nofork",
+ "--print-address=1", /* stdout */
+ NULL
+ };
+
+ g_spawn_async_with_pipes (NULL, /* working directory */
+ argv,
+ NULL, /* envp */
+ G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
+ NULL, /* child_setup */
+ NULL, /* user data */
+ daemon_pid,
+ NULL, /* child's stdin = /dev/null */
+ &address_fd,
+ NULL, /* child's stderr = our stderr */
+ &error);
+ g_assert_no_error (error);
+
+ address = g_string_new (NULL);
+
+ /* polling until the dbus-daemon writes out its address is a bit stupid,
+ * but at least it's simple, unlike dbus-launch... in principle we could
+ * use select() here, but life's too short */
+ while (1)
+ {
+ gssize bytes;
+ gchar buf[4096];
+ gchar *newline;
+
+ bytes = read (address_fd, buf, sizeof (buf));
+
+ if (bytes > 0)
+ g_string_append_len (address, buf, bytes);
+
+ newline = strchr (address->str, '\n');
+
+ if (newline != NULL)
+ {
+ g_string_truncate (address, newline - address->str);
+ break;
+ }
+
+ g_usleep (G_USEC_PER_SEC / 10);
+ }
+
+ return g_string_free (address, FALSE);
+}
+
+static DBusConnection *
+connect_to_bus (const gchar *address)
+{
+ DBusConnection *conn;
+ DBusError error = DBUS_ERROR_INIT;
+ dbus_bool_t ok;
+
+ conn = dbus_connection_open_private (address, &error);
+ assert_no_error (&error);
+ g_assert (conn != NULL);
+
+ ok = dbus_bus_register (conn, &error);
+ assert_no_error (&error);
+ g_assert (ok);
+ g_assert (dbus_bus_get_unique_name (conn) != NULL);
+
+ dbus_connection_setup_with_g_main (conn, NULL);
+ return conn;
+}
+
static DBusHandlerResult
echo_filter (DBusConnection *connection,
DBusMessage *message,
void *user_data)
{
- Fixture *f = user_data;
DBusMessage *reply;
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- /* WaitForever() never replies, emulating a service that has got stuck */
- if (dbus_message_is_method_call (message, "com.example", "WaitForever"))
- {
- f->wait_forever_called = TRUE;
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
reply = dbus_message_new_method_return (message);
if (reply == NULL)
@@ -124,7 +172,6 @@
const char *bug_ref;
guint min_messages;
const char *config_file;
- enum { SPECIFY_ADDRESS = 0, RELY_ON_DEFAULT } connect_mode;
} Config;
static void
@@ -132,57 +179,62 @@
gconstpointer context)
{
const Config *config = context;
+ gchar *dbus_daemon;
+ gchar *arg;
gchar *address;
- f->ctx = test_main_context_get ();
f->ge = NULL;
dbus_error_init (&f->e);
- if (config != NULL && config->connect_mode == RELY_ON_DEFAULT)
+ if (config != NULL && config->config_file != NULL)
{
- /* this is chosen to be something needing escaping */
- f->tmp_runtime_dir = g_dir_make_tmp ("dbus=daemon=test.XXXXXX", &f->ge);
- g_assert_no_error (f->ge);
+ if (g_getenv ("DBUS_TEST_DATA") == NULL)
+ {
+ g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s",
+ config->config_file);
+ f->skip = TRUE;
+ return;
+ }
- /* we're relying on being single-threaded for this to be safe */
- f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
- g_setenv ("XDG_RUNTIME_DIR", f->tmp_runtime_dir, TRUE);
+ arg = g_strdup_printf (
+ "--config-file=%s/%s",
+ g_getenv ("DBUS_TEST_DATA"), config->config_file);
}
-
- address = test_get_dbus_daemon (config ? config->config_file : NULL,
- TEST_USER_ME,
- &f->daemon_pid);
-
- if (address == NULL)
+ else if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
{
- f->skip = TRUE;
- return;
+ arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
+ g_getenv ("DBUS_TEST_SYSCONFDIR"));
}
-
- f->left_conn = test_connect_to_bus (f->ctx, address);
-
- if (config != NULL && config->connect_mode == RELY_ON_DEFAULT)
+ else if (g_getenv ("DBUS_TEST_DATA") != NULL)
{
- /* use the default bus for the echo service ("right"), to check that
- * it ends up on the same bus as the client ("left") */
- f->right_conn = dbus_bus_get_private (DBUS_BUS_SESSION, &f->e);
- test_assert_no_error (&f->e);
-
- if (!test_connection_setup (f->ctx, f->right_conn))
- g_error ("OOM");
+ arg = g_strdup_printf (
+ "--config-file=%s/valid-config-files/session.conf",
+ g_getenv ("DBUS_TEST_DATA"));
}
else
{
- f->right_conn = test_connect_to_bus (f->ctx, address);
+ arg = g_strdup ("--session");
}
+ dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
+
+ if (dbus_daemon == NULL)
+ dbus_daemon = g_strdup ("dbus-daemon");
+
+ 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);
g_free (address);
}
static void
add_echo_filter (Fixture *f)
{
- if (!dbus_connection_add_filter (f->right_conn, echo_filter, f, NULL))
+ if (!dbus_connection_add_filter (f->right_conn, echo_filter, NULL, NULL))
g_error ("OOM");
f->right_conn_echo = TRUE;
@@ -249,7 +301,7 @@
}
while (received < count)
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
elapsed = g_test_timer_elapsed ();
@@ -258,394 +310,6 @@
}
static void
-test_no_reply (Fixture *f,
- gconstpointer context)
-{
- const Config *config = context;
- DBusMessage *m;
- DBusPendingCall *pc;
- DBusMessage *reply = NULL;
- enum { TIMEOUT, DISCONNECT } mode;
- gboolean ok;
-
- if (f->skip)
- return;
-
- g_test_bug ("76112");
-
- if (config != NULL && config->config_file != NULL)
- mode = TIMEOUT;
- else
- mode = DISCONNECT;
-
- m = dbus_message_new_method_call (
- dbus_bus_get_unique_name (f->right_conn), "/",
- "com.example", "WaitForever");
-
- add_echo_filter (f);
-
- if (m == NULL)
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
- DBUS_TIMEOUT_INFINITE) ||
- pc == NULL)
- g_error ("OOM");
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &reply);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &reply, NULL))
- g_error ("OOM");
-
- dbus_pending_call_unref (pc);
- dbus_message_unref (m);
-
- if (mode == DISCONNECT)
- {
- while (!f->wait_forever_called)
- test_main_context_iterate (f->ctx, TRUE);
-
- dbus_connection_remove_filter (f->right_conn, echo_filter, f);
- dbus_connection_close (f->right_conn);
- dbus_connection_unref (f->right_conn);
- f->right_conn = NULL;
- }
-
- while (reply == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- /* using inefficient string comparison for better assertion message */
- g_assert_cmpstr (
- dbus_message_type_to_string (dbus_message_get_type (reply)), ==,
- dbus_message_type_to_string (DBUS_MESSAGE_TYPE_ERROR));
- ok = dbus_set_error_from_message (&f->e, reply);
- g_assert (ok);
- g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_NO_REPLY);
-
- if (mode == DISCONNECT)
- g_assert_cmpstr (f->e.message, ==,
- "Message recipient disconnected from message bus without replying");
- else
- g_assert_cmpstr (f->e.message, ==,
- "Message did not receive a reply (timeout by message bus)");
-}
-
-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_LINUX_SECURITY_LABEL = 8
- } 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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_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_test_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, "WindowsSID") == 0)
- {
-#ifdef G_OS_WIN32
- gchar *sid;
- char *self_sid;
-
- g_assert (!(seen & SEEN_WINDOWS_SID));
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
- DBUS_TYPE_STRING);
- dbus_message_iter_get_basic (&var_iter, &sid);
- g_test_message ("%s of this process is %s", name, sid);
- if (_dbus_getsid (&self_sid, 0))
- {
- g_assert_cmpstr (self_sid, ==, sid);
- LocalFree(self_sid);
- }
- seen |= SEEN_WINDOWS_SID;
-#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_test_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;
- }
- else if (g_strcmp0 (name, "LinuxSecurityLabel") == 0)
- {
-#ifdef __linux__
- gchar *label;
- int len;
- DBusMessageIter ay_iter;
-
- g_assert (!(seen & SEEN_LINUX_SECURITY_LABEL));
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
- DBUS_TYPE_ARRAY);
- dbus_message_iter_recurse (&var_iter, &ay_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&ay_iter), ==,
- DBUS_TYPE_BYTE);
- dbus_message_iter_get_fixed_array (&ay_iter, &label, &len);
- g_test_message ("%s of this process is %s", name, label);
- g_assert_cmpuint (strlen (label) + 1, ==, len);
- seen |= SEEN_LINUX_SECURITY_LABEL;
-#else
- g_assert_not_reached ();
-#endif
- }
-
- dbus_message_iter_next (&arr_iter);
- }
-
-#ifdef UNIX_USER_SHOULD_WORK
- g_assert (seen & SEEN_UNIX_USER);
-#endif
-
-#ifdef PID_SHOULD_WORK
- g_assert (seen & SEEN_PID);
-#endif
-
-#ifdef G_OS_WIN32
- g_assert (seen & SEEN_WINDOWS_SID);
-#endif
-}
-
-static void
-test_processid (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, "GetConnectionUnixProcessID");
- DBusPendingCall *pc;
- DBusError error = DBUS_ERROR_INIT;
- guint32 pid;
-
- 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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- if (dbus_set_error_from_message (&error, m))
- {
- g_assert_cmpstr (error.name, ==, DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN);
-
-#ifdef PID_SHOULD_WORK
- g_error ("Expected pid to be passed, but got %s: %s",
- error.name, error.message);
-#endif
-
- dbus_error_free (&error);
- }
- else if (dbus_message_get_args (m, &error,
- DBUS_TYPE_UINT32, &pid,
- DBUS_TYPE_INVALID))
- {
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "u");
- test_assert_no_error (&error);
-
- g_test_message ("GetConnectionUnixProcessID returned %u", pid);
-
-#ifdef G_OS_UNIX
- g_assert_cmpuint (pid, ==, getpid ());
-#elif defined(G_OS_WIN32)
- g_assert_cmpuint (pid, ==, GetCurrentProcessId ());
-#else
- g_assert_not_reached ();
-#endif
- }
- else
- {
- g_error ("Unexpected error: %s: %s", error.name, error.message);
- }
-}
-
-static void
-test_canonical_path_uae (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
- DBusPendingCall *pc;
- DBusMessageIter args_iter;
- DBusMessageIter arr_iter;
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
- /* Append an empty a{ss} (string => string dictionary). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "{ss}", &arr_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter))
- 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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- /* it succeeds */
- g_assert_cmpint (dbus_message_get_type (m), ==,
- DBUS_MESSAGE_TYPE_METHOD_RETURN);
-
- dbus_message_unref (m);
-
- /* Now try with the wrong object path */
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- "/com/example/Wrong", DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
- /* Append an empty a{ss} (string => string dictionary). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "{ss}", &arr_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter))
- 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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- /* it fails, yielding an error message with one string argument */
- g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
- g_assert_cmpstr (dbus_message_get_error_name (m), ==,
- DBUS_ERROR_ACCESS_DENIED);
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
-
- dbus_message_unref (m);
-}
-
-static void
teardown (Fixture *f,
gconstpointer context G_GNUC_UNUSED)
{
@@ -663,7 +327,7 @@
{
if (f->right_conn_echo)
{
- dbus_connection_remove_filter (f->right_conn, echo_filter, f);
+ dbus_connection_remove_filter (f->right_conn, echo_filter, NULL);
f->right_conn_echo = FALSE;
}
@@ -674,75 +338,31 @@
if (f->daemon_pid != 0)
{
- test_kill_pid (f->daemon_pid);
+#ifdef DBUS_WIN
+ TerminateProcess (f->daemon_pid, 1);
+#else
+ kill (f->daemon_pid, SIGTERM);
+#endif
+
g_spawn_close_pid (f->daemon_pid);
f->daemon_pid = 0;
}
-
- if (f->tmp_runtime_dir != NULL)
- {
- gchar *path;
-
- /* the socket may exist */
- path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir);
- g_assert (g_remove (path) == 0 || errno == ENOENT);
- g_free (path);
- /* there shouldn't be anything else in there */
- g_assert_cmpint (g_rmdir (f->tmp_runtime_dir), ==, 0);
-
- /* we're relying on being single-threaded for this to be safe */
- if (f->saved_runtime_dir != NULL)
- g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE);
- else
- g_unsetenv ("XDG_RUNTIME_DIR");
- g_free (f->saved_runtime_dir);
- g_free (f->tmp_runtime_dir);
- }
-
- test_main_context_unref (f->ctx);
}
static Config limited_config = {
- "34393", 10000, "valid-config-files/incoming-limit.conf",
- SPECIFY_ADDRESS
+ "34393", 10000, "valid-config-files/incoming-limit.conf"
};
-static Config finite_timeout_config = {
- NULL, 1, "valid-config-files/finite-timeout.conf",
- SPECIFY_ADDRESS
-};
-
-#ifdef DBUS_UNIX
-static Config listen_unix_runtime_config = {
- "61303", 1, "valid-config-files/listen-unix-runtime.conf",
- RELY_ON_DEFAULT
-};
-#endif
-
int
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
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 ("/no-reply/disconnect", Fixture, NULL,
- setup, test_no_reply, teardown);
- g_test_add ("/no-reply/timeout", Fixture, &finite_timeout_config,
- setup, test_no_reply, teardown);
- g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown);
- g_test_add ("/processid", Fixture, NULL, setup, test_processid, teardown);
- g_test_add ("/canonical-path/uae", Fixture, NULL,
- setup, test_canonical_path_uae, teardown);
-#ifdef DBUS_UNIX
- /* We can't test this in loopback.c with the rest of unix:runtime=yes,
- * because dbus_bus_get[_private] is the only way to use the default,
- * and that blocks on a round-trip to the dbus-daemon */
- g_test_add ("/unix-runtime-is-default", Fixture, &listen_unix_runtime_config,
- setup, test_echo, teardown);
-#endif
return g_test_run ();
}
diff --git a/test/fdpass.c b/test/fdpass.c
deleted file mode 100644
index 665b4a1..0000000
--- a/test/fdpass.c
+++ /dev/null
@@ -1,908 +0,0 @@
-/*
- * Copyright © 2010-2012 Nokia Corporation
- * Copyright © 2014 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 <dbus/dbus.h>
-#include <dbus/dbus-internals.h>
-#include <dbus/dbus-sysdeps.h>
-
-#include <glib.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef G_OS_UNIX
-# include <dbus/dbus-sysdeps-unix.h>
-
-# include <errno.h>
-# include <fcntl.h>
-# ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-# endif
-# include <sys/stat.h>
-# include <sys/time.h>
-# include <sys/types.h>
-# include <unistd.h>
-#endif
-
-#include "test-utils-glib.h"
-
-/* Arbitrary; included here to avoid relying on the default */
-#define MAX_MESSAGE_UNIX_FDS 20
-/* This test won't work on Linux unless this is true. */
-_DBUS_STATIC_ASSERT (MAX_MESSAGE_UNIX_FDS <= 253);
-
-/* Arbitrary; included here to avoid relying on the default. */
-#define MAX_INCOMING_UNIX_FDS (MAX_MESSAGE_UNIX_FDS * 4)
-
-/* Arbitrary, except that MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES should be
- * less than the process's file descriptor limit. */
-#define SOME_MESSAGES 20
-/* To cover some situations on Linux we want this to be true. */
-_DBUS_STATIC_ASSERT (MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES > 256);
-
-/* Linux won't allow more than 253 fds per sendmsg(). */
-#define TOO_MANY_FDS 255
-_DBUS_STATIC_ASSERT (MAX_MESSAGE_UNIX_FDS < TOO_MANY_FDS);
-
-/* As in test/relay.c, this is a miniature dbus-daemon: we relay messages
- * from the client on the left to the client on the right.
- *
- * left socket left dispatch right socket right
- * client ===========> server --------------> server ===========> client
- * conn conn conn conn
- */
-
-typedef struct {
- TestMainContext *ctx;
- DBusError e;
-
- DBusServer *server;
-
- DBusConnection *left_client_conn;
- DBusConnection *left_server_conn;
-
- DBusConnection *right_server_conn;
- DBusConnection *right_client_conn;
- /* queue of DBusMessage received by right_client_conn */
- GQueue messages;
-
- int fd_before;
-} Fixture;
-
-static void oom (const gchar *doing) G_GNUC_NORETURN;
-
-static void
-oom (const gchar *doing)
-{
- g_error ("out of memory (%s)", doing);
- abort ();
-}
-
-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
-left_server_message_cb (DBusConnection *server_conn,
- DBusMessage *message,
- void *data)
-{
- Fixture *f = data;
-
- g_assert (server_conn == f->left_server_conn);
- g_assert (f->right_server_conn != NULL);
-
- dbus_connection_send (f->right_server_conn, message, NULL);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult
-right_client_message_cb (DBusConnection *client_conn,
- DBusMessage *message,
- void *data)
-{
- Fixture *f = data;
-
- g_assert (client_conn == f->right_client_conn);
- g_queue_push_tail (&f->messages, dbus_message_ref (message));
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static void
-new_conn_cb (DBusServer *server,
- DBusConnection *server_conn,
- void *data)
-{
- Fixture *f = data;
-
- dbus_connection_set_max_message_unix_fds (server_conn,
- MAX_MESSAGE_UNIX_FDS);
- dbus_connection_set_max_received_unix_fds (server_conn,
- MAX_INCOMING_UNIX_FDS);
-
- if (f->left_server_conn == NULL)
- {
- f->left_server_conn = dbus_connection_ref (server_conn);
-
- if (!dbus_connection_add_filter (server_conn,
- left_server_message_cb, f, NULL))
- oom ("adding filter");
- }
- else
- {
- g_assert (f->right_server_conn == NULL);
- f->right_server_conn = dbus_connection_ref (server_conn);
- }
-
- test_connection_setup (f->ctx, server_conn);
-}
-
-static void
-test_connect (Fixture *f,
- gboolean should_support_fds)
-{
- char *address;
-
- g_assert (f->left_server_conn == NULL);
- g_assert (f->right_server_conn == NULL);
-
- address = dbus_server_get_address (f->server);
- g_assert (address != NULL);
-
- f->left_client_conn = dbus_connection_open_private (address, &f->e);
- assert_no_error (&f->e);
- g_assert (f->left_client_conn != NULL);
- test_connection_setup (f->ctx, f->left_client_conn);
-
- /* The left client connection is allowed to behave abusively. */
- dbus_connection_set_max_message_unix_fds (f->left_client_conn, 1000);
- dbus_connection_set_max_received_unix_fds (f->left_client_conn, 1000000);
-
- while (f->left_server_conn == NULL)
- {
- test_progress ('.');
- 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);
- test_connection_setup (f->ctx, f->right_client_conn);
-
- dbus_free (address);
-
- while (f->right_server_conn == NULL)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- if (!dbus_connection_add_filter (f->right_client_conn,
- right_client_message_cb, f, NULL))
- oom ("adding filter");
-
- /* The right client connection is allowed to queue all the messages. */
- dbus_connection_set_max_message_unix_fds (f->right_client_conn, 1000);
- dbus_connection_set_max_received_unix_fds (f->right_client_conn, 1000000);
-
- while (!dbus_connection_get_is_authenticated (f->left_client_conn) ||
- !dbus_connection_get_is_authenticated (f->right_client_conn) ||
- !dbus_connection_get_is_authenticated (f->left_server_conn) ||
- !dbus_connection_get_is_authenticated (f->right_server_conn))
- {
- test_progress ('*');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- if (!should_support_fds)
- return;
-
- if (!dbus_connection_can_send_type (f->left_client_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("left client connection cannot send Unix fds");
-
- if (!dbus_connection_can_send_type (f->left_server_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("left server connection cannot send Unix fds");
-
- if (!dbus_connection_can_send_type (f->right_client_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("right client connection cannot send Unix fds");
-
- if (!dbus_connection_can_send_type (f->right_server_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("right server connection cannot send Unix fds");
-}
-
-static void
-setup_common (Fixture *f,
- const char *address)
-{
- f->ctx = test_main_context_get ();
- dbus_error_init (&f->e);
- g_queue_init (&f->messages);
-
- f->server = dbus_server_listen (address, &f->e);
- assert_no_error (&f->e);
- g_assert (f->server != NULL);
-
- dbus_server_set_new_connection_function (f->server,
- new_conn_cb, f, NULL);
- test_server_setup (f->ctx, f->server);
-}
-
-static void
-setup_unsupported (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
-{
- setup_common (f, "tcp:host=127.0.0.1");
-}
-
-static void
-setup (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- /* We assume that anything with fd-passing supports the unix: transport */
- setup_common (f, "unix:tmpdir=/tmp");
-
- f->fd_before = open ("/dev/null", O_RDONLY);
-
- /* this should succeed on any reasonable Unix */
- if (f->fd_before < 0)
- g_error ("cannot open /dev/null for reading: %s", g_strerror (errno));
-
- _dbus_fd_set_close_on_exec (f->fd_before);
-#endif
-}
-
-static void
-test_unsupported (Fixture *f,
- gconstpointer data)
-{
- test_connect (f, FALSE);
-
- if (dbus_connection_can_send_type (f->left_client_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("left client connection claims it can send Unix fds");
-
- if (dbus_connection_can_send_type (f->left_server_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("left server connection claims it can send Unix fds");
-
- if (dbus_connection_can_send_type (f->right_client_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("right client connection claims it can send Unix fds");
-
- if (dbus_connection_can_send_type (f->right_server_conn,
- DBUS_TYPE_UNIX_FD))
- g_error ("right server connection claims it can send Unix fds");
-}
-
-static void
-test_relay (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- /* We assume that any platform with working fd-passing is POSIX,
- * and therefore has open() and fstat() */
- dbus_uint32_t serial;
- DBusMessage *outgoing, *incoming;
- int fd_after;
- struct stat stat_before;
- struct stat stat_after;
-
- test_connect (f, TRUE);
-
- outgoing = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing != NULL);
-
- if (!dbus_message_append_args (outgoing,
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
-
- if (!dbus_connection_send (f->left_client_conn, outgoing, &serial))
- oom ("sending message");
-
- dbus_message_unref (outgoing);
-
- while (g_queue_get_length (&f->messages) < 1)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 1);
-
- incoming = g_queue_pop_head (&f->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), ==,
- "com.example.Hello");
- g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Greeting");
- g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
- g_assert_cmpstr (dbus_message_get_signature (incoming), ==,
- DBUS_TYPE_UNIX_FD_AS_STRING);
- g_assert_cmpstr (dbus_message_get_path (incoming), ==, "/com/example/Hello");
- g_assert_cmpuint (dbus_message_get_serial (incoming), ==, serial);
-
- if (!dbus_message_get_args (incoming,
- &f->e,
- DBUS_TYPE_UNIX_FD, &fd_after,
- DBUS_TYPE_INVALID))
- g_error ("%s: %s", f->e.name, f->e.message);
-
- assert_no_error (&f->e);
-
- if (fstat (f->fd_before, &stat_before) < 0)
- g_error ("%s", g_strerror (errno));
-
- if (fstat (fd_after, &stat_after) < 0)
- g_error ("%s", g_strerror (errno));
-
- /* this seems like enough to say "it's the same file" */
- g_assert_cmpint (stat_before.st_dev, ==, stat_after.st_dev);
- g_assert_cmpint (stat_before.st_ino, ==, stat_after.st_ino);
- g_assert_cmpint (stat_before.st_rdev, ==, stat_after.st_rdev);
-
- dbus_message_unref (incoming);
-
- if (close (fd_after) < 0)
- g_error ("%s", g_strerror (errno));
-
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
- g_assert (dbus_connection_get_is_connected (f->left_client_conn));
- g_assert (dbus_connection_get_is_connected (f->left_server_conn));
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-test_limit (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- dbus_uint32_t serial;
- DBusMessage *outgoing, *incoming;
- int i;
-
- test_connect (f, TRUE);
-
- outgoing = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing != NULL);
-
- for (i = 0; i < MAX_MESSAGE_UNIX_FDS; i++)
- {
- if (!dbus_message_append_args (outgoing,
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
- }
-
- if (!dbus_connection_send (f->left_client_conn, outgoing, &serial))
- oom ("sending message");
-
- dbus_message_unref (outgoing);
-
- while (g_queue_get_length (&f->messages) < 1)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 1);
-
- incoming = g_queue_pop_head (&f->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), ==,
- "com.example.Hello");
- g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Greeting");
- g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
- g_assert_cmpstr (dbus_message_get_path (incoming), ==, "/com/example/Hello");
- g_assert_cmpuint (dbus_message_get_serial (incoming), ==, serial);
-
- dbus_message_unref (incoming);
-
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
- g_assert (dbus_connection_get_is_connected (f->left_client_conn));
- g_assert (dbus_connection_get_is_connected (f->left_server_conn));
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-test_too_many (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- DBusMessage *outgoing;
- unsigned int i;
-
- test_connect (f, TRUE);
-
- outgoing = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing != NULL);
-
- for (i = 0; i < MAX_MESSAGE_UNIX_FDS + GPOINTER_TO_UINT (data); i++)
- {
- if (!dbus_message_append_args (outgoing,
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
- }
-
- if (!dbus_connection_send (f->left_client_conn, outgoing, NULL))
- oom ("sending message");
-
- dbus_message_unref (outgoing);
-
- /* The sender is unceremoniously disconnected. */
- while (dbus_connection_get_is_connected (f->left_client_conn) ||
- dbus_connection_get_is_connected (f->left_server_conn))
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- /* The message didn't get through without its fds. */
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 0);
-
- /* The intended victim is unaffected by the left connection's
- * misbehaviour. */
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-test_too_many_split (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- DBusMessage *outgoing;
- int i;
- DBusSocket left_client_socket;
- char *payload;
- int payload_len;
- DBusString buffer;
- int fds[TOO_MANY_FDS];
- int done;
-
- /* This test deliberately pushes up against OS limits, so skip it
- * if we don't have enough fds. 4 times the maximum per message
- * ought to be enough: that will cover the message, the dup'd fds
- * we actually send, the copy that we potentially receive, and some
- * spare capacity for everything else. */
-#ifdef HAVE_GETRLIMIT
- struct rlimit lim;
-
- if (getrlimit (RLIMIT_NOFILE, &lim) == 0)
- {
- if (lim.rlim_cur != RLIM_INFINITY &&
- lim.rlim_cur < 4 * TOO_MANY_FDS)
- {
- g_test_skip ("not enough RLIMIT_NOFILE");
- return;
- }
- }
-#endif
-
- test_connect (f, TRUE);
-
- outgoing = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing != NULL);
-
- /* TOO_MANY_FDS fds are far too many: in particular, Linux doesn't allow
- * sending this many in a single sendmsg(). libdbus never splits
- * a message between two sendmsg() calls if it can help it, and
- * in particular it always sends all the fds with the first sendmsg(),
- * but malicious senders might not be so considerate. */
- for (i = 0; i < TOO_MANY_FDS; i++)
- {
- if (!dbus_message_append_args (outgoing,
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
- }
-
- /* This probably shouldn't work for messages with fds, but it does,
- * which is convenient for this sort of trickery. */
- if (!dbus_message_marshal (outgoing, &payload, &payload_len))
- oom ("marshalling message");
-
- _dbus_string_init_const_len (&buffer, payload, payload_len);
-
- for (i = 0; i < TOO_MANY_FDS; i++)
- {
- fds[i] = dup (f->fd_before);
-
- if (fds[i] < 0)
- g_error ("could not dup fd: %s", g_strerror (errno));
- }
-
- /* This is blatant cheating, and the API documentation specifically
- * tells you not use this function in this way. Never do this
- * in application code. */
- if (!dbus_connection_get_socket (f->left_client_conn,
- &left_client_socket.fd))
- g_error ("'unix:' DBusConnection should have had a socket");
-
- /* Just to be sure that we're at a message boundary. */
- dbus_connection_flush (f->left_client_conn);
-
- /* We have too many fds for one sendmsg(), so send the first half
- * (rounding down if odd) with the first byte... */
- done = _dbus_write_socket_with_unix_fds (left_client_socket, &buffer, 0, 1,
- &fds[0], TOO_MANY_FDS / 2);
-
- if (done < 0)
- g_error ("could not send first byte and first batch of fds: %s",
- g_strerror (errno));
-
- /* ... and the second half (rounding up if odd) with the rest of
- * the message */
- done = _dbus_write_socket_with_unix_fds (left_client_socket, &buffer, 1,
- payload_len - 1, &fds[TOO_MANY_FDS / 2],
- TOO_MANY_FDS - (TOO_MANY_FDS / 2));
-
- if (done < 0)
- {
- g_error ("could not send rest of message and rest of fds: %s",
- g_strerror (errno));
- }
- else if (done < payload_len - 1)
- {
- /* For simplicity, assume the socket buffer is big enough for the
- * whole message, which should be < 2 KiB. If this fails on some
- * OS, redo this test code to use a proper loop like the real
- * libdbus does. */
- g_error ("short write in sendmsg(), fix this test: %d/%d",
- done, payload_len - 1);
- }
-
- dbus_free (payload);
-
- for (i = 0; i < TOO_MANY_FDS; i++)
- close (fds[i]);
-
- dbus_message_unref (outgoing);
-
- /* The sender is unceremoniously disconnected. */
- while (dbus_connection_get_is_connected (f->left_client_conn) ||
- dbus_connection_get_is_connected (f->left_server_conn))
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- /* The message didn't get through without its fds. */
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 0);
-
- /* The intended victim is unaffected by the left connection's
- * misbehaviour. */
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-test_flood (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- unsigned int i, j;
- DBusMessage *outgoing[SOME_MESSAGES];
- dbus_uint32_t serial;
-
- test_connect (f, TRUE);
-
- for (j = 0; j < SOME_MESSAGES; j++)
- {
- outgoing[j] = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing[j] != NULL);
-
- for (i = 0; i < GPOINTER_TO_UINT (data); i++)
- {
- if (!dbus_message_append_args (outgoing[j],
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
- }
- }
-
- /* This is in its own loop so we do it as fast as possible */
- for (j = 0; j < SOME_MESSAGES; j++)
- {
- if (!dbus_connection_send (f->left_client_conn, outgoing[j], &serial))
- oom ("sending message");
- }
-
- for (j = 0; j < SOME_MESSAGES; j++)
- {
- dbus_message_unref (outgoing[j]);
- }
-
- while (g_queue_get_length (&f->messages) < SOME_MESSAGES)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, SOME_MESSAGES);
-
- for (j = 0; j < SOME_MESSAGES; j++)
- {
- DBusMessage *incoming;
-
- incoming = g_queue_pop_head (&f->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), ==,
- "com.example.Hello");
- g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Greeting");
- g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
- g_assert_cmpstr (dbus_message_get_path (incoming), ==, "/com/example/Hello");
-
- dbus_message_unref (incoming);
- }
-
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
- g_assert (dbus_connection_get_is_connected (f->left_client_conn));
- g_assert (dbus_connection_get_is_connected (f->left_server_conn));
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-test_odd_limit (Fixture *f,
- gconstpointer data)
-{
-#ifdef HAVE_UNIX_FD_PASSING
- DBusMessage *outgoing;
- int i;
-
- test_connect (f, TRUE);
- dbus_connection_set_max_message_unix_fds (f->left_server_conn, 7);
- dbus_connection_set_max_message_unix_fds (f->right_server_conn, 7);
-
- outgoing = dbus_message_new_signal ("/com/example/Hello",
- "com.example.Hello", "Greeting");
- g_assert (outgoing != NULL);
-
- for (i = 0; i < 7 + GPOINTER_TO_INT (data); i++)
- {
- if (!dbus_message_append_args (outgoing,
- DBUS_TYPE_UNIX_FD, &f->fd_before,
- DBUS_TYPE_INVALID))
- oom ("appending fd");
- }
-
- if (!dbus_connection_send (f->left_client_conn, outgoing, NULL))
- oom ("sending message");
-
- dbus_message_unref (outgoing);
-
- if (GPOINTER_TO_INT (data) > 0)
- {
- /* The sender is unceremoniously disconnected. */
- while (dbus_connection_get_is_connected (f->left_client_conn) ||
- dbus_connection_get_is_connected (f->left_server_conn))
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- /* The message didn't get through without its fds. */
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 0);
-
- /* The intended victim is unaffected by the left connection's
- * misbehaviour. */
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
- }
- else
- {
- DBusMessage *incoming;
-
- /* We're at or under the limit. The message gets through intact. */
- while (g_queue_get_length (&f->messages) < 1)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 1);
-
- incoming = g_queue_pop_head (&f->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), ==,
- "com.example.Hello");
- g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Greeting");
- g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL);
- g_assert_cmpstr (dbus_message_get_path (incoming), ==,
- "/com/example/Hello");
-
- dbus_message_unref (incoming);
-
- g_assert (dbus_connection_get_is_connected (f->right_client_conn));
- g_assert (dbus_connection_get_is_connected (f->right_server_conn));
- g_assert (dbus_connection_get_is_connected (f->left_client_conn));
- g_assert (dbus_connection_get_is_connected (f->left_server_conn));
- }
-#else
- g_test_skip ("fd-passing not supported on this platform");
-#endif
-}
-
-static void
-teardown (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
-{
- if (f->left_client_conn != NULL)
- {
- dbus_connection_close (f->left_client_conn);
- dbus_connection_unref (f->left_client_conn);
- f->left_client_conn = NULL;
- }
-
- if (f->right_client_conn != NULL)
- {
- dbus_connection_close (f->right_client_conn);
- dbus_connection_unref (f->right_client_conn);
- f->right_client_conn = NULL;
- }
-
- if (f->left_server_conn != NULL)
- {
- dbus_connection_close (f->left_server_conn);
- dbus_connection_unref (f->left_server_conn);
- f->left_server_conn = NULL;
- }
-
- if (f->right_server_conn != NULL)
- {
- dbus_connection_close (f->right_server_conn);
- dbus_connection_unref (f->right_server_conn);
- f->right_server_conn = NULL;
- }
-
- if (f->server != NULL)
- {
- dbus_server_disconnect (f->server);
- dbus_server_unref (f->server);
- f->server = NULL;
- }
-
- if (f->ctx != NULL)
- test_main_context_unref (f->ctx);
-
-#ifdef HAVE_UNIX_FD_PASSING
- if (f->fd_before >= 0 && close (f->fd_before) < 0)
- g_error ("%s", g_strerror (errno));
-#endif
-}
-
-int
-main (int argc,
- char **argv)
-{
- test_init (&argc, &argv);
-
-#ifdef HAVE_GETRLIMIT
- {
- struct rlimit lim;
-
- if (getrlimit (RLIMIT_NOFILE, &lim) < 0)
- g_error ("Failed to get RLIMIT_NOFILE limit: %s", g_strerror (errno));
-
- if (lim.rlim_cur != RLIM_INFINITY &&
- /* only run if we have a fairly generous margin of error
- * for stdout, stderr, duplicates, the D-Bus connection, etc. */
- lim.rlim_cur < 2 * MAX_MESSAGE_UNIX_FDS * SOME_MESSAGES)
- {
- g_message ("not enough RLIMIT_NOFILE to run this test");
- /* Autotools exit code for "all skipped" */
- return 77;
- }
- }
-#endif
-
- g_test_add ("/unsupported", Fixture, NULL, setup_unsupported,
- test_unsupported, teardown);
-
- g_test_add ("/relay", Fixture, NULL, setup,
- test_relay, teardown);
- g_test_add ("/limit", Fixture, NULL, setup,
- test_limit, teardown);
-
- g_test_add ("/too-many/plus1", Fixture, GUINT_TO_POINTER (1), setup,
- test_too_many, teardown);
- g_test_add ("/too-many/plus2", Fixture, GUINT_TO_POINTER (2), setup,
- test_too_many, teardown);
- g_test_add ("/too-many/plus17", Fixture, GUINT_TO_POINTER (17), setup,
- test_too_many, teardown);
-
- g_test_add ("/too-many/split", Fixture, NULL, setup,
- test_too_many_split, teardown);
-
- g_test_add ("/flood/1", Fixture, GUINT_TO_POINTER (1),
- setup, test_flood, teardown);
-#if MAX_MESSAGE_UNIX_FDS >= 2
- g_test_add ("/flood/half-limit", Fixture,
- GUINT_TO_POINTER (MAX_MESSAGE_UNIX_FDS / 2),
- setup, test_flood, teardown);
-#endif
-#if MAX_MESSAGE_UNIX_FDS >= 4
- g_test_add ("/flood/over-half-limit", Fixture,
- GUINT_TO_POINTER (3 * MAX_MESSAGE_UNIX_FDS / 4),
- setup, test_flood, teardown);
-#endif
- g_test_add ("/flood/limit", Fixture,
- GUINT_TO_POINTER (MAX_MESSAGE_UNIX_FDS), setup, test_flood, teardown);
-
- g_test_add ("/odd-limit/minus1", Fixture, GINT_TO_POINTER (-1), setup,
- test_odd_limit, teardown);
- g_test_add ("/odd-limit/at", Fixture, GINT_TO_POINTER (0), setup,
- test_odd_limit, teardown);
- g_test_add ("/odd-limit/plus1", Fixture, GINT_TO_POINTER (+1), setup,
- test_odd_limit, teardown);
- g_test_add ("/odd-limit/plus2", Fixture, GINT_TO_POINTER (+2), setup,
- test_odd_limit, teardown);
-
- return g_test_run ();
-}
diff --git a/test/glib-tap-test.sh b/test/glib-tap-test.sh
deleted file mode 100755
index 5e5e6e5..0000000
--- a/test/glib-tap-test.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# Wrapper to make GTest tests output TAP syntax, because Automake's test
-# drivers do not currently support passing the same command-line argument
-# to each test executable. All GTest tests produce TAP output if invoked
-# with the --tap option.
-#
-# Usage: "glib-tap-test.sh test-foo --verbose ..." is equivalent to
-# "test-foo --tap --verbose ..."
-
-set -e
-t="$1"
-shift
-
-case "$t" in
- (*.exe)
- # We're running a Windows executable, possibly on a Unix
- # platform. Avoid having invalid TAP syntax like "ok 3\r\n"
- # where "ok 3\n" was intended.
- echo 1 > "$t".exit-status.tmp
- (
- set +e
- "$t" --tap "$@"
- echo "$?" > "$t".exit-status.tmp
- ) | sed -e 's/\r$//'
- e="$(cat "$t".exit-status.tmp)"
- rm "$t".exit-status.tmp
- exit "$e"
- ;;
-
- (*)
- exec "$t" --tap "$@"
- ;;
-esac
diff --git a/test/internals/printf.c b/test/internals/printf.c
deleted file mode 100644
index 2006f32..0000000
--- a/test/internals/printf.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* 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
-
-/* This test outputs TAP syntax: http://testanything.org/ */
-int
-main (int argc,
- char **argv)
-{
- char buf[] = X_TIMES_1024 X_TIMES_1024 X_TIMES_1024 X_TIMES_1024;
- int i;
- int test_num = 0;
-
- do_test (1, "%d", 0);
- printf ("ok %d\n", ++test_num);
-
- do_test (7, "%d", 1234567);
- printf ("ok %d\n", ++test_num);
-
- do_test (3, "%f", 3.5);
- printf ("ok %d\n", ++test_num);
-
- do_test (0, "%s", "");
- printf ("ok %d\n", ++test_num);
-
- do_test (1024, "%s", X_TIMES_1024);
- printf ("ok %d\n", ++test_num);
-
- do_test (1025, "%s", X_TIMES_1024 "Y");
- printf ("ok %d\n", ++test_num);
-
- for (i = 4096; i > 0; i--)
- {
- buf[i] = '\0';
- do_test (i, "%s", buf);
- do_test (i + 3, "%s:%d", buf, 42);
- }
- printf ("ok %d\n", ++test_num);
-
- /* Tell the TAP driver that we have done all the tests we plan to do.
- * This is how it can distinguish between an unexpected exit and
- * successful completion. */
- printf ("1..%d\n", test_num);
- return 0;
-}
diff --git a/test/internals/refs.c b/test/internals/refs.c
index a465662..db43a4d 100644
--- a/test/internals/refs.c
+++ b/test/internals/refs.c
@@ -29,13 +29,14 @@
#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>
#include <dbus/dbus-message-internal.h>
#include <dbus/dbus-pending-call-internal.h>
#include <dbus/dbus-server-protected.h>
-#include "test-utils-glib.h"
+#include "test-utils.h"
static void
assert_no_error (const DBusError *e)
@@ -62,15 +63,12 @@
DBusMessage *message;
GThread *threads[N_THREADS];
gboolean last_unref;
- unsigned n_refs;
- unsigned n_threads;
} Fixture;
typedef void *(*RefFunc) (void *);
typedef void (*VoidFunc) (void *);
typedef struct {
- const Fixture *f;
void *thing;
RefFunc ref;
VoidFunc ref_void;
@@ -89,10 +87,9 @@
ref_thread (gpointer data)
{
Thread *thread = data;
- const Fixture *f = thread->f;
- unsigned i;
+ int i;
- for (i = 0; i < f->n_refs; i++)
+ for (i = 0; i < N_REFS; i++)
{
if (thread->lock != NULL)
(thread->lock) (thread->mutex);
@@ -119,10 +116,9 @@
cycle_thread (gpointer data)
{
Thread *thread = data;
- const Fixture *f = thread->f;
- unsigned i;
+ int i;
- for (i = 0; i < f->n_refs; i++)
+ for (i = 0; i < N_REFS; i++)
{
if (thread->lock != NULL)
(thread->lock) (thread->mutex);
@@ -151,10 +147,9 @@
unref_thread (gpointer data)
{
Thread *thread = data;
- const Fixture *f = thread->f;
- unsigned i;
+ int i;
- for (i = 0; i < f->n_refs; i++)
+ for (i = 0; i < N_REFS; i++)
{
if (thread->lock != NULL)
(thread->lock) (thread->mutex);
@@ -180,9 +175,9 @@
static void
wait_for_all_threads (Fixture *f)
{
- unsigned i;
+ int i;
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
g_thread_join (f->threads[i]);
}
@@ -206,20 +201,6 @@
if (!dbus_threads_init_default ())
g_error ("OOM");
- f->n_threads = N_THREADS;
- f->n_refs = N_REFS;
-
- // wine sets WINESERVERSOCKET for its child processes automatically
- if (g_getenv ("WINESERVERSOCKET") != NULL)
- {
- /* Our reference-counting is really slow under Wine (it involves
- * IPC to wineserver). Do fewer iterations: enough to demonstrate
- * that it works, rather than a performance test.
- */
- f->n_threads = 10;
- f->n_refs = 10;
- }
-
f->loop = _dbus_loop_new ();
g_assert (f->loop != NULL);
@@ -277,32 +258,28 @@
test_connection (Fixture *f,
gconstpointer data)
{
- Thread public_api = {
- f,
- f->connection,
+ Thread public_api = { f->connection,
(RefFunc) dbus_connection_ref,
NULL,
(VoidFunc) dbus_connection_unref,
NULL,
NULL,
NULL };
- Thread internal_api = {
- f,
- f->connection,
+ Thread internal_api = { f->connection,
(RefFunc) _dbus_connection_ref_unlocked,
NULL,
(VoidFunc) _dbus_connection_unref_unlocked,
f->connection,
(VoidFunc) _dbus_connection_lock,
(VoidFunc) _dbus_connection_unlock };
- unsigned i;
+ int i;
/* Use a slot as a pseudo-weakref */
if (!dbus_connection_set_data (f->connection, connection_slot, f,
last_unref))
g_error ("OOM");
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, ref_thread, &public_api);
@@ -314,7 +291,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, cycle_thread, &public_api);
@@ -326,7 +303,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, unref_thread, &public_api);
@@ -362,30 +339,26 @@
test_server (Fixture *f,
gconstpointer data)
{
- Thread public_api = {
- f,
- f->server,
+ Thread public_api = { f->server,
(RefFunc) dbus_server_ref,
NULL,
(VoidFunc) dbus_server_unref,
NULL,
NULL,
NULL };
- Thread internal_api = {
- f,
- f->server,
+ Thread internal_api = { f->server,
NULL,
(VoidFunc) _dbus_server_ref_unlocked,
(VoidFunc) _dbus_server_unref_unlocked,
f->server,
server_lock,
server_unlock };
- unsigned i;
+ int i;
if (!dbus_server_set_data (f->server, server_slot, f, last_unref))
g_error ("OOM");
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, ref_thread, &public_api);
@@ -397,7 +370,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, cycle_thread, &public_api);
@@ -409,7 +382,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, unref_thread, &public_api);
@@ -435,21 +408,19 @@
{
DBusMessage *message = dbus_message_new_signal ("/foo", "foo.bar.baz",
"Foo");
- Thread public_api = {
- f,
- message,
+ Thread public_api = { message,
(RefFunc) dbus_message_ref,
NULL,
(VoidFunc) dbus_message_unref,
NULL,
NULL,
NULL };
- unsigned i;
+ int i;
if (!dbus_message_set_data (message, message_slot, f, last_unref))
g_error ("OOM");
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
f->threads[i] = g_thread_new (NULL, ref_thread, &public_api);
g_assert (f->threads[i] != NULL);
@@ -457,7 +428,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
f->threads[i] = g_thread_new (NULL, cycle_thread, &public_api);
g_assert (f->threads[i] != NULL);
@@ -465,7 +436,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
f->threads[i] = g_thread_new (NULL, unref_thread, &public_api);
g_assert (f->threads[i] != NULL);
@@ -483,18 +454,14 @@
test_pending_call (Fixture *f,
gconstpointer data)
{
- Thread public_api = {
- f,
- NULL,
+ Thread public_api = { NULL,
(RefFunc) dbus_pending_call_ref,
NULL,
(VoidFunc) dbus_pending_call_unref,
NULL,
NULL,
NULL };
- Thread internal_api = {
- f,
- NULL,
+ Thread internal_api = { NULL,
(RefFunc) _dbus_pending_call_ref_unlocked,
NULL,
(VoidFunc) dbus_pending_call_unref,
@@ -502,16 +469,14 @@
(VoidFunc) _dbus_connection_lock,
(VoidFunc) _dbus_connection_unlock };
/* This one can't be used to ref, only to cycle or unref. */
- Thread unref_and_unlock_api = {
- f,
- NULL,
+ Thread unref_and_unlock_api = { NULL,
(RefFunc) _dbus_pending_call_ref_unlocked,
NULL,
(VoidFunc) _dbus_pending_call_unref_and_unlock,
f->connection,
(VoidFunc) _dbus_connection_lock,
NULL };
- unsigned i;
+ int i;
DBusPendingCall *pending_call;
_dbus_connection_lock (f->connection);
@@ -528,7 +493,7 @@
last_unref))
g_error ("OOM");
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
if ((i % 2) == 0)
f->threads[i] = g_thread_new (NULL, ref_thread, &public_api);
@@ -540,7 +505,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
switch (i % 3)
{
@@ -560,7 +525,7 @@
wait_for_all_threads (f);
- for (i = 0; i < f->n_threads; i++)
+ for (i = 0; i < N_THREADS; i++)
{
switch (i % 3)
{
@@ -621,7 +586,14 @@
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ /* In GLib >= 2.24, < 2.31 this acts like g_thread_init() but avoids
+ * the deprecation of that function. In GLib >= 2.32 this is not
+ * necessary at all.
+ */
+ g_type_init ();
+
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/refs/connection", Fixture, NULL, setup_connection,
test_connection, teardown);
diff --git a/test/internals/syslog.c b/test/internals/syslog.c
index 805c578..4f6b7c2 100644
--- a/test/internals/syslog.c
+++ b/test/internals/syslog.c
@@ -30,11 +30,10 @@
#include <glib.h>
+#define DBUS_COMPILATION /* this test uses libdbus-internal */
#include <dbus/dbus.h>
#include <dbus/dbus-sysdeps.h>
-#include "test-utils-glib.h"
-
typedef struct {
int dummy;
} Fixture;
@@ -53,10 +52,9 @@
test_syslog (Fixture *f,
gconstpointer data)
{
-#ifndef G_OS_WIN32
if (g_test_trap_fork (0, 0))
{
- _dbus_init_system_log (FALSE);
+ _dbus_init_system_log ();
_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 */
@@ -68,20 +66,18 @@
if (g_test_trap_fork (0, 0))
{
- _dbus_init_system_log (FALSE);
+ _dbus_init_system_log ();
_dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
- _dbus_system_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45);
_dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
exit (0);
}
g_test_trap_assert_passed ();
- g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "45\n*" MESSAGE "666\n*");
-#endif
+ g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*");
+
/* manual test (this is the best we can do on Windows) */
- _dbus_init_system_log (FALSE);
+ _dbus_init_system_log ();
_dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
- _dbus_system_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45);
_dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
}
@@ -95,7 +91,8 @@
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/syslog", Fixture, NULL, setup, test_syslog, teardown);
diff --git a/test/loopback.c b/test/loopback.c
index bf0542a..d0d69c8 100644
--- a/test/loopback.c
+++ b/test/loopback.c
@@ -1,8 +1,7 @@
/* Simple sanity-check for loopback through TCP and Unix sockets.
*
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
- * Copyright © 2010-2012 Nokia Corporation
- * Copyright © 2015 Collabora Ltd.
+ * Copyright © 2010-2011 Nokia Corporation
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -28,17 +27,11 @@
#include <config.h>
#include <glib.h>
-#include <glib/gstdio.h>
#include <dbus/dbus.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include "test-utils-glib.h"
+#include <dbus/dbus-glib-lowlevel.h>
typedef struct {
- TestMainContext *ctx;
DBusError e;
DBusServer *server;
@@ -47,9 +40,6 @@
GQueue server_messages;
DBusConnection *client_conn;
-
- gchar *tmp_runtime_dir;
- gchar *saved_runtime_dir;
} Fixture;
static void
@@ -82,7 +72,7 @@
g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn);
- test_connection_setup (f->ctx, server_conn);
+ dbus_connection_setup_with_g_main (server_conn, NULL);
have_mem = dbus_connection_add_filter (server_conn,
server_message_cb, f, NULL);
@@ -93,7 +83,6 @@
setup (Fixture *f,
gconstpointer addr)
{
- f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->server_messages);
@@ -103,59 +92,9 @@
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- test_server_setup (f->ctx, f->server);
+ dbus_server_setup_with_g_main (f->server, NULL);
}
-#ifdef DBUS_UNIX
-static void
-setup_runtime (Fixture *f,
- gconstpointer addr)
-{
- char *listening_at;
- GError *error = NULL;
-
- /* this is chosen to be something needing escaping */
- f->tmp_runtime_dir = g_dir_make_tmp ("dbus=daemon=test.XXXXXX", &error);
- g_assert_no_error (error);
-
- /* we're relying on being single-threaded for this to be safe */
- f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
- g_setenv ("XDG_RUNTIME_DIR", f->tmp_runtime_dir, TRUE);
-
- setup (f, addr);
-
- listening_at = dbus_server_get_address (f->server);
- g_test_message ("listening at %s", listening_at);
- g_assert (g_str_has_prefix (listening_at, "unix:path="));
- g_assert (strstr (listening_at, "dbus%3ddaemon%3dtest.") != NULL);
- g_assert (strstr (listening_at, "/bus,") != NULL ||
- g_str_has_suffix (listening_at, "/bus"));
-
- dbus_free (listening_at);
-}
-
-static void
-setup_no_runtime (Fixture *f,
- gconstpointer addr)
-{
- char *listening_at;
-
- /* we're relying on being single-threaded for this to be safe */
- f->saved_runtime_dir = g_strdup (g_getenv ("XDG_RUNTIME_DIR"));
- g_unsetenv ("XDG_RUNTIME_DIR");
-
- setup (f, addr);
-
- listening_at = dbus_server_get_address (f->server);
- g_test_message ("listening at %s", listening_at);
- /* we have fallen back to something in /tmp, either abstract or not */
- g_assert (g_str_has_prefix (listening_at, "unix:"));
- g_assert (strstr (listening_at, "=/tmp/") != NULL);
-
- dbus_free (listening_at);
-}
-#endif
-
static void
test_connect (Fixture *f,
gconstpointer addr G_GNUC_UNUSED)
@@ -166,76 +105,16 @@
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
g_assert (f->client_conn != NULL);
- test_connection_setup (f->ctx, f->client_conn);
+ dbus_connection_setup_with_g_main (f->client_conn, NULL);
while (f->server_conn == NULL)
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, 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)
- {
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
- }
-
- /* We get disconnected */
-
- while (g_queue_is_empty (&f->server_messages))
- {
- test_progress ('.');
- 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
test_message (Fixture *f,
gconstpointer addr)
{
@@ -255,8 +134,8 @@
while (g_queue_is_empty (&f->server_messages))
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
@@ -303,55 +182,13 @@
dbus_server_unref (f->server);
f->server = NULL;
}
-
- test_main_context_unref (f->ctx);
}
-#ifdef DBUS_UNIX
-static void
-teardown_no_runtime (Fixture *f,
- gconstpointer addr)
-{
- teardown (f, addr);
-
- /* we're relying on being single-threaded for this to be safe */
- if (f->saved_runtime_dir != NULL)
- g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE);
- else
- g_unsetenv ("XDG_RUNTIME_DIR");
- g_free (f->saved_runtime_dir);
-}
-
-static void
-teardown_runtime (Fixture *f,
- gconstpointer addr)
-{
- gchar *path;
-
- teardown (f, addr);
-
- /* the socket may exist */
- path = g_strdup_printf ("%s/bus", f->tmp_runtime_dir);
- g_assert (g_remove (path) == 0 || errno == ENOENT);
- g_free (path);
- /* there shouldn't be anything else in there */
- g_assert_cmpint (g_rmdir (f->tmp_runtime_dir), ==, 0);
-
- /* we're relying on being single-threaded for this to be safe */
- if (f->saved_runtime_dir != NULL)
- g_setenv ("XDG_RUNTIME_DIR", f->saved_runtime_dir, TRUE);
- else
- g_unsetenv ("XDG_RUNTIME_DIR");
- g_free (f->saved_runtime_dir);
- g_free (f->tmp_runtime_dir);
-}
-#endif
-
int
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
test_connect, teardown);
@@ -368,17 +205,7 @@
test_connect, teardown);
g_test_add ("/message/unix", Fixture, "unix:tmpdir=/tmp", setup,
test_message, teardown);
-
- g_test_add ("/connect/unix/runtime", Fixture,
- "unix:runtime=yes;unix:tmpdir=/tmp", setup_runtime, test_connect,
- teardown_runtime);
- g_test_add ("/connect/unix/no-runtime", Fixture,
- "unix:runtime=yes;unix:tmpdir=/tmp", setup_no_runtime, test_connect,
- teardown_no_runtime);
#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
deleted file mode 100644
index ee9bc52..0000000
--- a/test/manual-authz.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/* 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>
-
-#include <stdlib.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");
- abort ();
-}
-
-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/manual-dir-iter.c b/test/manual-dir-iter.c
deleted file mode 100644
index 21ac0e9..0000000
--- a/test/manual-dir-iter.c
+++ /dev/null
@@ -1,92 +0,0 @@
-#include <config.h>
-#include "test-utils.h"
-
-#include "dbus/dbus-macros.h"
-#include "dbus/dbus-sysdeps.h"
-
-static void oom (const char *doing) _DBUS_GNUC_NORETURN;
-static void die (const char *message) _DBUS_GNUC_NORETURN;
-
-void
-oom (const char *doing)
-{
- fprintf (stderr, "*** manual-dir-iter: OOM while %s\n", doing);
- exit (1);
-}
-
-void
-die (const char *message)
-{
- fprintf (stderr, "*** manual-dir-iter: %s\n", message);
- exit (1);
-}
-
-static void
-debug (const char *message)
-{
- fprintf (stdout, "+++ manual-dir-iter: %s\n", message);
-}
-
-int
-main (int argc,
- char **argv)
-{
- DBusString filename;
- DBusString dirname;
- DBusError tmp_error;
- DBusDirIter *dir;
-
- if (argc != 2)
- die ("syntax: manual-dir-iter <path>");
-
- dbus_error_init (&tmp_error);
-
- if (!_dbus_string_init (&filename))
- oom ("init filename");
-
- if (!_dbus_string_init (&dirname))
- oom ("init dirname");
-
- _dbus_string_append (&dirname, argv[1]);
- dir = _dbus_directory_open (&dirname, &tmp_error);
-
- if (dir == NULL)
- {
- fprintf (stderr, "could not open directory: %s: %s\n",
- tmp_error.name, tmp_error.message);
- exit(1);
- }
-
- while (_dbus_directory_get_next_file (dir, &filename, &tmp_error))
- {
- DBusString full_path;
- if (!_dbus_string_init (&full_path))
- {
- oom ("init full_path");
- }
-
- if (!_dbus_string_copy (&dirname, 0, &full_path, 0))
- {
- oom ("copying full_path to dirname");
- }
-
- if (!_dbus_concat_dir_and_file (&full_path, &filename))
- {
- oom ("concat full_path");
- }
- debug (_dbus_string_get_const_data (&filename));
- _dbus_string_free (&full_path);
- }
-
- if (dbus_error_is_set (&tmp_error))
- die (tmp_error.message);
-
- _dbus_string_free (&filename);
-
- if (dir)
- _dbus_directory_close (dir);
-
- _dbus_verbose ("*** Test dir name exiting\n");
-
- return 0;
-}
diff --git a/test/manual-paths.c b/test/manual-paths.c
deleted file mode 100644
index e392c5c..0000000
--- a/test/manual-paths.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Simple manual paths check
- *
- * syntax: manual-paths
- *
-*/
-
-#include "config.h"
-#include "dbus/dbus-list.h"
-#include "dbus/dbus-internals.h"
-#include "dbus/dbus-sysdeps.h"
-
-#include <stdio.h>
-
-static dbus_bool_t print_install_root()
-{
- char runtime_prefix[1000];
-
- if (!_dbus_get_install_root(runtime_prefix, sizeof(runtime_prefix)))
- {
- fprintf(stderr, "dbus_get_install_root() failed\n");
- return FALSE;
- }
- fprintf(stdout, "dbus_get_install_root() returned '%s'\n", runtime_prefix);
- return TRUE;
-}
-
-static dbus_bool_t print_service_dirs()
-{
- DBusList *dirs;
- DBusList *link;
- dirs = NULL;
-
- if (!_dbus_get_standard_session_servicedirs (&dirs))
- _dbus_assert_not_reached ("couldn't get standard dirs");
-
- while ((link = _dbus_list_pop_first_link (&dirs)))
- {
- printf ("default service dir: %s\n", (char *)link->data);
- dbus_free (link->data);
- _dbus_list_free_link (link);
- }
- dbus_free (dirs);
- return TRUE;
-}
-
-static dbus_bool_t print_replace_install_prefix(const char *s)
-{
- const char *s2 = _dbus_replace_install_prefix(s);
- if (!s2)
- return FALSE;
-
- fprintf(stdout, "replaced '%s' by '%s'\n", s, s2);
- return TRUE;
-}
-
-int
-main (int argc, char **argv)
-{
- if (!print_install_root())
- return -1;
-
- if (!print_service_dirs())
- return -2;
-
- if (!print_replace_install_prefix(DBUS_BINDIR "/dbus-daemon"))
- return -3;
-
- if (!print_replace_install_prefix("c:\\Windows\\System32\\testfile"))
- return -4;
-
- return 0;
-}
diff --git a/test/manual-tcp.c b/test/manual-tcp.c
deleted file mode 100644
index 64691c9..0000000
--- a/test/manual-tcp.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Simple manual tcp check
- *
- * supports:
- * - server listening check
- *
- * syntax: manual-tcp [<ipv4>|<ipv6>]
- *
-*/
-
-#include "config.h"
-#include "dbus/dbus-server-socket.h"
-
-#include <stdio.h>
-
-int
-main (int argc, char **argv)
-{
- DBusServer *server;
- DBusError error;
- int result = 0;
- int i;
-
- char *family = NULL;
-
- if (argc == 2)
- family = argv[1];
-
- for (i = 0; i < 1000; i++)
- {
- dbus_error_init (&error);
- server = _dbus_server_new_for_tcp_socket ("localhost", "localhost", "0", family, &error, FALSE);
- if (server == NULL)
- {
- printf("%d: %s %s\n",i, error.name, error.message);
- dbus_error_free(&error);
- result = -1;
- }
- else {
- printf("%d: %s \n",i, dbus_server_get_address(server));
- dbus_server_disconnect(server);
- dbus_server_unref(server);
- }
- }
- return result;
-}
diff --git a/test/marshal.c b/test/marshal.c
index 3353ec0..e9ac7e3 100644
--- a/test/marshal.c
+++ b/test/marshal.c
@@ -27,11 +27,9 @@
#include <config.h>
#include <glib.h>
-#include <string.h>
#include <dbus/dbus.h>
-
-#include "test-utils-glib.h"
+#include <dbus/dbus-glib-lowlevel.h>
typedef struct {
DBusError e;
@@ -246,30 +244,14 @@
main (int argc,
char **argv)
{
- int ret;
- char *aligned_le_blob;
- char *aligned_be_blob;
+ g_test_init (&argc, &argv, NULL);
- test_init (&argc, &argv);
-
- /* 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,
+ 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,
teardown);
- g_test_add ("/demarshal/needed/be", Fixture, aligned_be_blob, setup, test_needed,
+ g_test_add ("/demarshal/needed/be", Fixture, be_blob, setup, test_needed,
teardown);
- ret = g_test_run ();
- g_free (aligned_le_blob);
- g_free (aligned_be_blob);
- return ret;
+ return g_test_run ();
}
diff --git a/test/monitor.c b/test/monitor.c
deleted file mode 100644
index ad4b195..0000000
--- a/test/monitor.c
+++ /dev/null
@@ -1,1685 +0,0 @@
-/* Integration tests for monitor-mode D-Bus connections
- *
- * Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2015 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 <string.h>
-
-#include "test-utils-glib.h"
-
-typedef struct {
- const char *config_file;
- const char * const *match_rules;
- gboolean care_about_our_names;
-} Config;
-
-typedef struct {
- const Config *config;
- TestMainContext *ctx;
- DBusError e;
- GError *ge;
-
- gchar *address;
- GPid daemon_pid;
-
- DBusConnection *monitor;
- DBusConnection *sender;
- DBusConnection *recipient;
-
- GQueue monitored;
-
- const char *monitor_name;
- const char *sender_name;
- const char *recipient_name;
-
- DBusConnection *systemd;
- const char *systemd_name;
- DBusMessage *systemd_message;
- DBusConnection *activated;
- const char *activated_name;
- DBusMessage *activated_message;
-} Fixture;
-
-static const char * const no_match_rules[] = {
- NULL
-};
-
-static const char * const wildcard_match_rules[] = {
- "",
- NULL,
- FALSE
-};
-
-static const char * const eavesdrop_match_rules[] = {
- "eavesdrop=true",
- NULL,
- FALSE
-};
-
-static const char * const no_eavesdrop_match_rules[] = {
- "eavesdrop=false",
- NULL,
- FALSE
-};
-
-static const char * const selective_match_rules[] = {
- "interface='com.example.Interesting'",
- "interface='com.example.Fun'",
- NULL,
- FALSE
-};
-
-static Config forbidding_config = {
- "valid-config-files/forbidding.conf",
- NULL,
- FALSE
-};
-
-static Config wildcard_config = {
- NULL,
- wildcard_match_rules,
- FALSE
-};
-
-static Config selective_config = {
- NULL,
- selective_match_rules,
- FALSE
-};
-
-static Config no_rules_config = {
- NULL,
- no_match_rules,
- FALSE
-};
-
-static Config eavesdrop_config = {
- NULL,
- eavesdrop_match_rules,
- FALSE
-};
-
-static Config no_eavesdrop_config = {
- NULL,
- no_eavesdrop_match_rules,
- FALSE
-};
-
-#ifdef DBUS_UNIX
-static Config fake_systemd_config = {
- "valid-config-files/systemd-activation.conf",
- NULL,
- FALSE
-};
-#endif
-
-static Config side_effects_config = {
- NULL,
- NULL,
- TRUE
-};
-
-static inline const char *
-not_null2 (const char *x,
- const char *fallback)
-{
- if (x == NULL)
- return fallback;
-
- return x;
-}
-
-static inline const char *
-not_null (const char *x)
-{
- return not_null2 (x, "(null)");
-}
-
-#define log_message(m) _log_message (m, __FILE__, __LINE__)
-
-G_GNUC_UNUSED
-static void
-_log_message (DBusMessage *m,
- const char *file,
- int line)
-{
- g_test_message ("%s:%d: message type %d (%s)", file, line,
- dbus_message_get_type (m),
- dbus_message_type_to_string (dbus_message_get_type (m)));
- g_test_message ("\tfrom: %s",
- not_null2 (dbus_message_get_sender (m), "(dbus-daemon)"));
- g_test_message ("\tto: %s",
- not_null2 (dbus_message_get_destination (m), "(broadcast)"));
- g_test_message ("\tpath: %s",
- not_null (dbus_message_get_path (m)));
- g_test_message ("\tinterface: %s",
- not_null (dbus_message_get_interface (m)));
- g_test_message ("\tmember: %s",
- not_null (dbus_message_get_member (m)));
- g_test_message ("\tsignature: %s",
- not_null (dbus_message_get_signature (m)));
- g_test_message ("\terror name: %s",
- not_null (dbus_message_get_error_name (m)));
-
- if (strcmp ("s", dbus_message_get_signature (m)) == 0)
- {
- DBusError e = DBUS_ERROR_INIT;
- const char *s;
-
- dbus_message_get_args (m, &e,
- DBUS_TYPE_STRING, &s,
- DBUS_TYPE_INVALID);
- test_assert_no_error (&e);
- g_test_message ("\tstring payload: %s", s);
- }
-}
-
-/* these are macros so they get the right line number */
-
-#define assert_hello(m) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, DBUS_SERVICE_DBUS); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, "Hello"); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, ""); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
-} while (0)
-
-#define assert_hello_reply(m) \
-do { \
- DBusError _e = DBUS_ERROR_INIT; \
- const char *_s; \
- \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
- \
- dbus_message_get_args (m, &_e, \
- DBUS_TYPE_STRING, &_s, \
- DBUS_TYPE_INVALID); \
- test_assert_no_error (&_e); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
-} while (0)
-
-#define assert_name_acquired(m) \
-do { \
- DBusError _e = DBUS_ERROR_INIT; \
- const char *_s; \
- \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, "NameAcquired"); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
- \
- dbus_message_get_args (m, &_e, \
- DBUS_TYPE_STRING, &_s, \
- DBUS_TYPE_INVALID); \
- test_assert_no_error (&_e); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
-} while (0)
-
-#define assert_method_call(m, sender, \
- destination, path, iface, method, signature) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, method); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
-} while (0)
-
-#define assert_signal(m, \
- sender, path, iface, member, signature, \
- destination) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, member); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
-} while (0)
-
-#define assert_method_reply(m, sender, destination, signature) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
-} while (0)
-
-#define assert_error_reply(m, sender, destination, error_name) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_ERROR)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_error_name (m), ==, error_name); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
-} while (0)
-
-/* This is called after processing pending replies to our own method
- * calls, but before anything else.
- */
-static DBusHandlerResult
-monitor_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- Fixture *f = user_data;
-
- g_assert_cmpstr (dbus_message_get_interface (message), !=,
- "com.example.Tedious");
-
- /* we are not interested in the monitor getting NameAcquired or NameLost
- * for most tests */
- if (f->config == NULL || !f->config->care_about_our_names)
- {
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameAcquired") ||
- dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- DBusError e = DBUS_ERROR_INIT;
- const char *s;
-
- dbus_message_get_args (message, &e,
- DBUS_TYPE_STRING, &s,
- DBUS_TYPE_INVALID);
- test_assert_no_error (&e);
-
- if (strcmp (s, f->monitor_name) == 0)
- {
- /* ignore */
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- }
- }
-
- g_queue_push_tail (&f->monitored, dbus_message_ref (message));
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult
-recipient_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- g_assert_cmpstr (dbus_message_get_interface (message), !=,
- "com.example.CannotSend");
- g_assert_cmpstr (dbus_message_get_interface (message), !=,
- "com.example.CannotReceive");
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static DBusHandlerResult
-systemd_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- Fixture *f = user_data;
-
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameAcquired") ||
- dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- g_assert (f->systemd_message == NULL);
- f->systemd_message = dbus_message_ref (message);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static DBusHandlerResult
-activated_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- Fixture *f = user_data;
-
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameAcquired") ||
- dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- g_assert (f->activated_message == NULL);
- f->activated_message = dbus_message_ref (message);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void
-setup (Fixture *f,
- gconstpointer context)
-{
- f->config = context;
-
- f->ctx = test_main_context_get ();
-
- f->ge = NULL;
- dbus_error_init (&f->e);
-
- f->address = test_get_dbus_daemon (f->config ? f->config->config_file : NULL,
- TEST_USER_ME, &f->daemon_pid);
-
- if (f->address == NULL)
- return;
-
- f->monitor = test_connect_to_bus (f->ctx, f->address);
- f->monitor_name = dbus_bus_get_unique_name (f->monitor);
- f->sender = test_connect_to_bus (f->ctx, f->address);
- f->sender_name = dbus_bus_get_unique_name (f->sender);
- f->recipient = test_connect_to_bus (f->ctx, f->address);
- f->recipient_name = dbus_bus_get_unique_name (f->recipient);
-
- if (!dbus_connection_add_filter (f->monitor, monitor_filter, f, NULL))
- g_error ("OOM");
-
- if (!dbus_connection_add_filter (f->recipient, recipient_filter, f, NULL))
- g_error ("OOM");
-}
-
-static void
-become_monitor (Fixture *f)
-{
- DBusMessage *m;
- DBusPendingCall *pc;
- dbus_bool_t ok;
- DBusMessageIter appender, array_appender;
- const char * const *match_rules;
- int i;
- dbus_uint32_t zero = 0;
-
- dbus_connection_set_route_peer_messages (f->monitor, TRUE);
-
- if (f->config != NULL && f->config->match_rules != NULL)
- match_rules = f->config->match_rules;
- else
- match_rules = wildcard_match_rules;
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &appender);
-
- if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
- &array_appender))
- g_error ("OOM");
-
- for (i = 0; match_rules[i] != NULL; i++)
- {
- if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
- &match_rules[i]))
- g_error ("OOM");
- }
-
- if (!dbus_message_iter_close_container (&appender, &array_appender) ||
- !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) ||
- pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- ok = dbus_message_get_args (m, &f->e,
- DBUS_TYPE_INVALID);
- test_assert_no_error (&f->e);
- g_assert (ok);
-
- dbus_pending_call_unref (pc);
- dbus_message_unref (m);
- m = NULL;
-}
-
-/*
- * Test what happens if the method call arguments are invalid.
- */
-static void
-test_invalid (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
- DBusPendingCall *pc;
- dbus_bool_t ok;
- DBusMessageIter appender, array_appender;
- dbus_uint32_t zero = 0;
- dbus_uint32_t invalid_flags = G_MAXUINT32;
- const char *s;
-
- if (f->address == NULL)
- return;
-
- dbus_connection_set_route_peer_messages (f->monitor, TRUE);
-
- /* Try to become a monitor but specify nonzero flags - not allowed */
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &appender);
-
- if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
- &array_appender))
- g_error ("OOM");
-
- if (!dbus_message_iter_close_container (&appender, &array_appender) ||
- !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32,
- &invalid_flags))
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) ||
- pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
- g_assert_cmpstr (dbus_message_get_error_name (m), ==,
- DBUS_ERROR_INVALID_ARGS);
-
- /* Try to become a monitor but specify a bad match rule -
- * also not allowed */
-
- dbus_pending_call_unref (pc);
- dbus_message_unref (m);
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &appender);
-
- if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
- &array_appender))
- g_error ("OOM");
-
- /* Syntactically incorrect match rule taken from #92298 - was probably
- * intended to be path='/modules/...'
- */
- s = "interface='org.kde.walletd',member='/modules/kwalletd/org.kde.KWallet/walletOpened'";
-
- if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
- &s) ||
- !dbus_message_iter_close_container (&appender, &array_appender) ||
- !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero) ||
- !dbus_connection_send_with_reply (f->monitor, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) ||
- pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
- g_assert_cmpstr (dbus_message_get_error_name (m), ==,
- DBUS_ERROR_MATCH_RULE_INVALID);
-
- dbus_pending_call_unref (pc);
- dbus_message_unref (m);
-
- /* We did not become a monitor, so we can still call methods. */
-
- pc = NULL;
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetId");
-
- if (m == NULL)
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) ||
- pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- ok = dbus_message_get_args (m, &f->e,
- DBUS_TYPE_STRING, &s,
- DBUS_TYPE_INVALID);
- test_assert_no_error (&f->e);
- g_assert (ok);
- g_assert_cmpstr (s, !=, NULL);
- g_assert_cmpstr (s, !=, "");
-
- dbus_pending_call_unref (pc);
- dbus_message_unref (m);
-}
-
-/*
- * Test the side-effects of becoming a monitor.
- */
-static void
-test_become_monitor (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
- int ret;
- dbus_bool_t got_unique = FALSE, got_a = FALSE, got_b = FALSE, got_c = FALSE;
- dbus_bool_t lost_unique = FALSE, lost_a = FALSE, lost_b = FALSE, lost_c = FALSE;
-
- if (f->address == NULL)
- return;
-
- ret = dbus_bus_request_name (f->monitor, "com.example.A",
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-
- ret = dbus_bus_request_name (f->monitor, "com.example.B",
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-
- ret = dbus_bus_request_name (f->monitor, "com.example.C",
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-
- while (!got_unique || !got_a || !got_b || !got_c)
- {
- if (g_queue_is_empty (&f->monitored))
- test_main_context_iterate (f->ctx, TRUE);
-
- while ((m = g_queue_pop_head (&f->monitored)) != NULL)
- {
- if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
- "NameAcquired"))
- {
- const char *name;
- dbus_bool_t ok = dbus_message_get_args (m, &f->e,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
-
- g_assert_cmpstr (dbus_message_get_path (m), ==,
- DBUS_PATH_DBUS);
-
- test_assert_no_error (&f->e);
- g_assert (ok);
-
- if (g_str_equal (name, f->monitor_name))
- {
- g_assert (!got_unique);
- got_unique = TRUE;
- }
- else if (g_str_equal (name, "com.example.A"))
- {
- g_assert (!got_a);
- got_a = TRUE;
- }
- else if (g_str_equal (name, "com.example.B"))
- {
- g_assert (!got_b);
- got_b = TRUE;
- }
- else
- {
- g_assert_cmpstr (name, ==, "com.example.C");
- g_assert (!got_c);
- got_c = TRUE;
- }
- }
- else
- {
- g_error ("unexpected message %s.%s",
- dbus_message_get_interface (m),
- dbus_message_get_member (m));
- }
-
- dbus_message_unref (m);
- }
- }
-
- become_monitor (f);
-
- while (!lost_unique || !lost_a || !lost_b || !lost_c)
- {
- if (g_queue_is_empty (&f->monitored))
- test_main_context_iterate (f->ctx, TRUE);
-
- while ((m = g_queue_pop_head (&f->monitored)) != NULL)
- {
- if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- const char *name;
- dbus_bool_t ok = dbus_message_get_args (m, &f->e,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID);
-
- test_assert_no_error (&f->e);
- g_assert (ok);
-
- if (g_str_equal (name, f->monitor_name))
- {
- g_assert (!lost_unique);
- lost_unique = TRUE;
- }
- else if (g_str_equal (name, "com.example.A"))
- {
- g_assert (!lost_a);
- lost_a = TRUE;
- }
- else if (g_str_equal (name, "com.example.B"))
- {
- g_assert (!lost_b);
- lost_b = TRUE;
- }
- else
- {
- g_assert_cmpstr (name, ==, "com.example.C");
- g_assert (!lost_c);
- lost_c = TRUE;
- }
- }
- else
- {
- g_error ("unexpected message %s.%s",
- dbus_message_get_interface (m),
- dbus_message_get_member (m));
- }
-
- dbus_message_unref (m);
- }
- }
-
- /* Calling methods is forbidden; we get disconnected. */
- dbus_bus_add_match (f->monitor, "", &f->e);
- g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_NO_REPLY);
- g_assert (!dbus_connection_get_is_connected (f->monitor));
-
- while (TRUE)
- {
- if (g_queue_is_empty (&f->monitored))
- test_main_context_iterate (f->ctx, TRUE);
-
- /* When we iterate all the connection's messages, we see ourselves
- * losing all our names, then we're disconnected. */
- while ((m = g_queue_pop_head (&f->monitored)) != NULL)
- {
- if (dbus_message_is_signal (m, DBUS_INTERFACE_LOCAL, "Disconnected"))
- {
- dbus_message_unref (m);
- goto disconnected;
- }
- else
- {
- g_error ("unexpected message %s.%s",
- dbus_message_get_interface (m),
- dbus_message_get_member (m));
- }
-
- dbus_message_unref (m);
- }
- }
-
-disconnected:
-
- g_assert (lost_a);
- g_assert (lost_b);
- g_assert (lost_c);
-}
-
-static void
-test_broadcast (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
- test_assert_no_error (&f->e);
-
- become_monitor (f);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal1");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal2");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal3");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 3)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.bar",
- "BroadcastSignal1", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.bar",
- "BroadcastSignal2", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.bar",
- "BroadcastSignal3", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_forbidden_broadcast (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
- test_assert_no_error (&f->e);
-
- become_monitor (f);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
- "BroadcastSignal1");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
- "BroadcastSignal2");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
- "BroadcastSignal3");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 6)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
- "BroadcastSignal1", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.CannotReceive",
- "BroadcastSignal2", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
- "BroadcastSignal3", "", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_unicast_signal (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 3)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal1", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal2", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal3", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_forbidden (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
- "UnicastSignal1");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
- "UnicastSignal2");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
- "UnicastSignal3");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 6)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.CannotSend", "UnicastSignal1", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.CannotReceive", "UnicastSignal2", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.CannotSend", "UnicastSignal3", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_method_call (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- /* regression test for
- * https://bugs.freedesktop.org/show_bug.cgi?id=90952 */
- m = dbus_message_new_method_call (f->recipient_name, "/foo",
- DBUS_INTERFACE_PEER, "Ping");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
- DBUS_INTERFACE_PEER, "Ping", "");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_reply (m, f->recipient_name, f->sender_name, "");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-
- m = dbus_message_new_method_call (f->recipient_name, "/foo", "com.example.bar",
- "Call1");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
- "com.example.bar", "Call1", "");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, f->recipient_name, f->sender_name,
- DBUS_ERROR_UNKNOWN_METHOD);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_forbidden_method_call (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- m = dbus_message_new_method_call (f->recipient_name, "/foo",
- "com.example.CannotSend", "Call1");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
- "com.example.CannotSend", "Call1", "");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-
- m = dbus_message_new_method_call (f->recipient_name, "/foo",
- "com.example.CannotReceive", "Call2");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
- "com.example.CannotReceive", "Call2", "");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- DBUS_ERROR_ACCESS_DENIED);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_dbus_daemon (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
- int res;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- res = dbus_bus_request_name (f->sender, "com.example.Sender",
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (res, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-
- res = dbus_bus_release_name (f->sender, "com.example.Sender", &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (res, ==, DBUS_RELEASE_NAME_REPLY_RELEASED);
-
- while (g_queue_get_length (&f->monitored) < 8)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "RequestName", "su");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameOwnerChanged", "sss", NULL);
- dbus_message_unref (m);
-
- /* FIXME: should we get this? */
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameAcquired", "s", f->sender_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "ReleaseName", "s");
- dbus_message_unref (m);
-
- /* FIXME: should we get this? */
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameLost", "s", f->sender_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameOwnerChanged", "sss", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-static void
-test_selective (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- /* Match rules added before becoming a monitor should be cleared:
- * if they weren't, this test would get Interesting twice, then Tedious,
- * and only see Fun after that. */
- dbus_bus_add_match (f->monitor,
- "eavesdrop='true',interface='com.example.Interesting'", &f->e);
- test_assert_no_error (&f->e);
- dbus_bus_add_match (f->monitor,
- "eavesdrop='true',interface='com.example.Tedious'", &f->e);
- test_assert_no_error (&f->e);
-
- become_monitor (f);
-
- m = dbus_message_new_signal ("/foo", "com.example.Interesting",
- "UnicastSignal1");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.Tedious",
- "UnicastSignal2");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- m = dbus_message_new_signal ("/foo", "com.example.Fun",
- "UnicastSignal3");
- if (!dbus_message_set_destination (m, f->recipient_name))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- /* We get the interesting signal and the fun signal, but not the tedious
- * signal. */
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.Interesting", "UnicastSignal1", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.Fun", "UnicastSignal3", "", f->recipient_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- g_assert (m == NULL);
-}
-
-#ifdef DBUS_UNIX
-/* currently only used for the systemd activation test */
-static void
-expect_new_connection (Fixture *f)
-{
- DBusMessage *m;
-
- while (g_queue_get_length (&f->monitored) < 4)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_hello (m);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_hello_reply (m);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameOwnerChanged", "sss", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_name_acquired (m);
- dbus_message_unref (m);
-}
-
-/* currently only used for the systemd activation test */
-static void
-take_well_known_name (Fixture *f,
- DBusConnection *connection,
- const char *name)
-{
- int ret;
-
- ret = dbus_bus_request_name (connection, name,
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-}
-
-/* currently only used for the systemd activation test */
-static void
-expect_take_well_known_name (Fixture *f,
- DBusConnection *connection,
- const char *name)
-{
- DBusMessage *m;
- const char *connection_name = dbus_bus_get_unique_name (connection);
-
- while (g_queue_get_length (&f->monitored) < 4)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_call (m, connection_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "RequestName", "su");
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameOwnerChanged", "sss", NULL);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
- "NameAcquired", "s", connection_name);
- dbus_message_unref (m);
-
- m = g_queue_pop_head (&f->monitored);
- assert_method_reply (m, DBUS_SERVICE_DBUS, connection_name, "u");
- dbus_message_unref (m);
-}
-
-static void
-test_activation (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- become_monitor (f);
-
- /* The sender sends a message to an activatable service. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable1"))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- /* We observe the activation request, and the message that caused it,
- * before systemd has even joined the bus. */
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal1", "",
- "com.example.SystemdActivatable1");
- dbus_message_unref (m);
-
- /* The fake systemd connects to the bus. */
- f->systemd = test_connect_to_bus (f->ctx, f->address);
- if (!dbus_connection_add_filter (f->systemd, systemd_filter, f, NULL))
- g_error ("OOM");
- f->systemd_name = dbus_bus_get_unique_name (f->systemd);
-
- expect_new_connection (f);
- take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
- expect_take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
-
- /* It gets its activation request. */
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* systemd starts the activatable service. */
- f->activated = test_connect_to_bus (f->ctx, f->address);
- if (!dbus_connection_add_filter (f->activated, activated_filter,
- f, NULL))
- g_error ("OOM");
- f->activated_name = dbus_bus_get_unique_name (f->activated);
-
- expect_new_connection (f);
- take_well_known_name (f, f->activated, "com.example.SystemdActivatable1");
- expect_take_well_known_name (f, f->activated,
- "com.example.SystemdActivatable1");
-
- /* The message is delivered to the activatable service. */
- while (f->activated_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->activated_message;
- f->activated_message = NULL;
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal1", "",
- "com.example.SystemdActivatable1");
- dbus_message_unref (m);
-
- /* The sender sends a message to a different activatable service. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable2"))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- /* This time systemd is already ready for it. */
- while (g_queue_get_length (&f->monitored) < 2 ||
- f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* The monitor sees the activation request and the signal that
- * prompted it.*/
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal2", "",
- "com.example.SystemdActivatable2");
- dbus_message_unref (m);
-
- /* The activatable service takes its name. Here I'm faking it by using
- * an existing connection. */
- take_well_known_name (f, f->activated, "com.example.SystemdActivatable2");
-
- /* The message is delivered to the activatable service.
- * Implementation detail: the monitor sees this happen before it even
- * sees that the name request happened, which is pretty odd. */
- while (f->activated_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->activated_message;
- f->activated_message = NULL;
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal2", "",
- "com.example.SystemdActivatable2");
- dbus_message_unref (m);
-
- expect_take_well_known_name (f, f->activated,
- "com.example.SystemdActivatable2");
-
- /* A third activation. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable3"))
- g_error ("OOM");
- dbus_connection_send (f->sender, m, NULL);
- dbus_message_unref (m);
-
- /* Once again, we see the activation request and the reason. */
- while (g_queue_get_length (&f->monitored) < 2)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
- m = g_queue_pop_head (&f->monitored);
- assert_signal (m, f->sender_name, "/foo",
- "com.example.bar", "UnicastSignal3", "",
- "com.example.SystemdActivatable3");
- dbus_message_unref (m);
-
- /* systemd gets the request too. */
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* This time activation fails */
- m = dbus_message_new_signal ("/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Activator", "ActivationFailure");
-
- do
- {
- const char *unit = "dbus-com.example.SystemdActivatable3.service";
- const char *error_name = "com.example.Nope";
- const char *error_message = "Computer says no";
-
- if (!dbus_message_append_args (m,
- DBUS_TYPE_STRING, &unit,
- DBUS_TYPE_STRING, &error_name,
- DBUS_TYPE_STRING, &error_message,
- DBUS_TYPE_INVALID))
- g_error ("OOM");
- }
- while (0);
-
- if (!dbus_message_set_destination (m, "org.freedesktop.DBus"))
- g_error ("OOM");
- dbus_connection_send (f->systemd, m, NULL);
- dbus_message_unref (m);
-
- /* The monitor sees activation fail */
-
- /* Once again, we see the activation request and the reason. */
- while (g_queue_get_length (&f->monitored) < 1)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = g_queue_pop_head (&f->monitored);
- assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
- "com.example.Nope");
- dbus_message_unref (m);
-}
-#endif /* DBUS_UNIX */
-
-static void
-teardown (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
-{
- dbus_error_free (&f->e);
- g_clear_error (&f->ge);
-
- if (f->monitor != NULL)
- {
- dbus_connection_remove_filter (f->monitor, monitor_filter, f);
- dbus_connection_close (f->monitor);
- dbus_connection_unref (f->monitor);
- f->monitor = NULL;
- }
-
- if (f->sender != NULL)
- {
- dbus_connection_close (f->sender);
- dbus_connection_unref (f->sender);
- f->sender = NULL;
- }
-
- if (f->recipient != NULL)
- {
- dbus_connection_remove_filter (f->recipient, recipient_filter, f);
- dbus_connection_close (f->recipient);
- dbus_connection_unref (f->recipient);
- f->recipient = NULL;
- }
-
- if (f->systemd != NULL)
- {
- dbus_connection_remove_filter (f->systemd, systemd_filter, f);
- dbus_connection_close (f->systemd);
- dbus_connection_unref (f->systemd);
- f->systemd = NULL;
- }
-
- if (f->activated != NULL)
- {
- dbus_connection_remove_filter (f->activated, activated_filter, f);
- dbus_connection_close (f->activated);
- dbus_connection_unref (f->activated);
- f->activated = NULL;
- }
-
- test_kill_pid (f->daemon_pid);
- g_spawn_close_pid (f->daemon_pid);
-
- test_main_context_unref (f->ctx);
-
- g_queue_foreach (&f->monitored, (GFunc) dbus_message_unref, NULL);
- g_queue_clear (&f->monitored);
-
- g_free (f->address);
-}
-
-int
-main (int argc,
- char **argv)
-{
- test_init (&argc, &argv);
-
- g_test_add ("/monitor/invalid", Fixture, NULL,
- setup, test_invalid, teardown);
- g_test_add ("/monitor/become", Fixture, &side_effects_config,
- setup, test_become_monitor, teardown);
- g_test_add ("/monitor/broadcast", Fixture, NULL,
- setup, test_broadcast, teardown);
- g_test_add ("/monitor/forbidden-broadcast", Fixture, &forbidding_config,
- setup, test_forbidden_broadcast, teardown);
- g_test_add ("/monitor/unicast-signal", Fixture, NULL,
- setup, test_unicast_signal, teardown);
- g_test_add ("/monitor/forbidden", Fixture, &forbidding_config,
- setup, test_forbidden, teardown);
- g_test_add ("/monitor/method-call", Fixture, NULL,
- setup, test_method_call, teardown);
- g_test_add ("/monitor/forbidden-method", Fixture, &forbidding_config,
- setup, test_forbidden_method_call, teardown);
- g_test_add ("/monitor/dbus-daemon", Fixture, NULL,
- setup, test_dbus_daemon, teardown);
- g_test_add ("/monitor/selective", Fixture, &selective_config,
- setup, test_selective, teardown);
- g_test_add ("/monitor/wildcard", Fixture, &wildcard_config,
- setup, test_unicast_signal, teardown);
- g_test_add ("/monitor/no-rule", Fixture, &no_rules_config,
- setup, test_unicast_signal, teardown);
- g_test_add ("/monitor/eavesdrop", Fixture, &eavesdrop_config,
- setup, test_unicast_signal, teardown);
- g_test_add ("/monitor/no-eavesdrop", Fixture, &no_eavesdrop_config,
- setup, test_unicast_signal, teardown);
-
-#ifdef DBUS_UNIX
- /* this relies on the systemd activation code path */
- g_test_add ("/monitor/activation", Fixture, &fake_systemd_config,
- setup, test_activation, teardown);
-#endif
-
- return g_test_run ();
-}
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index 3b7fcc6..6aaf178 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -1,52 +1,35 @@
+# Everything in this directory is statically-linked to libdbus-internal
AM_CPPFLAGS = \
-I$(top_srcdir) \
- $(DBUS_STATIC_BUILD_CPPFLAGS) \
-DDBUS_COMPILATION \
+ -DDBUS_STATIC_BUILD \
$(NULL)
# if assertions are enabled, improve backtraces
AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
-TEST_EXTENSIONS = .sh
-
-SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
-SH_LOG_COMPILER = $(SHELL)
-
## 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
-TESTS =
-
-if DBUS_ENABLE_EMBEDDED_TESTS
-if DBUS_UNIX
-AM_TESTS_ENVIRONMENT = \
- export DBUS_TOP_BUILDDIR=@abs_top_builddir@; \
- export DBUS_TOP_SRCDIR=@abs_top_srcdir@; \
- export PYTHON=@PYTHON@; \
- export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \
- export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \
- export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \
- $(NULL)
-
-TESTS += \
- run-test.sh \
- run-test-systemserver.sh \
- $(NULL)
-endif
+if DBUS_BUILD_TESTS
+TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@ PYTHON=@PYTHON@
+TESTS=run-test.sh run-test-systemserver.sh
+else
+TESTS=
endif
EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py test-activation-forking.py
-if DBUS_ENABLE_EMBEDDED_TESTS
+if DBUS_BUILD_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
## build even when not doing "make check"
noinst_PROGRAMS=test-pending-call-dispatch test-pending-call-timeout test-threads-init test-ids test-shutdown test-privserver test-privserver-client test-autolaunch
-test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-1.la
-test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-1.la
-test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-1.la
-test_ids_LDADD=$(top_builddir)/dbus/libdbus-1.la
+test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-internal.la
+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
diff --git a/test/name-test/run-test-systemserver.sh b/test/name-test/run-test-systemserver.sh
index 9926cad..afd1f04 100755
--- a/test/name-test/run-test-systemserver.sh
+++ b/test/name-test/run-test-systemserver.sh
@@ -1,4 +1,14 @@
#! /bin/sh
+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
+
+ exit 1
+}
SCRIPTNAME=$0
MODE=$1
@@ -17,73 +27,25 @@
fi
if test -n "$DBUS_TEST_MONITOR"; then
- dbus-monitor --session >&2 &
+ 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
+ echo "Didn't get expected failure; output was:"
+ echo "====="
+ cat echo-error-output.tmp
+ echo "====="
+ exit 1
+fi
-# Translate a command and exit status into TAP syntax.
-# Usage: interpret_result $? description-of-test
-# Uses global variable $test_num.
-interpret_result () {
- e="$1"
- shift
- case "$e" in
- (0)
- echo "ok $test_num $*"
- ;;
- (77)
- echo "ok $test_num # SKIP $*"
- ;;
- (*)
- echo "not ok $test_num $*"
- ;;
- esac
- test_num=$(( $test_num + 1 ))
-}
+echo "running test echo signal"
+if test "x$PYTHON" = "x:"; then
+ echo "Skipped test-echo-signal: Python interpreter not found"
+elif ! $PYTHON $DBUS_TOP_SRCDIR/test/name-test/test-wait-for-echo.py; then
+ echo "Failed test-wait-for-echo"
+ exit 1
+fi
-dbus_send_test () {
- t="$1"
- expected_exit="$2"
- phrase="$3"
- shift 3
- e=0
- echo "# running test $t"
- "${DBUS_TOP_BUILDDIR}/libtool" --mode=execute $DEBUG "$DBUS_TOP_BUILDDIR/tools/dbus-send" "$@" > output.tmp 2>&1 || e=$?
- if [ $e != $expected_exit ]; then
- sed -e 's/^/# /' < output.tmp
- interpret_result "1" "$t" "$@" "(expected exit status $expected_exit, got $e)"
- return
- fi
- echo "# parsing results of test $t"
- if ! grep -q "$phrase" output.tmp; then
- sed -e 's/^/# /' < output.tmp
- interpret_result "1" "$t" "$@" "(Did not see \"$phrase\" in output)"
- return
- fi
- interpret_result "0" "$t" "$@" "(Saw \"$phrase\" in output as expected)"
- rm -f output.tmp
-}
-
-py_test () {
- t="$1"
- shift
- if test "x$PYTHON" = "x:"; then
- interpret_result 77 "$t" "(Python interpreter not found)"
- else
- e=0
- echo "# running test $t"
- $PYTHON "$DBUS_TOP_SRCDIR/test/name-test/$t" "$@" >&2 || e=$?
- interpret_result "$e" "$t" "$@"
- fi
-}
-
-test_num=1
-# TAP syntax: we plan to run 2 tests
-echo "1..2"
-
-dbus_send_test test-expected-echo-fail 1 DBus.Error --print-reply --dest=org.freedesktop.DBus.TestSuiteEchoService /org/freedesktop/TestSuite org.freedesktop.TestSuite.Echo string:hi
-py_test test-wait-for-echo.py
+exit 0
diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh
index 8b9e7ad..cad5937 100644
--- a/test/name-test/run-test.sh
+++ b/test/name-test/run-test.sh
@@ -1,5 +1,17 @@
#! /bin/sh
+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
+
+ exit 1
+}
+
+
SCRIPTNAME=$0
MODE=$1
@@ -15,66 +27,34 @@
fi
if test -n "$DBUS_TEST_MONITOR"; then
- dbus-monitor --session >&2 &
+ 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"
-# Translate a command and exit status into TAP syntax.
-# Usage: interpret_result $? description-of-test
-# Uses global variable $test_num.
-interpret_result () {
- e="$1"
- shift
- case "$e" in
- (0)
- echo "ok $test_num $*"
- ;;
- (77)
- echo "ok $test_num # SKIP $*"
- ;;
- (*)
- echo "not ok $test_num $*"
- ;;
- esac
- test_num=$(( $test_num + 1 ))
-}
+echo "running test-pending-call-dispatch"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-pending-call-dispatch || die "test-pending-call-dispatch failed"
-c_test () {
- t="$1"
- shift
- e=0
- echo "# running test $t"
- "${DBUS_TOP_BUILDDIR}/libtool" --mode=execute $DEBUG "$DBUS_TOP_BUILDDIR/test/name-test/$t" "$@" >&2 || e=$?
- echo "# exit status $e"
- interpret_result "$e" "$t" "$@"
-}
+echo "running test-pending-call-timeout"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-pending-call-timeout || die "test-pending-call-timeout failed"
-py_test () {
- t="$1"
- shift
- if test "x$PYTHON" = "x:"; then
- interpret_result 77 "$t" "(Python interpreter not found)"
- else
- e=0
- echo "# running test $t"
- $PYTHON "$DBUS_TOP_SRCDIR/test/name-test/$t" "$@" >&2 || e=$?
- interpret_result "$e" "$t" "$@"
- fi
-}
+echo "running test-threads-init"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-threads-init || die "test-threads-init failed"
-test_num=1
-# TAP test plan: we will run 8 tests
-echo "1..8"
+echo "running test-privserver-client"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-privserver-client || die "test-privserver-client failed"
-c_test test-ids
-c_test test-pending-call-dispatch
-c_test test-pending-call-timeout
-c_test test-threads-init
-c_test test-privserver-client
-c_test test-shutdown
-py_test test-activation-forking.py
-c_test test-autolaunch
+echo "running test-shutdown"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-shutdown || die "test-shutdown failed"
+
+echo "running test activation forking"
+if test "x$PYTHON" = "x:"; then
+ echo "Skipped test-activation-forking: Python interpreter not found"
+elif ! $PYTHON $DBUS_TOP_SRCDIR/test/name-test/test-activation-forking.py; then
+ echo "Failed test-activation-forking"
+ exit 1
+fi
+
+echo "running test-autolaunch"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-autolaunch || die "test-autolaunch failed"
diff --git a/test/name-test/test-activation-forking.py b/test/name-test/test-activation-forking.py
index f98537e..0d82075 100644
--- a/test/name-test/test-activation-forking.py
+++ b/test/name-test/test-activation-forking.py
@@ -3,7 +3,7 @@
import os,sys
try:
- from gi.repository import GObject
+ import gobject
import dbus
import dbus.mainloop.glib
except:
@@ -11,7 +11,7 @@
sys.exit(0)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-loop = GObject.MainLoop()
+loop = gobject.MainLoop()
exitcode = 0
@@ -54,7 +54,7 @@
if counter == 0:
print "Failed to get NameOwnerChanged for TestSuiteForkingEchoService"
sys.exit(1)
-GObject.timeout_add(15000, check_counter)
+gobject.timeout_add(15000, check_counter)
loop.run()
sys.exit(0)
diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c
index 8b5206a..5e51989 100644
--- a/test/name-test/test-autolaunch.c
+++ b/test/name-test/test-autolaunch.c
@@ -1,5 +1,3 @@
-#include "config.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -16,23 +14,21 @@
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 X11 autolaunch was enabled, we expect dbus-launch to have worked. */
- if (_dbus_getenv ("DISPLAY") != NULL && dbus_error_is_set (&error))
+ if (dbus_error_is_set (&error))
{
fprintf (stderr, "*** Failed to autolaunch session bus: %s\n",
error.message);
dbus_error_free (&error);
return 1;
}
-#endif
-
+#else
/* 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. */
@@ -42,6 +38,7 @@
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 a517e2a..5e22852 100644
--- a/test/name-test/test-threads-init.c
+++ b/test/name-test/test-threads-init.c
@@ -149,6 +149,12 @@
&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);
+
_run_iteration (conn);
_dbus_connection_test_get_locks (conn, &mutex2,
&dispatch_mutex2,
diff --git a/test/name-test/test-wait-for-echo.py b/test/name-test/test-wait-for-echo.py
index 49ecbb4..bd09e45 100755
--- a/test/name-test/test-wait-for-echo.py
+++ b/test/name-test/test-wait-for-echo.py
@@ -3,15 +3,15 @@
import os,sys
try:
+ import gobject
import dbus
import dbus.mainloop.glib
- from gi.repository import GObject
except:
print "Failed import, aborting test"
sys.exit(0)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-loop = GObject.MainLoop()
+loop = gobject.MainLoop()
exitcode = 0
@@ -21,7 +21,7 @@
exitcode = 1
loop.quit()
-GObject.timeout_add(7000, handle_noreceipt)
+gobject.timeout_add(7000, handle_noreceipt)
bus = dbus.SessionBus()
diff --git a/test/relay.c b/test/relay.c
index e275c16..f4129d0 100644
--- a/test/relay.c
+++ b/test/relay.c
@@ -29,8 +29,7 @@
#include <glib.h>
#include <dbus/dbus.h>
-
-#include "test-utils-glib.h"
+#include <dbus/dbus-glib-lowlevel.h>
/* This is basically a miniature dbus-daemon. We relay messages from the client
* on the left to the client on the right.
@@ -44,7 +43,6 @@
*/
typedef struct {
- TestMainContext *ctx;
DBusError e;
DBusServer *server;
@@ -115,14 +113,13 @@
f->right_server_conn = dbus_connection_ref (server_conn);
}
- test_connection_setup (f->ctx, server_conn);
+ dbus_connection_setup_with_g_main (server_conn, NULL);
}
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);
@@ -132,7 +129,7 @@
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- test_server_setup (f->ctx, f->server);
+ dbus_server_setup_with_g_main (f->server, NULL);
}
static void
@@ -151,25 +148,25 @@
f->left_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->left_client_conn != NULL);
- test_connection_setup (f->ctx, f->left_client_conn);
+ dbus_connection_setup_with_g_main (f->left_client_conn, NULL);
while (f->left_server_conn == NULL)
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
f->right_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->right_client_conn != NULL);
- test_connection_setup (f->ctx, f->right_client_conn);
+ dbus_connection_setup_with_g_main (f->right_client_conn, NULL);
dbus_free (address);
while (f->right_server_conn == NULL)
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
have_mem = dbus_connection_add_filter (f->right_client_conn,
@@ -210,8 +207,8 @@
while (g_queue_get_length (&f->messages) < 2)
{
- test_progress ('.');
- test_main_context_iterate (f->ctx, TRUE);
+ g_print (".");
+ g_main_context_iteration (NULL, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 2);
@@ -240,7 +237,7 @@
/* 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);
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
for (i = 0; i < MANY; i++)
{
@@ -256,7 +253,7 @@
{
while (g_queue_is_empty (&f->messages))
{
- test_main_context_iterate (f->ctx, TRUE);
+ g_main_context_iteration (NULL, TRUE);
}
while ((incoming = g_queue_pop_head (&f->messages)) != NULL)
@@ -273,7 +270,6 @@
{
if (f->left_client_conn != NULL)
{
- test_connection_shutdown(NULL, f->left_client_conn);
dbus_connection_close (f->left_client_conn);
dbus_connection_unref (f->left_client_conn);
f->left_client_conn = NULL;
@@ -281,7 +277,6 @@
if (f->right_client_conn != NULL)
{
- test_connection_shutdown(NULL, f->right_client_conn);
dbus_connection_close (f->right_client_conn);
dbus_connection_unref (f->right_client_conn);
f->right_client_conn = NULL;
@@ -289,7 +284,6 @@
if (f->left_server_conn != NULL)
{
- test_connection_shutdown(NULL, f->left_server_conn);
dbus_connection_close (f->left_server_conn);
dbus_connection_unref (f->left_server_conn);
f->left_server_conn = NULL;
@@ -297,7 +291,6 @@
if (f->right_server_conn != NULL)
{
- test_connection_shutdown(NULL, f->right_server_conn);
dbus_connection_close (f->right_server_conn);
dbus_connection_unref (f->right_server_conn);
f->right_server_conn = NULL;
@@ -309,15 +302,14 @@
dbus_server_unref (f->server);
f->server = NULL;
}
-
- test_main_context_unref (f->ctx);
}
int
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/connect", Fixture, NULL, setup,
test_connect, teardown);
diff --git a/test/sd-activation.c b/test/sd-activation.c
deleted file mode 100644
index f045012..0000000
--- a/test/sd-activation.c
+++ /dev/null
@@ -1,559 +0,0 @@
-/* Unit tests for systemd activation.
- *
- * Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2015 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 <string.h>
-
-#include "test-utils-glib.h"
-
-typedef struct {
- TestMainContext *ctx;
- DBusError e;
- GError *ge;
-
- gchar *address;
- GPid daemon_pid;
-
- DBusConnection *caller;
- const char *caller_name;
- DBusConnection *systemd;
- const char *systemd_name;
- DBusMessage *systemd_message;
- DBusConnection *activated;
- const char *activated_name;
- DBusMessage *activated_message;
-} Fixture;
-
-/* this is a macro so it gets the right line number */
-#define assert_signal(m, \
- sender, path, iface, member, signature, \
- destination) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, member); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
-} while (0)
-
-#define assert_method_call(m, sender, \
- destination, path, iface, method, signature) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, method); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
-} while (0)
-
-#define assert_method_reply(m, sender, destination, signature) \
-do { \
- g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
- ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
- g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
- g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
- g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
- g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
- g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
- g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
-} while (0)
-
-static DBusHandlerResult
-systemd_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- Fixture *f = user_data;
-
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameAcquired") ||
- dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- g_test_message("sender %s iface %s member %s",
- dbus_message_get_sender (message),
- dbus_message_get_interface (message),
- dbus_message_get_member (message));
-
-
- g_assert (f->systemd_message == NULL);
- f->systemd_message = dbus_message_ref (message);
-
- if (dbus_message_is_method_call (message, "org.freedesktop.systemd1.Manager",
- "SetEnvironment"))
- {
- g_assert (dbus_message_get_no_reply (message));
- g_test_message("got call");
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static DBusHandlerResult
-activated_filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- Fixture *f = user_data;
-
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameAcquired") ||
- dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
- "NameLost"))
- {
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- g_assert (f->activated_message == NULL);
- f->activated_message = dbus_message_ref (message);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void
-setup (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
-{
- f->ctx = test_main_context_get ();
-
- f->ge = NULL;
- dbus_error_init (&f->e);
-
- f->address = test_get_dbus_daemon (
- "valid-config-files/systemd-activation.conf",
- TEST_USER_ME, &f->daemon_pid);
-
- if (f->address == NULL)
- return;
-
- f->caller = test_connect_to_bus (f->ctx, f->address);
- f->caller_name = dbus_bus_get_unique_name (f->caller);
-}
-
-static void
-take_well_known_name (Fixture *f,
- DBusConnection *connection,
- const char *name)
-{
- int ret;
-
- ret = dbus_bus_request_name (connection, name,
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-}
-
-static void
-test_activation (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
-
- if (f->address == NULL)
- return;
-
- /* The sender sends a message to an activatable service. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable1"))
- g_error ("OOM");
- dbus_connection_send (f->caller, m, NULL);
- dbus_message_unref (m);
-
- /* The fake systemd connects to the bus. */
- f->systemd = test_connect_to_bus (f->ctx, f->address);
- if (!dbus_connection_add_filter (f->systemd, systemd_filter, f, NULL))
- g_error ("OOM");
- f->systemd_name = dbus_bus_get_unique_name (f->systemd);
- take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
-
- /* It gets its activation request. */
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* systemd starts the activatable service. */
- f->activated = test_connect_to_bus (f->ctx, f->address);
- if (!dbus_connection_add_filter (f->activated, activated_filter,
- f, NULL))
- g_error ("OOM");
- f->activated_name = dbus_bus_get_unique_name (f->activated);
- take_well_known_name (f, f->activated, "com.example.SystemdActivatable1");
-
- /* The message is delivered to the activatable service. */
- while (f->activated_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->activated_message;
- f->activated_message = NULL;
- assert_signal (m, f->caller_name, "/foo",
- "com.example.bar", "UnicastSignal1", "",
- "com.example.SystemdActivatable1");
- dbus_message_unref (m);
-
- /* The sender sends a message to a different activatable service. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable2"))
- g_error ("OOM");
- dbus_connection_send (f->caller, m, NULL);
- dbus_message_unref (m);
-
- /* This time systemd is already ready for it. */
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* A malicious process tries to disrupt the activation.
- * In a more realistic scenario this would be another parallel
- * connection. */
- m = dbus_message_new_signal ("/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Activator", "ActivationFailure");
- if (!dbus_message_set_destination (m, "org.freedesktop.DBus"))
- g_error ("OOM");
-
- do
- {
- const char *unit = "dbus-com.example.SystemdActivatable2.service";
- const char *error_name = "com.example.Malice";
- const char *error_message = "I'm on yr bus, making yr activations fail";
-
- if (!dbus_message_append_args (m,
- DBUS_TYPE_STRING, &unit,
- DBUS_TYPE_STRING, &error_name,
- DBUS_TYPE_STRING, &error_message,
- DBUS_TYPE_INVALID))
- g_error ("OOM");
- }
- while (0);
-
- dbus_connection_send (f->caller, m, NULL);
- dbus_message_unref (m);
-
- /* This is just to make sure that the malicious message has arrived and
- * been processed by the dbus-daemon, i.e. @caller won the race
- * with @activated. */
- take_well_known_name (f, f->caller, "com.example.Sync");
-
- /* The activatable service takes its name. Here I'm faking it by using
- * an existing connection; in real life it would be yet another
- * connection. */
- take_well_known_name (f, f->activated, "com.example.SystemdActivatable2");
-
- /* The message is delivered to the activatable service. */
- while (f->activated_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->activated_message;
- f->activated_message = NULL;
- assert_signal (m, f->caller_name, "/foo",
- "com.example.bar", "UnicastSignal2", "",
- "com.example.SystemdActivatable2");
- dbus_message_unref (m);
-
- /* A third activation. */
- m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
- if (!dbus_message_set_destination (m, "com.example.SystemdActivatable3"))
- g_error ("OOM");
- dbus_connection_send (f->caller, m, NULL);
- dbus_message_unref (m);
-
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
- assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
- "org.freedesktop.systemd1");
- dbus_message_unref (m);
-
- /* This time activation fails */
- m = dbus_message_new_signal ("/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Activator", "ActivationFailure");
-
- do
- {
- const char *unit = "dbus-com.example.SystemdActivatable3.service";
- const char *error_name = "com.example.Nope";
- const char *error_message = "Computer says no";
-
- if (!dbus_message_append_args (m,
- DBUS_TYPE_STRING, &unit,
- DBUS_TYPE_STRING, &error_name,
- DBUS_TYPE_STRING, &error_message,
- DBUS_TYPE_INVALID))
- g_error ("OOM");
- }
- while (0);
-
- if (!dbus_message_set_destination (m, "org.freedesktop.DBus"))
- g_error ("OOM");
- dbus_connection_send (f->systemd, m, NULL);
- dbus_message_unref (m);
-}
-
-static void
-test_uae (Fixture *f,
- gconstpointer context)
-{
- DBusMessage *m;
- DBusPendingCall *pc;
- DBusMessageIter args_iter, arr_iter, entry_iter;
- const char *s;
-
- if (f->address == NULL)
- return;
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
- /* Append an empty a{ss} (string => string dictionary). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "{ss}", &arr_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter))
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->caller, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- assert_method_reply (m, DBUS_SERVICE_DBUS, f->caller_name, "");
- dbus_message_unref (m);
-
- /* The fake systemd connects to the bus. */
- f->systemd = test_connect_to_bus (f->ctx, f->address);
- if (!dbus_connection_add_filter (f->systemd, systemd_filter, f, NULL))
- g_error ("OOM");
- f->systemd_name = dbus_bus_get_unique_name (f->systemd);
- take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
-
- /* It gets the SetEnvironment */
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
-
- /* With activation, the destination is the well-known name */
- assert_method_call (m, DBUS_SERVICE_DBUS, "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
- "SetEnvironment", "as");
-
- 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_STRING);
- dbus_message_iter_recurse (&args_iter, &arr_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&arr_iter), ==,
- DBUS_TYPE_INVALID);
- dbus_message_iter_next (&args_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
- DBUS_TYPE_INVALID);
- dbus_message_unref (m);
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
-
- {
- const char *k1 = "Key1", *v1 = "Value1",
- *k2 = "Key2", *v2 = "Value2";
-
- /* Append a filled a{ss} (string => string dictionary). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "{ss}", &arr_iter) ||
- !dbus_message_iter_open_container (&arr_iter, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry_iter) ||
- !dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING,
- &k1) ||
- !dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING,
- &v1) ||
- !dbus_message_iter_close_container (&arr_iter, &entry_iter) ||
- !dbus_message_iter_open_container (&arr_iter, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry_iter) ||
- !dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING,
- &k2) ||
- !dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING,
- &v2) ||
- !dbus_message_iter_close_container (&arr_iter, &entry_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter))
- g_error ("OOM");
- }
-
- if (!dbus_connection_send_with_reply (f->caller, m, &pc,
- DBUS_TIMEOUT_USE_DEFAULT) || pc == NULL)
- g_error ("OOM");
-
- dbus_message_unref (m);
- m = NULL;
-
- if (dbus_pending_call_get_completed (pc))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- assert_method_reply (m, DBUS_SERVICE_DBUS, f->caller_name, "");
- dbus_message_unref (m);
-
- while (f->systemd_message == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- m = f->systemd_message;
- f->systemd_message = NULL;
-
- /* Without activation, the destination is the unique name */
- assert_method_call (m, DBUS_SERVICE_DBUS, f->systemd_name,
- "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
- "SetEnvironment", "as");
-
- 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_STRING);
- dbus_message_iter_recurse (&args_iter, &arr_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&arr_iter), ==,
- DBUS_TYPE_STRING);
- dbus_message_iter_get_basic (&arr_iter, &s);
- g_assert_cmpstr (s, ==, "Key1=Value1");
- dbus_message_iter_next (&arr_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&arr_iter), ==,
- DBUS_TYPE_STRING);
- dbus_message_iter_get_basic (&arr_iter, &s);
- g_assert_cmpstr (s, ==, "Key2=Value2");
- dbus_message_iter_next (&arr_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&arr_iter), ==,
- DBUS_TYPE_INVALID);
- dbus_message_iter_next (&args_iter);
- g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
- DBUS_TYPE_INVALID);
- dbus_message_unref (m);
-}
-
-static void
-teardown (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
-{
- dbus_error_free (&f->e);
- g_clear_error (&f->ge);
-
- if (f->caller != NULL)
- {
- dbus_connection_close (f->caller);
- dbus_connection_unref (f->caller);
- f->caller = NULL;
- }
-
- if (f->systemd != NULL)
- {
- dbus_connection_remove_filter (f->systemd, systemd_filter, f);
- dbus_connection_close (f->systemd);
- dbus_connection_unref (f->systemd);
- f->systemd = NULL;
- }
-
- if (f->activated != NULL)
- {
- dbus_connection_remove_filter (f->activated, activated_filter, f);
- dbus_connection_close (f->activated);
- dbus_connection_unref (f->activated);
- f->activated = NULL;
- }
-
- test_kill_pid (f->daemon_pid);
- g_spawn_close_pid (f->daemon_pid);
- test_main_context_unref (f->ctx);
- g_free (f->address);
-}
-
-int
-main (int argc,
- char **argv)
-{
- test_init (&argc, &argv);
-
- g_test_add ("/sd-activation/activation", Fixture, NULL,
- setup, test_activation, teardown);
- g_test_add ("/sd-activation/uae", Fixture, NULL,
- setup, test_uae, teardown);
-
- return g_test_run ();
-}
diff --git a/test/shell-test.c b/test/shell-test.c
index 61280d6..b479a9c 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>
@@ -9,13 +9,8 @@
#include <dbus/dbus-string.h>
#include <dbus/dbus-sysdeps.h>
-static int test_num = 0;
-static int num_failed = 0;
-
static dbus_bool_t
-test_command_line_internal (dbus_bool_t should_work,
- const char *arg1,
- va_list var_args)
+test_command_line (const char *arg1, ...)
{
int i, original_argc, shell_argc;
char **shell_argv;
@@ -23,8 +18,10 @@
char *command_line, *tmp;
DBusString str;
DBusList *list = NULL, *node;
+ va_list var_args;
DBusError error;
+ va_start (var_args, arg1);
_dbus_list_append (&list, (char *)arg1);
do
{
@@ -33,6 +30,7 @@
break;
_dbus_list_append (&list, tmp);
} while (tmp);
+ va_end (var_args);
original_argc = _dbus_list_get_length (&list);
original_argv = dbus_new (char *, original_argc);
@@ -48,28 +46,23 @@
_dbus_list_clear (&list);
command_line = _dbus_string_get_data (&str);
- printf ("# Testing command line '%s'\n", command_line);
+ printf ("\n\nTesting command line '%s'\n", command_line);
dbus_error_init (&error);
if (!_dbus_shell_parse_argv (command_line, &shell_argc, &shell_argv, &error))
{
- printf ("# Error%s parsing command line: %s\n",
- should_work ? "" : " (as expected)",
- error.message ? error.message : "");
- dbus_free (original_argv);
- return !should_work;
+ fprintf (stderr, "Error parsing command line: %s\n", error.message ? error.message : "");
+ return FALSE;
}
else
{
if (shell_argc != original_argc)
{
- printf ("# Number of arguments returned (%d) don't match original (%d)\n",
+ printf ("Number of arguments returned (%d) don't match original (%d)\n",
shell_argc, original_argc);
- dbus_free (original_argv);
- dbus_free_string_array (shell_argv);
return FALSE;
}
- printf ("# Number of arguments: %d\n", shell_argc);
+ printf ("Number of arguments: %d\n", shell_argc);
for (i = 0; i < shell_argc; i++)
{
char *unquoted;
@@ -81,8 +74,6 @@
printf ("Position %d, returned argument (%s) does not match original (%s)\n",
i, shell_argv[i], unquoted);
dbus_free (unquoted);
- dbus_free (original_argv);
- dbus_free_string_array (shell_argv);
return FALSE;
}
dbus_free (unquoted);
@@ -92,79 +83,27 @@
dbus_free_string_array (shell_argv);
}
-
+
_dbus_string_free (&str);
- dbus_free (original_argv);
-
- if (!should_work)
- {
- printf ("# Expected an error\n");
- return FALSE;
- }
-
+
return TRUE;
}
-static void
-test_command_line (const char *arg1, ...)
-{
- va_list var_args;
-
- va_start (var_args, arg1);
-
- if (test_command_line_internal (TRUE, arg1, var_args))
- {
- printf ("ok %d\n", ++test_num);
- }
- else
- {
- printf ("not ok %d\n", ++test_num);
- num_failed++;
- }
-
- va_end (var_args);
-}
-
-static void
-test_command_line_fails (const char *arg1, ...)
-{
- va_list var_args;
-
- va_start (var_args, arg1);
-
- if (test_command_line_internal (FALSE, arg1, var_args))
- {
- printf ("ok %d\n", ++test_num);
- }
- else
- {
- printf ("not ok %d\n", ++test_num);
- num_failed++;
- }
-
- va_end (var_args);
-}
-
-/* This test outputs TAP syntax: http://testanything.org/ */
int
main (int argc, char **argv)
{
- test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL);
- test_command_line ("command", "-s", NULL);
- test_command_line ("/opt/gnome/bin/service-start", NULL);
- test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL);
- test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL);
- test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL);
- test_command_line ("rsync-to-server", NULL);
- test_command_line ("test-segfault", "--no-segfault", NULL);
- test_command_line ("evolution", "mailto:pepe@cuco.com", NULL);
- test_command_line ("run", "\"a \n multiline\"", NULL);
- test_command_line_fails ("ls", "\"a wrong string'", NULL);
-
- /* Tell the TAP driver that we have done all the tests we plan to do.
- * This is how it can distinguish between an unexpected exit and
- * successful completion. */
- printf ("1..%d\n", test_num);
-
- return (num_failed != 0);
+ if (!test_command_line ("command", "-s", "--force-shutdown", "\"a string\"", "123", NULL)
+ || !test_command_line ("command", "-s", NULL)
+ || !test_command_line ("/opt/gnome/bin/service-start", NULL)
+ || !test_command_line ("grep", "-l", "-r", "-i", "'whatever'", "files*.c", NULL)
+ || !test_command_line ("/home/boston/johnp/devel-local/dbus/test/test-segfault", NULL)
+ || !test_command_line ("ls", "-l", "-a", "--colors", _dbus_get_tmpdir(), NULL)
+ || !test_command_line ("rsync-to-server", NULL)
+ || !test_command_line ("test-segfault", "--no-segfault", NULL)
+ || !test_command_line ("evolution", "mailto:pepe@cuco.com", NULL)
+ || !test_command_line ("run", "\"a \n multiline\"", NULL)
+ || test_command_line ("ls", "\"a wrong string'", NULL) /* invalid command line */ )
+ return -1;
+
+ return 0;
}
diff --git a/test/spawn-test.c b/test/spawn-test.c
index 12d37c8..f1a5505 100644
--- a/test/spawn-test.c
+++ b/test/spawn-test.c
@@ -1,8 +1,10 @@
#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
@@ -16,7 +18,7 @@
{
char **argv_copy;
int i;
- DBusError error = DBUS_ERROR_INIT;
+ DBusError error;
if (argc < 2)
{
@@ -30,7 +32,7 @@
argv_copy [i] = argv[i + 1];
argv_copy[argc - 1] = NULL;
- if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL, setup_func, NULL, &error))
+ if (!_dbus_spawn_async_with_babysitter (NULL, 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 bf960c9..88db963 100644
--- a/test/syntax.c
+++ b/test/syntax.c
@@ -30,8 +30,6 @@
#include <dbus/dbus.h>
-#include "test-utils-glib.h"
-
typedef struct {
DBusError e;
} Fixture;
@@ -180,14 +178,12 @@
const char * const valid_strings[] = {
"",
- "\xc2\xa9", /* UTF-8 (c) symbol */
- "\xef\xbf\xbe", /* U+FFFE is reserved but Corrigendum 9 says it's OK */
+ "\xc2\xa9",
NULL
};
const char * const invalid_strings[] = {
- "\xa9", /* Latin-1 (c) symbol */
- "\xed\xa0\x80", /* UTF-16 surrogates are not valid in UTF-8 */
+ "\xa9",
NULL
};
@@ -271,7 +267,7 @@
main (int argc,
char **argv)
{
- test_init (&argc, &argv);
+ g_test_init (&argc, &argv, NULL);
g_test_add ("/syntax/path", Fixture, &paths, setup, test_syntax, teardown);
g_test_add ("/syntax/interface", Fixture, &interfaces,
diff --git a/test/tap-test.sh.in b/test/tap-test.sh.in
deleted file mode 100644
index 743cdf3..0000000
--- a/test/tap-test.sh.in
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-# Wrapper to make an Automake-style test output TAP syntax:
-#
-# - arbitrary stdout/stderr is sent to stderr where it will not be
-# interpreted as TAP
-# - it is treated as a single test-case
-# - exit 77 is a skip
-# - exit 0 is a pass
-# - anything else is a failure
-#
-# Usage: use sed to replace @RUN@ with the shell command-line to be run.
-
-set -e
-
-# we plan to do 1 test-case
-echo "1..1"
-
-e=0
-@RUN@ >&2 || e=$?
-
-case "$e" in
- (0)
- echo "ok 1 @RUN@"
- ;;
- (77)
- echo "ok 1 # SKIP @RUN@"
- ;;
- (*)
- echo "not ok 1 @RUN@ (exit status $e)"
- ;;
-esac
diff --git a/test/test-dbus-daemon-fork.sh b/test/test-dbus-daemon-fork.sh
deleted file mode 100755
index d616445..0000000
--- a/test/test-dbus-daemon-fork.sh
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/bin/sh
-
-# Copyright © 2016 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.
-
-set -e
-
-export DBUS_DEBUG_OUTPUT=1
-export DBUS_USE_TEST_BINARY=1
-echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
-echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
-
-if test -n "$DBUS_TEST_DATA"; then
- echo "# test data: $DBUS_TEST_DATA"
- config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
-elif test -n "$DBUS_TEST_DATADIR"; then
- echo "# datadir: $DBUS_TEST_DATADIR"
- config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
-else
- echo "# using standard session bus configuration"
- config="--session"
-fi
-
-if ! workdir="$(mktemp -d)"; then
- echo "1..0 # SKIP - mktemp -d doesn't work"
- exit 0
-fi
-
-echo "1..3"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-rm -f "$workdir"/address "$workdir"/pid
-
-${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
- 8>"$workdir/address" 9>"$workdir/pid"
-
-export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 1 - normal dbus-daemon"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-rm -f "$workdir"/address "$workdir"/pid
-
-${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
- 8>"$workdir/address" 9>"$workdir/pid" <&-
-
-export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 2 - dbus-daemon with stdin closed"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-rm -f "$workdir"/address "$workdir"/pid
-
-${DBUS_TEST_DAEMON} --fork --print-address=8 --print-pid=9 "$config" \
- 8>"$workdir/address" 9>"$workdir/pid" <&- >&- 2>&-
-
-export DBUS_SESSION_BUS_ADDRESS="$(cat "$workdir"/address)"
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-DBUS_SESSION_BUS_PID="$(cat "$workdir"/pid)"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 3 - dbus-daemon with stdin, stdout, stderr closed"
-
-rm -r "$workdir"
diff --git a/test/test-dbus-launch-eval.sh b/test/test-dbus-launch-eval.sh
deleted file mode 100755
index 289c548..0000000
--- a/test/test-dbus-launch-eval.sh
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/bin/sh
-
-# Copyright © 2016 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.
-
-set -e
-
-export DBUS_DEBUG_OUTPUT=1
-export DBUS_USE_TEST_BINARY=1
-echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
-echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}"
-echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
-
-if test -n "$DBUS_TEST_DATA"; then
- echo "# test data: $DBUS_TEST_DATA"
- config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
-elif test -n "$DBUS_TEST_DATADIR"; then
- echo "# datadir: $DBUS_TEST_DATADIR"
- config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
-else
- echo "# using standard session bus configuration"
- # add a harmless command-line argument
- config="--sh-syntax"
-fi
-
-echo "1..3"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-
-eval "$(${DBUS_TEST_DBUS_LAUNCH} --sh-syntax "$config")"
-
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-env | grep '^DBUS_SESSION_BUS_ADDRESS='
-
-test -n "$DBUS_SESSION_BUS_PID"
-test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 1 - normal dbus-launch"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-
-eval "$(${DBUS_TEST_DBUS_LAUNCH} --sh-syntax "$config" <&-)"
-
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-env | grep '^DBUS_SESSION_BUS_ADDRESS='
-
-test -n "$DBUS_SESSION_BUS_PID"
-test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 2 - dbus-launch with stdin closed"
-
-unset DBUS_SESSION_BUS_ADDRESS
-unset DBUS_SESSION_BUS_PID
-
-# we can't close stdout because that breaks --sh-syntax
-eval "$(${DBUS_TEST_DBUS_LAUNCH} --sh-syntax "$config" <&- 2>&-)"
-
-test -n "$DBUS_SESSION_BUS_ADDRESS"
-env | grep '^DBUS_SESSION_BUS_ADDRESS='
-
-test -n "$DBUS_SESSION_BUS_PID"
-test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
-kill -0 "$DBUS_SESSION_BUS_PID"
-
-${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
-kill "$DBUS_SESSION_BUS_PID"
-
-echo "ok 3 - dbus-launch with stdin and stderr closed"
diff --git a/test/test-dbus-launch-x11.sh b/test/test-dbus-launch-x11.sh
deleted file mode 100755
index 8278e85..0000000
--- a/test/test-dbus-launch-x11.sh
+++ /dev/null
@@ -1,255 +0,0 @@
-#!/bin/sh
-
-# Copyright © 2016 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.
-
-set -e
-set -x
-
-export DBUS_DEBUG_OUTPUT=1
-export DBUS_USE_TEST_BINARY=1
-echo "# dbus-daemon binary: ${DBUS_TEST_DAEMON:=dbus-daemon}"
-echo "# dbus-launch binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-launch}"
-echo "# dbus-monitor binary: ${DBUS_TEST_DBUS_LAUNCH:=dbus-monitor}"
-echo "# dbus-send binary: ${DBUS_TEST_DBUS_SEND:=dbus-send}"
-
-if test -n "$DBUS_TEST_DATA"; then
- echo "# test data: $DBUS_TEST_DATA"
- bus_config="--config-file=$DBUS_TEST_DATA/valid-config-files/session.conf"
- launch_config="$bus_config"
-elif test -n "$DBUS_TEST_DATADIR"; then
- echo "# datadir: $DBUS_TEST_DATADIR"
- bus_config="--config-file=$DBUS_TEST_DATADIR/dbus-1/session.conf"
- launch_config="$bus_config"
-else
- echo "# using standard session bus configuration"
- bus_config="--session"
- # dbus-launch doesn't accept --session so add a harmless command-line
- # argument
- launch_config="--sh-syntax"
-fi
-
-if ! workdir="$(mktemp -d)"; then
- echo "1..0 # SKIP - mktemp -d doesn't work"
- exit 0
-fi
-
-if ! xvfb-run --auto-servernum true; then
- echo "1..0 # SKIP - xvfb-run doesn't work"
- exit 0
-fi
-
-test_num=0
-x_session_pid=
-unset DISPLAY
-unset XAUTHORITY
-
-start_xvfb () {
- rm -f "$workdir/display"
- rm -f "$workdir/ready"
- rm -f "$workdir/x-session-pid"
- rm -f "$workdir/xauthority"
- rm -f "$workdir/xvfb-done"
-
- # Run an X session in the background for up to 5 minutes.
- (
- set +e
- xvfb-run --auto-servernum \
- sh -c 'echo "$$" > "$1/x-session-pid"; echo "$XAUTHORITY" > "$1/xauthority"; echo "$DISPLAY" > "$1/display"; touch "$1/ready"; exec sleep 300' \
- sh "$workdir"
- touch "$workdir/xvfb-done"
- ) &
-
- tries=0
- while ! [ -e "$workdir/ready" ]; do
- if [ $tries -ge 10 ]; then
- echo "# Failed to start xvfb-run within $tries seconds"
- exit 1
- fi
- tries=$(($tries + 1))
- sleep 1
- done
-
- x_session_pid="$(cat "$workdir/x-session-pid")"
- export DISPLAY="$(cat "$workdir/display")"
- export XAUTHORITY="$(cat "$workdir/xauthority")"
- kill -0 "$x_session_pid"
-}
-
-test_disconnection () {
- rm -f "$workdir/disconnected"
- (
- set +e
- ${DBUS_TEST_DBUS_MONITOR} > "$workdir/dbus-monitor.log" 2>&1
- touch "$workdir/disconnected"
- ) &
-
- kill "$x_session_pid"
-
- tries=0
- while ! [ -e "$workdir/disconnected" ]; do
- if [ $tries -ge 10 ]; then
- echo "# dbus-monitor was not disconnected within $tries seconds" >&2
- exit 1
- fi
- tries=$(($tries + 1))
- sleep 1
- done
-
- tries=0
- while ! [ -e "$workdir/xvfb-done" ]; do
- if [ $tries -ge 10 ]; then
- echo "# xvfb-run did not exit within $tries seconds" >&2
- exit 1
- fi
- tries=$(($tries + 1))
- sleep 1
- done
-}
-
-test_exit_with_x11 () {
- unset DBUS_SESSION_BUS_ADDRESS
- unset DBUS_SESSION_BUS_PID
- unset DBUS_SESSION_BUS_WINDOWID
-
- start_xvfb
- eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --exit-with-session "$launch_config" </dev/null)"
-
- test -n "$DBUS_SESSION_BUS_ADDRESS"
- env | grep '^DBUS_SESSION_BUS_ADDRESS='
-
- test -n "$DBUS_SESSION_BUS_PID"
- test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
- kill -0 "$DBUS_SESSION_BUS_PID"
-
- test -n "$DBUS_SESSION_BUS_WINDOWID"
- test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
-
- ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
- test_disconnection
-
- test_num=$(($test_num + 1))
- echo "ok ${test_num} - dbus-launch --exit-with-session"
-}
-
-test_autolaunch () {
- unset DBUS_SESSION_BUS_ADDRESS
- unset DBUS_SESSION_BUS_PID
- unset DBUS_SESSION_BUS_WINDOWID
- unset XDG_RUNTIME_DIR
- fake_uuid="ffffffffffffffffffffffffffffffff"
-
- start_xvfb
- eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
-
- test -n "$DBUS_SESSION_BUS_ADDRESS"
- env | grep '^DBUS_SESSION_BUS_ADDRESS='
-
- test -n "$DBUS_SESSION_BUS_PID"
- test "x$(env | grep '^DBUS_SESSION_BUS_PID=')" = "x"
- kill -0 "$DBUS_SESSION_BUS_PID"
-
- test -n "$DBUS_SESSION_BUS_WINDOWID"
- test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
-
- # It is idempotent
- old_address="$DBUS_SESSION_BUS_ADDRESS"
- old_pid="$DBUS_SESSION_BUS_PID"
- old_window="$DBUS_SESSION_BUS_WINDOWID"
- eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
- test "$DBUS_SESSION_BUS_ADDRESS" = "$old_address"
- test "$DBUS_SESSION_BUS_PID" = "$old_pid"
- test "$DBUS_SESSION_BUS_WINDOWID" = "$old_window"
-
- ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
- test_disconnection
-
- test_num=$(($test_num + 1))
- echo "ok ${test_num} - dbus-launch --autolaunch"
-}
-
-test_xdg_runtime_dir () {
- unset DBUS_SESSION_BUS_ADDRESS
- unset DBUS_SESSION_BUS_PID
- unset DBUS_SESSION_BUS_WINDOWID
- export XDG_RUNTIME_DIR="$workdir"
- fake_uuid="ffffffffffffffffffffffffffffffff"
-
- if echo "$workdir" | grep '[^0-9A-Za-z_-/.]'; then
- test_num=$(($test_num + 1))
- echo "ok ${test_num} # SKIP - $workdir would need escaping"
- return
- fi
-
- ${DBUS_TEST_DAEMON} "$bus_config" --address="unix:path=$XDG_RUNTIME_DIR/bus" --print-pid=9 --fork 9>"$workdir/bus-pid"
- bus_pid="$(cat "$workdir/bus-pid")"
- kill -0 "$bus_pid"
-
- start_xvfb
- eval "$($DBUS_TEST_DBUS_LAUNCH --sh-syntax --autolaunch=${fake_uuid} "$launch_config" </dev/null)"
-
- env | grep '^DBUS_SESSION_BUS_ADDRESS='
- test "$DBUS_SESSION_BUS_ADDRESS" = "unix:path=$XDG_RUNTIME_DIR/bus"
-
- # When dbus-launch picks up the address from XDG_RUNTIME_DIR/bus, it
- # doesn't know the pid
- test -z "$DBUS_SESSION_BUS_PID"
-
- # It still knows which window it stashed the information in
- test -n "$DBUS_SESSION_BUS_WINDOWID"
- test "x$(env | grep '^DBUS_SESSION_BUS_WINDOWID=')" = "x"
-
- ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
- kill "$x_session_pid"
-
- tries=0
- while ! [ -e "$workdir/xvfb-done" ]; do
- if [ $tries -ge 10 ]; then
- echo "# xvfb-run did not exit within $tries seconds" >&2
- exit 1
- fi
- tries=$(($tries + 1))
- sleep 1
- done
-
- # dbus-launch has gone but the dbus-daemon is still alive
- ${DBUS_TEST_DBUS_SEND} --session --dest=org.freedesktop.DBus \
- --type=method_call --print-reply / org.freedesktop.DBus.ListNames >&2
-
- kill "$bus_pid"
-
- test_num=$(($test_num + 1))
- echo "ok ${test_num} - dbus-launch --autolaunch with XDG_RUNTIME_DIR"
-}
-
-echo "1..3"
-test_exit_with_x11
-test_autolaunch
-test_xdg_runtime_dir
-
-# vim:set sw=4 sts=4 et:
diff --git a/test/test-exit.c b/test/test-exit.c
index b4f967a..f335818 100644
--- a/test/test-exit.c
+++ b/test/test-exit.c
@@ -1,5 +1,3 @@
-#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-segfault.c b/test/test-segfault.c
index b6c0f8a..329a21f 100644
--- a/test/test-segfault.c
+++ b/test/test-segfault.c
@@ -9,60 +9,18 @@
#include <sys/resource.h>
#endif
-#ifdef HAVE_SYS_PRCTL_H
-#include <sys/prctl.h>
-#endif
-
-#ifdef DBUS_WIN
-#include <stdio.h>
-#include <windows.h>
-
-int
-exception_handler(LPEXCEPTION_POINTERS p);
-
-/* Explicit Windows exception handlers needed to supress OS popups */
-int
-exception_handler(LPEXCEPTION_POINTERS p)
-{
- fprintf(stderr, "test-segfault: raised fatal exception as intended\n");
- ExitProcess(0xc0000005);
-}
-#endif
-
int
main (int argc, char **argv)
{
char *p;
-#ifdef DBUS_WIN
- /* Disable Windows popup dialog when an app crashes so that app quits
- * immediately with error code instead of waiting for user to dismiss
- * the dialog. */
- DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
- SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
- /* Disable "just in time" debugger */
- SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler);
-#endif
-
#if HAVE_SETRLIMIT
- /* No core dumps please, we know we crashed. */
struct rlimit r = { 0, };
getrlimit (RLIMIT_CORE, &r);
r.rlim_cur = 0;
setrlimit (RLIMIT_CORE, &r);
-#endif
-
-#if defined(HAVE_PRCTL) && defined(PR_SET_DUMPABLE)
- /* Really, no core dumps please. On Linux, if core_pattern is
- * set to a pipe (for abrt/apport/corekeeper/etc.), RLIMIT_CORE of 0
- * is ignored (deliberately, so people can debug init(8) and other
- * early stuff); but Linux has PR_SET_DUMPABLE, so we can avoid core
- * dumps anyway. */
- prctl (PR_SET_DUMPABLE, 0, 0, 0, 0);
-#endif
-
-#ifdef HAVE_RAISE
+
raise (SIGSEGV);
#endif
p = NULL;
diff --git a/test/test-service.c b/test/test-service.c
index c0bd2c6..7181fa3 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -400,18 +400,20 @@
int result;
DBusConnection *connection;
const char *name;
-#ifndef DBUS_WIN
- dbus_bool_t do_fork = FALSE;
-#endif
+ dbus_bool_t do_fork;
+
if (argc != 3)
{
name = "org.freedesktop.DBus.TestSuiteEchoService";
+ do_fork = FALSE;
}
else
{
name = argv[1];
#ifndef DBUS_WIN
do_fork = strcmp (argv[2], "fork") == 0;
+#else
+ do_fork = FALSE;
#endif
}
diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c
deleted file mode 100644
index e084977..0000000
--- a/test/test-utils-glib.c
+++ /dev/null
@@ -1,472 +0,0 @@
-/* Utility functions for tests that rely on GLib
- *
- * Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2013-2015 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 "test-utils-glib.h"
-
-#include <string.h>
-
-#ifdef DBUS_WIN
-# include <io.h>
-# include <windows.h>
-#else
-# include <errno.h>
-# include <signal.h>
-# include <unistd.h>
-# include <sys/types.h>
-# include <pwd.h>
-#endif
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-#include <dbus/dbus.h>
-
-#ifdef G_OS_WIN
-# define isatty(x) _isatty(x)
-#endif
-
-void
-_test_assert_no_error (const DBusError *e,
- const char *file,
- int line)
-{
- if (G_UNLIKELY (dbus_error_is_set (e)))
- g_error ("%s:%d: expected success but got error: %s: %s",
- file, line, e->name, e->message);
-}
-
-#ifdef DBUS_UNIX
-static void
-child_setup (gpointer user_data)
-{
- const struct passwd *pwd = user_data;
- uid_t uid = geteuid ();
-
- if (pwd == NULL || (pwd->pw_uid == uid && getuid () == uid))
- return;
-
- if (uid != 0)
- g_error ("not currently euid 0: %lu", (unsigned long) uid);
-
- if (setuid (pwd->pw_uid) != 0)
- g_error ("could not setuid (%lu): %s",
- (unsigned long) pwd->pw_uid, g_strerror (errno));
-
- uid = getuid ();
-
- if (uid != pwd->pw_uid)
- g_error ("after successful setuid (%lu) my uid is %ld",
- (unsigned long) pwd->pw_uid, (unsigned long) uid);
-
- uid = geteuid ();
-
- if (uid != pwd->pw_uid)
- g_error ("after successful setuid (%lu) my euid is %ld",
- (unsigned long) pwd->pw_uid, (unsigned long) uid);
-}
-#endif
-
-static gchar *
-spawn_dbus_daemon (const gchar *binary,
- const gchar *configuration,
- const gchar *listen_address,
- TestUser user,
- GPid *daemon_pid)
-{
- GError *error = NULL;
- GString *address;
- gint address_fd;
- GPtrArray *argv;
-#ifdef DBUS_UNIX
- const struct passwd *pwd = NULL;
-#endif
-
- if (user != TEST_USER_ME)
- {
-#ifdef DBUS_UNIX
- if (getuid () != 0)
- {
- g_test_skip ("cannot use alternative uid when not uid 0");
- return NULL;
- }
-
- switch (user)
- {
- case TEST_USER_ROOT:
- break;
-
- case TEST_USER_MESSAGEBUS:
- pwd = getpwnam (DBUS_USER);
-
- if (pwd == NULL)
- {
- gchar *message = g_strdup_printf ("user '%s' does not exist",
- DBUS_USER);
-
- g_test_skip (message);
- g_free (message);
- return NULL;
- }
-
- break;
-
- case TEST_USER_OTHER:
- pwd = getpwnam (DBUS_TEST_USER);
-
- if (pwd == NULL)
- {
- gchar *message = g_strdup_printf ("user '%s' does not exist",
- DBUS_TEST_USER);
-
- g_test_skip (message);
- g_free (message);
- return NULL;
- }
-
- break;
-
- default:
- g_assert_not_reached ();
- }
-#else
- g_test_skip ("cannot use alternative uid on Windows");
- return NULL;
-#endif
- }
-
- argv = g_ptr_array_new_with_free_func (g_free);
- g_ptr_array_add (argv, g_strdup (binary));
- g_ptr_array_add (argv, g_strdup (configuration));
- g_ptr_array_add (argv, g_strdup ("--nofork"));
- g_ptr_array_add (argv, g_strdup ("--print-address=1")); /* stdout */
-
- if (listen_address != NULL)
- g_ptr_array_add (argv, g_strdup (listen_address));
-
-#ifdef DBUS_UNIX
- g_ptr_array_add (argv, g_strdup ("--systemd-activation"));
-#endif
-
- g_ptr_array_add (argv, NULL);
-
- g_spawn_async_with_pipes (NULL, /* working directory */
- (gchar **) argv->pdata,
- NULL, /* envp */
- G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
-#ifdef DBUS_UNIX
- child_setup, (gpointer) pwd,
-#else
- NULL, NULL,
-#endif
- daemon_pid,
- NULL, /* child's stdin = /dev/null */
- &address_fd,
- NULL, /* child's stderr = our stderr */
- &error);
- g_assert_no_error (error);
-
- g_ptr_array_free (argv, TRUE);
-
- address = g_string_new (NULL);
-
- /* polling until the dbus-daemon writes out its address is a bit stupid,
- * but at least it's simple, unlike dbus-launch... in principle we could
- * use select() here, but life's too short */
- while (1)
- {
- gssize bytes;
- gchar buf[4096];
- gchar *newline;
-
- bytes = read (address_fd, buf, sizeof (buf));
-
- if (bytes > 0)
- g_string_append_len (address, buf, bytes);
-
- newline = strchr (address->str, '\n');
-
- if (newline != NULL)
- {
- if ((newline > address->str) && ('\r' == newline[-1]))
- newline -= 1;
- g_string_truncate (address, newline - address->str);
- break;
- }
-
- g_usleep (G_USEC_PER_SEC / 10);
- }
-
- g_close (address_fd, NULL);
-
- return g_string_free (address, FALSE);
-}
-
-gchar *
-test_get_dbus_daemon (const gchar *config_file,
- TestUser user,
- GPid *daemon_pid)
-{
- gchar *dbus_daemon;
- gchar *arg;
- const gchar *listen_address = NULL;
- gchar *address;
-
- /* we often have to override this because on Windows, the default may be
- * autolaunch:, which is globally-scoped and hence unsuitable for
- * regression tests */
- listen_address = "--address=" TEST_LISTEN;
-
- if (config_file != NULL)
- {
-
- if (g_getenv ("DBUS_TEST_DATA") == NULL)
- {
- g_test_message ("set DBUS_TEST_DATA to a directory containing %s",
- config_file);
- g_test_skip ("DBUS_TEST_DATA not set");
- return NULL;
- }
-
- arg = g_strdup_printf (
- "--config-file=%s/%s",
- g_getenv ("DBUS_TEST_DATA"), config_file);
-
- /* The configuration file is expected to give a suitable address,
- * do not override it */
- listen_address = NULL;
- }
- else if (g_getenv ("DBUS_TEST_DATADIR") != NULL)
- {
- arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
- g_getenv ("DBUS_TEST_DATADIR"));
- }
- else if (g_getenv ("DBUS_TEST_DATA") != NULL)
- {
- arg = g_strdup_printf (
- "--config-file=%s/valid-config-files/session.conf",
- g_getenv ("DBUS_TEST_DATA"));
- }
- else
- {
- arg = g_strdup ("--session");
- }
-
- dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
-
- if (dbus_daemon == NULL)
- dbus_daemon = g_strdup ("dbus-daemon");
-
- if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
- {
- if (config_file != NULL || user != TEST_USER_ME)
- {
- g_test_skip ("cannot use DBUS_TEST_DAEMON_ADDRESS for "
- "unusally-configured dbus-daemon");
- address = NULL;
- }
- else
- {
- address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS"));
- }
- }
- else
- {
- address = spawn_dbus_daemon (dbus_daemon, arg,
- listen_address, user, daemon_pid);
- }
-
- g_free (dbus_daemon);
- g_free (arg);
- return address;
-}
-
-DBusConnection *
-test_connect_to_bus (TestMainContext *ctx,
- const gchar *address)
-{
- DBusConnection *conn;
- DBusError error = DBUS_ERROR_INIT;
- dbus_bool_t ok;
-
- conn = dbus_connection_open_private (address, &error);
- test_assert_no_error (&error);
- g_assert (conn != NULL);
-
- ok = dbus_bus_register (conn, &error);
- test_assert_no_error (&error);
- g_assert (ok);
- g_assert (dbus_bus_get_unique_name (conn) != NULL);
-
- test_connection_setup (ctx, conn);
- return conn;
-}
-
-DBusConnection *
-test_connect_to_bus_as_user (TestMainContext *ctx,
- const char *address,
- TestUser user)
-{
- /* For now we only do tests like this on Linux, because I don't know how
- * safe this use of setresuid() is on other platforms */
-#if defined(HAVE_GETRESUID) && defined(HAVE_SETRESUID) && defined(__linux__)
- uid_t ruid, euid, suid;
- const struct passwd *pwd;
- DBusConnection *conn;
- const char *username;
-
- switch (user)
- {
- case TEST_USER_ME:
- return test_connect_to_bus (ctx, address);
-
- case TEST_USER_ROOT:
- username = "root";
- break;
-
- case TEST_USER_MESSAGEBUS:
- username = DBUS_USER;
- break;
-
- case TEST_USER_OTHER:
- username = DBUS_TEST_USER;
- break;
-
- default:
- g_return_val_if_reached (NULL);
- }
-
- if (getresuid (&ruid, &euid, &suid) != 0)
- g_error ("getresuid: %s", g_strerror (errno));
-
- if (ruid != 0 || euid != 0 || suid != 0)
- {
- g_test_message ("not uid 0 (ruid=%ld euid=%ld suid=%ld)",
- (unsigned long) ruid, (unsigned long) euid, (unsigned long) suid);
- g_test_skip ("not uid 0");
- return NULL;
- }
-
- pwd = getpwnam (username);
-
- if (pwd == NULL)
- {
- g_test_message ("getpwnam(\"%s\"): %s", username, g_strerror (errno));
- g_test_skip ("not uid 0");
- return NULL;
- }
-
- /* Impersonate the desired user while we connect to the bus.
- * This should work, because we're root. */
- if (setresuid (pwd->pw_uid, pwd->pw_uid, 0) != 0)
- g_error ("setresuid(%ld, (same), 0): %s",
- (unsigned long) pwd->pw_uid, g_strerror (errno));
-
- conn = test_connect_to_bus (ctx, address);
-
- /* go back to our saved uid */
- if (setresuid (0, 0, 0) != 0)
- g_error ("setresuid(0, 0, 0): %s", g_strerror (errno));
-
- return conn;
-
-#else
-
- switch (user)
- {
- case TEST_USER_ME:
- return test_connect_to_bus (ctx, address);
-
- default:
- g_test_skip ("setresuid() not available, or unsure about "
- "credentials-passing semantics on this platform");
- return NULL;
- }
-
-#endif
-}
-
-void
-test_kill_pid (GPid pid)
-{
-#ifdef DBUS_WIN
- if (pid != NULL)
- TerminateProcess (pid, 1);
-#else
- if (pid > 0)
- kill (pid, SIGTERM);
-#endif
-}
-
-static gboolean
-time_out (gpointer data)
-{
- g_error ("timed out");
- return FALSE;
-}
-
-#ifdef G_OS_UNIX
-static void
-wrap_abort (int signal)
-{
- abort ();
-}
-#endif
-
-void
-test_init (int *argcp, char ***argvp)
-{
- g_test_init (argcp, argvp, NULL);
- g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
-
- /* Prevent tests from hanging forever. This is intended to be long enough
- * that any reasonable regression test on any reasonable hardware would
- * have finished. */
-#define TIMEOUT 60
-
- g_timeout_add_seconds (TIMEOUT, time_out, NULL);
-#ifdef G_OS_UNIX
- /* The GLib main loop might not be running (we don't use it in every
- * test). Die with SIGALRM shortly after if necessary. */
- alarm (TIMEOUT + 10);
-
- /* Get a core dump from the SIGALRM. */
- {
- struct sigaction act = { };
-
- act.sa_handler = wrap_abort;
-
- sigaction (SIGALRM, &act, NULL);
- }
-#endif
-}
-
-void
-test_progress (char symbol)
-{
- if (g_test_verbose () && isatty (1))
- g_print ("%c", symbol);
-}
diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h
deleted file mode 100644
index acacee0..0000000
--- a/test/test-utils-glib.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Utility functions for tests that rely on GLib
- *
- * Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2013-2015 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.
- */
-
-#ifndef TEST_UTILS_GLIB_H
-#define TEST_UTILS_GLIB_H
-
-#include <dbus/dbus.h>
-
-#include <glib.h>
-
-#include "test-utils.h"
-
-/*
- * Multi-user support for regression tests run with root privileges in
- * a continuous integration system.
- *
- * A developer would normally run the tests as their own uid. Tests run
- * as TEST_USER_ME are run, and the others are skipped.
- *
- * In a CI system that has access to root privileges, most tests should still
- * be run as an arbitrary non-root user, as above.
- *
- * Certain tests can usefully be run again, as root. When this is done,
- * tests using TEST_USER_ROOT, TEST_USER_MESSAGEBUS and/or TEST_USER_OTHER
- * can exercise situations that only arise when there's more than one uid.
- */
-typedef enum {
- /* Whatever user happens to be running the regression test;
- * such tests also work on Windows */
- TEST_USER_ME,
- /* Must be uid 0 on Unix; the test is skipped on Windows */
- TEST_USER_ROOT,
- /* The user who would normally run the system bus. This is the DBUS_USER
- * from configure.ac, usually 'messagebus' but perhaps 'dbus' or
- * '_dbus'. */
- TEST_USER_MESSAGEBUS,
- /* An unprivileged user who is neither root nor DBUS_USER.
- * This is DBUS_TEST_USER from configure.ac, usually 'nobody'. */
- TEST_USER_OTHER
-} TestUser;
-
-#define test_assert_no_error(e) _test_assert_no_error (e, __FILE__, __LINE__)
-void _test_assert_no_error (const DBusError *e,
- const char *file,
- int line);
-
-gchar *test_get_dbus_daemon (const gchar *config_file,
- TestUser user,
- GPid *daemon_pid);
-
-DBusConnection *test_connect_to_bus (TestMainContext *ctx,
- const gchar *address);
-DBusConnection *test_connect_to_bus_as_user (TestMainContext *ctx,
- const char *address,
- TestUser user);
-
-void test_kill_pid (GPid pid);
-
-void test_init (int *argcp, char ***argvp);
-
-void test_progress (char symbol);
-
-#if !GLIB_CHECK_VERSION (2, 38, 0)
-#define g_test_skip(s) my_test_skip (s)
-static inline void my_test_skip (const gchar *s)
-{
- g_test_message ("SKIP: %s", s);
-}
-#endif
-
-#endif
diff --git a/test/test-utils.c b/test/test-utils.c
index cb6cf1f..c3c3ed3 100644
--- a/test/test-utils.c
+++ b/test/test-utils.c
@@ -98,10 +98,9 @@
}
dbus_bool_t
-test_connection_setup (TestMainContext *ctx,
+test_connection_setup (DBusLoop *loop,
DBusConnection *connection)
{
- DBusLoop *loop = ctx;
CData *cd;
cd = NULL;
@@ -151,15 +150,8 @@
return FALSE;
}
-static void
-die (const char *message)
-{
- fprintf (stderr, "*** %s", message);
- exit (1);
-}
-
void
-test_connection_shutdown (TestMainContext *ctx,
+test_connection_shutdown (DBusLoop *loop,
DBusConnection *connection)
{
if (!dbus_connection_set_watch_functions (connection,
@@ -167,14 +159,14 @@
NULL,
NULL,
NULL, NULL))
- die ("setting watch functions to NULL failed");
+ _dbus_assert_not_reached ("setting watch functions to NULL failed");
if (!dbus_connection_set_timeout_functions (connection,
NULL,
NULL,
NULL,
NULL, NULL))
- die ("setting timeout functions to NULL failed");
+ _dbus_assert_not_reached ("setting timeout functions to NULL failed");
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
}
@@ -261,10 +253,9 @@
}
dbus_bool_t
-test_server_setup (TestMainContext *ctx,
+test_server_setup (DBusLoop *loop,
DBusServer *server)
{
- DBusLoop *loop = ctx;
ServerData *sd;
sd = serverdata_new (loop, server);
@@ -305,7 +296,7 @@
}
void
-test_server_shutdown (TestMainContext *ctx,
+test_server_shutdown (DBusLoop *loop,
DBusServer *server)
{
dbus_server_disconnect (server);
@@ -314,44 +305,11 @@
NULL, NULL, NULL,
NULL,
NULL))
- die ("setting watch functions to NULL failed");
+ _dbus_assert_not_reached ("setting watch functions to NULL failed");
if (!dbus_server_set_timeout_functions (server,
NULL, NULL, NULL,
NULL,
NULL))
- die ("setting timeout functions to NULL failed");
-}
-
-TestMainContext *
-test_main_context_get (void)
-{
- return _dbus_loop_new ();
-}
-
-TestMainContext *
-test_main_context_ref (TestMainContext *ctx)
-{
- return _dbus_loop_ref (ctx);
-}
-
-void test_main_context_unref (TestMainContext *ctx)
-{
- _dbus_loop_unref (ctx);
-}
-
-void test_main_context_iterate (TestMainContext *ctx,
- dbus_bool_t may_block)
-{
- _dbus_loop_iterate (ctx, may_block);
-}
-
-void
-test_pending_call_store_reply (DBusPendingCall *pc,
- void *data)
-{
- DBusMessage **message_p = data;
-
- *message_p = dbus_pending_call_steal_reply (pc);
- _dbus_assert (*message_p != NULL);
+ _dbus_assert_not_reached ("setting timeout functions to NULL failed");
}
diff --git a/test/test-utils.h b/test/test-utils.h
index 39fae77..3e1e55e 100644
--- a/test/test-utils.h
+++ b/test/test-utils.h
@@ -1,31 +1,25 @@
#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.h>
-
#include <dbus/dbus-mainloop.h>
#include <dbus/dbus-internals.h>
-typedef DBusLoop TestMainContext;
+#undef DBUS_COMPILATION
-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,
+dbus_bool_t test_connection_setup (DBusLoop *loop,
DBusConnection *connection);
-void test_connection_shutdown (TestMainContext *ctx,
+void test_connection_shutdown (DBusLoop *loop,
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 (TestMainContext *ctx,
+dbus_bool_t test_server_setup (DBusLoop *loop,
DBusServer *server);
-void test_server_shutdown (TestMainContext *ctx,
+void test_server_shutdown (DBusLoop *loop,
DBusServer *server);
-void test_pending_call_store_reply (DBusPendingCall *pc,
- void *data);
#endif
diff --git a/test/uid-permissions.c b/test/uid-permissions.c
deleted file mode 100644
index 57f7ec9..0000000
--- a/test/uid-permissions.c
+++ /dev/null
@@ -1,274 +0,0 @@
-/* Integration tests for the dbus-daemon's uid-based hardening
- *
- * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
- * Copyright © 2010-2011 Nokia Corporation
- * Copyright © 2015 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 "test-utils-glib.h"
-
-typedef struct {
- gboolean skip;
-
- TestMainContext *ctx;
-
- DBusError e;
- GError *ge;
-
- GPid daemon_pid;
-
- DBusConnection *conn;
-} Fixture;
-
-typedef struct {
- const char *config_file;
- TestUser user;
- gboolean expect_success;
-} Config;
-
-static void
-setup (Fixture *f,
- gconstpointer context)
-{
- const Config *config = context;
- gchar *address;
-
- f->ctx = test_main_context_get ();
- f->ge = NULL;
- dbus_error_init (&f->e);
-
- address = test_get_dbus_daemon (config ? config->config_file : NULL,
- TEST_USER_MESSAGEBUS,
- &f->daemon_pid);
-
- if (address == NULL)
- {
- f->skip = TRUE;
- return;
- }
-
- f->conn = test_connect_to_bus_as_user (f->ctx, address,
- config ? config->user : TEST_USER_ME);
-
- if (f->conn == NULL)
- f->skip = TRUE;
-
- g_free (address);
-}
-
-static void
-test_uae (Fixture *f,
- gconstpointer context)
-{
- const Config *config = context;
- DBusMessage *m;
- DBusPendingCall *pc;
- DBusMessageIter args_iter;
- DBusMessageIter arr_iter;
-
- if (f->skip)
- return;
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
- /* Append an empty a{ss} (string => string dictionary). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "{ss}", &arr_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter))
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- if (config->expect_success)
- {
- /* it succeeds */
- g_assert_cmpint (dbus_message_get_type (m), ==,
- DBUS_MESSAGE_TYPE_METHOD_RETURN);
- }
- else
- {
- /* it fails, yielding an error message with one string argument */
- g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
- g_assert_cmpstr (dbus_message_get_error_name (m), ==,
- DBUS_ERROR_ACCESS_DENIED);
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
- }
-
- dbus_message_unref (m);
-}
-
-static void
-test_monitor (Fixture *f,
- gconstpointer context)
-{
- const Config *config = context;
- DBusMessage *m;
- DBusPendingCall *pc;
- DBusMessageIter args_iter;
- DBusMessageIter arr_iter;
- dbus_uint32_t no_flags = 0;
-
- if (f->skip)
- return;
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
-
- if (m == NULL)
- g_error ("OOM");
-
- dbus_message_iter_init_append (m, &args_iter);
-
- /* Append an empty as (string array). */
- if (!dbus_message_iter_open_container (&args_iter, DBUS_TYPE_ARRAY,
- "s", &arr_iter) ||
- !dbus_message_iter_close_container (&args_iter, &arr_iter) ||
- !dbus_message_iter_append_basic (&args_iter,
- DBUS_TYPE_UINT32, &no_flags))
- g_error ("OOM");
-
- if (!dbus_connection_send_with_reply (f->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))
- test_pending_call_store_reply (pc, &m);
- else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
- &m, NULL))
- g_error ("OOM");
-
- while (m == NULL)
- test_main_context_iterate (f->ctx, TRUE);
-
- if (config->expect_success)
- {
- /* it succeeds */
- g_assert_cmpint (dbus_message_get_type (m), ==,
- DBUS_MESSAGE_TYPE_METHOD_RETURN);
- }
- else
- {
- /* it fails, yielding an error message with one string argument */
- g_assert_cmpint (dbus_message_get_type (m), ==, DBUS_MESSAGE_TYPE_ERROR);
- g_assert_cmpstr (dbus_message_get_error_name (m), ==,
- DBUS_ERROR_ACCESS_DENIED);
- g_assert_cmpstr (dbus_message_get_signature (m), ==, "s");
- }
-
- dbus_message_unref (m);
-}
-
-static void
-teardown (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
-{
- dbus_error_free (&f->e);
- g_clear_error (&f->ge);
-
- if (f->conn != NULL)
- {
- dbus_connection_close (f->conn);
- dbus_connection_unref (f->conn);
- f->conn = NULL;
- }
-
- if (f->daemon_pid != 0)
- {
- test_kill_pid (f->daemon_pid);
- g_spawn_close_pid (f->daemon_pid);
- f->daemon_pid = 0;
- }
-
- test_main_context_unref (f->ctx);
-}
-
-static Config root_ok_config = {
- "valid-config-files/multi-user.conf",
- TEST_USER_ROOT,
- TRUE
-};
-
-static Config messagebus_ok_config = {
- "valid-config-files/multi-user.conf",
- TEST_USER_MESSAGEBUS,
- TRUE
-};
-
-static Config other_fail_config = {
- "valid-config-files/multi-user.conf",
- TEST_USER_OTHER,
- FALSE
-};
-
-int
-main (int argc,
- char **argv)
-{
- test_init (&argc, &argv);
-
- /* UpdateActivationEnvironment used to be allowed by dbus-daemon for root
- * and messagebus but not for other users (although system.conf forbids it
- * for everyone, and it's useless). It is now hard-coded to fail on a
- * system bus for everyone, so don't assert that root and messagebus
- * may call it; continue to assert that it is denied for unprivileged
- * users though. */
- g_test_add ("/uid-permissions/uae/other", Fixture, &other_fail_config,
- setup, test_uae, teardown);
-
- /* BecomeMonitor has the behaviour that UAE used to have. */
- g_test_add ("/uid-permissions/monitor/root", Fixture, &root_ok_config,
- setup, test_monitor, teardown);
- g_test_add ("/uid-permissions/monitor/messagebus", Fixture, &messagebus_ok_config,
- setup, test_monitor, teardown);
- g_test_add ("/uid-permissions/monitor/other", Fixture, &other_fail_config,
- setup, test_monitor, teardown);
-
- return g_test_run ();
-}
diff --git a/tools/Android.mk b/tools/Android.mk
index 7570668..a5d33f7 100644
--- a/tools/Android.mk
+++ b/tools/Android.mk
@@ -1,25 +1,17 @@
LOCAL_PATH := $(call my-dir)
-dbusToolsCommonCIncludes := $(LOCAL_PATH)/..
dbusToolsCommonCFlags := \
-DDBUS_COMPILATION \
-DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\" \
-Wno-unused-parameter
-dbusToolsCommonSharedLibraries := libdbus
# common
include $(CLEAR_VARS)
-LOCAL_SRC_FILES := \
- dbus-print-message.c \
- dbus-echo.c \
- dbus-spam.c \
- tool-common.c
-LOCAL_C_INCLUDES += $(dbusToolsCommonCIncludes)
-LOCAL_SHARED_LIBRARIES += $(dbusToolsCommonSharedLibraries)
+LOCAL_SRC_FILES := dbus-print-message.c
+LOCAL_SHARED_LIBRARIES += libdbus
LOCAL_CFLAGS += $(dbusToolsCommonCFlags)
-LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_MODULE := libdbus-tools-common
include $(BUILD_STATIC_LIBRARY)
@@ -28,8 +20,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := dbus-monitor.c
-LOCAL_C_INCLUDES += $(dbusToolsCommonCIncludes)
-LOCAL_SHARED_LIBRARIES += $(dbusToolsCommonSharedLibraries)
+LOCAL_SHARED_LIBRARIES += libdbus
LOCAL_STATIC_LIBRARIES += libdbus-tools-common
LOCAL_CFLAGS += $(dbusToolsCommonCFlags)
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
@@ -41,8 +32,7 @@
include $(CLEAR_VARS)
LOCAL_SRC_FILES := dbus-send.c
-LOCAL_C_INCLUDES += $(dbusToolsCommonCIncludes)
-LOCAL_SHARED_LIBRARIES += $(dbusToolsCommonSharedLibraries)
+LOCAL_SHARED_LIBRARIES += libdbus
LOCAL_STATIC_LIBRARIES += libdbus-tools-common
LOCAL_CFLAGS += $(dbusToolsCommonCFlags)
LOCAL_MODULE := dbus-send
diff --git a/tools/GetAllMatchRules.py b/tools/GetAllMatchRules.py
deleted file mode 100755
index 6a7e4cd..0000000
--- a/tools/GetAllMatchRules.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env python
-
-import sys
-import argparse
-import dbus
-import time
-
-def get_cmdline(pid):
- cmdline = ''
- if pid > 0:
- try:
- procpath = '/proc/' + str(pid) + '/cmdline'
- with open(procpath, 'r') as f:
- cmdline = " ".join(f.readline().split('\0'))
- except:
- pass
- return cmdline
-
-# Parsing parameters
-
-parser = argparse.ArgumentParser(description='Testing D-Bus match rules')
-parser.add_argument('--session', help='session bus', action="store_true")
-parser.add_argument('--system', help='system bus', action="store_true")
-parser.add_argument('--all', help='print all match rules', action="store_true")
-args = parser.parse_args()
-
-if args.system and args.session:
- parser.print_help()
- sys.exit(1)
-
-# Fetch data from the bus driver
-
-if args.system:
- bus = dbus.SystemBus()
-else:
- bus = dbus.SessionBus()
-
-remote_object = bus.get_object("org.freedesktop.DBus",
- "/org/freedesktop/DBus")
-bus_iface = dbus.Interface(remote_object, "org.freedesktop.DBus")
-stats_iface = dbus.Interface(remote_object, "org.freedesktop.DBus.Debug.Stats")
-
-try:
- match_rules = stats_iface.GetAllMatchRules()
-except:
- print("GetConnectionMatchRules failed: did you enable the Stats interface?")
- sys.exit(1)
-
-names = bus_iface.ListNames()
-unique_names = [ a for a in names if a.startswith(":") ]
-pids = dict((name, bus_iface.GetConnectionUnixProcessID(name)) for name in unique_names)
-cmds = dict((name, get_cmdline(pids[name])) for name in unique_names)
-well_known_names = [ a for a in names if a not in unique_names ]
-owners = dict((wkn, bus_iface.GetNameOwner(wkn)) for wkn in well_known_names)
-
-rules = dict((k_rules,
- dict({
- 'wkn': [k for k, v in owners.items() if v == k_rules],
- 'pid': pids[k_rules],
- 'cmd': cmds[k_rules] or "",
- 'rules': v_rules,
- 'warnings': dict({
- 'not_signal': [a for a in v_rules if "type='signal'" not in a],
- 'no_sender': [a for a in v_rules if "sender=" not in a],
- 'local': [a for a in v_rules if "org.freedesktop.DBus.Local" in a],
- 'NameOwnerChanged_arg0': [a for a in v_rules if "member='NameOwnerChanged'" in a and "arg0" not in a]
- })
- })
- ) for k_rules, v_rules in match_rules.items())
-
-warnings = dict({
- 'not_signal': 'Match rule without selecting signals',
- 'no_sender': 'Match rule without a sender criteria',
- 'local': 'Match rule on the org.freedesktop.DBus.Local interface',
- 'NameOwnerChanged_arg0': 'Match rule on NameOwnerChanged without a arg0* criteria'
- })
-
-# Print the match rules
-
-# print all match rules without analysing them
-if args.all:
- for name in rules:
- print("Connection %s with pid %d '%s' (%s): %d match rules, %d warnings"
- % (name, rules[name]['pid'], rules[name]['cmd'],
- ' '.join(rules[name]['wkn']), len(rules[name]['rules']),
- len(sum(rules[name]['warnings'].values(), []))))
- for rule in rules[name]['rules']:
- print("\t%s" % (rule))
- print("")
- sys.exit(0)
-
-# analyse match rules and print only the suspicious ones
-for conn,data in rules.items():
- warnings_count = len(sum(data['warnings'].values(), []))
- if warnings_count == 0:
- continue
-
- print("Connection %s with pid %d '%s' (%s): %d match rules, %d warnings"
- % (conn, data['pid'], data['cmd'], ' '.join(data['wkn']),
- len(data['rules']), warnings_count))
-
- for warn_code,rule_list in [(warn_code,rule_list) \
- for warn_code, rule_list \
- in data['warnings'].items() \
- if len(rule_list) > 0]:
- print(" - %s:" % (warnings[warn_code]))
- for rule in rule_list:
- print(" - %s" % (rule))
-
- print("")
-
-sys.exit(0)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 56a0b7f..cfd54b8 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,3 +1,5 @@
+configdir=$(sysconfdir)/dbus-1
+
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(DBUS_STATIC_BUILD_CPPFLAGS) \
@@ -13,14 +15,11 @@
dbus-launch \
dbus-monitor \
dbus-send \
- dbus-test-tool \
- dbus-update-activation-environment \
$(NULL)
if DBUS_UNIX
bin_PROGRAMS += \
dbus-cleanup-sockets \
- dbus-run-session \
dbus-uuidgen \
$(NULL)
endif
@@ -28,18 +27,12 @@
dbus_send_SOURCES= \
dbus-print-message.c \
dbus-print-message.h \
- dbus-send.c \
- tool-common.c \
- tool-common.h \
- $(NULL)
+ dbus-send.c
-dbus_monitor_SOURCES = \
- dbus-monitor.c \
- dbus-print-message.c \
- dbus-print-message.h \
- tool-common.c \
- tool-common.h \
- $(NULL)
+dbus_monitor_SOURCES= \
+ dbus-monitor.c \
+ dbus-print-message.c \
+ dbus-print-message.h
if DBUS_WIN
dbus_launch_SOURCES= \
@@ -49,24 +42,7 @@
dbus_launch_SOURCES= \
dbus-launch.c \
dbus-launch-x11.c \
- dbus-launch.h \
- tool-common.c \
- tool-common.h \
- $(NULL)
-dbus_launch_CPPFLAGS = \
- $(AM_CPPFLAGS) \
- $(NULL)
-dbus_launch_LDADD = \
- $(top_builddir)/dbus/libdbus-1.la \
- $(DBUS_X_LIBS) \
- $(NULL)
-
-dbus_run_session_SOURCES = \
- dbus-run-session.c
-
-dbus_run_session_LDADD = \
- $(top_builddir)/dbus/libdbus-1.la \
- $(NULL)
+ dbus-launch.h
endif
dbus_cleanup_sockets_SOURCES= \
@@ -88,28 +64,10 @@
$(top_builddir)/dbus/libdbus-1.la \
$(NULL)
-examplesdir = ${docdir}/examples
-dist_examples_SCRIPTS = \
- GetAllMatchRules.py \
+dbus_launch_LDADD = \
+ $(DBUS_X_LIBS) \
$(NULL)
-dbus_test_tool_SOURCES = \
- dbus-echo.c \
- dbus-spam.c \
- tool-common.c \
- tool-common.h \
- test-tool.c \
- test-tool.h \
- $(NULL)
-dbus_test_tool_LDADD = $(top_builddir)/dbus/libdbus-1.la
-
-dbus_update_activation_environment_SOURCES = \
- dbus-update-activation-environment.c \
- tool-common.c \
- tool-common.h \
- $(NULL)
-dbus_update_activation_environment_LDADD = $(top_builddir)/dbus/libdbus-1.la
-
EXTRA_DIST = run-with-tmp-session-bus.sh strtoll.c strtoull.c
CLEANFILES = \
run-with-tmp-session-bus.conf
diff --git a/tools/dbus-echo.c b/tools/dbus-echo.c
deleted file mode 100644
index 738b1cb..0000000
--- a/tools/dbus-echo.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* dbus-echo.c - a plain libdbus echo server
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <dbus/dbus.h>
-
-#include "dbus/dbus-sysdeps.h"
-#include "test-tool.h"
-#include "tool-common.h"
-
-static int sleep_ms = -1;
-static dbus_bool_t noreply = FALSE;
-static dbus_bool_t noread = FALSE;
-
-static void
-usage_echo (int exit_with)
-{
- fprintf (stderr,
- "Usage: dbus-test-tool echo [OPTIONS]\n"
- "\n"
- "Respond to all method calls with an empty reply.\n"
- "\n"
- "Options:\n"
- "\n"
- " --name=NAME claim this well-known name first\n"
- "\n"
- " --sleep-ms=N sleep N milliseconds before sending each reply\n"
- "\n"
- " --session use the session bus (default)\n"
- " --system use the system bus\n"
- );
- exit (exit_with);
-}
-
-static void
-usage_black_hole (int exit_with)
-{
- fprintf (stderr,
- "Usage: dbus-test-tool black-hole [OPTIONS]\n"
- "\n"
- "Receive method calls but do not reply.\n"
- "\n"
- "Options:\n"
- "\n"
- " --name=NAME claim this well-known name first\n"
- "\n"
- " --no-read don't read anything on the D-Bus socket\n"
- "\n"
- " --session use the session bus (default)\n"
- " --system use the system bus\n"
- );
- exit (exit_with);
-}
-
-static DBusHandlerResult
-filter (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- DBusMessage *reply;
-
- if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (sleep_ms > 0)
- {
- _dbus_sleep_milliseconds (sleep_ms);
- }
-
- if (!noreply)
- {
- reply = dbus_message_new_method_return (message);
-
- if (reply == NULL)
- tool_oom ("allocating reply");
-
- if (!dbus_connection_send (connection, reply, NULL))
- tool_oom ("sending reply");
-
- dbus_message_unref (reply);
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusConnection *
-init_connection (DBusBusType type, const char *name)
-{
- DBusConnection *connection;
- DBusError error = DBUS_ERROR_INIT;
-
- connection = dbus_bus_get (type, &error);
-
- if (connection == NULL)
- {
- fprintf (stderr, "Failed to connect to bus: %s: %s\n",
- error.name, error.message);
- dbus_error_free (&error);
- exit (1);
- }
-
- if (name != NULL)
- {
- if (dbus_bus_request_name (connection, name, DBUS_NAME_FLAG_DO_NOT_QUEUE,
- NULL) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
- {
- fprintf (stderr, "failed to take bus name %s\n", name);
- exit (1);
- }
- }
- else
- {
- printf ("%s\n", dbus_bus_get_unique_name (connection));
- }
-
- if (!dbus_connection_add_filter (connection, filter, NULL, NULL))
- tool_oom ("adding message filter");
-
- return connection;
-}
-
-int
-dbus_test_tool_echo (int argc, char **argv)
-{
- DBusConnection *connection;
- DBusBusType type = DBUS_BUS_SESSION;
- int i;
- const char *name = NULL;
-
- /* argv[1] is the tool name, so start from 2 */
-
- for (i = 2; i < argc; i++)
- {
- const char *arg = argv[i];
-
- if (strcmp (arg, "--system") == 0)
- {
- type = DBUS_BUS_SYSTEM;
- }
- else if (strcmp (arg, "--session") == 0)
- {
- type = DBUS_BUS_SESSION;
- }
- else if (strstr (arg, "--name=") == arg)
- {
- name = arg + strlen ("--name=");
- }
- else if (strstr (arg, "--sleep-ms=") == arg)
- {
- sleep_ms = atoi (arg + strlen ("--sleep-ms="));
- }
- else
- {
- usage_echo (2);
- }
- }
-
- connection = init_connection (type, name);
-
- while (dbus_connection_read_write_dispatch (connection, -1))
- {}
-
- dbus_connection_unref (connection);
- return 0;
-}
-
-int
-dbus_test_tool_black_hole (int argc, char **argv)
-{
- DBusConnection *connection;
- DBusBusType type = DBUS_BUS_SESSION;
- int i;
- const char *name = NULL;
-
- /* argv[1] is the tool name, so start from 2 */
-
- for (i = 2; i < argc; i++)
- {
- const char *arg = argv[i];
-
- if (strcmp (arg, "--system") == 0)
- {
- type = DBUS_BUS_SYSTEM;
- }
- else if (strcmp (arg, "--session") == 0)
- {
- type = DBUS_BUS_SESSION;
- }
- else if (strstr (arg, "--name=") == arg)
- {
- name = arg + strlen ("--name=");
- }
- else if (strcmp (arg, "--no-read") == 0)
- {
- noread = TRUE;
- }
- else
- {
- usage_black_hole (2);
- }
- }
-
- connection = init_connection (type, name);
-
- if (noread)
- {
- while (1)
- _dbus_sleep_milliseconds (3600);
- }
-
- noreply = TRUE;
-
- while (dbus_connection_read_write_dispatch (connection, -1))
- {}
-
- dbus_connection_unref (connection);
- return 0;
-}
diff --git a/tools/dbus-launch-win.c b/tools/dbus-launch-win.c
index 1dfd095..215fac3 100644
--- a/tools/dbus-launch-win.c
+++ b/tools/dbus-launch-win.c
@@ -89,7 +89,7 @@
wchar_t *p;
wchar_t *daemon_name;
int result;
-
+ int showConsole = 0;
#ifdef DBUS_WINCE
char *s = NULL;
#else
@@ -102,6 +102,10 @@
BOOL inherit = TRUE;
DWORD flags = 0;
+#ifdef AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE
+ if (verbose)
+ showConsole = 1;
+#endif
GetModuleFileNameW (NULL, dbusDaemonPath, DIM (dbusDaemonPath));
daemon_name = WCSTRINGIFY(DBUS_DAEMON_NAME) L".exe";
@@ -155,8 +159,8 @@
if (result == 0)
{
if (verbose)
- fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%u\n",
- (unsigned)GetLastError ());
+ fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%d\n",
+ GetLastError ());
return 4;
}
diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c
index a09444b..c7e3330 100644
--- a/tools/dbus-launch-x11.c
+++ b/tools/dbus-launch-x11.c
@@ -414,7 +414,7 @@
"# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will\n"
"# be used rather than this file.\n"
"# See \"man dbus-launch\" for more details.\n"
- "DBUS_SESSION_BUS_ADDRESS='%s'\n"
+ "DBUS_SESSION_BUS_ADDRESS=%s\n"
"DBUS_SESSION_BUS_PID=%ld\n"
"DBUS_SESSION_BUS_WINDOWID=%ld\n",
get_machine_uuid (),
diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c
index 80e4a24..1ec9ae5 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -38,19 +38,11 @@
#include <sys/select.h>
#include <time.h>
-#include <dbus/dbus.h>
-#include "dbus/dbus-internals.h"
-
#ifdef DBUS_BUILD_X11
#include <X11/Xlib.h>
extern Display *xdisplay;
#endif
-#include "dbus/dbus-internals.h"
-#include "dbus/dbus-sysdeps-unix.h"
-
-#include "tool-common.h"
-
/* PROCESSES
*
* If you are in a shell and run "dbus-launch myapp", here is what happens:
@@ -110,33 +102,56 @@
exit (1);
}
- machine_uuid = _dbus_strdup (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 */
static int
read_machine_uuid_if_needed (void)
{
+ FILE *f;
+ char uuid[UUID_MAXLEN];
+ size_t len;
+ int ret = FALSE;
+
if (machine_uuid != NULL)
return TRUE;
- machine_uuid = dbus_get_local_machine_id ();
-
- if (machine_uuid == NULL)
+ f = fopen (DBUS_MACHINE_UUID_FILE, "r");
+ if (f == NULL)
return FALSE;
+ if (fgets (uuid, UUID_MAXLEN, f) == NULL)
+ goto out;
+
+ len = strlen (uuid);
+ if (len < 32)
+ goto out;
+
+ /* rstrip the read uuid */
+ while (len > 31 && isspace(uuid[len - 1]))
+ len--;
+
+ if (len != 32)
+ goto out;
+
+ uuid[len] = '\0';
+ machine_uuid = xstrdup (uuid);
verbose ("UID: %s\n", machine_uuid);
- return TRUE;
+ ret = TRUE;
+
+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;
@@ -161,16 +176,12 @@
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] [--binary-syntax] [--close-stderr]"
- " [--exit-with-session] [--autolaunch=MACHINEID]"
- " [--config-file=FILENAME] [PROGRAM] [ARGS...]\n");
+ fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n");
exit (ecode);
}
@@ -205,26 +216,6 @@
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 */
@@ -389,9 +380,6 @@
static void
kill_bus(void)
{
- if (bus_pid_to_kill <= 0)
- return;
-
verbose ("Killing message bus and exiting babysitter\n");
kill (bus_pid_to_kill, SIGTERM);
sleep (3);
@@ -426,8 +414,7 @@
else if (c_shell_syntax)
{
printf ("setenv DBUS_SESSION_BUS_ADDRESS '%s';\n", bus_address);
- if (bus_pid)
- printf ("set DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
+ printf ("set DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
if (bus_wid)
printf ("set DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid);
fflush (stdout);
@@ -436,8 +423,7 @@
{
printf ("DBUS_SESSION_BUS_ADDRESS='%s';\n", bus_address);
printf ("export DBUS_SESSION_BUS_ADDRESS;\n");
- if (bus_pid)
- printf ("DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
+ printf ("DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
if (bus_wid)
printf ("DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid);
fflush (stdout);
@@ -445,8 +431,7 @@
else
{
printf ("DBUS_SESSION_BUS_ADDRESS=%s\n", bus_address);
- if (bus_pid)
- printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
+ printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
if (bus_wid)
printf ("DBUS_SESSION_BUS_WINDOWID=%ld\n", (long) bus_wid);
fflush (stdout);
@@ -460,7 +445,9 @@
{
switch (sig)
{
+#ifdef SIGHUP
case SIGHUP:
+#endif
case SIGINT:
case SIGTERM:
got_sighup = TRUE;
@@ -522,7 +509,7 @@
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");
- kill_bus_and_exit (1);
+ exit (1);
}
while (TRUE)
@@ -646,7 +633,6 @@
s = getenv ("DBUS_DEBUG_OUTPUT");
if (s == NULL || *s == '\0')
dup2 (dev_null_fd, 2);
- close (dev_null_fd);
}
else
{
@@ -768,35 +754,31 @@
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])
- {
- while (i > 1)
- free (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])
+ 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");
@@ -840,27 +822,10 @@
int bus_pid_to_babysitter_pipe[2];
int bus_address_to_launcher_pipe[2];
char *config_file;
- dbus_bool_t user_bus_supported = FALSE;
- DBusString user_bus;
- const char *error_str;
-
+
exit_with_session = FALSE;
config_file = NULL;
-
- /* Ensure that the first three fds are open, to ensure that when we
- * create other file descriptors (for example for epoll, inotify or
- * a socket), they never get assigned as fd 0, 1 or 2. If they were,
- * which could happen if our caller had (incorrectly) closed those
- * standard fds, then we'd start dbus-daemon with those fds closed,
- * which is unexpected and could cause it to misbehave. */
- if (!_dbus_ensure_standard_fds (0, &error_str))
- {
- fprintf (stderr,
- "dbus-launch: fatal error setting up standard fds: %s: %s\n",
- error_str, _dbus_strerror (errno));
- return 1;
- }
-
+
prev_arg = NULL;
i = 1;
while (i < argc)
@@ -1010,7 +975,6 @@
char *address;
pid_t pid;
long wid;
- DBusError error = DBUS_ERROR_INIT;
if (get_machine_uuid () == NULL)
{
@@ -1018,37 +982,6 @@
exit (1);
}
- if (!_dbus_string_init (&user_bus))
- tool_oom ("initializing");
-
- /* If we have an XDG_RUNTIME_DIR and it contains a suitable socket,
- * dbus-launch --autolaunch can use it, since --autolaunch implies
- * "I'm OK with getting a bus that is already active".
- *
- * (However, plain dbus-launch without --autolaunch must not do so,
- * because that would break lots of regression tests, which often
- * use dbus-launch instead of the more appropriate dbus-run-session.)
- *
- * At this stage, we just save the user bus's address; later on, the
- * "babysitter" process will be available to advertise the user-bus
- * on the X11 display and in ~/.dbus/session-bus, for full
- * backwards compatibility.
- */
- if (!_dbus_lookup_user_bus (&user_bus_supported, &user_bus, &error))
- {
- fprintf (stderr, "%s\n", error.message);
- exit (1);
- }
- else if (user_bus_supported)
- {
- verbose ("=== Using existing user bus \"%s\"\n",
- _dbus_string_get_const_data (&user_bus));
- }
- else
- {
- _dbus_string_free (&user_bus);
- }
-
verbose ("Autolaunch enabled (using X11).\n");
if (!exit_with_session)
{
@@ -1158,22 +1091,6 @@
close (bus_pid_to_babysitter_pipe[READ_END]);
close (bus_pid_to_babysitter_pipe[WRITE_END]);
- /* If we have a user bus and want to use it, do so instead of
- * exec'ing a new dbus-daemon. */
- if (autolaunch && user_bus_supported)
- {
- do_write (bus_pid_to_launcher_pipe[WRITE_END], "0\n", 2);
- close (bus_pid_to_launcher_pipe[WRITE_END]);
-
- do_write (bus_address_to_launcher_pipe[WRITE_END],
- _dbus_string_get_const_data (&user_bus),
- _dbus_string_get_length (&user_bus));
- do_write (bus_address_to_launcher_pipe[WRITE_END], "\n", 1);
- close (bus_address_to_launcher_pipe[WRITE_END]);
-
- exit (0);
- }
-
sprintf (write_pid_fd_as_string,
"%d", bus_pid_to_launcher_pipe[WRITE_END]);
@@ -1182,41 +1099,24 @@
verbose ("Calling exec()\n");
-#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");
+#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);
- 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 */
+ 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 */
execl (DBUS_DAEMONDIR"/dbus-daemon",
DBUS_DAEMONDIR"/dbus-daemon",
@@ -1261,6 +1161,7 @@
char *end;
long wid = 0;
long val;
+ int ret2;
verbose ("=== Parent dbus-launch continues\n");
@@ -1329,17 +1230,11 @@
bus_pid = val;
- /* Have to initialize bus_pid_to_kill ASAP, so that the
- X error callback can kill it if an error happens. */
- bus_pid_to_kill = bus_pid;
-
close (bus_pid_to_launcher_pipe[READ_END]);
#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 */
@@ -1349,6 +1244,7 @@
{
char *address = NULL;
/* another window got added. Return its address */
+ bus_pid_to_kill = bus_pid;
if (x11_get_address (&address, &bus_pid, &wid)
&& address != NULL)
{
diff --git a/tools/dbus-launch.h b/tools/dbus-launch.h
index d0ede6b..8220bb8 100644
--- a/tools/dbus-launch.h
+++ b/tools/dbus-launch.h
@@ -26,8 +26,6 @@
#include <sys/types.h>
-#include <dbus/dbus.h>
-
#ifndef TRUE
#define TRUE (1)
#endif
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 483d42e..a4b5478 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -20,9 +20,6 @@
*/
#include <config.h>
-
-#include "dbus/dbus-internals.h" /* just for the macros */
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -37,39 +34,81 @@
#include <time.h>
#include "dbus-print-message.h"
-#include "tool-common.h"
#define EAVESDROPPING_RULE "eavesdrop=true"
-#ifndef STDOUT_FILENO
-#define STDOUT_FILENO 1
+#ifdef DBUS_WIN
+
+/* gettimeofday is not defined on windows */
+#define DBUS_SECONDS_SINCE_1601 11644473600LL
+#define DBUS_USEC_IN_SEC 1000000LL
+
+#ifdef DBUS_WINCE
+
+#ifndef _IOLBF
+#define _IOLBF 0x40
+#endif
+#ifndef _IONBF
+#define _IONBF 0x04
#endif
-/* http://www.tcpdump.org/linktypes.html */
-#define LINKTYPE_DBUS 231
+void
+GetSystemTimeAsFileTime (LPFILETIME ftp)
+{
+ SYSTEMTIME st;
+ GetSystemTime (&st);
+ SystemTimeToFileTime (&st, ftp);
+}
+#endif
+
+static int
+gettimeofday (struct timeval *__p,
+ void *__t)
+{
+ union {
+ unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
+ FILETIME ft;
+ } now;
+
+ GetSystemTimeAsFileTime (&now.ft);
+ __p->tv_usec = (long) ((now.ns100 / 10LL) % DBUS_USEC_IN_SEC);
+ __p->tv_sec = (long)(((now.ns100 / 10LL) / DBUS_SECONDS_SINCE_1601) - DBUS_SECONDS_SINCE_1601);
+
+ return 0;
+}
+#endif
+
+inline static void
+oom (const char *doing)
+{
+ fprintf (stderr, "OOM while %s\n", doing);
+ exit (1);
+}
static DBusHandlerResult
monitor_filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+ DBusMessage *message,
+ void *user_data)
{
- long sec = 0, usec = 0;
-
- _dbus_get_real_time (&sec, &usec);
-
- print_message (message, FALSE, sec, usec);
+ print_message (message, FALSE);
if (dbus_message_is_signal (message,
DBUS_INTERFACE_LOCAL,
"Disconnected"))
exit (0);
-
- /* Monitors must not allow libdbus to reply to messages, so we eat
- * the message. See bug 1719.
+
+ /* Conceptually we want this to be
+ * DBUS_HANDLER_RESULT_NOT_YET_HANDLED, but this raises
+ * some problems. See bug 1719.
*/
return DBUS_HANDLER_RESULT_HANDLED;
}
+#ifdef __APPLE__
+#define PROFILE_TIMED_FORMAT "%s\t%lu\t%d"
+#else
+#define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu"
+#endif
#define TRAP_NULL_STRING(str) ((str) ? (str) : "<none>")
typedef enum
@@ -85,30 +124,23 @@
} ProfileAttributeFlags;
static void
-profile_print_headers (void)
-{
- printf ("#type\ttimestamp\tserial\tsender\tdestination\tpath\tinterface\tmember\n");
- printf ("#\t\t\t\t\tin_reply_to\n");
-}
-
-static void
profile_print_with_attrs (const char *type, DBusMessage *message,
- long sec, long usec, ProfileAttributeFlags attrs)
+ struct timeval *t, ProfileAttributeFlags attrs)
{
- printf ("%s\t%ld.%06ld", type, sec, usec);
+ printf (PROFILE_TIMED_FORMAT, type, t->tv_sec, t->tv_usec);
if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL)
printf ("\t%u", dbus_message_get_serial (message));
+ if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL)
+ printf ("\t%u", dbus_message_get_reply_serial (message));
+
if (attrs & PROFILE_ATTRIBUTE_FLAG_SENDER)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_sender (message)));
if (attrs & PROFILE_ATTRIBUTE_FLAG_DESTINATION)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_destination (message)));
- if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL)
- printf ("\t%u", dbus_message_get_reply_serial (message));
-
if (attrs & PROFILE_ATTRIBUTE_FLAG_PATH)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_path (message)));
@@ -127,61 +159,53 @@
static void
print_message_profile (DBusMessage *message)
{
- static dbus_bool_t first = TRUE;
- long sec = 0, usec = 0;
+ struct timeval t;
- if (first)
+ if (gettimeofday (&t, NULL) < 0)
{
- profile_print_headers ();
- first = FALSE;
+ printf ("un\n");
+ return;
}
- _dbus_get_real_time (&sec, &usec);
-
switch (dbus_message_get_type (message))
{
case DBUS_MESSAGE_TYPE_METHOD_CALL:
- profile_print_with_attrs ("mc", message, sec, usec,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_SENDER |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_PATH |
- PROFILE_ATTRIBUTE_FLAG_INTERFACE |
- PROFILE_ATTRIBUTE_FLAG_MEMBER);
- break;
+ profile_print_with_attrs ("mc", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_SENDER |
+ PROFILE_ATTRIBUTE_FLAG_PATH |
+ PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+ PROFILE_ATTRIBUTE_FLAG_MEMBER);
+ break;
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
- profile_print_with_attrs ("mr", message, sec, usec,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_SENDER |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
- break;
+ profile_print_with_attrs ("mr", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+ break;
case DBUS_MESSAGE_TYPE_ERROR:
- profile_print_with_attrs ("err", message, sec, usec,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_SENDER |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
- break;
+ profile_print_with_attrs ("err", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+ break;
case DBUS_MESSAGE_TYPE_SIGNAL:
- profile_print_with_attrs ("sig", message, sec, usec,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_SENDER |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_PATH |
- PROFILE_ATTRIBUTE_FLAG_INTERFACE |
- PROFILE_ATTRIBUTE_FLAG_MEMBER);
- break;
+ profile_print_with_attrs ("sig", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_PATH |
+ PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+ PROFILE_ATTRIBUTE_FLAG_MEMBER);
+ break;
default:
- printf ("%s\t%ld.%06ld", "tun", sec, usec);
- break;
+ printf (PROFILE_TIMED_FORMAT "\n", "tun", t.tv_sec, t.tv_usec);
+ break;
}
}
static DBusHandlerResult
-profile_filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+profile_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
print_message_profile (message);
@@ -193,79 +217,10 @@
return DBUS_HANDLER_RESULT_HANDLED;
}
-typedef enum {
- BINARY_MODE_NOT,
- BINARY_MODE_RAW,
- BINARY_MODE_PCAP
-} BinaryMode;
-
-static DBusHandlerResult
-binary_filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- BinaryMode mode = _DBUS_POINTER_TO_INT (user_data);
- char *blob;
- int len;
-
- /* It would be nice if we could do a zero-copy "peek" one day, but libdbus
- * is so copy-happy that this isn't really a big deal.
- */
- if (!dbus_message_marshal (message, &blob, &len))
- tool_oom ("retrieving message");
-
- switch (mode)
- {
- case BINARY_MODE_PCAP:
- {
- long tv_sec, tv_usec;
- /* seconds, microseconds, bytes captured (possibly truncated),
- * original length.
- * http://wiki.wireshark.org/Development/LibpcapFileFormat
- */
- dbus_uint32_t header[4] = { 0, 0, len, len };
-
- /* If this gets padded then we'd need to write it out in pieces */
- _DBUS_STATIC_ASSERT (sizeof (header) == 16);
-
- _dbus_get_real_time (&tv_sec, &tv_usec);
- header[0] = tv_sec;
- header[1] = tv_usec;
-
- if (!tool_write_all (STDOUT_FILENO, header, sizeof (header)))
- {
- perror ("dbus-monitor: write");
- exit (1);
- }
- }
- break;
-
- case BINARY_MODE_RAW:
- default:
- /* nothing special, just the raw message stream */
- break;
- }
-
- if (!tool_write_all (STDOUT_FILENO, blob, len))
- {
- perror ("dbus-monitor: write");
- exit (1);
- }
-
- dbus_free (blob);
-
- if (dbus_message_is_signal (message,
- DBUS_INTERFACE_LOCAL,
- "Disconnected"))
- exit (0);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
static void
usage (char *name, int ecode)
{
- fprintf (stderr, "Usage: %s [--system | --session | --address ADDRESS] [--monitor | --profile | --pcap | --binary ] [watch expressions]\n", name);
+ fprintf (stderr, "Usage: %s [--system | --session | --address ADDRESS] [--monitor | --profile ] [watch expressions]\n", name);
exit (ecode);
}
@@ -284,66 +239,6 @@
}
}
-static dbus_bool_t
-become_monitor (DBusConnection *connection,
- int numFilters,
- const char * const *filters)
-{
- DBusError error = DBUS_ERROR_INIT;
- DBusMessage *m;
- DBusMessage *r;
- int i;
- dbus_uint32_t zero = 0;
- DBusMessageIter appender, array_appender;
-
- m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
-
- if (m == NULL)
- tool_oom ("becoming a monitor");
-
- dbus_message_iter_init_append (m, &appender);
-
- if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
- &array_appender))
- tool_oom ("opening string array");
-
- for (i = 0; i < numFilters; i++)
- {
- if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
- &filters[i]))
- tool_oom ("adding filter to array");
- }
-
- if (!dbus_message_iter_close_container (&appender, &array_appender) ||
- !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
- tool_oom ("finishing arguments");
-
- r = dbus_connection_send_with_reply_and_block (connection, m, -1, &error);
-
- if (r != NULL)
- {
- dbus_message_unref (r);
- }
- else if (dbus_error_has_name (&error, DBUS_ERROR_UNKNOWN_INTERFACE))
- {
- fprintf (stderr, "dbus-monitor: unable to enable new-style monitoring, "
- "your dbus-daemon is too old. Falling back to eavesdropping.\n");
- dbus_error_free (&error);
- }
- else
- {
- fprintf (stderr, "dbus-monitor: unable to enable new-style monitoring: "
- "%s: \"%s\". Falling back to eavesdropping.\n",
- error.name, error.message);
- dbus_error_free (&error);
- }
-
- dbus_message_unref (m);
-
- return (r != NULL);
-}
-
int
main (int argc, char *argv[])
{
@@ -353,7 +248,7 @@
DBusHandleMessageFunction filter_func = monitor_filter_func;
char *address = NULL;
dbus_bool_t seen_bus_type = FALSE;
- BinaryMode binary_mode = BINARY_MODE_NOT;
+
int i = 0, j = 0, numFilters = 0;
char **filters = NULL;
@@ -395,31 +290,15 @@
usage (argv[0], 1);
}
else if (!strcmp (arg, "--help"))
- usage (argv[0], 0);
+ usage (argv[0], 0);
else if (!strcmp (arg, "--monitor"))
- {
- filter_func = monitor_filter_func;
- binary_mode = BINARY_MODE_NOT;
- }
+ filter_func = monitor_filter_func;
else if (!strcmp (arg, "--profile"))
- {
- filter_func = profile_filter_func;
- binary_mode = BINARY_MODE_NOT;
- }
- else if (!strcmp (arg, "--binary"))
- {
- filter_func = binary_filter_func;
- binary_mode = BINARY_MODE_RAW;
- }
- else if (!strcmp (arg, "--pcap"))
- {
- filter_func = binary_filter_func;
- binary_mode = BINARY_MODE_PCAP;
- }
+ filter_func = profile_filter_func;
else if (!strcmp (arg, "--"))
- continue;
+ continue;
else if (arg[0] == '-')
- usage (argv[0], 1);
+ usage (argv[0], 1);
else {
unsigned int filter_len;
numFilters++;
@@ -430,10 +309,10 @@
filters = (char **) realloc (filters, numFilters * sizeof (char *));
if (filters == NULL)
- tool_oom ("adding a new filter slot");
- filters[j] = (char *) malloc (filter_len);
+ oom ("adding a new filter slot");
+ filters[j] = (char *) malloc (filter_len * sizeof (char *));
if (filters[j] == NULL)
- tool_oom ("adding a new filter");
+ oom ("adding a new filter");
snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg);
j++;
}
@@ -447,12 +326,12 @@
if (connection)
{
if (!dbus_bus_register (connection, &error))
- {
+ {
fprintf (stderr, "Failed to register connection to bus at %s: %s\n",
- address, error.message);
+ address, error.message);
dbus_error_free (&error);
exit (1);
- }
+ }
}
}
else
@@ -483,40 +362,11 @@
exit (1);
}
- /* Receive o.fd.Peer messages as normal messages, rather than having
- * libdbus handle them internally, which is the wrong thing for
- * a monitor */
- dbus_connection_set_route_peer_messages (connection, TRUE);
-
- if (!dbus_connection_add_filter (connection, filter_func,
- _DBUS_INT_TO_POINTER (binary_mode), NULL))
+ if (numFilters)
{
- fprintf (stderr, "Couldn't add filter!\n");
- exit (1);
- }
-
- if (become_monitor (connection, numFilters,
- (const char * const *) filters))
- {
- /* no more preparation needed */
- }
- else if (numFilters)
- {
- size_t offset = 0;
for (i = 0; i < j; i++)
{
- 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);
- }
-
+ dbus_bus_add_match (connection, filters[i], &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "Failed to setup match \"%s\": %s\n",
@@ -524,64 +374,37 @@
dbus_error_free (&error);
exit (1);
}
- free(filters[i]);
+ free(filters[i]);
}
}
else
{
dbus_bus_add_match (connection,
- EAVESDROPPING_RULE,
- &error);
+ EAVESDROPPING_RULE ",type='signal'",
+ &error);
if (dbus_error_is_set (&error))
- {
- dbus_error_free (&error);
- dbus_bus_add_match (connection,
- "",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- }
+ goto lose;
+ dbus_bus_add_match (connection,
+ EAVESDROPPING_RULE ",type='method_call'",
+ &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;
}
- switch (binary_mode)
- {
- case BINARY_MODE_NOT:
- case BINARY_MODE_RAW:
- break;
-
- case BINARY_MODE_PCAP:
- {
- /* We're not using libpcap because the file format is simple
- * enough not to need it.
- * http://wiki.wireshark.org/Development/LibpcapFileFormat */
- struct {
- dbus_uint32_t magic;
- dbus_uint16_t major_version;
- dbus_uint16_t minor_version;
- dbus_int32_t timezone;
- dbus_uint32_t precision;
- dbus_uint32_t max_length;
- dbus_uint32_t link_type;
- } header = {
- 0xA1B2C3D4U, /* magic number */
- 2, 4, /* v2.4 */
- 0, /* capture in GMT */
- 0, /* no opinion on timestamp precision */
- (1 << 27), /* D-Bus spec says so */
- LINKTYPE_DBUS
- };
-
- /* Assert that there is no padding */
- _DBUS_STATIC_ASSERT (sizeof (header) == 24);
-
- if (!tool_write_all (STDOUT_FILENO, &header, sizeof (header)))
- {
- perror ("dbus-monitor: write");
- exit (1);
- }
- }
- break;
- }
+ if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) {
+ fprintf (stderr, "Couldn't add filter!\n");
+ exit (1);
+ }
while (dbus_connection_read_write_dispatch(connection, -1))
;
diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c
index aaaca15..75d00ac 100644
--- a/tools/dbus-print-message.c
+++ b/tools/dbus-print-message.c
@@ -23,22 +23,9 @@
#include <config.h>
#include "dbus-print-message.h"
-#ifdef DBUS_UNIX
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <arpa/inet.h>
-#endif
-
#include <stdlib.h>
#include "config.h"
-#include "tool-common.h"
-
static const char*
type_to_name (int message_type)
{
@@ -67,9 +54,7 @@
}
static void
-print_hex (const unsigned char *bytes,
- unsigned int len,
- int depth)
+print_hex (unsigned char *bytes, unsigned int len, int depth)
{
unsigned int i, columns;
@@ -111,471 +96,52 @@
#define DEFAULT_SIZE 100
-#include <inttypes.h>
-#define DBUS_INT64_PRINTF_ARGUMENT PRIi64
-#define DBUS_UINT64_PRINTF_ARGUMENT PRIu64
-#define MAXPFX 4096
-
-static int
-pf_can_simple(DBusMessageIter *iter)
-{
- switch (dbus_message_iter_get_arg_type(iter))
- {
- case DBUS_TYPE_STRING:
- case DBUS_TYPE_INT16:
- case DBUS_TYPE_INT32:
- case DBUS_TYPE_UINT16:
- case DBUS_TYPE_UINT32:
- case DBUS_TYPE_INT64:
- case DBUS_TYPE_UINT64:
- case DBUS_TYPE_BYTE:
- case DBUS_TYPE_BOOLEAN:
- case DBUS_TYPE_DOUBLE:
- return 1;
- default:
- return 0;
- }
-}
-
-static void pf_key(DBusMessageIter *iter, const char *pfx, char *buf, size_t sz)
-{
- char *sv;
- dbus_bool_t bv;
- dbus_int16_t i16v;
- dbus_int32_t i32v;
- dbus_int64_t i64v;
- dbus_uint16_t u16v;
- dbus_uint32_t u32v;
- dbus_uint64_t u64v;
- unsigned char u8v;
- double dv;
-
- switch (dbus_message_iter_get_arg_type(iter)) {
- case DBUS_TYPE_STRING:
- dbus_message_iter_get_basic(iter, &sv);
- snprintf(buf, sz, "%s/%s", pfx, sv);
- break;
- case DBUS_TYPE_BOOLEAN:
- dbus_message_iter_get_basic(iter, &bv);
- snprintf(buf, sz, "%s/%s", pfx, (bv ? "true" : "false"));
- break;
- case DBUS_TYPE_INT16:
- dbus_message_iter_get_basic(iter, &i16v);
- snprintf(buf, sz, "%s/%d", pfx, i16v);
- break;
- case DBUS_TYPE_INT32:
- dbus_message_iter_get_basic(iter, &i32v);
- snprintf(buf, sz, "%s/%d", pfx, i32v);
- break;
- case DBUS_TYPE_INT64:
- dbus_message_iter_get_basic(iter, &i64v);
-#ifdef DBUS_INT64_PRINTF_ARGUMENT
- snprintf(buf, sz, "%s/%" DBUS_INT64_PRINTF_ARGUMENT, pfx, i64v);
-#else
- snprintf(buf, sz, "%s/[int64]", pfx);
-#endif
- break;
- case DBUS_TYPE_UINT16:
- dbus_message_iter_get_basic(iter, &u16v);
- snprintf(buf, sz, "%s/%u", pfx, u16v);
- break;
- case DBUS_TYPE_UINT32:
- dbus_message_iter_get_basic(iter, &u32v);
- snprintf(buf, sz, "%s/%u", pfx, u32v);
- break;
- case DBUS_TYPE_UINT64:
- dbus_message_iter_get_basic(iter, &u64v);
-#ifdef DBUS_UINT64_PRINTF_ARGUMENT
- snprintf(buf, sz, "%s/%" DBUS_UINT64_PRINTF_ARGUMENT, pfx, u64v);
-#else
- snprintf(buf, sz, "%s/[uint64]", pfx);
-#endif
- break;
- case DBUS_TYPE_BYTE:
- dbus_message_iter_get_basic(iter, &u8v);
- snprintf(buf, sz, "%s/%02x", pfx, (unsigned int)u8v & 0xFF);
- break;
- case DBUS_TYPE_DOUBLE:
- dbus_message_iter_get_basic(iter, &dv);
- snprintf(buf, sz, "%s/%g", pfx, dv);
- break;
- default:
- snprintf(buf, sz, "%s/[pf-unknown]", pfx);
- break;
- }
-}
-
-static void print_fixed_iter(DBusMessageIter *iter, const char *pfx, int all);
-
-static void pf_string(DBusMessageIter *iter, const char *pfx)
-{
- char *val;
- dbus_message_iter_get_basic(iter, &val);
- printf("%s%s%s\n", pfx, pfx[0] ? " " : "", val);
-}
-
-static void pf_boolean(DBusMessageIter *iter, const char *pfx)
-{
- dbus_bool_t bv;
- dbus_message_iter_get_basic(iter, &bv);
- printf("%s%s%s\n", pfx, pfx[0] ? " " : "", (bv ? "true" : "false"));
-}
-
-static void pf_uint16(DBusMessageIter *iter, const char *pfx)
-{
- dbus_uint16_t uv;
- dbus_message_iter_get_basic(iter, &uv);
- printf("%s%s%u\n", pfx, pfx[0] ? " " : "", uv);
-}
-
-static void pf_int16(DBusMessageIter *iter, const char *pfx)
-{
- dbus_int16_t iv;
- dbus_message_iter_get_basic(iter, &iv);
- printf("%s%s%d\n", pfx, pfx[0] ? " " : "", iv);
-}
-
-static void pf_uint32(DBusMessageIter *iter, const char *pfx)
-{
- dbus_uint32_t uv;
- dbus_message_iter_get_basic(iter, &uv);
- printf("%s%s%u\n", pfx, pfx[0] ? " " : "", uv);
-}
-
-static void pf_int32(DBusMessageIter *iter, const char *pfx)
-{
- dbus_int32_t iv;
- dbus_message_iter_get_basic(iter, &iv);
- printf("%s%s%d\n", pfx, pfx[0] ? " " : "", iv);
-}
-
-static void pf_uint64(DBusMessageIter *iter, const char *pfx)
-{
- dbus_uint64_t uv;
- dbus_message_iter_get_basic(iter, &uv);
-#ifdef DBUS_UINT64_PRINTF_ARGUMENT
- printf("%s%s%" DBUS_UINT64_PRINTF_ARGUMENT "\n", pfx, pfx[0] ? " " : "", uv);
-#else
- printf("%s%s[uint64]\n", pfx, pfx[0] ? " " : "");
-#endif
-}
-
-static void pf_int64(DBusMessageIter *iter, const char *pfx)
-{
- dbus_int64_t iv;
- dbus_message_iter_get_basic(iter, &iv);
-#ifdef DBUS_INT64_PRINTF_ARGUMENT
- printf("%s%s%" DBUS_INT64_PRINTF_ARGUMENT "\n", pfx, pfx[0] ? " " : "", iv);
-#else
- printf("%s%s[int64]\n", pfx, pfx[0] ? " " : "");
-#endif
-}
-
-static void pf_double(DBusMessageIter *iter, const char *pfx)
-{
- double dv;
- dbus_message_iter_get_basic(iter, &dv);
- printf("%s%s%g\n", pfx, pfx[0] ? " " : "", dv);
-}
-
-static void pf_byte(DBusMessageIter *iter, const char *pfx)
-{
- unsigned char bv;
- dbus_message_iter_get_basic(iter, &bv);
- printf("%s%s%02x\n", pfx, pfx[0] ? " " : "", (unsigned int)bv & 0xFF);
-}
-
-static void pf_array(DBusMessageIter *iter, const char *pfx)
-{
- int type;
- DBusMessageIter subiter;
- char npfx[MAXPFX];
- int i = 0;
-
- dbus_message_iter_recurse(iter, &subiter);
- type = dbus_message_iter_get_arg_type(&subiter);
-
- while (type != DBUS_TYPE_INVALID)
- {
- snprintf(npfx, sizeof(npfx), "%s/%d", pfx, i);
- print_fixed_iter(&subiter, npfx, 0);
- dbus_message_iter_next(&subiter);
- type = dbus_message_iter_get_arg_type(&subiter);
- i++;
- }
-}
-
-static void pf_variant(DBusMessageIter *iter, const char *pfx)
-{
- DBusMessageIter subiter;
- dbus_message_iter_recurse(iter, &subiter);
- print_fixed_iter(&subiter, pfx, 0);
-}
-
-static void pf_dict(DBusMessageIter *iter, const char *pfx)
-{
- DBusMessageIter subiter;
- char npfx[MAXPFX];
-
- dbus_message_iter_recurse(iter, &subiter);
- /* Nasty hack to make string -> thing dicts more parseable. */
- if (pf_can_simple(&subiter))
- {
- pf_key(&subiter, pfx, npfx, sizeof(npfx));
- }
- else
- {
- snprintf(npfx, MAXPFX, "%s/[complex-key]", pfx);
- }
- dbus_message_iter_next(&subiter);
- print_fixed_iter(&subiter, npfx, 0);
-}
-
-static void print_fixed_iter(DBusMessageIter *iter, const char *pfx, int all)
-{
- static struct {
- int type;
- void (*func)(DBusMessageIter *iter, const char *pfx);
- } printers[] = {
- { DBUS_TYPE_STRING, pf_string },
- { DBUS_TYPE_ARRAY, pf_array },
- { DBUS_TYPE_STRUCT, pf_array }, /* yes, really. They're identical. */
- { DBUS_TYPE_VARIANT, pf_variant },
- { DBUS_TYPE_DICT_ENTRY, pf_dict },
- { DBUS_TYPE_BOOLEAN, pf_boolean },
- { DBUS_TYPE_UINT32, pf_uint32 },
- { DBUS_TYPE_INT32, pf_int32 },
- { DBUS_TYPE_SIGNATURE, pf_string },
- { DBUS_TYPE_OBJECT_PATH, pf_string },
- { DBUS_TYPE_INT16, pf_int16 },
- { DBUS_TYPE_UINT16, pf_uint16 },
- { DBUS_TYPE_INT64, pf_int64 },
- { DBUS_TYPE_UINT64, pf_uint64 },
- { DBUS_TYPE_DOUBLE, pf_double },
- { DBUS_TYPE_BYTE, pf_byte },
- { 0, NULL }
- };
- int type;
- int i;
-
- do
- {
- type = dbus_message_iter_get_arg_type(iter);
- if (type == DBUS_TYPE_INVALID)
- return;
- for (i = 0; printers[i].func; i++)
- {
- if (printers[i].type == type)
- {
- printers[i].func(iter, pfx);
- break;
- }
- }
- if (!printers[i].func)
- {
- printf("print-fixed-iter: no idea what %d is\n", type);
- }
- }
- while (all && dbus_message_iter_next(iter));
-}
-
-void print_message_fixed(DBusMessage *msg)
-{
- DBusMessageIter iter;
- int type;
-
- type = dbus_message_get_type(msg);
- dbus_message_iter_init(msg, &iter);
- print_fixed_iter(&iter, "", 1);
-}
-
static void
print_ay (DBusMessageIter *iter, int depth)
{
- /* True if every byte in the bytestring (so far) is printable
- * ASCII, with one exception: the last byte is also allowed to be \0. */
+ /* Not using DBusString because it's not public API. It's 2009, and I'm
+ * manually growing a string chunk by chunk.
+ */
+ unsigned char *bytes = malloc (DEFAULT_SIZE + 1);
+ unsigned int len = 0;
+ unsigned int max = DEFAULT_SIZE;
dbus_bool_t all_ascii = TRUE;
- const unsigned char *bytes;
- int len;
- int i;
+ int current_type;
- dbus_message_iter_get_fixed_array (iter, &bytes, &len);
-
- for (i = 0; i < len; i++)
+ while ((current_type = dbus_message_iter_get_arg_type (iter))
+ != DBUS_TYPE_INVALID)
{
- if ((bytes[i] < 32 || bytes[i] > 126) &&
- (i < len - 1 || bytes[i] != '\0'))
+ unsigned char val;
+
+ dbus_message_iter_get_basic (iter, &val);
+ bytes[len] = val;
+ len++;
+
+ if (val < 32 || val > 126)
+ all_ascii = FALSE;
+
+ if (len == max)
{
- all_ascii = FALSE;
- break;
+ max *= 2;
+ bytes = realloc (bytes, max + 1);
}
+
+ dbus_message_iter_next (iter);
}
- if (all_ascii && len > 0 && bytes[len - 1] == '\0')
+ if (all_ascii)
{
- printf ("array of bytes \"%s\" + \\0\n", bytes);
- }
- else if (all_ascii)
- {
- unsigned char *copy = dbus_malloc (len + 1);
-
- if (copy == NULL)
- tool_oom ("copying bytestring");
-
- memcpy (copy, bytes, len);
- copy[len] = '\0';
- printf ("array of bytes \"%s\"\n", copy);
- dbus_free (copy);
+ bytes[len] = '\0';
+ printf ("array of bytes \"%s\"\n", bytes);
}
else
{
print_hex (bytes, len, depth);
}
+
+ free (bytes);
}
-#ifdef DBUS_UNIX
-static void
-print_fd (int fd, int depth)
-{
- int ret;
- struct stat statbuf = {0,};
- union {
- struct sockaddr sa;
- struct sockaddr_storage storage;
- struct sockaddr_un un;
- struct sockaddr_in ipv4;
- struct sockaddr_in6 ipv6;
- } addr, peer;
- char hostip[INET6_ADDRSTRLEN];
- int addrlen = sizeof (addr);
- int peerlen = sizeof (peer);
- int has_peer;
-
- /* Don't print the fd number: it is different in every process and since
- * dbus-monitor closes the fd after reading it, the same number would be
- * printed again and again.
- */
- printf ("file descriptor\n");
- if (fd == -1)
- return;
-
- ret = fstat (fd, &statbuf);
- if (ret == -1)
- return;
-
- indent (depth+1);
- printf ("inode: %d\n", (int) statbuf.st_ino);
-
- indent (depth+1);
- printf ("type: ");
- if (S_ISREG(statbuf.st_mode))
- printf ("file\n");
- if (S_ISDIR(statbuf.st_mode))
- printf ("directory\n");
- if (S_ISCHR(statbuf.st_mode))
- printf ("char\n");
- if (S_ISBLK(statbuf.st_mode))
- printf ("block\n");
- if (S_ISFIFO(statbuf.st_mode))
- printf ("fifo\n");
- if (S_ISLNK(statbuf.st_mode))
- printf ("link\n");
- if (S_ISSOCK(statbuf.st_mode))
- printf ("socket\n");
-
- /* If it's not a socket, getsockname will just return -1 with errno
- * ENOTSOCK. */
-
- memset (&addr, 0, sizeof (addr));
- memset (&peer, 0, sizeof (peer));
-
- if (getsockname(fd, &addr.sa, &addrlen))
- return;
-
- has_peer = !getpeername(fd, &peer.sa, &peerlen);
-
- indent (depth+1);
- printf ("address family: ");
- switch (addr.sa.sa_family)
- {
- case AF_UNIX:
- printf("unix\n");
- if (addr.un.sun_path[0] == '\0')
- {
- /* Abstract socket might not be zero-terminated and length is
- * variable. Who designed this interface?
- * Write the name in the same way as /proc/net/unix
- * See manual page unix(7)
- */
- indent (depth+1);
- printf ("name @%.*s\n",
- (int) (addrlen - sizeof (sa_family_t) - 1),
- &(addr.un.sun_path[1]));
-
- if (has_peer)
- {
- indent (depth+1);
- printf ("peer @%.*s\n",
- (int) (addrlen - sizeof (sa_family_t) - 1),
- &(addr.un.sun_path[1]));
- }
- }
- else
- {
- indent (depth+1);
- printf ("name %s\n", addr.un.sun_path);
- if (has_peer)
- {
- indent (depth+1);
- printf ("peer %s\n", peer.un.sun_path);
- }
- }
- break;
-
- case AF_INET:
- printf ("inet\n");
- if (inet_ntop (AF_INET, &addr.ipv4.sin_addr, hostip, sizeof (hostip)))
- {
- indent (depth+1);
- printf ("name %s port %u\n", hostip, ntohs (addr.ipv4.sin_port));
- }
- if (has_peer && inet_ntop (AF_INET, &peer.ipv4.sin_addr, hostip, sizeof (hostip)))
- {
- indent (depth+1);
- printf ("peer %s port %u\n", hostip, ntohs (peer.ipv4.sin_port));
- }
-
- break;
-
-#ifdef AF_INET6
- case AF_INET6:
- printf ("inet6\n");
- if (inet_ntop (AF_INET6, &addr.ipv6.sin6_addr, hostip, sizeof (hostip)))
- {
- indent (depth+1);
- printf ("name %s port %u\n", hostip, ntohs (addr.ipv6.sin6_port));
- }
- if (has_peer && inet_ntop (AF_INET6, &peer.ipv6.sin6_addr, hostip, sizeof (hostip)))
- {
- indent (depth+1);
- printf ("peer %s port %u\n", hostip, ntohs (peer.ipv6.sin6_port));
- }
- break;
-#endif
-
-#ifdef AF_BLUETOOTH
- case AF_BLUETOOTH:
- printf ("bluetooth\n");
- break;
-#endif
-
- default:
- printf ("unknown (%d)\n", addr.sa.sa_family);
- break;
- }
-}
-#endif
-
static void
print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
{
@@ -584,230 +150,212 @@
int type = dbus_message_iter_get_arg_type (iter);
if (type == DBUS_TYPE_INVALID)
- break;
+ break;
indent(depth);
switch (type)
- {
- case DBUS_TYPE_STRING:
- {
- char *val;
- dbus_message_iter_get_basic (iter, &val);
- if (!literal)
- printf ("string \"");
- printf ("%s", val);
- if (!literal)
- printf ("\"\n");
- break;
- }
+ {
+ case DBUS_TYPE_STRING:
+ {
+ char *val;
+ dbus_message_iter_get_basic (iter, &val);
+ if (!literal)
+ printf ("string \"");
+ printf ("%s", val);
+ if (!literal)
+ printf ("\"\n");
+ break;
+ }
- case DBUS_TYPE_SIGNATURE:
- {
- char *val;
- dbus_message_iter_get_basic (iter, &val);
- if (!literal)
- printf ("signature \"");
- printf ("%s", val);
- if (!literal)
- printf ("\"\n");
- break;
- }
+ case DBUS_TYPE_SIGNATURE:
+ {
+ char *val;
+ dbus_message_iter_get_basic (iter, &val);
+ if (!literal)
+ printf ("signature \"");
+ printf ("%s", val);
+ if (!literal)
+ printf ("\"\n");
+ break;
+ }
- case DBUS_TYPE_OBJECT_PATH:
- {
- char *val;
- dbus_message_iter_get_basic (iter, &val);
- if (!literal)
- printf ("object path \"");
- printf ("%s", val);
- if (!literal)
- printf ("\"\n");
- break;
- }
+ case DBUS_TYPE_OBJECT_PATH:
+ {
+ char *val;
+ dbus_message_iter_get_basic (iter, &val);
+ if (!literal)
+ printf ("object path \"");
+ printf ("%s", val);
+ if (!literal)
+ printf ("\"\n");
+ break;
+ }
- case DBUS_TYPE_INT16:
- {
- dbus_int16_t val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("int16 %d\n", val);
- break;
- }
+ case DBUS_TYPE_INT16:
+ {
+ dbus_int16_t val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("int16 %d\n", val);
+ break;
+ }
- case DBUS_TYPE_UINT16:
- {
- dbus_uint16_t val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("uint16 %u\n", val);
- break;
- }
+ case DBUS_TYPE_UINT16:
+ {
+ dbus_uint16_t val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("uint16 %u\n", val);
+ break;
+ }
- case DBUS_TYPE_INT32:
- {
- dbus_int32_t val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("int32 %d\n", val);
- break;
- }
+ case DBUS_TYPE_INT32:
+ {
+ dbus_int32_t val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("int32 %d\n", val);
+ break;
+ }
- case DBUS_TYPE_UINT32:
- {
- dbus_uint32_t val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("uint32 %u\n", val);
- break;
- }
+ case DBUS_TYPE_UINT32:
+ {
+ dbus_uint32_t val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("uint32 %u\n", val);
+ break;
+ }
- case DBUS_TYPE_INT64:
- {
- dbus_int64_t val;
- dbus_message_iter_get_basic (iter, &val);
+ case DBUS_TYPE_INT64:
+ {
+ dbus_int64_t val;
+ dbus_message_iter_get_basic (iter, &val);
#ifdef DBUS_INT64_PRINTF_MODIFIER
printf ("int64 %" DBUS_INT64_PRINTF_MODIFIER "d\n", val);
#else
printf ("int64 (omitted)\n");
#endif
- break;
- }
+ break;
+ }
- case DBUS_TYPE_UINT64:
- {
- dbus_uint64_t val;
- dbus_message_iter_get_basic (iter, &val);
+ case DBUS_TYPE_UINT64:
+ {
+ dbus_uint64_t val;
+ dbus_message_iter_get_basic (iter, &val);
#ifdef DBUS_INT64_PRINTF_MODIFIER
printf ("uint64 %" DBUS_INT64_PRINTF_MODIFIER "u\n", val);
#else
printf ("uint64 (omitted)\n");
#endif
- break;
- }
+ break;
+ }
- case DBUS_TYPE_DOUBLE:
- {
- double val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("double %g\n", val);
- break;
- }
+ case DBUS_TYPE_DOUBLE:
+ {
+ double val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("double %g\n", val);
+ break;
+ }
- case DBUS_TYPE_BYTE:
- {
- unsigned char val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("byte %d\n", val);
- break;
- }
+ case DBUS_TYPE_BYTE:
+ {
+ unsigned char val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("byte %d\n", val);
+ break;
+ }
- case DBUS_TYPE_BOOLEAN:
- {
- dbus_bool_t val;
- dbus_message_iter_get_basic (iter, &val);
- printf ("boolean %s\n", val ? "true" : "false");
- break;
- }
+ case DBUS_TYPE_BOOLEAN:
+ {
+ dbus_bool_t val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("boolean %s\n", val ? "true" : "false");
+ break;
+ }
- case DBUS_TYPE_VARIANT:
- {
- DBusMessageIter subiter;
+ case DBUS_TYPE_VARIANT:
+ {
+ DBusMessageIter subiter;
- dbus_message_iter_recurse (iter, &subiter);
+ dbus_message_iter_recurse (iter, &subiter);
- printf ("variant ");
- print_iter (&subiter, literal, depth+1);
- break;
- }
- case DBUS_TYPE_ARRAY:
- {
- int current_type;
- DBusMessageIter subiter;
+ printf ("variant ");
+ print_iter (&subiter, literal, depth+1);
+ break;
+ }
+ case DBUS_TYPE_ARRAY:
+ {
+ int current_type;
+ DBusMessageIter subiter;
- dbus_message_iter_recurse (iter, &subiter);
+ dbus_message_iter_recurse (iter, &subiter);
- current_type = dbus_message_iter_get_arg_type (&subiter);
+ current_type = dbus_message_iter_get_arg_type (&subiter);
- if (current_type == DBUS_TYPE_BYTE)
- {
- print_ay (&subiter, depth);
- break;
- }
+ if (current_type == DBUS_TYPE_BYTE)
+ {
+ print_ay (&subiter, depth);
+ break;
+ }
- printf("array [\n");
- while (current_type != DBUS_TYPE_INVALID)
- {
- print_iter (&subiter, literal, depth+1);
+ printf("array [\n");
+ while (current_type != DBUS_TYPE_INVALID)
+ {
+ print_iter (&subiter, literal, depth+1);
- dbus_message_iter_next (&subiter);
- current_type = dbus_message_iter_get_arg_type (&subiter);
+ dbus_message_iter_next (&subiter);
+ current_type = dbus_message_iter_get_arg_type (&subiter);
- if (current_type != DBUS_TYPE_INVALID)
- printf (",");
- }
- indent(depth);
- printf("]\n");
- break;
- }
- case DBUS_TYPE_DICT_ENTRY:
- {
- DBusMessageIter subiter;
+ if (current_type != DBUS_TYPE_INVALID)
+ printf (",");
+ }
+ indent(depth);
+ printf("]\n");
+ break;
+ }
+ case DBUS_TYPE_DICT_ENTRY:
+ {
+ DBusMessageIter subiter;
- dbus_message_iter_recurse (iter, &subiter);
+ dbus_message_iter_recurse (iter, &subiter);
- printf("dict entry(\n");
- print_iter (&subiter, literal, depth+1);
- dbus_message_iter_next (&subiter);
- print_iter (&subiter, literal, depth+1);
- indent(depth);
- printf(")\n");
- break;
- }
+ printf("dict entry(\n");
+ print_iter (&subiter, literal, depth+1);
+ dbus_message_iter_next (&subiter);
+ print_iter (&subiter, literal, depth+1);
+ indent(depth);
+ printf(")\n");
+ break;
+ }
+
+ case DBUS_TYPE_STRUCT:
+ {
+ int current_type;
+ DBusMessageIter subiter;
- case DBUS_TYPE_STRUCT:
- {
- int current_type;
- DBusMessageIter subiter;
+ dbus_message_iter_recurse (iter, &subiter);
- dbus_message_iter_recurse (iter, &subiter);
-
- printf("struct {\n");
- while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
- {
- print_iter (&subiter, literal, depth+1);
- dbus_message_iter_next (&subiter);
- if (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID)
- printf (",");
- }
- indent(depth);
- printf("}\n");
- break;
- }
-
-#ifdef DBUS_UNIX
- case DBUS_TYPE_UNIX_FD:
- {
- int fd;
- dbus_message_iter_get_basic (iter, &fd);
-
- print_fd (fd, depth+1);
-
- /* dbus_message_iter_get_basic() duplicated the fd, we need to
- * close it after use. The original fd will be closed when the
- * DBusMessage is released.
- */
- close (fd);
-
- break;
- }
-#endif
-
- default:
- printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
- break;
- }
+ printf("struct {\n");
+ while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
+ {
+ print_iter (&subiter, literal, depth+1);
+ dbus_message_iter_next (&subiter);
+ if (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID)
+ printf (",");
+ }
+ indent(depth);
+ printf("}\n");
+ break;
+ }
+
+ default:
+ printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
+ break;
+ }
} while (dbus_message_iter_next (iter));
}
void
-print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec)
+print_message (DBusMessage *message, dbus_bool_t literal)
{
DBusMessageIter iter;
const char *sender;
@@ -820,48 +368,37 @@
if (!literal)
{
- if (sec != 0 || usec != 0)
- {
- printf ("%s time=%ld.%06ld sender=%s -> destination=%s",
- type_to_name (message_type), sec, usec,
- sender ? sender : "(null sender)",
- destination ? destination : "(null destination)");
- }
- else
- {
- printf ("%s sender=%s -> destination=%s",
- type_to_name (message_type),
- sender ? sender : "(null sender)",
- destination ? destination : "(null destination)");
- }
-
+ printf ("%s sender=%s -> dest=%s",
+ type_to_name (message_type),
+ sender ? sender : "(null sender)",
+ destination ? destination : "(null destination)");
+
switch (message_type)
- {
- case DBUS_MESSAGE_TYPE_METHOD_CALL:
- case DBUS_MESSAGE_TYPE_SIGNAL:
- printf (" serial=%u path=%s; interface=%s; member=%s\n",
+ {
+ case DBUS_MESSAGE_TYPE_METHOD_CALL:
+ case DBUS_MESSAGE_TYPE_SIGNAL:
+ printf (" serial=%u path=%s; interface=%s; member=%s\n",
dbus_message_get_serial (message),
- dbus_message_get_path (message),
- dbus_message_get_interface (message),
- dbus_message_get_member (message));
- break;
+ dbus_message_get_path (message),
+ dbus_message_get_interface (message),
+ dbus_message_get_member (message));
+ break;
- case DBUS_MESSAGE_TYPE_METHOD_RETURN:
- printf (" serial=%u reply_serial=%u\n",
- dbus_message_get_serial (message),
+ case DBUS_MESSAGE_TYPE_METHOD_RETURN:
+ printf (" reply_serial=%u\n",
dbus_message_get_reply_serial (message));
- break;
+ break;
- case DBUS_MESSAGE_TYPE_ERROR:
- printf (" error_name=%s reply_serial=%u\n",
- dbus_message_get_error_name (message),
+ case DBUS_MESSAGE_TYPE_ERROR:
+ printf (" error_name=%s reply_serial=%u\n",
+ dbus_message_get_error_name (message),
dbus_message_get_reply_serial (message));
- break;
+ break;
- default:
- printf ("\n");
- break;
- }
+ default:
+ printf ("\n");
+ break;
+ }
}
dbus_message_iter_init (message, &iter);
diff --git a/tools/dbus-print-message.h b/tools/dbus-print-message.h
index 9f80116..26700d8 100644
--- a/tools/dbus-print-message.h
+++ b/tools/dbus-print-message.h
@@ -26,7 +26,6 @@
#include <string.h>
#include <dbus/dbus.h>
-void print_message_fixed (DBusMessage *message);
-void print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec);
+void print_message (DBusMessage *message, dbus_bool_t literal);
#endif /* DBUS_PRINT_MESSAGE_H */
diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c
deleted file mode 100644
index 105ab3b..0000000
--- a/tools/dbus-run-session.c
+++ /dev/null
@@ -1,464 +0,0 @@
-/* -*- 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 ef0d6fc..e403a58 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -25,7 +25,6 @@
#include <string.h>
#include <dbus/dbus.h>
-#include "dbus/dbus-internals.h"
#ifndef HAVE_STRTOLL
#undef strtoll
@@ -52,7 +51,7 @@
static void
usage (int ecode)
{
- fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--fixed] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname);
+ 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);
exit (ecode);
}
@@ -144,85 +143,21 @@
}
}
-// Note: buffer must be pre-allocated and at least as big as str.
-static int
-get_next_token (const char *str, int loc, char *buffer)
-{
- int str_index, buffer_index = 0;
-
- enum State {START, ESCAPE};
- enum State state = START;
-
- for (str_index = loc; str[str_index] != '\0'; str_index++)
- {
- if (state == START)
- {
- switch (str[str_index])
- {
- case '\\':
- state = ESCAPE;
- continue;
-
- // If we hit a , in the start state, we should treat it as
- // an argument separator since it's not escaped.
- case ',':
- buffer[buffer_index] = '\0';
- return str_index + 1;
- }
- }
- else if (state == ESCAPE)
- {
- // If the \ doesn't immediately precede a , or another \, then
- // it's not being used as an escape character.
- // Similarly, if we have a string of multiple \s as the last
- // characters, then they're also not being used as escape characters.
- if ((str[str_index] != ',' && str[str_index] != '\\') ||
- (str[str_index] == '\\' && str[str_index + 1] == '\0'))
- {
- buffer[buffer_index] = '\\';
- buffer_index++;
- }
-
- state = START;
- }
-
- buffer[buffer_index] = str[str_index];
- buffer_index++;
- }
-
- // If we end on a single \, then it's not being used as an escape character.
- // Note the earlier check will only catch if we end on a string of multiple
- // \s.
- if (state == ESCAPE)
- {
- buffer[buffer_index] = '\\';
- buffer_index++;
- }
- buffer[buffer_index] = '\0';
-
- return -1;
-}
-
static void
append_array (DBusMessageIter *iter, int type, const char *value)
{
- char *buffer = strdup (value);
+ const char *val;
+ char *dupval = strdup (value);
- int loc = 0;
- while (loc >= 0)
+ val = strtok (dupval, ",");
+ while (val != NULL)
{
- loc = get_next_token (value, loc, buffer);
-
- // We don't want to include empty strings, even if there are
- // several commas directly beside each other.
- if (buffer[0] != '\0')
- append_arg (iter, type, buffer);
+ append_arg (iter, type, val);
+ val = strtok (NULL, ",");
}
- free (buffer);
+ free (dupval);
}
-static int type_from_name(const char *name);
-
static void
append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value)
{
@@ -246,30 +181,7 @@
fprintf (stderr, "%s: Malformed dictionary\n", appname);
exit (1);
}
- if (valtype == DBUS_TYPE_VARIANT)
- {
- char sig[2];
- char *c = strchr(val, ':');
- if (!c)
- {
- fprintf (stderr, "Missing type in variant dict\n");
- exit (1);
- }
- *(c++) = '\0';
- sig[0] = type_from_name(val);
- sig[1] = '\0';
- DBusMessageIter subsubiter;
- dbus_message_iter_open_container (&subiter,
- DBUS_TYPE_VARIANT,
- sig,
- &subsubiter);
- append_arg(&subsubiter, sig[0], c);
- dbus_message_iter_close_container (&subiter, &subsubiter);
- }
- else
- {
- append_arg (&subiter, valtype, val);
- }
+ append_arg (&subiter, valtype, val);
dbus_message_iter_close_container (iter, &subiter);
val = strtok (NULL, ",");
@@ -317,8 +229,8 @@
DBusConnection *connection;
DBusError error;
DBusMessage *message;
- dbus_bool_t print_reply;
- dbus_bool_t print_reply_literal;
+ int print_reply;
+ int print_reply_literal;
int reply_timeout;
DBusMessageIter iter;
int i;
@@ -329,10 +241,7 @@
int message_type = DBUS_MESSAGE_TYPE_SIGNAL;
const char *type_str = NULL;
const char *address = NULL;
- const char *sender = NULL;
- int is_bus = FALSE;
int session_or_system = FALSE;
- int fixed = 0;
appname = argv[0];
@@ -357,82 +266,38 @@
type = DBUS_BUS_SESSION;
session_or_system = TRUE;
}
- else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg))
+ else if (strstr (arg, "--address") == arg)
{
- if (arg[2] == 'b') /* bus */
- {
- is_bus = TRUE;
- }
- else if (arg[2] == 'p') /* peer */
- {
- is_bus = FALSE;
- }
- else /* address; keeping backwards compatibility */
- {
- is_bus = FALSE;
- }
+ address = strchr (arg, '=');
- address = strchr (arg, '=') + 1;
-
- if (address[0] == '\0')
+ if (address == NULL)
{
- fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n");
+ fprintf (stderr, "\"--address=\" requires an ADDRESS\n");
usage (1);
}
- }
- else if (strstr (arg, "--sender=") == arg)
- {
- sender = strchr (arg, '=') + 1;
-
- if (sender[0] == '\0')
+ else
{
- fprintf (stderr, "\"--sender=\" requires a NAME\n");
- usage (1);
+ address = address + 1;
}
}
else if (strncmp (arg, "--print-reply", 13) == 0)
{
print_reply = TRUE;
message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
- if (strcmp (arg + 13, "=literal") == 0)
+ if (*(arg + 13) != '\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)
- {
- if (*(strchr (arg, '=') + 1) == '\0')
- {
- fprintf (stderr, "\"--dest=\" requires an NAME\n");
- usage (1);
- }
- dest = strchr (arg, '=') + 1;
- }
+ dest = strchr (arg, '=') + 1;
else if (strstr (arg, "--type=") == arg)
type_str = strchr (arg, '=') + 1;
else if (!strcmp(arg, "--help"))
usage (0);
- else if (!strcmp(arg, "--fixed"))
- fixed = 1;
else if (arg[0] == '-')
usage (1);
else if (path == NULL)
@@ -447,7 +312,7 @@
if (session_or_system &&
(address != NULL))
{
- fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n");
+ fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n");
usage (1);
}
@@ -465,12 +330,6 @@
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);
@@ -489,37 +348,6 @@
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 (sender != NULL)
- {
- switch(dbus_bus_request_name (connection, sender, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error))
- {
- case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
- /* success */
- break;
- case DBUS_REQUEST_NAME_REPLY_EXISTS:
- fprintf (stderr, "Requested name \"%s\" already has owner\n", sender);
- exit (1);
- case -1:
- fprintf (stderr, "Failed to request sender name \"%s\": %s\n", sender, error.message);
- dbus_error_free(&error);
- exit (1);
- default:
- /* This should be unreachable if the bus is compliant */
- fprintf (stderr, "Request of sender name failed unexpectedly\n");
- exit (1);
- }
- }
if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
{
@@ -634,11 +462,7 @@
exit (1);
}
*(c++) = 0;
- if (!strcmp(arg, "variant"))
- /* Hack: support variant values for dictionaries. */
- secondary_type = DBUS_TYPE_VARIANT;
- else
- secondary_type = type_from_name (arg);
+ secondary_type = type_from_name (arg);
sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
sig[1] = type;
sig[2] = secondary_type;
@@ -700,13 +524,7 @@
if (reply)
{
- long sec, usec;
-
- _dbus_get_real_time (&sec, &usec);
- if (fixed)
- print_message_fixed (reply);
- else
- print_message (reply, print_reply_literal, sec, usec);
+ print_message (reply, print_reply_literal);
dbus_message_unref (reply);
}
}
diff --git a/tools/dbus-spam.c b/tools/dbus-spam.c
deleted file mode 100644
index c78d8ea..0000000
--- a/tools/dbus-spam.c
+++ /dev/null
@@ -1,524 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* dbus-spam.c - a plain libdbus message-sender, loosely based on dbus-send
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <dbus/dbus.h>
-
-#include "test-tool.h"
-#include "tool-common.h"
-
-static dbus_bool_t ignore_errors = FALSE;
-
-static void
-usage (int ecode)
-{
- fprintf (stderr,
- "Usage: dbus-test-tool spam [OPTIONS]\n"
- "\n"
- "Repeatedly call com.example.Spam() on the given D-Bus service.\n"
- "\n"
- "Options:\n"
- "\n"
- " --session use the session bus (default)\n"
- " --system use the system bus\n"
- "\n"
- " --ignore-errors ignore errors\n"
- " --dest=NAME call methods on NAME (default " DBUS_SERVICE_DBUS ")\n"
- "\n"
- " --count=N send N messages (default 1)\n"
- " --queue=N queue up N messages at a time (default 1)\n"
- " --flood send all messages immediately\n"
- " --no-reply set the NO_REPLY flag (implies --flood)\n"
- " --messages-per-conn=N after sending messages-per-conn, wait\n"
- " for the pending replies if any, then reconnect\n"
- " (default: don't reconnect)\n"
- "\n"
- " --string send payload as a string (default)\n"
- " --bytes send payload as a byte-array\n"
- " --empty send an empty payload\n"
- "\n"
- " --payload=S use S as payload (default \"hello, world!\")\n"
- " --stdin read payload from stdin, until EOF\n"
- " --message-stdin read a complete D-Bus message from stdin\n"
- " --random-size read whitespace-separated ASCII decimal\n"
- " payload sizes from stdin and pick one randomly\n"
- " for each message\n"
- "\n"
- " --seed=SEED seed for srand (default is time())\n"
- "\n"
- );
- exit (ecode);
-}
-
-static void
-pc_notify (DBusPendingCall *pc,
- void *data)
-{
- DBusMessage *message;
- int *received_p = data;
- DBusError error;
-
- dbus_error_init (&error);
-
- message = dbus_pending_call_steal_reply (pc);
-
- if (!ignore_errors && dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_ERROR)
- {
- dbus_set_error_from_message (&error, message);
- fprintf (stderr, "Failed to receive reply #%d: %s: %s\n", *received_p,
- error.name, error.message);
- }
- else
- {
- VERBOSE (stderr, "received message #%d\n", *received_p);
- }
-
- (*received_p)++;
-}
-
-static void
-consume_stdin (char **payload_p,
- size_t *len_p)
-{
- const size_t BLOCK_SIZE = 4096;
- size_t len = BLOCK_SIZE;
- size_t pos = 0;
- size_t n;
- char *buf;
-
- buf = dbus_malloc (len);
-
- if (buf == NULL)
- tool_oom ("reading payload from stdin");
-
- while (1)
- {
- if (len - pos < BLOCK_SIZE)
- {
- char *tmp = dbus_realloc (buf, len + BLOCK_SIZE);
-
- if (tmp == NULL)
- tool_oom ("reading payload from stdin");
-
- buf = tmp;
- len += BLOCK_SIZE;
- }
-
- n = fread (buf + pos, 1, len - pos, stdin);
-
- if (n <= 0)
- {
- /* EOF or error - treat as EOF */
- break;
- }
-
- pos += n;
- }
-
- *len_p = pos;
- *payload_p = buf;
-}
-
-int
-dbus_test_tool_spam (int argc, char **argv)
-{
- DBusConnection *connection = NULL;
- DBusError error = DBUS_ERROR_INIT;
- DBusBusType type = DBUS_BUS_SESSION;
- const char *destination = DBUS_SERVICE_DBUS;
- int i;
- int count = 1;
- int sent = 0;
- unsigned int sent_in_this_conn = 0;
- int received = 0;
- unsigned int received_before_this_conn = 0;
- int queue_len = 1;
- const char *payload = NULL;
- char *payload_buf = NULL;
- size_t payload_len;
- int payload_type = DBUS_TYPE_STRING;
- DBusMessage *template = NULL;
- dbus_bool_t flood = FALSE;
- dbus_bool_t no_reply = FALSE;
- unsigned int messages_per_conn = 0;
- unsigned int seed = time (NULL);
- int n_random_sizes = 0;
- unsigned int *random_sizes = NULL;
-
- /* argv[1] is the tool name, so start from 2 */
-
- for (i = 2; i < argc; i++)
- {
- const char *arg = argv[i];
-
- if (strcmp (arg, "--system") == 0)
- {
- type = DBUS_BUS_SYSTEM;
- }
- else if (strcmp (arg, "--session") == 0)
- {
- type = DBUS_BUS_SESSION;
- }
- else if (strstr (arg, "--count=") == arg)
- {
- count = atoi (arg + strlen ("--count="));
-
- if (count < 1)
- usage (2);
- }
- else if (strcmp (arg, "--ignore-errors") == 0)
- {
- ignore_errors = TRUE;
- }
- else if (strstr (arg, "--dest=") == arg)
- {
- destination = arg + strlen ("--dest=");
- }
- else if (strstr (arg, "--payload=") == arg)
- {
- payload = arg + strlen ("--payload=");
- }
- else if (strcmp (arg, "--stdin") == 0)
- {
- consume_stdin (&payload_buf, &payload_len);
- payload = payload_buf;
- }
- else if (strcmp (arg, "--message-stdin") == 0)
- {
- consume_stdin (&payload_buf, &payload_len);
- payload = payload_buf;
- template = dbus_message_demarshal (payload, payload_len, &error);
-
- if (template == NULL)
- {
- fprintf (stderr, "Unable to demarshal template message: %s: %s",
- error.name, error.message);
- exit (1);
- }
-
- if (dbus_message_get_type (template) != DBUS_MESSAGE_TYPE_METHOD_CALL)
- {
- fprintf (stderr, "Template message must be a method call\n");
- exit (1);
- }
- }
- else if (strcmp (arg, "--random-size") == 0)
- {
- unsigned int len, max = 0;
- int j, consumed = 0;
- const char *p;
-
- consume_stdin (&payload_buf, &payload_len);
-
- for (p = payload_buf; p < payload_buf + payload_len; p += consumed)
- {
- /* the space character matches any (or no) whitespace */
- if (sscanf (p, " %u %n", &len, &consumed) == 0)
- break;
-
- n_random_sizes++;
- }
-
- random_sizes = dbus_new0 (int, n_random_sizes);
-
- if (random_sizes == NULL)
- tool_oom ("allocating array of message lengths");
-
- for (p = payload_buf, j = 0;
- p < payload_buf + payload_len && j < n_random_sizes;
- p += consumed, j++)
- {
- sscanf (p, " %u %n", &len, &consumed);
- random_sizes[j] = len;
-
- if (len > max)
- max = len;
- }
-
- dbus_free (payload_buf);
- payload_len = max + 1;
- payload_buf = dbus_new (char, payload_len);
- payload = payload_buf;
-
- if (payload_buf == NULL)
- tool_oom ("allocating maximum-sized payload");
-
- memset (payload_buf, 'X', payload_len);
- payload_buf[payload_len - 1] = '\0';
- }
- else if (strcmp (arg, "--empty") == 0)
- {
- payload_type = DBUS_TYPE_INVALID;
- }
- else if (strcmp (arg, "--string") == 0)
- {
- payload_type = DBUS_TYPE_STRING;
- }
- else if (strcmp (arg, "--bytes") == 0)
- {
- payload_type = DBUS_TYPE_ARRAY;
- }
- else if (strcmp (arg, "--flood") == 0)
- {
- if (queue_len > 1)
- usage (2);
-
- if (messages_per_conn > 0)
- usage (2);
-
- flood = TRUE;
- queue_len = -1;
- }
- else if (strcmp (arg, "--no-reply") == 0)
- {
- if (queue_len > 1)
- usage (2);
-
- queue_len = -1;
- no_reply = TRUE;
- }
- else if (strstr (arg, "--queue=") == arg)
- {
- if (flood || no_reply)
- usage (2);
-
- queue_len = atoi (arg + strlen ("--queue="));
-
- if (queue_len < 1)
- usage (2);
- }
- else if (strstr (arg, "--seed=") == arg)
- {
- seed = strtoul (arg + strlen ("--seed="), NULL, 10);
- }
- else if (strstr (arg, "--messages-per-conn=") == arg)
- {
- messages_per_conn = atoi (arg + strlen ("--messages-per-conn="));
-
- if (messages_per_conn > 0 && flood)
- usage (2);
- }
- else
- {
- usage (2);
- }
- }
-
- srand (seed);
-
- if (payload == NULL)
- {
- payload = "hello, world!";
- payload_len = strlen (payload);
- }
-
- VERBOSE (stderr, "Will send up to %d messages, with up to %d queued, max %d per connection\n",
- count, queue_len, messages_per_conn);
-
- while (no_reply ? sent < count : received < count)
- {
- /* Connect?
- * - In the first iteration
- * or
- * - When messages_per_conn messages have been sent and no replies are being waited for
- */
- if (connection == NULL ||
- (messages_per_conn > 0 && sent_in_this_conn == messages_per_conn &&
- (no_reply || received - received_before_this_conn == messages_per_conn)))
- {
- if (connection != NULL)
- {
- dbus_connection_flush (connection);
- dbus_connection_close (connection);
- dbus_connection_unref (connection);
- }
-
- VERBOSE (stderr, "New connection.\n");
- connection = dbus_bus_get_private (type, &error);
-
- if (connection == NULL)
- {
- fprintf (stderr, "Failed to connect to bus: %s: %s\n",
- error.name, error.message);
- dbus_error_free (&error);
- dbus_free (random_sizes);
- dbus_free (payload_buf);
- return 1;
- }
-
- sent_in_this_conn = 0;
- received_before_this_conn = received;
- }
-
- /* Send another message? Only if we don't exceed the 3 limits:
- * - total amount of messages
- * - messages sent on this connection
- * - queue
- */
- while (sent < count &&
- (messages_per_conn == 0 || sent_in_this_conn < messages_per_conn) &&
- (queue_len == -1 || sent_in_this_conn < queue_len + received - received_before_this_conn))
- {
- DBusMessage *message;
-
- if (template != NULL)
- {
- message = dbus_message_copy (template);
-
- if (message == NULL)
- tool_oom ("copying message");
-
- dbus_message_set_no_reply (message, no_reply);
- }
- else
- {
- dbus_bool_t mem;
- unsigned int len = 0;
-
- message = dbus_message_new_method_call (destination,
- "/",
- "com.example",
- "Spam");
-
- if (message == NULL)
- tool_oom ("allocating message");
-
- dbus_message_set_no_reply (message, no_reply);
-
- switch (payload_type)
- {
- case DBUS_TYPE_STRING:
- if (random_sizes != NULL)
- {
- /* this isn't fair, strictly speaking - the first few
- * are a bit more likely to be chosen, unless
- * RAND_MAX is divisible by n_random_sizes - but it's
- * good enough for traffic-generation */
- len = random_sizes[rand () % n_random_sizes];
- payload_buf[len] = '\0';
- }
-
- mem = dbus_message_append_args (message,
- DBUS_TYPE_STRING, &payload,
- DBUS_TYPE_INVALID);
-
- if (random_sizes != NULL)
- {
- /* undo the truncation above */
- payload_buf[len] = 'X';
- }
-
- break;
-
- case DBUS_TYPE_ARRAY:
- len = payload_len;
-
- /* as above, not strictly fair, but close enough */
- if (random_sizes != NULL)
- len = random_sizes[rand () % n_random_sizes];
-
- mem = dbus_message_append_args (message,
- DBUS_TYPE_ARRAY,
- DBUS_TYPE_BYTE,
- &payload,
- (dbus_uint32_t) len,
- DBUS_TYPE_INVALID);
- break;
-
- default:
- mem = TRUE;
- }
-
- if (!mem)
- tool_oom ("building message");
- }
-
- if (no_reply)
- {
- if (!dbus_connection_send (connection, message, NULL))
- tool_oom ("sending message");
-
- VERBOSE (stderr, "sent message #%d\n", sent);
- sent++;
- sent_in_this_conn++;
- }
- else
- {
- DBusPendingCall *pc;
-
- if (!dbus_connection_send_with_reply (connection,
- message,
- &pc,
- DBUS_TIMEOUT_INFINITE))
- tool_oom ("sending message");
-
- VERBOSE (stderr, "sent message #%d\n", sent);
- sent++;
- sent_in_this_conn++;
-
- if (pc == NULL)
- tool_oom ("sending message");
-
- if (dbus_pending_call_get_completed (pc))
- pc_notify (pc, &received);
- else if (!dbus_pending_call_set_notify (pc, pc_notify, &received,
- NULL))
- tool_oom ("setting pending call notifier");
-
- dbus_pending_call_unref (pc);
- }
-
- dbus_message_unref (message);
- }
-
- if (!dbus_connection_read_write_dispatch (connection, -1))
- {
- fprintf (stderr, "Disconnected from bus\n");
- exit (1);
- }
- }
-
- if (connection != NULL)
- {
- dbus_connection_flush (connection);
- dbus_connection_close (connection);
- dbus_connection_unref (connection);
- }
-
- VERBOSE (stderr, "Done\n");
-
- dbus_free (payload_buf);
- dbus_free (random_sizes);
-
- if (template != NULL)
- dbus_message_unref (template);
-
- dbus_shutdown ();
- return 0;
-}
diff --git a/tools/dbus-update-activation-environment.c b/tools/dbus-update-activation-environment.c
deleted file mode 100644
index 160ac5d..0000000
--- a/tools/dbus-update-activation-environment.c
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * dbus-update-activation-environment - update D-Bus, and optionally
- * systemd, activation environment
- *
- * Copyright © 2014-2015 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 <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_SYSEXITS_H
-# include <sysexits.h>
-#endif
-
-#include <dbus/dbus.h>
-
-#ifdef DBUS_UNIX
-# include <unistd.h>
-# include <sys/stat.h>
-# include <sys/types.h>
-#endif
-
-#include "tool-common.h"
-
-#define PROGNAME "dbus-update-activation-environment"
-
-#ifndef EX_USAGE
-# define EX_USAGE 64
-#endif
-
-#ifndef EX_UNAVAILABLE
-# define EX_UNAVAILABLE 69
-#endif
-
-#ifndef EX_OSERR
-# define EX_OSERR 71
-#endif
-
-#ifdef DBUS_WIN
-/* The Windows C runtime uses a different name */
-#define environ _environ
-#else
-/* apparently this is the portable way to get the entire environment...
- * GNU platforms also put it in unistd.h but that's not portable */
-extern char **environ;
-#endif
-
-/* we don't really have anything useful to say about the stage at which we
- * failed */
-#define oom() tool_oom ("updating environment")
-
-static dbus_bool_t verbose = FALSE;
-
-static void say (const char *format, ...) _DBUS_GNUC_PRINTF (1, 2);
-
-static void
-say (const char *format,
- ...)
-{
- va_list ap;
-
- if (!verbose)
- return;
-
- fprintf (stderr, "%s: ", PROGNAME);
- va_start (ap, format);
- vfprintf (stderr, format, ap);
- fputc ('\n', stderr);
- va_end (ap);
-}
-
-#ifdef __linux__
-static dbus_bool_t
-systemd_user_running (void)
-{
- char *xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
- char *path;
- struct stat buf;
- dbus_bool_t ret = FALSE;
-
- if (xdg_runtime_dir == NULL)
- return FALSE;
-
- /* Assume that XDG_RUNTIME_DIR/systemd exists if and only if
- * "systemd --user" is running. It's OK to use asprintf() here
- * because we know we're on Linux. */
- if (asprintf (&path, "%s/systemd", xdg_runtime_dir) < 0)
- oom ();
-
- if (stat (path, &buf) == 0)
- ret = TRUE;
-
- free (path);
- return ret;
-}
-#endif
-
-int
-main (int argc, char **argv)
-{
- DBusConnection *conn;
- DBusMessage *msg;
- DBusMessage *reply;
- DBusError error = DBUS_ERROR_INIT;
- DBusMessageIter msg_iter;
- DBusMessageIter array_iter;
- int i;
- int first_non_option = argc;
- dbus_bool_t all = FALSE;
-#ifdef __linux__
- DBusMessage *sd_msg = NULL;
- DBusMessageIter sd_msg_iter;
- DBusMessageIter sd_array_iter;
- dbus_bool_t systemd = FALSE;
-#endif
-
- for (i = 1; i < argc; i++)
- {
- if (argv[i][0] != '-')
- {
- first_non_option = i;
- break;
- }
- else if (strcmp (argv[i], "--") == 0)
- {
- first_non_option = i + 1;
- break;
- }
- else if (strcmp (argv[i], "--all") == 0)
- {
- all = TRUE;
- }
- else if (strcmp (argv[i], "--systemd") == 0)
- {
-#ifdef __linux__
- systemd = TRUE;
-#else
- say ("not on Linux, ignoring --systemd argument");
-#endif
- }
- else if (strcmp (argv[i], "--verbose") == 0)
- {
- verbose = TRUE;
- }
- else
- {
- fprintf (stderr,
- "%1$s: update environment variables that will be set for D-Bus\n"
- " session services\n"
- "\n"
- "%1$s [options] VAR[=VAL] [VAR2[=VAL2] ...]\n"
- " Add specified variables to D-Bus activation environment.\n"
- " If omitted, values are taken from current environment;\n"
- " variables not found in the environment are ignored.\n"
- "%1$s --all\n"
- " Add entire current environment to D-Bus activation\n"
- " environment.\n"
- "\n"
- "Options:\n"
- "\n"
- "--all\n"
- " Upload all environment variables.\n"
- "--systemd\n"
- " Also update the 'systemd --user' environment\n"
- " if possible.\n"
- "--verbose\n"
- " Talk about it.\n"
- ,
- PROGNAME);
- exit (EX_USAGE);
- }
- }
-
- if (all && first_non_option < argc)
- {
- fprintf (stderr, "%s: error: --all cannot be used with VAR or "
- "VAR=VAL arguments\n", PROGNAME);
- exit (EX_USAGE);
- }
-
- conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
-
- if (conn == NULL)
- {
- fprintf (stderr,
- "%s: error: unable to connect to D-Bus: %s\n", PROGNAME,
- error.message);
- exit (EX_OSERR);
- }
-
- msg = dbus_message_new_method_call (DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, "UpdateActivationEnvironment");
-
- if (msg == NULL)
- oom ();
-
- dbus_message_iter_init_append (msg, &msg_iter);
-
- if (!dbus_message_iter_open_container (&msg_iter, DBUS_TYPE_ARRAY,
- "{ss}", &array_iter))
- oom ();
-
-#ifdef __linux__
- if (systemd)
- {
- if (!systemd_user_running ())
- {
- /* This is only best-effort. */
- say ("systemd --user not found, ignoring --systemd argument");
- systemd = FALSE;
- }
- }
-
- if (systemd)
- {
- sd_msg = dbus_message_new_method_call ("org.freedesktop.systemd1",
- "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
- "SetEnvironment");
-
- if (sd_msg == NULL)
- oom ();
-
- dbus_message_iter_init_append (sd_msg, &sd_msg_iter);
-
- if (!dbus_message_iter_open_container (&sd_msg_iter, DBUS_TYPE_ARRAY,
- "s", &sd_array_iter))
- oom ();
- }
-#endif
-
- for (i = all ? 0 : first_non_option;
- all ? environ[i] != NULL : i < argc;
- i++)
- {
- const char *var;
- char *copy;
- char *eq;
- const char *val;
- DBusMessageIter pair_iter;
-
- if (all)
- var = environ[i];
- else
- var = argv[i];
-
- copy = strdup (var);
-
- if (copy == NULL)
- oom ();
-
- if (!dbus_validate_utf8 (var, NULL))
- {
- /* var is either of the form VAR or VAR=VAL */
- fprintf (stderr,
- "%s: warning: environment variable not UTF-8: %s\n",
- PROGNAME, var);
- goto next;
- }
-
- eq = strchr (copy, '=');
-
- if (eq == NULL)
- {
- if (all)
- {
- /* items in the environment block should be of the form
- * VAR=VAL */
- fprintf (stderr,
- "%s: warning: environment variable without '=': %s\n",
- PROGNAME, var);
- goto next;
- }
- else
- {
- /* items on the command-line may be of the form VAR
- * in which case we infer the value from the environment */
- val = getenv (var);
-
- if (val == NULL)
- {
- /* nothing to be done here */
- goto next;
- }
-
- if (!dbus_validate_utf8 (val, NULL))
- {
- fprintf (stderr,
- "%s: warning: environment variable not UTF-8: %s=%s\n",
- PROGNAME, var, val);
- goto next;
- }
- }
- }
- else
- {
- /* split VAR=VAL into VAR and VAL */
- *eq = '\0';
- val = eq + 1;
- }
-
-#ifdef __linux__
- if (systemd)
- {
- char *combined;
-
- /* recombine if necessary */
- if (asprintf (&combined, "%s=%s", copy, val) < 0)
- oom ();
-
- if (!dbus_message_iter_append_basic (&sd_array_iter,
- DBUS_TYPE_STRING, &combined))
- oom ();
-
- free (combined);
- }
-#endif
-
- if (!dbus_message_iter_open_container (&array_iter,
- DBUS_TYPE_DICT_ENTRY, NULL, &pair_iter))
- oom ();
-
- say ("setting %s=%s", copy, val);
-
- if (!dbus_message_iter_append_basic (&pair_iter, DBUS_TYPE_STRING,
- ©))
- oom ();
-
- if (!dbus_message_iter_append_basic (&pair_iter, DBUS_TYPE_STRING,
- &val))
- oom ();
-
- if (!dbus_message_iter_close_container (&array_iter, &pair_iter))
- oom ();
-
-next:
- free (copy);
- }
-
- if (!dbus_message_iter_close_container (&msg_iter, &array_iter))
- oom ();
-
-#ifdef __linux__
- if (systemd &&
- !dbus_message_iter_close_container (&sd_msg_iter, &sd_array_iter))
- oom ();
-#endif
-
- reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
-
- if (reply == NULL)
- {
- fprintf (stderr,
- "%s: error sending to dbus-daemon: %s: %s\n",
- PROGNAME, error.name, error.message);
- exit (EX_UNAVAILABLE);
- }
-
- if (dbus_set_error_from_message (&error, msg) ||
- !dbus_message_get_args (msg, &error, DBUS_TYPE_INVALID))
- {
- fprintf (stderr,
- "%s: error from dbus-daemon: %s: %s\n",
- PROGNAME, error.name, error.message);
- exit (EX_UNAVAILABLE);
- }
-
- dbus_message_unref (reply);
-
-#ifdef __linux__
- if (systemd)
- {
- reply = dbus_connection_send_with_reply_and_block (conn, sd_msg, -1,
- &error);
-
- /* non-fatal, the main purpose of this thing is to communicate
- * with dbus-daemon */
- if (reply == NULL)
- {
- fprintf (stderr,
- "%s: warning: error sending to systemd: %s: %s\n",
- PROGNAME, error.name, error.message);
- }
- else if (dbus_set_error_from_message (&error, msg) ||
- !dbus_message_get_args (msg, &error, DBUS_TYPE_INVALID))
- {
- fprintf (stderr,
- "%s: warning: error from systemd: %s: %s\n",
- PROGNAME, error.name, error.message);
- }
-
- if (reply != NULL)
- dbus_message_unref (reply);
-
- dbus_message_unref (sd_msg);
- dbus_error_free (&error);
- }
-#endif
-
- dbus_message_unref (msg);
- dbus_connection_unref (conn);
- return 0;
-}
diff --git a/tools/dbus-uuidgen.c b/tools/dbus-uuidgen.c
index 03ce553..c8ba1cf 100644
--- a/tools/dbus-uuidgen.c
+++ b/tools/dbus-uuidgen.c
@@ -137,12 +137,15 @@
else
{
char *uuid;
-
- if (_dbus_create_uuid (&uuid, &error))
+ if (dbus_internal_do_not_use_create_uuid (&uuid))
{
printf ("%s\n", uuid);
dbus_free (uuid);
}
+ else
+ {
+ dbus_set_error (&error, DBUS_ERROR_NO_MEMORY, "No memory");
+ }
}
if (dbus_error_is_set (&error))
diff --git a/tools/lcov.am b/tools/lcov.am
index ac34867..7ba4991 100644
--- a/tools/lcov.am
+++ b/tools/lcov.am
@@ -21,10 +21,10 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lcov-reset:
- lcov --directory @abs_top_builddir@ --zerocounters
+ lcov --directory @abs_top_srcdir@ --zerocounters
lcov-report:
- lcov --directory @abs_top_builddir@ --capture \
+ lcov --directory @abs_top_srcdir@ --capture \
--output-file @abs_top_builddir@/lcov.info
$(mkdir_p) @abs_top_builddir@/lcov.html
git_commit=`GIT_DIR=@abs_top_srcdir@/.git git log -1 --pretty=format:%h 2>/dev/null`;\
diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh
index 94ae8fc..c39999f 100644
--- a/tools/run-with-tmp-session-bus.sh
+++ b/tools/run-with-tmp-session-bus.sh
@@ -1,15 +1,16 @@
#! /bin/sh
-SCRIPTNAME="$0"
-WRAPPED_SCRIPT="$1"
+SCRIPTNAME=$0
+WRAPPED_SCRIPT=$1
shift
-CONFIG_FILE=./tmp-session-bus.$$.conf
-
-die ()
+die()
{
- echo "$SCRIPTNAME: $*" >&2
- rm -f "$CONFIG_FILE"
+ 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
exit 1
}
@@ -17,6 +18,10 @@
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
@@ -45,18 +50,27 @@
unset DBUS_SESSION_BUS_ADDRESS
unset DBUS_SESSION_BUS_PID
-# 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
+echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
+
+DBUS_USE_TEST_BINARY=1
export DBUS_USE_TEST_BINARY
+eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
-$DBUS_TOP_BUILDDIR/tools/dbus-run-session \
- --config-file="$CONFIG_FILE" \
- --dbus-daemon="$DBUS_TOP_BUILDDIR/bus/dbus-daemon" \
- -- \
- "$WRAPPED_SCRIPT" "$@"
-error=$?
+if test -z "$DBUS_SESSION_BUS_PID" ; then
+ die "Failed to launch message bus for test script to run"
+fi
-# clean up
-rm -f "$CONFIG_FILE"
-exit $error
+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
+
+exit 0
diff --git a/tools/strtoll.c b/tools/strtoll.c
index 7360c63..e4f5770 100644
--- a/tools/strtoll.c
+++ b/tools/strtoll.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include "config.h"
#include <limits.h>
#ifdef HAVE_ERRNO_H
diff --git a/tools/strtoull.c b/tools/strtoull.c
index 3559554..459c509 100644
--- a/tools/strtoull.c
+++ b/tools/strtoull.c
@@ -27,7 +27,6 @@
* SUCH DAMAGE.
*/
-#include "config.h"
#include <limits.h>
#ifdef HAVE_ERRNO_H
diff --git a/tools/test-tool.c b/tools/test-tool.c
deleted file mode 100644
index 149c10a..0000000
--- a/tools/test-tool.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* dbus-test-tool - D-Bus swiss army knife
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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 "test-tool.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <dbus/dbus.h>
-
-static struct {
- const char *name;
- int (*callback) (int, char **);
-} subcommands[] = {
- { "black-hole", dbus_test_tool_black_hole },
- { "echo", dbus_test_tool_echo },
- { "spam", dbus_test_tool_spam },
- { NULL, NULL }
-};
-
-static void usage (int exit_with) _DBUS_GNUC_NORETURN;
-
-static void
-usage (int exit_with)
-{
- int i;
-
- fprintf (stderr,
- "Usage: dbus-test-tool SUBCOMMAND [OPTIONS]\n"
- "\n"
- "Known SUBCOMMANDs are:\n"
- "\n"
- );
-
- for (i = 0; subcommands[i].name != NULL; i++)
- {
- fprintf (stderr, "- %s\n", subcommands[i].name);
- }
-
- fprintf (stderr,
- "\n"
- "For more information: dbus-test-tool SUBCOMMAND --help\n"
- );
-
- exit (exit_with);
-}
-
-int
-main (int argc, char **argv)
-{
- int i;
-
- if (argc < 2)
- {
- usage (2);
- }
-
- for (i = 0; subcommands[i].name != NULL; i++)
- {
- if (!strcmp (argv[1], subcommands[i].name))
- return subcommands[i].callback (argc, argv);
- }
-
- usage (2);
- return 2;
-}
diff --git a/tools/test-tool.h b/tools/test-tool.h
deleted file mode 100644
index 8143cd5..0000000
--- a/tools/test-tool.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* dbus-test-tool - D-Bus swiss army knife
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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_TEST_TOOL_H
-#define DBUS_TEST_TOOL_H
-
-int dbus_test_tool_black_hole (int argc, char **argv);
-int dbus_test_tool_echo (int argc, char **argv);
-int dbus_test_tool_spam (int argc, char **argv);
-
-#endif
diff --git a/tools/tool-common.c b/tools/tool-common.c
deleted file mode 100644
index 3202032..0000000
--- a/tools/tool-common.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* tool-common - common functionality for dbus-test-tool modules
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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 "tool-common.h"
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#ifdef DBUS_WIN
-#include <io.h>
-#include <windows.h>
-#else
-#include <unistd.h>
-#endif
-
-void
-tool_oom (const char *doing)
-{
- fprintf (stderr, "OOM while %s\n", doing);
- exit (1);
-}
-
-#ifdef DBUS_WIN
-typedef int WriteResult;
-#define write(fd, buf, len) _write(fd, buf, len)
-#else
-typedef ssize_t WriteResult;
-#endif
-
-dbus_bool_t
-tool_write_all (int fd,
- const void *buf,
- size_t size)
-{
- const char *p = buf;
- size_t bytes_written = 0;
-
- while (size > bytes_written)
- {
- WriteResult res = write (fd, p, size - bytes_written);
-
- if (res < 0)
- {
- if (errno == EINTR)
- continue;
- else
- return FALSE;
- }
- else
- {
- size_t this_time = (size_t) res;
- p += this_time;
- bytes_written += this_time;
- }
- }
-
- return TRUE;
-}
diff --git a/tools/tool-common.h b/tools/tool-common.h
deleted file mode 100644
index e6397ff..0000000
--- a/tools/tool-common.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
-/* tool-common - common functionality for dbus-test-tool modules
- *
- * Copyright © 2003 Philip Blundell <philb@gnu.org>
- * Copyright © 2011 Nokia Corporation
- * Copyright © 2014 Collabora Ltd.
- *
- * 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_TOOL_COMMON_H
-#define DBUS_TOOL_COMMON_H
-
-#include <dbus/dbus.h>
-
-#if 0
-#define VERBOSE fprintf
-#else
-#define VERBOSE(...) do {} while (0)
-#endif
-
-void tool_oom (const char *doing) _DBUS_GNUC_NORETURN;
-dbus_bool_t tool_write_all (int fd, const void *buf, size_t size);
-
-#endif