diff options
author | Simon McVittie <smcv@debian.org> | 2015-02-19 13:35:29 +0000 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2015-02-19 13:35:29 +0000 |
commit | 5a676818770d64c5508f5cf28e22228f68b325aa (patch) | |
tree | acfbf8e52304dce6a8450ad3c390cdf874a6fd3e /tools/dbus-monitor.c | |
parent | 8fd2c8098849695fce037fa3731a916ac5354e91 (diff) | |
parent | 87fe648a5c883d1f790a5d40abfd4a68aff0784c (diff) | |
download | dbus-5a676818770d64c5508f5cf28e22228f68b325aa.tar.gz |
Imported Upstream version 1.9.12upstream/1.9.12
Diffstat (limited to 'tools/dbus-monitor.c')
-rw-r--r-- | tools/dbus-monitor.c | 111 |
1 files changed, 61 insertions, 50 deletions
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index ad776904..14ceae90 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -74,7 +74,7 @@ GetSystemTimeAsFileTime (LPFILETIME ftp) static int gettimeofday (struct timeval *__p, - void *__t) + void *__t) { union { unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */ @@ -91,8 +91,8 @@ gettimeofday (struct timeval *__p, static DBusHandlerResult monitor_filter_func (DBusConnection *connection, - DBusMessage *message, - void *user_data) + DBusMessage *message, + void *user_data) { print_message (message, FALSE); @@ -107,14 +107,6 @@ monitor_filter_func (DBusConnection *connection, return DBUS_HANDLER_RESULT_HANDLED; } -#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 #define TRAP_NULL_STRING(str) ((str) ? (str) : "<none>") typedef enum @@ -130,23 +122,30 @@ typedef enum } ProfileAttributeFlags; static void +profile_print_headers (void) +{ + printf ("#type\ttimestamp\tserial\tsender\tdestination\tpath\tinterface\tmember\n"); + printf ("#\t\t\t\t\tin_reply_to\n"); +} + +static void profile_print_with_attrs (const char *type, DBusMessage *message, struct timeval *t, ProfileAttributeFlags attrs) { - printf (PROFILE_TIMED_FORMAT, type, t->tv_sec, t->tv_usec); + printf ("%s\t%lu.%06lu", type, (unsigned long) t->tv_sec, (unsigned long) t->tv_usec); if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL) printf ("\t%u", dbus_message_get_serial (message)); - if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL) - printf ("\t%u", dbus_message_get_reply_serial (message)); - if (attrs & PROFILE_ATTRIBUTE_FLAG_SENDER) printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_sender (message))); if (attrs & PROFILE_ATTRIBUTE_FLAG_DESTINATION) printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_destination (message))); + if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL) + printf ("\t%u", dbus_message_get_reply_serial (message)); + if (attrs & PROFILE_ATTRIBUTE_FLAG_PATH) printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_path (message))); @@ -165,6 +164,7 @@ profile_print_with_attrs (const char *type, DBusMessage *message, static void print_message_profile (DBusMessage *message) { + static dbus_bool_t first = TRUE; struct timeval t; if (gettimeofday (&t, NULL) < 0) @@ -173,45 +173,56 @@ print_message_profile (DBusMessage *message) return; } + if (first) + { + profile_print_headers (); + first = FALSE; + } + switch (dbus_message_get_type (message)) { case DBUS_MESSAGE_TYPE_METHOD_CALL: - profile_print_with_attrs ("mc", message, &t, - PROFILE_ATTRIBUTE_FLAG_SERIAL | - PROFILE_ATTRIBUTE_FLAG_SENDER | - PROFILE_ATTRIBUTE_FLAG_PATH | - PROFILE_ATTRIBUTE_FLAG_INTERFACE | - PROFILE_ATTRIBUTE_FLAG_MEMBER); - break; + profile_print_with_attrs ("mc", message, &t, + PROFILE_ATTRIBUTE_FLAG_SERIAL | + PROFILE_ATTRIBUTE_FLAG_SENDER | + PROFILE_ATTRIBUTE_FLAG_DESTINATION | + PROFILE_ATTRIBUTE_FLAG_PATH | + PROFILE_ATTRIBUTE_FLAG_INTERFACE | + PROFILE_ATTRIBUTE_FLAG_MEMBER); + break; case DBUS_MESSAGE_TYPE_METHOD_RETURN: - profile_print_with_attrs ("mr", message, &t, - PROFILE_ATTRIBUTE_FLAG_SERIAL | - PROFILE_ATTRIBUTE_FLAG_DESTINATION | - PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); - break; + profile_print_with_attrs ("mr", message, &t, + PROFILE_ATTRIBUTE_FLAG_SERIAL | + PROFILE_ATTRIBUTE_FLAG_SENDER | + PROFILE_ATTRIBUTE_FLAG_DESTINATION | + PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); + break; case DBUS_MESSAGE_TYPE_ERROR: - profile_print_with_attrs ("err", message, &t, - PROFILE_ATTRIBUTE_FLAG_SERIAL | - PROFILE_ATTRIBUTE_FLAG_DESTINATION | - PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); - break; + profile_print_with_attrs ("err", message, &t, + PROFILE_ATTRIBUTE_FLAG_SERIAL | + PROFILE_ATTRIBUTE_FLAG_SENDER | + PROFILE_ATTRIBUTE_FLAG_DESTINATION | + PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL); + break; case DBUS_MESSAGE_TYPE_SIGNAL: - profile_print_with_attrs ("sig", message, &t, - PROFILE_ATTRIBUTE_FLAG_SERIAL | - PROFILE_ATTRIBUTE_FLAG_PATH | - PROFILE_ATTRIBUTE_FLAG_INTERFACE | - PROFILE_ATTRIBUTE_FLAG_MEMBER); - break; + profile_print_with_attrs ("sig", message, &t, + PROFILE_ATTRIBUTE_FLAG_SERIAL | + PROFILE_ATTRIBUTE_FLAG_SENDER | + PROFILE_ATTRIBUTE_FLAG_DESTINATION | + PROFILE_ATTRIBUTE_FLAG_PATH | + PROFILE_ATTRIBUTE_FLAG_INTERFACE | + PROFILE_ATTRIBUTE_FLAG_MEMBER); + break; default: - printf (PROFILE_TIMED_FORMAT "\n", "tun", t.tv_sec, t.tv_usec); - break; + printf ("%s\t%lu.%06lu", "tun", (unsigned long) t.tv_sec, (unsigned long) t.tv_usec); + break; } } static DBusHandlerResult -profile_filter_func (DBusConnection *connection, - DBusMessage *message, - void *user_data) +profile_filter_func (DBusConnection *connection, + DBusMessage *message, + void *user_data) { print_message_profile (message); @@ -431,7 +442,7 @@ main (int argc, char *argv[]) usage (argv[0], 1); } else if (!strcmp (arg, "--help")) - usage (argv[0], 0); + usage (argv[0], 0); else if (!strcmp (arg, "--monitor")) { filter_func = monitor_filter_func; @@ -453,9 +464,9 @@ main (int argc, char *argv[]) binary_mode = BINARY_MODE_PCAP; } else if (!strcmp (arg, "--")) - continue; + continue; else if (arg[0] == '-') - usage (argv[0], 1); + usage (argv[0], 1); else { unsigned int filter_len; numFilters++; @@ -483,12 +494,12 @@ main (int argc, char *argv[]) if (connection) { if (!dbus_bus_register (connection, &error)) - { + { fprintf (stderr, "Failed to register connection to bus at %s: %s\n", - address, error.message); + address, error.message); dbus_error_free (&error); exit (1); - } + } } } else @@ -548,7 +559,7 @@ main (int argc, char *argv[]) dbus_bus_add_match (connection, filters[i] + offset, &error); } - if (dbus_error_is_set (&error)) + if (dbus_error_is_set (&error)) { fprintf (stderr, "Failed to setup match \"%s\": %s\n", filters[i], error.message); |