X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Fdbus-monitor.c;h=a4b5478205a4217bfbc794084f3412223674a948;hb=7d9239c9c78cb6d0b9c282376fcf3cda1de23209;hp=5edb5c0b90acba09c4bf64e468e998c8d72c4e75;hpb=46b8034540b34d63c6b56a7eb2ca4507496ee747;p=platform%2Fupstream%2Fdbus.git diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index 5edb5c0..a4b5478 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, @@ -230,14 +239,6 @@ only_one_type (dbus_bool_t *seen_bus_type, } } -static dbus_bool_t sigint_received = FALSE; - -static void -sigint_handler (int signum) -{ - sigint_received = TRUE; -} - int main (int argc, char *argv[]) { @@ -299,11 +300,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++; } } @@ -369,22 +380,22 @@ main (int argc, char *argv[]) else { dbus_bus_add_match (connection, - "type='signal'", + EAVESDROPPING_RULE ",type='signal'", &error); if (dbus_error_is_set (&error)) goto lose; dbus_bus_add_match (connection, - "type='method_call'", + EAVESDROPPING_RULE ",type='method_call'", &error); if (dbus_error_is_set (&error)) goto lose; dbus_bus_add_match (connection, - "type='method_return'", + EAVESDROPPING_RULE ",type='method_return'", &error); if (dbus_error_is_set (&error)) goto lose; dbus_bus_add_match (connection, - "type='error'", + EAVESDROPPING_RULE ",type='error'", &error); if (dbus_error_is_set (&error)) goto lose;