D-Bus unit tests

Thomas Sondergaard ts at medical-insight.com
Wed Nov 12 11:53:23 PST 2014


On 2014-11-12 13:38, Simon McVittie wrote:
> 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
>> qputenv("DBUS_SESSION_BUS_ADDRESS",
>> 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

Thanks, I will do just that!


>> 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.

Thanks for the clarification.

>
>> 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.

What you wrote above seems very accurate :-)

>
>> 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.
>

Thanks for the help!

Thomas



More information about the dbus mailing list