Fix verbose packet dumping functions.
authorRichard Jones <rjones@trick.home.annexia.org>
Thu, 17 Sep 2009 13:50:04 +0000 (14:50 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Thu, 17 Sep 2009 15:01:52 +0000 (16:01 +0100)
Add the configure parameter --enable-packet-dump so that this
code can be enabled without editing the source.

This code is normally commented out, because it is too verbose
unless you happen to be debugging the underlying protocol.  Because
it is normally commented out, I found it had bit-rotted slightly.
This commit also fixes the obvious problems.

configure.ac
daemon/configure.ac
daemon/proto.c
src/guestfs.c

index 95ab51e..e144ac8 100644 (file)
@@ -358,6 +358,14 @@ version of febootstrap.
     AC_MSG_RESULT([yes])
 fi
 
     AC_MSG_RESULT([yes])
 fi
 
+dnl Enable packet dumps when in verbose mode.  This generates lots
+dnl of debug info, only useful for people debugging the RPC mechanism.
+AC_ARG_ENABLE([packet-dump],
+        [AS_HELP_STRING([--enable-packet-dump],
+          [enable packet dumps in verbose mode @<:@default=no@:>@])],
+        [AC_DEFINE([ENABLE_PACKET_DUMP],[1],[Enable packet dumps in verbose mode.])],
+        [])
+
 dnl Readline.
 AC_ARG_WITH([readline],
     [AS_HELP_STRING([--with-readline],
 dnl Readline.
 AC_ARG_WITH([readline],
     [AS_HELP_STRING([--with-readline],
index 8506ef7..c5cd0c7 100644 (file)
@@ -37,6 +37,14 @@ AC_ARG_ENABLE([debug-command],
   [AC_DEFINE_UNQUOTED([ENABLE_DEBUG_COMMAND],[1],[Enable the 'debug' command])],
   [])
 
   [AC_DEFINE_UNQUOTED([ENABLE_DEBUG_COMMAND],[1],[Enable the 'debug' command])],
   [])
 
+dnl Enable packet dumps when in verbose mode.  This generates lots
+dnl of debug info, only useful for people debugging the RPC mechanism.
+AC_ARG_ENABLE([packet-dump],
+        [AS_HELP_STRING([--enable-packet-dump],
+          [enable packet dumps in verbose mode @<:@default=no@:>@])],
+        [AC_DEFINE([ENABLE_PACKET_DUMP],[1],[Enable packet dumps in verbose mode.])],
+        [])
+
 dnl For strchrnul(3), asprintf(3), futimens(2) and getline(3).
 AC_GNU_SOURCE
 
 dnl For strchrnul(3), asprintf(3), futimens(2) and getline(3).
 AC_GNU_SOURCE
 
index 431f219..d03a048 100644 (file)
@@ -81,12 +81,12 @@ main_loop (int _sock)
 
     xread (sock, buf, len);
 
 
     xread (sock, buf, len);
 
-#if 0
+#ifdef ENABLE_PACKET_DUMP
     if (verbose) {
     if (verbose) {
-      int i, j;
+      size_t i, j;
 
       for (i = 0; i < len; i += 16) {
 
       for (i = 0; i < len; i += 16) {
-        printf ("%04x: ", i);
+        printf ("%04zx: ", i);
         for (j = i; j < MIN (i+16, len); ++j)
           printf ("%02x ", (unsigned char) buf[j]);
         for (; j < i+16; ++j)
         for (j = i; j < MIN (i+16, len); ++j)
           printf ("%02x ", (unsigned char) buf[j]);
         for (; j < i+16; ++j)
index 17974fd..8c05c40 100644 (file)
@@ -1900,20 +1900,20 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
   }
 
   /* Got the full message, caller can start processing it. */
   }
 
   /* Got the full message, caller can start processing it. */
-#if 0
+#ifdef ENABLE_PACKET_DUMP
   if (g->verbose) {
   if (g->verbose) {
-    size_t i, j;
+    ssize_t i, j;
 
     for (i = 0; i < nr; i += 16) {
 
     for (i = 0; i < nr; i += 16) {
-      printf ("%04x: ", i);
+      printf ("%04zx: ", i);
       for (j = i; j < MIN (i+16, nr); ++j)
       for (j = i; j < MIN (i+16, nr); ++j)
-        printf ("%02x ", (unsigned char) (*buf_rtn)[j]);
+        printf ("%02x ", (*(unsigned char **)buf_rtn)[j]);
       for (; j < i+16; ++j)
         printf ("   ");
       printf ("|");
       for (; j < i+16; ++j)
         printf ("   ");
       printf ("|");
-      for (j = i; j < MIN (i+16, g->nr); ++j)
-        if (isprint ((*buf_rtn)[j]))
-          printf ("%c", (*buf_rtn)[j]);
+      for (j = i; j < MIN (i+16, nr); ++j)
+        if (isprint ((*(char **)buf_rtn)[j]))
+          printf ("%c", (*(char **)buf_rtn)[j]);
         else
           printf (".");
       for (; j < i+16; ++j)
         else
           printf (".");
       for (; j < i+16; ++j)