[PATCH] Fix verbose packet dumping functions.
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Another thought on this .. does gnulib have (or want) canonical hexdumping code? Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Richard W.M. Jones wrote: ...
Subject: [PATCH 3/5] Fix verbose packet dumping functions.
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 fixes the obvious problems. --- daemon/proto.c | 4 ++-- src/guestfs.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/daemon/proto.c b/daemon/proto.c index 431f219..817a995 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -83,10 +83,10 @@ main_loop (int _sock)
#if 0
Looks fine. You might want to change that "#if 0" to something like "#if LIBGUESTFS_ENABLE_PACKET_DUMP" so that you can enable it without modifying the code. Then there'd be less risk of accidentally committing a change that was required solely for debugging.
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 17974fd..e9961d1 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -1902,18 +1902,18 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn) /* Got the full message, caller can start processing it. */ #if 0 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)
On Thu, Sep 17, 2009 at 04:52:33PM +0200, Jim Meyering wrote:
Looks fine. You might want to change that "#if 0" to something like "#if LIBGUESTFS_ENABLE_PACKET_DUMP" so that you can enable it without modifying the code. Then there'd be less risk of accidentally committing a change that was required solely for debugging.
Good idea - I pushed a variation on this theme: http://git.et.redhat.com/?p=libguestfs.git;a=commitdiff;h=bb02f0fbe80ef09373... Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
participants (2)
-
Jim Meyering -
Richard W.M. Jones