Major flaw in libnm_glib



Whilst playing around with libnm_glib for some little project that
should use NM's functionality (the connect/disconnect signals), I was
faced with (what I think is) a major flaw in the library.

It looks like libdbus and it's derivates abort() when you try to init
the dbus library more than once. As libnm_dbus calls
dbus_g_thread_init() while initializing a libnm_glib_ctx, this will make
any application using libnm_glib crash when it's already using the
system bus, or will be using it later.

Proof of concept:

nicolas marslander ~/Projects/nmtest $ cat test1.c
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <NetworkManager/libnm_glib.h>

static void state_change(libnm_glib_ctx *ctx, gpointer user_data) {
        g_print("State change: %d\n",
libnm_glib_get_network_state(ctx));
}

int main(int argc, char *argv[]) {
        libnm_glib_ctx *ctx = NULL;
        GMainLoop *loop = NULL;
        DBusGConnection *conn = NULL;
        GError *error = NULL;

        g_type_init();

        loop = g_main_loop_new(NULL, FALSE);
        g_assert(loop != NULL);

        if(argc > 1) {
                g_debug("Getting system bus handle, app should crash");
                conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
                if(error != NULL) {
                        g_warning("DBus error: %s", error->message);
                        g_error_free(error);
                        return 1;
                }
        }

        ctx = libnm_glib_init();
        g_assert(ctx != NULL);

        libnm_glib_register_callback(ctx, state_change, NULL, NULL);
        g_print("Current state: %d\n",
libnm_glib_get_network_state(ctx));

        g_main_loop_run(loop);

        libnm_glib_shutdown(ctx);

        return 0;
}
nicolas marslander ~/Projects/nmtest $ gcc -o test1 `pkg-config --libs
--cflags glib-2.0 libnm_glib dbus-glib-1` -g test1.c -Wall
nicolas marslander ~/Projects/nmtest $ ./test1
Current state: 3
State change: 3
^C
nicolas marslander ~/Projects/nmtest $ ./test1 1
** (process:29769): DEBUG: Getting system bus handle, app should crash
29769: assertion failed "allocator->lock == mutex" file
"dbus-dataslot.c" line 82 function _dbus_data_slot_allocator_alloc
Aborted


As you can see, as long as I don't do any dbus (system-bus) actions,
everything works fine. When I initialize libnm_dbus after I already
connected to the bus (and initialized the dbus subsystem), the whole app
crashed hard.

This *might* be a bug in libdbus, don't know very well. I rather think
libnm_glib should/could be changed to get a reference to an existing
DBusConnection, so it might even become possible to have NM running on a
non-standard bus one day (whether thats of any use is questionable
though ;-)).
Is there any reason libnm_glib is threaded, by the way?


Anyway, iirc Dan mentioned once the glib helpers would be rewritten one
day. I could give that a shot if wanted... But I guess the dbus
interface will somewhat change in the 0.7 timeframe?


Regards,

Ikke
http://www.eikke.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]