Newbie question: dbus_bus_get() and dbus_error_is_set()
Will Thompson
will.thompson at collabora.co.uk
Wed Apr 6 06:08:27 PDT 2011
On 06/04/11 12:29, Dan Arrhenius wrote:
> I'm just starting to play with libdbus-1 and have a question about the
> error parameter to dbus_bus_get().
>
> I tried to force an error with the following code:
>
> ....
> DBusError err;
> DBusConnection* connection;
>
> dbus_error_init (&err);
> connection = dbus_bus_get ((DBusBusType)42, &err);
> if (dbus_error_is_set(&err)) {
> fprintf (stderr, "dbus_bus_get() failed: %s\n", err.message);
> dbus_error_free (&err);
> exit (1);
> }
> ....
>
> An error is printed to stderr by libdbus and dbus_bus_get() returns
> NULL, but dbus_error_is_set() doesn't return true and err.message is NULL.
> Is this normal behavior in libdbus, to not use the error parameter for
> some errors and instead return NULL ?
I think the argument here is that the DBusError will be set for errors
that can occur in normal use (such as “the system bus isn't running for
some reason”), but by passing an invalid parameter to dbus_bus_get()
you're stepping into the realm of undefined behaviour.
Regards,
--
Will
More information about the dbus
mailing list