summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRobert McQueen <robot101@debian.org>2005-10-29 17:02:58 +0000
committerRobert McQueen <robot101@debian.org>2005-10-29 17:02:58 +0000
commit2d74492ba2c61a41d9d22a8872806a8184acef16 (patch)
tree130906074c1b591f35fec59753a11f27416108ac /tools
parent8c9701d6c53621f933d57bfcdc4a1a62217ff266 (diff)
2005-10-29 Robert McQueen <robot101@debian.org>
* glib/Makefile.am, glib/examples/Makefile.am, glib/examples/statemachine/Makefile.am: Merge patch from Ubuntu by Daniel Stone to replace explicit calls to libtool with $(LIBTOOL). * test/python/.cvsignore: Add run-with-tmp-session-bus.conf. * tools/dbus-monitor.1, tools/dbus-monitor.c: Merge dbus-monitor patch from Ubuntu by Daniel Silverstone to allow specifying match rules on the command line.
Diffstat (limited to 'tools')
-rw-r--r--tools/dbus-monitor.115
-rw-r--r--tools/dbus-monitor.c77
2 files changed, 65 insertions, 27 deletions
diff --git a/tools/dbus-monitor.1 b/tools/dbus-monitor.1
index d6a780dd..6a8a2126 100644
--- a/tools/dbus-monitor.1
+++ b/tools/dbus-monitor.1
@@ -9,6 +9,7 @@ dbus-monitor \- debug probe to print message bus messages
.PP
.B dbus-monitor
[\-\-system | \-\-session]
+[watch expressions]
.SH DESCRIPTION
@@ -25,6 +26,11 @@ The \-\-system and \-\-session options direct \fIdbus-monitor\fP to
monitor the system or session buses respectively. If neither is
specified, \fIdbus-monitor\fP monitors the session bus.
+.PP
+In order to get \fIdbus-monitor\fP to see the messages you are interested
+in, you should specify a set of watch expressions as you would expect to
+be passed to the \fIdbus_bus_add_watch\fP function.
+
.PP
The message bus configuration may keep \fIdbus-monitor\fP from seeing
all messages, especially if you run the monitor as a non-root user.
@@ -37,6 +43,15 @@ Monitor the system message bus.
.I "--session"
Monitor the session message bus. (This is the default.)
+.SH EXAMPLE
+Here is an example of using dbus-monitor to watch for the gnome typing
+monitor to say things
+.nf
+
+ dbus-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
+
+.fi
+
.SH AUTHOR
dbus-monitor was written by Philip Blundell.
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index 9bd95ea3..d768cad3 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -49,7 +49,7 @@ filter_func (DBusConnection *connection,
static void
usage (char *name, int ecode)
{
- fprintf (stderr, "Usage: %s [--system | --session]\n", name);
+ fprintf (stderr, "Usage: %s [--system | --session] [watch expressions]\n", name);
exit (ecode);
}
@@ -60,8 +60,8 @@ main (int argc, char *argv[])
DBusError error;
DBusBusType type = DBUS_BUS_SESSION;
GMainLoop *loop;
- int i;
-
+ int i = 0, j = 0, numFilters = 0;
+ char **filters = NULL;
for (i = 1; i < argc; i++)
{
char *arg = argv[i];
@@ -73,14 +73,18 @@ main (int argc, char *argv[])
else if (!strcmp (arg, "--help"))
usage (argv[0], 0);
else if (!strcmp (arg, "--"))
- break;
+ continue;
else if (arg[0] == '-')
usage (argv[0], 1);
+ else {
+ numFilters++;
+ filters = (char **)realloc(filters, numFilters * sizeof(char *));
+ filters[j] = (char *)malloc((strlen(arg) + 1) * sizeof(char *));
+ snprintf(filters[j], strlen(arg) + 1, "%s", arg);
+ j++;
+ }
}
- if (argc > 2)
- usage (argv[0], 1);
-
loop = g_main_loop_new (NULL, FALSE);
dbus_error_init (&error);
@@ -96,26 +100,45 @@ main (int argc, char *argv[])
dbus_connection_setup_with_g_main (connection, NULL);
- dbus_bus_add_match (connection,
- "type='signal'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='method_call'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='method_return'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
- dbus_bus_add_match (connection,
- "type='error'",
- &error);
- if (dbus_error_is_set (&error))
- goto lose;
+ if (numFilters)
+ {
+ for (i = 0; i < j; i++)
+ {
+ dbus_bus_add_match (connection, filters[i], &error);
+ if (dbus_error_is_set (&error))
+ {
+ fprintf (stderr, "Failed to setup match \"%s\": %s\n",
+ filters[i], error.message);
+ dbus_error_free (&error);
+ exit (1);
+ }
+ free(filters[i]);
+ }
+ }
+ else
+ {
+ dbus_bus_add_match (connection,
+ "type='signal'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='method_call'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='method_return'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ dbus_bus_add_match (connection,
+ "type='error'",
+ &error);
+ if (dbus_error_is_set (&error))
+ goto lose;
+ }
+
if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) {
fprintf (stderr, "Couldn't add filter!\n");
exit (1);