static void ibus_bus_connect (IBusBus *bus) { IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); /* destry old connection at first */ if (priv->connection != NULL) { ibus_object_destroy ((IBusObject *)priv->connection); g_assert (priv->connection == NULL); } if (ibus_get_address () != NULL) { priv->connection = ibus_connection_open (ibus_get_address ()); } if (priv->connection) { ibus_bus_hello (bus); g_signal_connect (priv->connection, "destroy", (GCallback) _connection_destroy_cb, bus); g_signal_emit (bus, bus_signals[CONNECTED], 0); if (priv->watch_dbus_signal) { ibus_bus_watch_dbus_signal (bus); } /** Watch ibus signals. */ const gchar *rule = "type='signal'," "path='" IBUS_PATH_IBUS "'," "interface='" IBUS_INTERFACE_IBUS "'"; ibus_bus_add_match (bus, rule); g_signal_connect (priv->connection, "ibus-signal", (GCallback) _connection_ibus_signal_cb, bus); } }
static void ibus_bus_connect (IBusBus *bus) { IBusBusPrivate *priv; priv = IBUS_BUS_GET_PRIVATE (bus); #if 0 socket_path = ibus_get_socket_path (); if (stat (socket_path, &buf) != 0) { g_warning ("Can not get stat from %s!", socket_path); return; } if (buf.st_uid != ibus_get_daemon_uid ()) { g_warning ("The owner of %s is not %s!", socket_path, ibus_get_user_name ()); return; } if (priv->connection != NULL) { ibus_object_destroy ((IBusObject *) priv->connection); } #endif if (ibus_get_address () != NULL) { priv->connection = ibus_connection_open (ibus_get_address ()); } if (priv->connection) { ibus_bus_hello (bus); g_signal_connect (priv->connection, "destroy", (GCallback) _connection_destroy_cb, bus); g_signal_emit (bus, bus_signals[CONNECTED], 0); if (priv->watch_dbus_signal) { ibus_bus_watch_dbus_signal (bus); } } }
gboolean bus_server_listen (BusServer *server) { g_assert (BUS_IS_SERVER (server)); const gchar *mechanisms[] = { "EXTERNAL", NULL }; const gchar *address = "unix:tmpdir=/tmp/"; gboolean retval; #if 0 path = ibus_get_socket_folder (); mkdir (path, 0700); chmod (path, 0700); address = ibus_get_address (); #endif retval = ibus_server_listen (IBUS_SERVER (server), address); #if 0 chmod (ibus_get_socket_path (), 0600); #endif ibus_server_set_auth_mechanisms ((IBusServer *)server, mechanisms); if (!retval) { #if 0 g_printerr ("Can not listen on %s! Please try remove directory %s and run again.", address, path); #else g_printerr ("Can not listen on %s!", address); #endif exit (-1); } ibus_write_address (ibus_server_get_address (IBUS_SERVER (server))); return retval; }
gboolean bus_server_listen (BusServer *server) { g_assert (BUS_IS_SERVER (server)); // const gchar *address = "unix:abstract=/tmp/ibus-c" const gchar *address; gchar *path; gboolean retval; path = g_strdup_printf("/tmp/ibus-%s", ibus_get_user_name ()); mkdir (path, 0775); address = ibus_get_address (); retval = ibus_server_listen (IBUS_SERVER (server), address); if (!retval) { g_printerr ("Can not listen on %s! Please try remove directory %s and run again.", address, path); exit (-1); } g_free(path); return retval; }
gint main (gint argc, gchar **argv) { setlocale (LC_ALL, ""); GOptionContext *context = g_option_context_new ("- ibus daemon"); g_option_context_add_main_entries (context, entries, "ibus-daemon"); g_argv = g_strdupv (argv); GError *error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s\n", error->message); g_error_free (error); exit (-1); } if (g_gdbus_timeout < -1) { g_printerr ("Bad timeout (must be >= -1): %d\n", g_gdbus_timeout); exit (-1); } if (g_mempro) { g_mem_set_vtable (glib_mem_profiler_table); signal (SIGUSR2, _sig_usr2_handler); } /* check uid */ { const gchar *username = ibus_get_user_name (); uid_t uid = getuid (); struct passwd *pwd = getpwuid (uid); if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) { g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n"); exit (-1); } } /* daemonize process */ if (daemonize) { if (daemon (1, 0) != 0) { g_printerr ("Can not daemonize ibus.\n"); exit (-1); } } /* create a new process group. this is important to kill all of its children by SIGTERM at a time in bus_ibus_impl_destroy. */ setpgid (0, 0); ibus_init (); ibus_set_log_handler (g_verbose); /* check if ibus-daemon is running in this session */ if (ibus_get_address () != NULL) { IBusBus *bus = ibus_bus_new (); if (ibus_bus_is_connected (bus)) { if (!replace) { g_printerr ("current session already has an ibus-daemon.\n"); exit (-1); } ibus_bus_exit (bus, FALSE); while (ibus_bus_is_connected (bus)) { g_main_context_iteration (NULL, TRUE); } } g_object_unref (bus); } bus_server_init (); if (!single) { /* execute config component */ if (g_strcmp0 (config, "default") == 0) { BusComponent *component; component = bus_ibus_impl_lookup_component_by_name ( BUS_DEFAULT_IBUS, IBUS_SERVICE_CONFIG); if (component) { bus_component_set_restart (component, restart); } if (component == NULL || !bus_component_start (component, g_verbose)) { g_printerr ("Can not execute default config program\n"); exit (-1); } } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) { if (!execute_cmdline (config)) exit (-1); } /* execute panel component */ if (g_strcmp0 (panel, "default") == 0) { BusComponent *component; component = bus_ibus_impl_lookup_component_by_name ( BUS_DEFAULT_IBUS, IBUS_SERVICE_PANEL); if (component) { bus_component_set_restart (component, restart); } if (component == NULL || !bus_component_start (component, g_verbose)) { g_printerr ("Can not execute default panel program\n"); exit (-1); } } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) { if (!execute_cmdline (panel)) exit (-1); } } /* execute ibus xim server */ if (xim) { if (!execute_cmdline (LIBEXECDIR "/ibus-x11 --kill-daemon")) exit (-1); } bus_server_run (); return 0; }
gint main (gint argc, gchar **argv) { GOptionContext *context; BusServer *server; IBusBus *bus; GError *error = NULL; setlocale (LC_ALL, ""); context = g_option_context_new ("- ibus daemon"); g_option_context_add_main_entries (context, entries, "ibus-daemon"); g_argv = g_strdupv (argv); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s\n", error->message); exit (-1); } if (g_mempro) { g_mem_set_vtable (glib_mem_profiler_table); signal (SIGUSR2, _sig_usr2_handler); } /* check uid */ { const gchar *username = ibus_get_user_name (); uid_t uid = getuid (); struct passwd *pwd = getpwuid (uid); if (pwd == NULL || g_strcmp0 (pwd->pw_name, username) != 0) { g_printerr ("Please run ibus-daemon with login user! Do not run ibus-daemon with sudo or su.\n"); exit (-1); } } /* daemonize process */ if (daemonize) { if (daemon (1, 0) != 0) { g_printerr ("Can not daemonize ibus.\n"); exit (-1); } } /* create a new process group */ setpgrp (); g_type_init (); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_DEBUG | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, _my_log_handler, NULL); /* check if ibus-daemon is running in this session */ if (ibus_get_address () != NULL) { bus = ibus_bus_new (); if (ibus_bus_is_connected (bus)) { if (!replace) { g_printerr ("current session already has an ibus-daemon.\n"); exit (-1); } ibus_bus_exit (bus, FALSE); while (ibus_bus_is_connected (bus)) { g_main_context_iteration (NULL, TRUE); } } g_object_unref (bus); bus = NULL; } /* create ibus server */ server = bus_server_get_default (); bus_server_listen (server); if (!single) { /* execute config component */ 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, g_verbose)) { g_printerr ("Can not execute default config program\n"); exit (-1); } } else if (g_strcmp0 (config, "disable") != 0 && g_strcmp0 (config, "") != 0) { if (!execute_cmdline (config)) exit (-1); } /* execut panel component */ 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, g_verbose)) { g_printerr ("Can not execute default panel program\n"); exit (-1); } } else if (g_strcmp0 (panel, "disable") != 0 && g_strcmp0 (panel, "") != 0) { if (!execute_cmdline (panel)) exit (-1); } } /* execute ibus xim server */ if (xim) { if (!execute_cmdline (LIBEXECDIR"/ibus-x11 --kill-daemon")) exit (-1); } bus_server_run (server); return 0; }