From 1606c279204270ffce506ca424692c3f8478bebc Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Thu, 7 Jul 2011 16:10:54 +0100 Subject: [PATCH 2/2] Add "eavesdrop=true" as constant match rule for dbus-monitor Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37890 Bug-NB: NB#269748 Origin: vendor, Maemo --- tools/dbus-monitor.c | 29 ++++++++++++++++++++++++----- 1 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index 5edb5c0..ba9f9cc 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -35,6 +35,8 @@ #include "dbus-print-message.h" +#define EAVESDROPPING_RULE "eavesdrop=true" + #ifdef DBUS_WIN /* gettimeofday is not defined on windows */ @@ -76,6 +78,13 @@ gettimeofday (struct timeval *__p, } #endif +inline static void +oom (const char *doing) +{ + fprintf (stderr, "OOM while %s\n", doing); + exit (1); +} + static DBusHandlerResult monitor_filter_func (DBusConnection *connection, DBusMessage *message, @@ -299,11 +308,21 @@ main (int argc, char *argv[]) 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++; + unsigned int filter_len; + numFilters++; + /* Prepend a rule (and a comma) to enable the monitor to eavesdrop. + * Prepending allows the user to add eavesdrop=false at command line + * in order to disable eavesdropping when needed */ + filter_len = strlen (EAVESDROPPING_RULE) + 1 + strlen (arg) + 1; + + filters = (char **) realloc (filters, numFilters * sizeof (char *)); + if (filters == NULL) + oom ("adding a new filter slot"); + filters[j] = (char *) malloc (filter_len * sizeof (char *)); + if (filters[j] == NULL) + oom ("adding a new filter"); + snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg); + j++; } } -- 1.7.5.4