New API: is-lv: check if a block device is a logical volume (RHBZ#619793)
[libguestfs.git] / daemon / proto.c
index 1ad9d11..6fa243f 100644 (file)
@@ -289,7 +289,7 @@ reply (xdrproc_t xdrp, char *ret)
      * we want to return an error message instead. (RHBZ#509597).
      */
     if (!(*xdrp) (&xdr, ret)) {
-      reply_with_perror ("guestfsd: failed to encode reply body\n");
+      reply_with_error ("guestfsd: failed to encode reply body\n(maybe the reply exceeds the maximum message size in the protocol?)");
       xdr_destroy (&xdr);
       return;
     }
@@ -324,6 +324,9 @@ receive_file (receive_cb cb, void *opaque)
   uint32_t len;
 
   for (;;) {
+    if (verbose)
+      fprintf (stderr, "receive_file: reading length word\n");
+
     /* Read the length word. */
     if (xread (sock, lenbuf, 4) == -1)
       exit (EXIT_FAILURE);
@@ -361,15 +364,18 @@ receive_file (receive_cb cb, void *opaque)
     free (buf);
 
     if (verbose)
-      printf ("receive_file: got chunk: cancel = %d, len = %d, buf = %p\n",
-              chunk.cancel, chunk.data.data_len, chunk.data.data_val);
+      fprintf (stderr, "receive_file: got chunk: cancel = %d, len = %d, buf = %p\n",
+               chunk.cancel, chunk.data.data_len, chunk.data.data_val);
 
     if (chunk.cancel) {
-      fprintf (stderr, "receive_file: received cancellation from library\n");
+      if (verbose)
+        fprintf (stderr, "receive_file: received cancellation from library\n");
       xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
       return -2;
     }
     if (chunk.data.data_len == 0) {
+      if (verbose)
+        fprintf (stderr, "receive_file: end of file, leaving function\n");
       xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
       return 0;                        /* end of file */
     }
@@ -380,13 +386,16 @@ receive_file (receive_cb cb, void *opaque)
       r = 0;
 
     xdr_free ((xdrproc_t) xdr_guestfs_chunk, (char *) &chunk);
-    if (r == -1)               /* write error */
+    if (r == -1) {             /* write error */
+      if (verbose)
+        fprintf (stderr, "receive_file: write error\n");
       return -1;
+    }
   }
 }
 
 /* Send a cancellation flag back to the library. */
-void
+int
 cancel_receive (void)
 {
   XDR xdr;
@@ -399,11 +408,11 @@ cancel_receive (void)
 
   if (xwrite (sock, fbuf, sizeof fbuf) == -1) {
     perror ("write to socket");
-    return;
+    return -1;
   }
 
   /* Keep receiving chunks and discarding, until library sees cancel. */
-  (void) receive_file (NULL, NULL);
+  return receive_file (NULL, NULL);
 }
 
 static int check_for_library_cancellation (void);