]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-monitor: Add timestamp to --monitor mode.
authorRalf Habacker <ralf.habacker@freenet.de>
Mon, 23 Feb 2015 21:00:46 +0000 (22:00 +0100)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Tue, 24 Feb 2015 13:29:45 +0000 (13:29 +0000)
Use cross platform function _dbus_get_real_time() for fetching current time.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
[smcv: use %ld to avoid needing casts; reinstate printing the timestamp;
libdbus-1 is sufficient now that fd.o#83115 is fixed; print timestamp for
non-literal dbus-send replies too]
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
dbus/dbus-sysdeps.h
tools/dbus-monitor.c
tools/dbus-print-message.c
tools/dbus-print-message.h
tools/dbus-send.c

index e7a556b2a6b40e4d31a08b14a6b85ae00bd528d7..2dbc420dca4d193c176d8110020d0d4bd492df70 100644 (file)
@@ -336,6 +336,7 @@ DBUS_PRIVATE_EXPORT
 void _dbus_get_monotonic_time (long *tv_sec,
                                long *tv_usec);
 
+DBUS_PRIVATE_EXPORT
 void _dbus_get_real_time (long *tv_sec,
                           long *tv_usec);
 
index 14ceae90d513edb29da5ccd70423d3a7c1165a2e..0aea2e71bc9b2f32eb3caf6a48f3b19010a79728 100644 (file)
 /* http://www.tcpdump.org/linktypes.html */
 #define LINKTYPE_DBUS 231
 
