diff options
Diffstat (limited to 'tools/dbus-monitor.c')
-rw-r--r-- | tools/dbus-monitor.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index a4b54782..ff8390d7 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -106,6 +106,9 @@ monitor_filter_func (DBusConnection *connection, #ifdef __APPLE__ #define PROFILE_TIMED_FORMAT "%s\t%lu\t%d" +#elif defined(__NetBSD__) +#include <inttypes.h> +#define PROFILE_TIMED_FORMAT "%s\t%" PRId64 "\t%d" #else #define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu" #endif @@ -310,7 +313,7 @@ main (int argc, char *argv[]) filters = (char **) realloc (filters, numFilters * sizeof (char *)); if (filters == NULL) oom ("adding a new filter slot"); - filters[j] = (char *) malloc (filter_len * sizeof (char *)); + filters[j] = (char *) malloc (filter_len); if (filters[j] == NULL) oom ("adding a new filter"); snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg); @@ -364,41 +367,45 @@ main (int argc, char *argv[]) if (numFilters) { + size_t offset = 0; for (i = 0; i < j; i++) { - dbus_bus_add_match (connection, filters[i], &error); - if (dbus_error_is_set (&error)) + dbus_bus_add_match (connection, filters[i] + offset, &error); + if (dbus_error_is_set (&error) && i == 0 && offset == 0) + { + /* We might be talking to a pre-1.5.6 dbus-daemon + * which wouldn't understand eavesdrop=true. + * If this works, carry on with offset > 0 + * on the remaining iterations. */ + offset = strlen (EAVESDROPPING_RULE) + 1; + dbus_error_free (&error); + dbus_bus_add_match (connection, filters[i] + offset, &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]); + free(filters[i]); } } else { dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='signal'", - &error); - if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='method_call'", - &error); + EAVESDROPPING_RULE, + &error); if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='method_return'", - &error); - if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='error'", - &error); - if (dbus_error_is_set (&error)) - goto lose; + { + dbus_error_free (&error); + dbus_bus_add_match (connection, + "", + &error); + if (dbus_error_is_set (&error)) + goto lose; + } } if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) { |