Newbie question: dbus_bus_get() and dbus_error_is_set()
Dan Arrhenius
dan at keystream.se
Wed Apr 6 06:29:58 PDT 2011
On 04/06/2011 03:08 PM, Will Thompson wrote:
> 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,
I agree that it isn't normal behavior to intentionally pass invalid parameters ;-)
But since dbus_bus_get() prints out an error text to stderr and returns NULL I would say
that it knows very well that something is wrong. And it wouldn't be to much to ask that it
could indicate in the error parameter that an error occurred. At least the
documentation(doxygen) could be updated to inform that the function can return NULL.
Regards,
Dan
More information about the dbus
mailing list