From bcf7868d4a42de8b7c2a54b74615dbe54e83e00d Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Sun, 31 May 2009 11:13:11 +0800 Subject: [PATCH] Add verbose argument for ibus_component_start function Do not use g_usleep --- bus/ibusimpl.c | 27 ++++++++++++++++----------- bus/main.c | 10 +++++----- src/ibuscomponent.c | 9 +++++++-- src/ibuscomponent.h | 4 +++- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c index 9baf74f..77a0fe5 100644 --- a/bus/ibusimpl.c +++ b/bus/ibusimpl.c @@ -64,6 +64,8 @@ static void _factory_destroy_cb (BusFactoryProxy *factory, static IBusServiceClass *parent_class = NULL; +extern gboolean g_verbose; + GType bus_ibus_impl_get_type (void) { @@ -233,7 +235,7 @@ bus_ibus_impl_set_preload_engines (BusIBusImpl *ibus, component = ibus_component_get_from_engine ((IBusEngineDesc *) ibus->engine_list->data); if (component && !ibus_component_is_running (component)) { - ibus_component_start (component); + ibus_component_start (component, g_verbose); } } } @@ -616,6 +618,7 @@ bus_ibus_impl_create_engine (IBusEngineDesc *engine_desc) IBusComponent *comp; BusFactoryProxy *factory; BusEngineProxy *engine; + GTimeVal t1, t2; factory = bus_factory_proxy_get_from_engine (engine_desc); @@ -625,24 +628,26 @@ bus_ibus_impl_create_engine (IBusEngineDesc *engine_desc) g_assert (comp); if (!ibus_component_is_running (comp)) { - ibus_component_start (comp); + ibus_component_start (comp, g_verbose); gint time = 0; - while (time < G_USEC_PER_SEC * 3) { + g_get_current_time (&t1); + while (1) { if (g_main_context_pending (NULL)) { g_main_context_iteration (NULL, FALSE); + factory = bus_factory_proxy_get_from_engine (engine_desc); + if (factory != NULL) { + break; + } } - else { - g_usleep (50 * 1000); - time += 50 * 1000; - } - factory = bus_factory_proxy_get_from_engine (engine_desc); - if (factory != NULL) { + g_get_current_time (&t2); + if (t2.tv_sec - t1.tv_sec >= 5) break; - } } } - factory = bus_factory_proxy_get_from_engine (engine_desc); + else { + factory = bus_factory_proxy_get_from_engine (engine_desc); + } } if (factory == NULL) { diff --git a/bus/main.c b/bus/main.c index ab4786e..2e227ea 100644 --- a/bus/main.c +++ b/bus/main.c @@ -39,7 +39,7 @@ static gchar *config = "default"; static gchar *desktop = "gnome"; static gchar *address = ""; gboolean g_rescan = FALSE; -static gboolean verbose = FALSE; +gboolean g_verbose = FALSE; static const GOptionEntry entries[] = { @@ -52,7 +52,7 @@ static const GOptionEntry entries[] = { "address", 'a', 0, G_OPTION_ARG_STRING, &address, "specify the address of ibus daemon.", "address" }, { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "if there is an old ibus-daemon is running, it will be replaced.", NULL }, { "re-scan", 't', 0, G_OPTION_ARG_NONE, &g_rescan, "force to re-scan components, and re-create registry cache.", NULL }, - { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose.", NULL }, + { "verbose", 'v', 0, G_OPTION_ARG_NONE, &g_verbose, "verbose.", NULL }, { NULL }, }; @@ -138,7 +138,7 @@ _my_log_handler (const gchar *log_domain, const gchar *message, gpointer user_data) { - if (verbose) { + if (g_verbose) { g_log_default_handler (log_domain, log_level, message, user_data); } } @@ -219,7 +219,7 @@ main (gint argc, gchar **argv) if (g_strcmp0 (config, "default") == 0) { IBusComponent *component; component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG); - if (component == NULL || !ibus_component_start (component)) { + if (component == NULL || !ibus_component_start (component, g_verbose)) { g_printerr ("Can not execute default config program\n"); exit (-1); } @@ -232,7 +232,7 @@ main (gint argc, gchar **argv) if (g_strcmp0 (panel, "default") == 0) { IBusComponent *component; component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL); - if (component == NULL || !ibus_component_start (component)) { + if (component == NULL || !ibus_component_start (component, g_verbose)) { g_printerr ("Can not execute default panel program\n"); exit (-1); } diff --git a/src/ibuscomponent.c b/src/ibuscomponent.c index a3fca11..cb5bf32 100644 --- a/src/ibuscomponent.c +++ b/src/ibuscomponent.c @@ -656,7 +656,7 @@ ibus_component_child_cb (GPid pid, } gboolean -ibus_component_start (IBusComponent *component) +ibus_component_start (IBusComponent *component, gboolean verbose) { g_assert (IBUS_IS_COMPONENT (component)); @@ -667,6 +667,7 @@ ibus_component_start (IBusComponent *component) gchar **argv; gboolean retval; GError *error; + GSpawnFlags flags; error = NULL; if (!g_shell_parse_argv (component->exec, &argc, &argv, &error)) { @@ -676,8 +677,12 @@ ibus_component_start (IBusComponent *component) } error = NULL; + flags = G_SPAWN_DO_NOT_REAP_CHILD; + if (!verbose) { + flags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL; + } retval = g_spawn_async (NULL, argv, NULL, - G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL, + flags, NULL, NULL, &(component->pid), &error); g_strfreev (argv) diff --git a/src/ibuscomponent.h b/src/ibuscomponent.h index 18a9f06..b737d1d 100644 --- a/src/ibuscomponent.h +++ b/src/ibuscomponent.h @@ -227,11 +227,13 @@ gboolean ibus_component_check_modification /** * ibus_component_start: * @component: An IBusComponent. + * @verbose: if redirect the child output to /dev/null * @returns: TRUE if the component is started; FALSE otherwise. * * Whether the IBusComponent is started. */ -gboolean ibus_component_start (IBusComponent *component); +gboolean ibus_component_start (IBusComponent *component, + gboolean verbose); /** * ibus_component_stop: -- 2.7.4