From d7ae1e35d892c50ee33213e7a95b6347cdaaf45d Mon Sep 17 00:00:00 2001 From: Jesse Keating Date: Wed, 14 Jan 2009 16:18:05 -0800 Subject: Create a loop for dbus and pump the loop to process all the dbus messages. This fixes network bringup in loader. In a normal env, something like GTK processes all the dbus messages as part of it's main loop. We don't have anything like that in loader so we have to turn that crank manually, and enough times to clear out all the pending messages. Signed-off-by: David Cantrell --- loader/net.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'loader') diff --git a/loader/net.c b/loader/net.c index eef0234c1..4d08d3437 100644 --- a/loader/net.c +++ b/loader/net.c @@ -1895,6 +1895,8 @@ int get_connection(iface_t *iface) { int count = 0; NMClient *client = NULL; NMState state; + GMainLoop *loop; + GMainContext *ctx; if (iface == NULL) { return 1; @@ -1921,8 +1923,21 @@ int get_connection(iface_t *iface) { return 2; } + /* Create a loop for processing dbus signals */ + loop = g_main_loop_new(NULL, FALSE); + ctx = g_main_loop_get_context(loop); + + /* pump the loop until all the messages are clear */ + while (g_main_context_pending (ctx)) { + g_main_context_iteration (ctx, FALSE); + } + /* send message and block until a reply or error comes back */ while (count < 45) { + /* pump the loop again to clear the messages */ + while (g_main_context_pending (ctx)) { + g_main_context_iteration (ctx, FALSE); + } state = nm_client_get_state(client); if (state == NM_STATE_CONNECTED) { @@ -1937,6 +1952,7 @@ int get_connection(iface_t *iface) { count++; } + g_main_loop_unref(loop); g_object_unref(client); return 3; } -- cgit