From 1d6621087b630bbfb01913ed34156e4dc30b6de7 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 22 Jun 2014 10:22:05 +0300 Subject: [PATCH] client: Wait for D-Bus before processing stdin This should make it possible to do some scripting with bluetoothctl. Otherwise stdin is processed before we're connected to D-Bus and most commands will fail as a consequence. --- client/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/main.c b/client/main.c index 3244d425f..774c0cd6b 100644 --- a/client/main.c +++ b/client/main.c @@ -1464,6 +1464,13 @@ static GOptionEntry options[] = { { NULL }, }; +static void client_ready(GDBusClient *client, void *user_data) +{ + guint *input = user_data; + + *input = setup_standard_input(); +} + int main(int argc, char *argv[]) { GOptionContext *context; @@ -1501,7 +1508,6 @@ int main(int argc, char *argv[]) rl_set_prompt(PROMPT_OFF); rl_redisplay(); - input = setup_standard_input(); signal = setup_signalfd(); client = g_dbus_client_new(dbus_conn, "org.bluez", "/org/bluez"); @@ -1512,11 +1518,15 @@ int main(int argc, char *argv[]) g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed, property_changed, NULL); + input = 0; + g_dbus_client_set_ready_watch(client, client_ready, &input); + g_main_loop_run(main_loop); g_dbus_client_unref(client); g_source_remove(signal); - g_source_remove(input); + if (input > 0) + g_source_remove(input); rl_message(""); rl_callback_handler_remove(); -- 2.47.3