D-Bus unit tests

Ralf Habacker ralf.habacker at freenet.de
Wed Nov 12 05:49:42 PST 2014

Am 12.11.2014 um 13:38 schrieb Simon McVittie:
> On 12/11/14 09:32, Thomas Sondergaard wrote:
>> My thinking is that I need to do something like this:
>> qputenv("DBUS_SESSION_BUS_ADDRESS", "autolaunch:");
>> QDBusConnection::sessionBus(); // Trigger connect
>> getDBusAddress(QDBusConnection::sessionBus()));
> Autolaunching (the autolaunch transport and dbus-launch) is not the
> right tool for this, at least on Unix. You should either start a new
> dbus-daemon "by hand" and put its address in DBUS_SESSION_BUS_ADDRESS,
> like GTestDBus in recent GLib, or use a script or executable that does that.
> The dbus-run-session tool in recent dbus packages launches a new
> dbus-daemon for its child process, runs the child process with the right
> environment variables, waits for that process to terminate, and kills
> the temporary dbus-daemon. with-session-bus.sh in various Telepathy
> packages was an older implementation of dbus-run-session, in shell script.
> Please look at the implementation of GTestDBus, dbus-run-session or
> with-session-bus.sh to see:
> * the dbus-daemon command-line options you can use for this
> * the environment variables you should set in the child
> * the environment variables you should unset in the child
>> If another process
>> has already been started with autolaunch: I get connected to it's
>> dbus-daemon (on RHEL7 linux, haven't tried on Windows).
> On Unix systems, if you are in an X11 session, you get one autolaunched
> dbus-daemon per uid per X server.
>> Btw, this seems
>> inconsistent with http://dbus.freedesktop.org/doc/dbus-launch.1.html
>> which says "Whenever an autolaunch occurs, the application that had to
>> start a new bus will be in its own little world".
> Suggestions for better/clearer wording welcome.
>> I hope you can help me with this. I'd like a solution that works on both
>> Linux and Windows.
> Sorry, I think you will probably need slightly different "machinery" on
> Windows, because child processes and pipes don't work the same, and
> neither does the autolaunch transport.
> Some of the dbus regression tests (e.g. test/dbus-daemon.c) start a
> dbus-daemon in as close as possible to the same way on Unix and Windows,
> but to do that, they have to tell it to output its address on stdout.
for example by using the following command line, which should work
platform independent.

dbus-daemon --config-file=... --adress=tcp:host=localhost,port=0

"port=0" let the dbus-daemon select a free port see

and --print-address reports the currently used address for clients to

You may also use --print-pid=3 to get the pid of the daemon to stderr
for later killing.


More information about the dbus mailing list