Change protocol to send Linux errno from daemon to library.
[libguestfs.git] / daemon / proto.c
index ee1c400..628e86c 100644 (file)
@@ -179,7 +179,7 @@ main_loop (int _sock)
   }
 }
 
-static void send_error (const char *msg);
+static void send_error (int errnum, const char *msg);
 
 void
 reply_with_error (const char *fs, ...)
@@ -191,7 +191,7 @@ reply_with_error (const char *fs, ...)
   vsnprintf (err, sizeof err, fs, args);
   va_end (args);
 
-  send_error (err);
+  send_error (0, err);
 }
 
 void
@@ -207,11 +207,11 @@ reply_with_perror_errno (int err, const char *fs, ...)
 
   snprintf (buf2, sizeof buf2, "%s: %s", buf1, strerror (err));
 
-  send_error (buf2);
+  send_error (err, buf2);
 }
 
 static void
-send_error (const char *msg)
+send_error (int errnum, const char *msg)
 {
   XDR xdr;
   char buf[GUESTFS_ERROR_LEN + 200];
@@ -236,6 +236,7 @@ send_error (const char *msg)
     exit (EXIT_FAILURE);
   }
 
+  err.linux_errno = errnum;
   err.error_message = (char *) msg;
 
   if (!xdr_guestfs_message_error (&xdr, &err)) {
@@ -395,7 +396,7 @@ receive_file (receive_cb cb, void *opaque)
 }
 
 /* Send a cancellation flag back to the library. */
-void
+int
 cancel_receive (void)
 {
   XDR xdr;
@@ -408,11 +409,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);