~ubuntu-branches/ubuntu/quantal/ibus/quantal

« back to all changes in this revision

Viewing changes to bus/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry Warsaw
  • Date: 2011-08-11 17:00:57 UTC
  • mfrom: (6.2.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110811170057-6dmbfs4s3cchzl7x
Tags: 1.3.99.20110419-1ubuntu1
* Merge with Debian unstable.  Remaining Ubuntu changes:
  - Indicator support:
    + Add 05_appindicator.patch: Use an indicator rather than a notification
      icon.
    + debian/control: Recommend python-appindicator.
  - debian/control: Install im-switch instead of im-config by default.
  - debian/README.source: Removed, it was outdated and no longer correct
  - debian/patches/01_ubuntu_desktop: Fix "Desktop entry needs the
    X-Ubuntu-Gettext-Domain key"  (LP: #457632)
  - debian/patches/02_title_update.patch: Rename "IBus Preferences" to
    "Keyboard Input Methods"
  - debian/patches/06_locale_parser.patch: Cherry-picked from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 * Boston, MA 02111-1307, USA.
21
21
 */
22
22
#include <config.h>
23
 
#include <dbus/dbus.h>
24
23
#include <unistd.h>
25
24
#include <sys/types.h>
26
25
#include <sys/stat.h>
29
28
#include <stdlib.h>
30
29
#include <locale.h>
31
30
#include <signal.h>
 
31
#include <glib.h>
 
32
#include <gio/gio.h>
 
33
#include <ibus.h>
32
34
#include "server.h"
33
35
#include "ibusimpl.h"
34
36
 
42
44
static gchar *panel = "default";
43
45
static gchar *config = "default";
44
46
static gchar *desktop = "gnome";
45
 
static gchar *address = "";
 
47
gchar *g_address = "unix:tmpdir=/tmp";
46
48
gchar *g_cache = "auto";
47
49
gboolean g_mempro = FALSE;
48
50
gboolean g_verbose = FALSE;
49
 
gint   g_dbus_timeout = 5000;
 
51
gint   g_gdbus_timeout = 5000;
50
52
#ifdef G_THREADS_ENABLED
51
53
gint   g_monitor_timeout = 0;
52
54
#endif
65
67
    { "single",    's', 0, G_OPTION_ARG_NONE,   &single,    "do not execute panel and config module.", NULL },
66
68
    { "xim",       'x', 0, G_OPTION_ARG_NONE,   &xim,       "execute ibus XIM server.", NULL },
67
69
    { "desktop",   'n', 0, G_OPTION_ARG_STRING, &desktop,   "specify the name of desktop session. [default=gnome]", "name" },
68
 
    { "panel",     'p', 0, G_OPTION_ARG_STRING, &panel,     "specify the cmdline of panel program.", "cmdline" },
69
 
    { "config",    'c', 0, G_OPTION_ARG_STRING, &config,    "specify the cmdline of config program.", "cmdline" },
70
 
    { "address",   'a', 0, G_OPTION_ARG_STRING, &address,   "specify the address of ibus daemon.", "address" },
 
70
    { "panel",     'p', 0, G_OPTION_ARG_STRING, &panel,     "specify the cmdline of panel program. pass 'disable' not to start a panel program.", "cmdline" },
 
71
    { "config",    'c', 0, G_OPTION_ARG_STRING, &config,    "specify the cmdline of config program. pass 'disable' not to start a config program.", "cmdline" },
 
72
    { "address",   'a', 0, G_OPTION_ARG_STRING, &g_address,   "specify the address of ibus daemon.", "address" },
71
73
    { "replace",   'r', 0, G_OPTION_ARG_NONE,   &replace,   "if there is an old ibus-daemon is running, it will be replaced.", NULL },
72
74
    { "cache",     't', 0, G_OPTION_ARG_STRING, &g_cache,   "specify the cache mode. [auto/refresh/none]", NULL },
73
 
    { "timeout",   'o', 0, G_OPTION_ARG_INT,    &g_dbus_timeout, "dbus reply timeout in milliseconds.", "timeout [default is 2000]" },
 
75
    { "timeout",   'o', 0, G_OPTION_ARG_INT,    &g_gdbus_timeout, "gdbus reply timeout in milliseconds. pass -1 to use the default timeout of gdbus.", "timeout [default is 5000]" },
74
76
#ifdef G_THREADS_ENABLED
75
77
    { "monitor-timeout", 'j', 0, G_OPTION_ARG_INT,    &g_monitor_timeout, "timeout of poll changes of engines in seconds. 0 to disable it. ", "timeout [default is 0]" },
76
78
#endif
80
82
    { NULL },
81
83
};
82
84
 
 
85
/**
 
86
 * execute_cmdline:
 
87
 * @cmdline: An absolute path of the executable and its parameters, e.g.  "/usr/lib/ibus/ibus-x11 --kill-daemon".
 
88
 * @returns: TRUE if both parsing cmdline and executing the command succeed.
 
89
 *
 
90
 * Execute cmdline. Child process's stdin, stdout, and stderr are attached to /dev/null.
 
91
 * You don't have to handle SIGCHLD from the child process since glib will do.
 
92
 */
