Question regarding GMainLoop usage

Sandeep Puddupakkam (spuddupa) spuddupa at cisco.com
Mon Oct 26 17:03:05 PDT 2009


Hi,

I am newbie to dbus and any help would be greatly appreciated.

Software Version info:

Upstart 0.5

D-Bus 1.2.1

D-Bus GLib Bindings 0.75 (05 Jun 2008)

 

 

I am trying to write a c library that uses dbus-glib to talk to upstart
0.5

I want to use a GMainLoop to receive upstart job/instance signals as
well as handle callbacks to upstart async api calls (emit event, start
job etc).

 

My library has a init function that does the following. Processes call
this init function before making any upstart api calls.

int sysmgr_clientlib_init()

{

            /* Initialize the dbus connection */

            myconn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);

            if (myconn == NULL)

            {

                        handleError("sysmgrlib_init failed.","Unable to
open connection to dbus", TRUE);

            }

            /* Initialize the upstart Proxy */

            upstartProxy = dbus_g_proxy_new_for_name(myconn,

 
UPSTART_SERVICE,UPSTART_SERVICE_PATH,UPSTART_INTERFACE);

            if (NULL == upstartProxy)

            {

                        handleError("sysmgrlib_init failed.","Unable to
get upstart proxy",TRUE);

            }

            //Add the signals for Upstart Proxy. This should happen only
once.

            //connect/disconnect happens on EnableSignal and
DisableSignal function.

            dbus_g_proxy_add_signal (upstartProxy, "JobAdded",
DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);

            dbus_g_proxy_add_signal (upstartProxy, "JobRemoved",
DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);

 

            //Start a gthread that runs a GMainLoop

            if( (gtmainloop =
g_thread_create((GThreadFunc)ThreadGMainLoop, NULL, TRUE, &error)) ==
NULL)

            {

                        handleError("sysmgrlib_init failed. Thread
creation failed.",error->message,TRUE);

            }

            if(NULL!=error)

                        g_clear_error(&error);

            <snip/>//Other initialization.

            return 0;

}

static void * ThreadGMainLoop(void * UNUSED (ptr))

{

            mainloop = g_main_loop_new(NULL, FALSE);

            if (NULL == mainloop)

            {

                        handleError("GMainLoop initialization failed.",

                                                "Signals and Async
callbacks will not be handled", TRUE);

            }

            verbose("g_main_loop_run starting");

            g_main_loop_run(mainloop);

            verbose("g_main_loop_run exited");

            fflush(stdout);

            return NULL;

}

void sysmgr_clientlib_release()

{

            if(0==sysmgr_clientlib_init_done)

                        return;

            g_main_loop_quit(mainloop);

            g_object_unref(upstartProxy);

            upstartProxy=NULL;

            <snip/>

}

 

I am running into a crash rarely (not easy to duplicate) on a dual
processor ppc based board.

I have not seen this crash on a single processor system.

The crash seems to indicate that the connection object is null.

 

Does the logic above of starting a gmainloop in a separate thread look
ok?

I added a sleep(1) after the g_thread creation before making my first
API call and I have not seen a crash in the last couple of days of my
testing. 

Is this because the g_main_loop is getting more time to complete its
initialize now after I introduced the sleep?

 

Any suggestions/feedback on the logic would be greatly appreciated.

 

 

Thanks and Regards,

 

Sandeep

 

Crash info indicating connection=NULL

--------------------------------------------------------

Thread 1 (process 5979):

#0  _dbus_connection_lock (connection=0x0)

    at /nobackup/spuddupa/nova/contrib/dbus/dbus/dbus-connection.c:355

No locals.

#1  0x0f81aafc in _dbus_pending_call_get_connection_and_lock
(pending=0x100244c8)

    at /nobackup/spuddupa/nova/contrib/dbus/dbus/dbus-pending-call.c:309

No locals.

#2  0x0f80b0e8 in reply_handler_timeout (data=0x100244c8)

    at /nobackup/spuddupa/nova/contrib/dbus/dbus/dbus-connection.c:3104

        connection = (DBusConnection *) 0x1001b980

        status = 16

#3  0x0f820088 in dbus_timeout_handle (timeout=0xf80b0c8)

    at /nobackup/spuddupa/nova/contrib/dbus/dbus/dbus-timeout.c:473

No locals.

#4  0x0f90b518 in timeout_handler_dispatch (data=0x0)

    at /nobackup/spuddupa/nova/contrib/dbus-glib/dbus/dbus-gmain.c:343

No locals.

#5  0x0f71a454 in g_timeout_dispatch (source=0x48828d9c, 

    callback=0xf81aafc <_dbus_pending_call_get_connection_and_lock+32>, 

    user_data=0x10024518) at
/nobackup/spuddupa/nova/contrib/glib/glib/gmain.c:3293

No locals.

#6  0x0f716fac in IA__g_main_context_dispatch (context=0x1001b980)

    at /nobackup/spuddupa/nova/contrib/glib/glib/gmain.c:1934

No locals.

#7  0x0f718f78 in g_main_context_iterate (context=0x1001b980, block=0,
dispatch=259105812, 

    self=0x48828d9c) at
/nobackup/spuddupa/nova/contrib/glib/glib/gmain.c:2565

        max_priority = 0

        timeout = 0

        some_ready = 1

        nfds = 2

        allocated_nfds = 1

        fds = (GPollFD *) 0xf78e79c

        __PRETTY_FUNCTION__ = "g_main_context_iterate"

#8  0x0f719374 in IA__g_main_loop_run (loop=0x1001e2d8)

    at /nobackup/spuddupa/nova/contrib/glib/glib/gmain.c:2769

        got_ownership = 260156156

        self = (GThread *) 0x1001dbf0

        __PRETTY_FUNCTION__ = "IA__g_main_loop_run"

#9  0x0ffdbcf8 in ThreadGMainLoop ()

No symbol table info available.

#10 0x0f738784 in g_thread_create_proxy (data=0x0)

    at /nobackup/spuddupa/nova/contrib/glib/glib/gthread.c:561

        thread = (GRealThread *) 0x1001e2e0

        __PRETTY_FUNCTION__ = "g_thread_create_proxy"

#11 0x0f32fd94 in start_thread (arg=0x0) at pthread_create.c:263

        pd = (struct pthread *) 0x488294f0

        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {1216515712, 0,
254999900, -1, 0, 0, 

        268557320, 1208130000, 268557296, 259229272, 255112832, 1, 7, 0,
-1075695120, 

        8195840, 1216516256, 8195840, 1216516240, 255112376, 1216517360,
1107829794, 

        0 <repeats 90 times>}, mask_was_saved = 0}}, priv = {pad = {0x0,
0x0, 0x0, 0x0}, 

    data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}

        not_first_call = 0

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20091026/dc7d0444/attachment-0001.html 


More information about the dbus mailing list