diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-09-28 14:14:07 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2009-09-28 14:14:07 +0100 |
commit | 2c88f0fd32043a347ef4f906dd2787356a173556 (patch) | |
tree | d60b02ab353ae6ab114883b1f9a397649080dbdc /util | |
parent | d972798216ce7ee8128996f27355cbe6e816de00 (diff) | |
download | telepathy-mission-control-2c88f0fd32043a347ef4f906dd2787356a173556.tar.gz |
mc-wait-for-name: wait for a finite time (currently 5 minutes), and define exit status better
Diffstat (limited to 'util')
-rw-r--r-- | util/mc-wait-for-name.1.in | 18 | ||||
-rw-r--r-- | util/wait-for-name.c | 56 |
2 files changed, 62 insertions, 12 deletions
diff --git a/util/mc-wait-for-name.1.in b/util/mc-wait-for-name.1.in index c49f3b89..e4ce204e 100644 --- a/util/mc-wait-for-name.1.in +++ b/util/mc-wait-for-name.1.in @@ -21,14 +21,18 @@ will be provided automatically (after a while) by the desktop session. .SH EXIT STATUS .TP 0 -The bus name eventually appeared +The bus name eventually appeared. .TP -Non-zero -mc-wait-for-name was unable to connect to the session bus, or some other error -occurred +64 (EX_USAGE) +Invocation error (too many or too few arguments, or the bus name given was +not a syntactically valid well-known bus name). +.TP +69 (EX_UNAVAILABLE) +mc-wait-for-name was unable to connect to the session bus. +.TP +75 (EX_TEMPFAIL) +The name did not appear within a reasonable time. .SH OPTIONS There are no additional command-line options. .SH BUGS -If the requested well-known bus name never appears, then -.B mc-wait-for-name -will only exit when the session bus terminates. +The "reasonable time" to wait is currently hard-coded. diff --git a/util/wait-for-name.c b/util/wait-for-name.c index 9756ca37..af8bcdb4 100644 --- a/util/wait-for-name.c +++ b/util/wait-for-name.c @@ -30,14 +30,40 @@ * */ +#ifdef HAVE_SYSEXITS_H +# include <sysexits.h> +#else +# define EX_USAGE 64 +# define EX_UNAVAILABLE 69 +# define EX_SOFTWARE 70 +# define EX_TEMPFAIL 75 +#endif + #include <glib.h> + #include <telepathy-glib/dbus.h> +static int exit_status = EX_SOFTWARE; +static guint timeout_id = 0; +static guint idle_id = 0; + +static gboolean +quit_because_found (gpointer data) +{ + idle_id = 0; + g_main_loop_quit (data); + g_main_loop_unref (data); + exit_status = 0; + return FALSE; +} + static gboolean -quit (gpointer data) +quit_because_timeout (gpointer data) { + timeout_id = 0; g_main_loop_quit (data); g_main_loop_unref (data); + exit_status = EX_TEMPFAIL; return FALSE; } @@ -54,10 +80,14 @@ noc_cb (TpDBusDaemon *bus_daemon, else { g_debug ("%s now owned by %s", name, new_owner); - g_idle_add (quit, g_main_loop_ref (data)); + + if (idle_id == 0) + idle_id = g_idle_add (quit_because_found, g_main_loop_ref (data)); } } +#define WFN_TIMEOUT (5 * 60) /* 5 minutes */ + int main (int argc, char **argv) @@ -73,7 +103,7 @@ main (int argc, NULL)) { g_message ("Usage: mc-wait-for-name com.example.SomeBusName"); - return 2; + return EX_USAGE; } g_type_init (); @@ -83,16 +113,32 @@ main (int argc, { g_message ("%s", error->message); g_error_free (error); - return 1; + return EX_UNAVAILABLE; } loop = g_main_loop_new (NULL, FALSE); tp_dbus_daemon_watch_name_owner (bus_daemon, argv[1], noc_cb, g_main_loop_ref (loop), (GDestroyNotify) g_main_loop_unref); + + g_timeout_add_seconds (WFN_TIMEOUT, quit_because_timeout, + g_main_loop_ref (loop)); + g_main_loop_run (loop); + if (timeout_id != 0) + { + g_source_remove (timeout_id); + g_main_loop_unref (loop); + } + + if (idle_id != 0) + { + g_source_remove (idle_id); + g_main_loop_unref (loop); + } + g_main_loop_unref (loop); g_object_unref (bus_daemon); - return 0; + return exit_status; } |