83
93
static gboolean
84
94
execute_cmdline (const gchar *cmdline)
85
95
{
86
96
    g_assert (cmdline);
87
97
 
88
 
    gint argc;
89
 
    gchar **argv;
90
 
    gboolean retval;
91
 
    GError *error;
92
 
 
93
 
    error = NULL;
 
98
    gint argc = 0;
 
99
    gchar **argv = NULL;
 
100
    GError *error = NULL;
94
101
    if (!g_shell_parse_argv (cmdline, &argc, &argv, &error)) {
95
102
        g_warning ("Can not parse cmdline `%s` exec: %s", cmdline, error->message);
96
103
        g_error_free (error);
98
105
    }
99
106
 
100
107
    error = NULL;
101
 
    retval = g_spawn_async (NULL, argv, NULL,
 
108
    gboolean retval = g_spawn_async (NULL, argv, NULL,
102
109
                            G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
103
110
                            NULL, NULL,
104
111
                            NULL, &error);
156
163
}
157
164
#endif
158
165
 
 
166
/*
 
167
 * _sig_usr2_handler:
 
168
 * @sig: the signal number, which is usually SIGUSR2.
 
169
 *
 
170
 * A signal handler for SIGUSR2 signal. Dump a summary of memory usage to stderr.
 
171
 */
159
172
static void
160
173
_sig_usr2_handler (int sig)
161
174
{
165
178
gint
166
179
main (gint argc, gchar **argv)
167
180
{
168
 
    GOptionContext *context;
169
 
    BusServer *server;
170
 
    IBusBus *bus;
171
 
 
172
 
    GError *error = NULL;
173
 
 
174
181
    setlocale (LC_ALL, "");
175
182
 
176
 
    context = g_option_context_new ("- ibus daemon");
177
 
 
 
183
    GOptionContext *context = g_option_context_new ("- ibus daemon");
178
184
    g_option_context_add_main_entries (context, entries, "ibus-daemon");
179
185
 
180
186
    g_argv = g_strdupv (argv);
 
187
    GError *error = NULL;
181
188
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
182
189
        g_printerr ("Option parsing failed: %s\n", error->message);
 
190
        g_error_free (error);
 
191
        exit (-1);
 
192
    }
 
193
    if (g_gdbus_timeout < -1) {
 
194
        g_printerr ("Bad timeout (must be >= -1): %d\n", g_gdbus_timeout);
183
195
        exit (-1);
184
196
    }
185
197
 
208
220
        }
209
221
    }
210
222
 
211
 
    /* create a new process group */
 
223
    /* create a new process group. this is important to kill all of its children by SIGTERM at a time in bus_ibus_impl_destroy. */
212
224
    setpgid (0, 0);
213
225
 
214
 
    g_type_init ();
 
226
    ibus_init ();
215
227
 
216
228
#ifdef G_THREADS_ENABLED
217
229
    g_thread_init (NULL);
218
230
#endif
219
 
    ibus_set_log_handler(g_verbose);
 
231
    ibus_set_log_handler (g_verbose);
220
232
 
221
233
    /* check if ibus-daemon is running in this session */
222
234
    if (ibus_get_address () != NULL) {
223
 
        bus = ibus_bus_new ();
 
235
        IBusBus *bus = ibus_bus_new ();
224
236
 
225
237
        if (ibus_bus_is_connected (bus)) {
226
238
            if (!replace) {
233
245
            }
234
246
        }
235
247
        g_object_unref (bus);
236
 
        bus = NULL;
237
248
    }
238
249
 
239
 
    /* create ibus server */
240
 
    server = bus_server_get_default ();
241
 
    bus_server_listen (server);
242
 
 
 
250
    bus_server_init ();
243
251
    if (!single) {
244
252
        /* execute config component */
245
253
        if (g_strcmp0 (config, "default") == 0) {
246
 
            IBusComponent *component;
 
254
            BusComponent *component;
247
255
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_CONFIG);
248
256
            if (component) {
249
 
                ibus_component_set_restart (component, restart);
 
257
                bus_component_set_restart (component, restart);
250
258
            }
251
 
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
 
259
            if (component == NULL || !bus_component_start (component, g_verbose)) {
252
260
                g_printerr ("Can not execute default config program\n");
253
261
                exit (-1);
254
262
            }
257
265
                exit (-1);
258
266
        }
259
267
 
260
 
        /* execut panel component */
 
268
        /* execute panel component */
261
269
        if (g_strcmp0 (panel, "default") == 0) {
262
 
            IBusComponent *component;
 
270
            BusComponent *component;
263
271
            component = bus_registry_lookup_component_by_name (BUS_DEFAULT_REGISTRY, IBUS_SERVICE_PANEL);
264
272
            if (component) {
265
 
                ibus_component_set_restart (component, restart);
 
273
                bus_component_set_restart (component, restart);
266
274
            }
267
 
            if (component == NULL || !ibus_component_start (component, g_verbose)) {
 
275
            if (component == NULL || !bus_component_start (component, g_verbose)) {
268
276
                g_printerr ("Can not execute default panel program\n");
269
277
                exit (-1);
270
278
            }
276
284
 
277
285
    /* execute ibus xim server */
278
286
    if (xim) {
279
 
        if (!execute_cmdline (LIBEXECDIR"/ibus-x11 --kill-daemon"))
 
287
        if (!execute_cmdline (LIBEXECDIR "/ibus-x11 --kill-daemon"))
280
288
            exit (-1);
281
289
    }
282
290
 
283
 
    bus_server_run (server);
284
 
 
 
291
    bus_server_run ();
285
292
    return 0;
286
293
}