-#ifdef DBUS_WIN
-
-/* gettimeofday is not defined on windows */
-#define DBUS_SECONDS_SINCE_1601 11644473600LL
-#define DBUS_USEC_IN_SEC        1000000LL
-
-#ifdef DBUS_WINCE
-
-#ifndef _IOLBF
-#define _IOLBF 0x40
-#endif
-#ifndef _IONBF
-#define _IONBF 0x04
-#endif
-
-void
-GetSystemTimeAsFileTime (LPFILETIME ftp)
-{
-  SYSTEMTIME st;
-  GetSystemTime (&st);
-  SystemTimeToFileTime (&st, ftp);
-}
-#endif
-
-static int
-gettimeofday (struct timeval *__p,
-              void *__t)
-{
-  union {
-      unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
-      FILETIME           ft;
-    } now;
-
-  GetSystemTimeAsFileTime (&now.ft);
-  __p->tv_usec = (long) ((now.ns100 / 10LL) % DBUS_USEC_IN_SEC);
-  __p->tv_sec  = (long)(((now.ns100 / 10LL) / DBUS_SECONDS_SINCE_1601) - DBUS_SECONDS_SINCE_1601);
-
-  return 0;
-}
-#endif
-
 static DBusHandlerResult
 monitor_filter_func (DBusConnection     *connection,
                      DBusMessage        *message,
                      void               *user_data)
 {
-  print_message (message, FALSE);
+  long sec = 0, usec = 0;
+
+  _dbus_get_real_time (&sec, &usec);
+
+  print_message (message, FALSE, sec, usec);
   
   if (dbus_message_is_signal (message,
                               DBUS_INTERFACE_LOCAL,
@@ -130,9 +93,9 @@ profile_print_headers (void)
 
 static void
 profile_print_with_attrs (const char *type, DBusMessage *message,
-  struct timeval *t, ProfileAttributeFlags attrs)
+  long sec, long usec, ProfileAttributeFlags attrs)
 {
-  printf ("%s\t%lu.%06lu", type, (unsigned long) t->tv_sec, (unsigned long) t->tv_usec);
+  printf ("%s\t%ld.%06ld", type, sec, usec);
 
   if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL)
     printf ("\t%u", dbus_message_get_serial (message));
@@ -165,13 +128,7 @@ static void
 print_message_profile (DBusMessage *message)
 {
   static dbus_bool_t first = TRUE;
-  struct timeval t;
-
-  if (gettimeofday (&t, NULL) < 0)
-    {
-      printf ("un\n");
-      return;
-    }
+  long sec = 0, usec = 0;
 
   if (first)
     {
@@ -179,10 +136,12 @@ print_message_profile (DBusMessage *message)
       first = FALSE;
     }
 
+  _dbus_get_real_time (&sec, &usec);
+
   switch (dbus_message_get_type (message))
     {
       case DBUS_MESSAGE_TYPE_METHOD_CALL:
-        profile_print_with_attrs ("mc", message, &t,
+        profile_print_with_attrs ("mc", message, sec, usec,
           PROFILE_ATTRIBUTE_FLAG_SERIAL |
           PROFILE_ATTRIBUTE_FLAG_SENDER |
           PROFILE_ATTRIBUTE_FLAG_DESTINATION |
@@ -191,21 +150,21 @@ print_message_profile (DBusMessage *message)
           PROFILE_ATTRIBUTE_FLAG_MEMBER);
         break;
       case DBUS_MESSAGE_TYPE_METHOD_RETURN:
-        profile_print_with_attrs ("mr", message, &t,
+        profile_print_with_attrs ("mr", message, sec, usec,
           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_print_with_attrs ("err", message, sec, usec,
           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_print_with_attrs ("sig", message, sec, usec,
           PROFILE_ATTRIBUTE_FLAG_SERIAL |
           PROFILE_ATTRIBUTE_FLAG_SENDER |
           PROFILE_ATTRIBUTE_FLAG_DESTINATION |
@@ -214,7 +173,7 @@ print_message_profile (DBusMessage *message)
           PROFILE_ATTRIBUTE_FLAG_MEMBER);
         break;
       default:
-        printf ("%s\t%lu.%06lu", "tun", (unsigned long) t.tv_sec, (unsigned long) t.tv_usec);
+        printf ("%s\t%ld.%06ld", "tun", sec, usec);
         break;
     }
 }
index 27c88964db54969d540aaaa3e935af6024182527..d598b53395c0f4a0e7863b357e8861e33b639d6a 100644 (file)
@@ -529,7 +529,7 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
 }
 
 void
-print_message (DBusMessage *message, dbus_bool_t literal)
+print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec)
 {
   DBusMessageIter iter;
   const char *sender;
@@ -542,11 +542,21 @@ print_message (DBusMessage *message, dbus_bool_t literal)
   
   if (!literal)
     {
-      printf ("%s sender=%s -> dest=%s",
-              type_to_name (message_type),
-              sender ? sender : "(null sender)",
-              destination ? destination : "(null destination)");
-  
+      if (sec != 0 || usec != 0)
+        {
+          printf ("%s time=%ld.%06ld sender=%s -> dest=%s",
+                  type_to_name (message_type), sec, usec,
+                  sender ? sender : "(null sender)",
+                  destination ? destination : "(null destination)");
+        }
+      else
+        {
+          printf ("%s sender=%s -> dest=%s",
+                  type_to_name (message_type),
+                  sender ? sender : "(null sender)",
+                  destination ? destination : "(null destination)");
+        }
+
       switch (message_type)
         {
         case DBUS_MESSAGE_TYPE_METHOD_CALL:
index 26700d8431b399ae505ff9f89da17f769f65a22d..d45bc79d25d57b97add041e037e7748fa59afbe7 100644 (file)
@@ -26,6 +26,6 @@
 #include <string.h>
 #include <dbus/dbus.h>
 
-void print_message (DBusMessage *message, dbus_bool_t literal);
+void print_message (DBusMessage *message, dbus_bool_t literal, long sec, long usec);
 
 #endif /* DBUS_PRINT_MESSAGE_H */
index d3ff2589895fae611523d0f7b623cd6935f9e5d3..2a99e9af7257b1c9f14c9ba13875318e3a11b2c9 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include <dbus/dbus.h>
+#include "dbus/dbus-internals.h"
 
 #ifndef HAVE_STRTOLL
 #undef strtoll
@@ -573,7 +574,10 @@ main (int argc, char *argv[])
 
       if (reply)
         {
-          print_message (reply, print_reply_literal);
+          long sec, usec;
+
+          _dbus_get_real_time (&sec, &usec);
+          print_message (reply, print_reply_literal, sec, usec);
           dbus_message_unref (reply);
         }
     }