diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-01-18 13:08:50 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-01-18 13:08:50 +0000 |
commit | 2c5307ef3c901a39d2187048835b173b5a7a201d (patch) | |
tree | 0d733a298fb443a2ca089985adf98c4dc295d4d2 | |
parent | d3b777f9eb7e5484326038f4b615553ce0160c9f (diff) |
list-managers: exit 1 on failure, and don't leak the TpDBusDaemon
-rw-r--r-- | examples/client/list-managers.c | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/examples/client/list-managers.c b/examples/client/list-managers.c index f7466943b..33e8aee71 100644 --- a/examples/client/list-managers.c +++ b/examples/client/list-managers.c @@ -1,8 +1,8 @@ /* * telepathy-example-list-managers - list installed connection managers * - * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/> - * Copyright (C) 2007 Nokia Corporation + * Copyright (C) 2007-2008 Collabora Ltd. <http://www.collabora.co.uk/> + * Copyright (C) 2007-2008 Nokia Corporation * * Copying and distribution of this file, with or without modification, * are permitted in any medium without royalty provided the copyright @@ -12,18 +12,24 @@ #include <telepathy-glib/connection-manager.h> #include <telepathy-glib/debug.h> -void +typedef struct { + GMainLoop *mainloop; + int exit_code; +} ExampleData; + +static void got_connection_managers (TpConnectionManager * const *cms, gsize n_cms, const GError *error, gpointer user_data, GObject *unused) { - GMainLoop *mainloop = user_data; + ExampleData *data = user_data; if (error != NULL) { g_warning ("%s", error->message); + data->exit_code = 1; } else { @@ -45,25 +51,26 @@ got_connection_managers (TpConnectionManager * const *cms, } } - g_main_loop_quit (mainloop); + g_main_loop_quit (data->mainloop); } int main (int argc, char **argv) { - GMainLoop *mainloop; + ExampleData data = { g_main_loop_new (NULL, FALSE), 0 }; + TpDBusDaemon *bus_daemon; g_type_init (); tp_debug_set_flags (g_getenv ("EXAMPLE_DEBUG")); - mainloop = g_main_loop_new (NULL, FALSE); - - tp_list_connection_managers (tp_dbus_daemon_new (tp_get_bus ()), - got_connection_managers, mainloop, NULL, NULL); + bus_daemon = tp_dbus_daemon_new (tp_get_bus ()); - g_main_loop_run (mainloop); + tp_list_connection_managers (bus_daemon, got_connection_managers, &data, + NULL, NULL); - g_main_loop_unref (mainloop); - return 0; + g_main_loop_run (data.mainloop); + g_main_loop_unref (data.mainloop); + g_object_unref (bus_daemon); + return data.exit_code; } |