X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Fproto.c;h=ffb4a4e8db3301f26b0907b4253276deda2fd456;hb=9222136ac9b2e404dba128b1ac74dacaa8bf1038;hp=cd61f18dd1d9bffc36fd3ae13f3402206593f2ce;hpb=170f262f0413de843af62b968f6d12c1c476ae7f;p=libguestfs.git diff --git a/daemon/proto.c b/daemon/proto.c index cd61f18..ffb4a4e 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -51,6 +51,14 @@ 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 + /* Read the length word. */ xread (sock, lenbuf, 4); xdrmem_create (&xdr, lenbuf, 4, XDR_DECODE); @@ -71,6 +79,7 @@ main_loop (int _sock) xread (sock, buf, len); +#if 0 if (verbose) { int i, j; @@ -91,6 +100,7 @@ main_loop (int _sock) printf ("|\n"); } } +#endif /* Decode the message header. */ xdrmem_create (&xdr, buf, len, XDR_DECODE); @@ -201,8 +211,14 @@ send_error (const char *msg) xdr_uint32_t (&xdr, &len); xdr_destroy (&xdr); - (void) xwrite (sock, lenbuf, 4); - (void) xwrite (sock, buf, len); + if (xwrite (sock, lenbuf, 4) == -1) { + fprintf (stderr, "xwrite failed\n"); + exit (1); + } + if (xwrite (sock, buf, len) == -1) { + fprintf (stderr, "xwrite failed\n"); + exit (1); + } } void @@ -242,8 +258,14 @@ reply (xdrproc_t xdrp, char *ret) xdr_uint32_t (&xdr, &len); xdr_destroy (&xdr); - (void) xwrite (sock, lenbuf, 4); - (void) xwrite (sock, buf, len); + if (xwrite (sock, lenbuf, 4) == -1) { + fprintf (stderr, "xwrite failed\n"); + exit (1); + } + if (xwrite (sock, buf, len) == len) { + fprintf (stderr, "xwrite failed\n"); + exit (1); + } } /* Receive file chunks, repeatedly calling 'cb'. */