From bb02f0fbe80ef093731bc9a6a407f1edaccf991d Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 17 Sep 2009 14:50:04 +0100 Subject: Fix verbose packet dumping functions. 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 | 8 ++++++++ daemon/configure.ac | 8 ++++++++ daemon/proto.c | 6 +++--- src/guestfs.c | 14 +++++++------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 95ab51eb..e144ac80 100644 --- a/configure.ac +++ b/configure.ac @@ -358,6 +358,14 @@ version of febootstrap. 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], diff --git a/daemon/configure.ac b/daemon/configure.ac index 8506ef7f..c5cd0c7f 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -37,6 +37,14 @@ AC_ARG_ENABLE([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 diff --git a/daemon/proto.c b/daemon/proto.c index 431f219a..d03a048c 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -81,12 +81,12 @@ main_loop (int _sock) xread (sock, buf, len); -#if 0 +#ifdef ENABLE_PACKET_DUMP if (verbose) { - int i, j; + size_t i, j; 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) diff --git a/src/guestfs.c b/src/guestfs.c index 17974fd3..8c05c40a 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -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. */ -#if 0 +#ifdef ENABLE_PACKET_DUMP if (g->verbose) { - size_t i, j; + ssize_t i, j; for (i = 0; i < nr; i += 16) { - printf ("%04x: ", i); + printf ("%04zx: ", i); 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; 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) -- cgit