+ DBusBusType type = DBUS_BUS_SESSION;
+ DBusHandleMessageFunction filter_func = monitor_filter_func;
+ char *address = NULL;
+ dbus_bool_t seen_bus_type = FALSE;
+
+ int i = 0, j = 0, numFilters = 0;
+ char **filters = NULL;
+
+ /* Set stdout to be unbuffered; this is basically so that if people
+ * do dbus-monitor > file, then send SIGINT via Control-C, they
+ * don't lose the last chunk of messages.
+ */
+
+#ifdef DBUS_WIN
+ setvbuf (stdout, NULL, _IONBF, 0);
+#else
+ setvbuf (stdout, NULL, _IOLBF, 0);
+#endif
+
+ for (i = 1; i < argc; i++)
+ {
+ char *arg = argv[i];
+
+ if (!strcmp (arg, "--system"))
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+ type = DBUS_BUS_SYSTEM;
+ }
+ else if (!strcmp (arg, "--session"))
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+ type = DBUS_BUS_SESSION;
+ }
+ else if (!strcmp (arg, "--address"))
+ {
+ only_one_type (&seen_bus_type, argv[0]);
+
+ if (i+1 < argc)
+ {
+ address = argv[i+1];
+ i++;
+ }
+ else
+ usage (argv[0], 1);
+ }
+ else if (!strcmp (arg, "--help"))
+ usage (argv[0], 0);
+ else if (!strcmp (arg, "--monitor"))
+ filter_func = monitor_filter_func;
+ else if (!strcmp (arg, "--profile"))
+ filter_func = profile_filter_func;
+ else if (!strcmp (arg, "--"))
+ continue;
+ else if (arg[0] == '-')
+ usage (argv[0], 1);
+ else {
+ 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;