X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fproto.c;h=a0d3736a788f3a9765231ef3fcee228115728f6b;hp=d935ded587a12daf19c48d032f0ecd76c6e7ca97;hb=7cd4b6aeee3693463b03608a31cf53f21152c2e8;hpb=d1c35f871022e40f9abd93048c1115c6565f94cb diff --git a/daemon/proto.c b/daemon/proto.c index d935ded..a0d3736 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -24,11 +24,13 @@ #include #include #include -#include #include /* defines MIN */ #include #include +#include "c-ctype.h" +#include "ignore-value.h" + #include "daemon.h" #include "../src/guestfs_protocol.h" @@ -45,7 +47,7 @@ main_loop (int _sock) XDR xdr; char *buf; char lenbuf[4]; - unsigned len; + uint32_t len; struct guestfs_message_header hdr; struct timeval start_t, end_t; int64_t start_us, end_us, elapsed_us; @@ -53,16 +55,16 @@ main_loop (int _sock) sock = _sock; for (;;) { -#if 0 /* Most common errors are leaked memory and leaked file descriptors, * so run this between each command: */ - if (verbose) - system ("ls -l /proc/self/fd"); -#endif + if (verbose && 0) + ignore_value (system ("ls -l /proc/self/fd")); /* Read the length word. */ - xread (sock, lenbuf, 4); + if (xread (sock, lenbuf, 4) == -1) + exit (1); + xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE); xdr_uint32_t (&xdr, &len); xdr_destroy (&xdr); @@ -79,21 +81,22 @@ main_loop (int _sock) continue; } - xread (sock, buf, len); + if (xread (sock, buf, len) == -1) + exit (1); -#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) printf (" "); printf ("|"); for (j = i; j < MIN (i+16, len); ++j) - if (isprint (buf[j])) + if (c_isprint (buf[j])) printf ("%c", buf[j]); else printf ("."); @@ -307,7 +310,9 @@ receive_file (receive_cb cb, void *opaque) for (;;) { /* Read the length word. */ - xread (sock, lenbuf, 4); + if (xread (sock, lenbuf, 4) == -1) + exit (1); + xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE); xdr_uint32_t (&xdr, &len); xdr_destroy (&xdr); @@ -327,7 +332,8 @@ receive_file (receive_cb cb, void *opaque) return -1; } - xread (sock, buf, len); + if (xread (sock, buf, len) == -1) + exit (1); xdrmem_create (&xdr, buf, len, XDR_DECODE); memset (&chunk, 0, sizeof chunk); @@ -444,10 +450,8 @@ check_for_library_cancellation (void) /* Read the message from the daemon. */ r = xread (sock, buf, sizeof buf); - if (r == -1) { - perror ("read"); + if (r == -1) return 0; - } xdrmem_create (&xdr, buf, sizeof buf, XDR_DECODE); xdr_uint32_t (&xdr, &flag);