dbus_g_bus_get and error reporting

Paul Kuliniewicz kuliniew at purdue.edu
Tue Aug 17 22:47:03 PDT 2004


I've noticed that dbus_g_bus_get() in CVS behaves a bit unexpectedly
when it fails.  It's intuitive to expect it to return NULL on failure,
but it actually returns 4 -- the result of
DBUS_G_CONNECTION_FROM_CONNECTION(NULL).  This leads to confusing
behavior when using this non-null but clearly invalid pointer later on,
since any D-BUS functions that recover the DBusConnection will see NULL
and report that, when the user didn't pass in a NULL.

It's probably better to have dbus_g_bus_get() just return NULL if it
fails, to avoid surprising the user.  True, an error can currently be
detected by checking if a GError was created, but the user's expectation
would be just to check for a NULL return.  (The test case
test/glib/test-service-glib falls into this trap, for example.)  I'm not
including a patch to make this change since it's so trivial.

And while we're on the subject, does anyone know what would make
test-service-glib (after being corrected for the above) fail with the
following error message?

Failed to open connection to bus: D-BUS error
org.freedesktop.DBus.Error.Disconnected: Disconnected prior to receiving
a reply

D-BUS is running and the environment variables are set properly.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://freedesktop.org/pipermail/dbus/attachments/20040818/d80e71a0/attachment.pgp


More information about the dbus mailing list