summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-03-18 18:27:21 +0000
committerRichard W.M. Jones <rjones@redhat.com>2011-03-18 18:27:24 +0000
commitf4d996fd26762053d68f46de5790aae893f03d38 (patch)
tree503049720d83e3d115afe55e5e04b5abd57a0939 /daemon
parent33b638109ed66ea360b53b80b1f407b3a5f5ec39 (diff)
downloadlibguestfs-f4d996fd26762053d68f46de5790aae893f03d38.tar.gz
libguestfs-f4d996fd26762053d68f46de5790aae893f03d38.tar.xz
libguestfs-f4d996fd26762053d68f46de5790aae893f03d38.zip
proto: Fix both-ends-cancel case.
In the case where both ends cancel at the same time (eg. both ends realize there are errors before or during the transfer), previously we skipped sending back an error from the daemon, on the spurious basis that the library would not need it (the library is cancelling because of its own error). However this is wrong: we should always send back an error message from the daemon in order to preserve synchronization of the protocol. A simple test case is: $ guestfish -N fs -m /dev/sda1 upload nosuchfile / libguestfs: error: open: nosuchfile: No such file or directory libguestfs: error: unexpected procedure number (66/282) (Notice two things: there are errors at both ends, and the loss of synchronization). After applying this commit, the loss of synchronization does not occur and we just see the library error: $ guestfish -N fs -m /dev/sda1 upload nosuchfile / libguestfs: error: open: nosuchfile: No such file or directory The choice of displaying the library or the daemon error is fairly arbitrary in this case -- it would be valid to display either or even to combine them into one error. Displaying the library error only makes the code considerably simpler. This commit also (re-)enables a test for this case.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/base64.c5
-rw-r--r--daemon/debug.c5
-rw-r--r--daemon/tar.c5
-rw-r--r--daemon/upload.c5
4 files changed, 16 insertions, 4 deletions
diff --git a/daemon/base64.c b/daemon/base64.c
index 7e07a6ad..f55e1f51 100644
--- a/daemon/base64.c
+++ b/daemon/base64.c
@@ -77,8 +77,11 @@ do_base64_in (const char *file)
return -1;
}
if (r == -2) { /* cancellation from library */
+ /* This error is ignored by the library since it initiated the
+ * cancel. Nevertheless we must send an error reply here.
+ */
+ reply_with_error ("file upload cancelled");
pclose (fp);
- /* Do NOT send any error. */
return -1;
}
diff --git a/daemon/debug.c b/daemon/debug.c
index 091e7410..cd3e8a5f 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -540,8 +540,11 @@ do_debug_upload (const char *filename, int mode)
return -1;
}
if (r == -2) { /* cancellation from library */
+ /* This error is ignored by the library since it initiated the
+ * cancel. Nevertheless we must send an error reply here.
+ */
+ reply_with_error ("file upload cancelled");
close (fd);
- /* Do NOT send any error. */
return -1;
}
diff --git a/daemon/tar.c b/daemon/tar.c
index 3c756afc..39fce8c9 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -118,8 +118,11 @@ do_tXz_in (const char *dir, const char *filter)
return -1;
}
if (r == -2) { /* cancellation from library */
+ /* This error is ignored by the library since it initiated the
+ * cancel. Nevertheless we must send an error reply here.
+ */
+ reply_with_error ("file upload cancelled");
pclose (fp);
- /* Do NOT send any error. */
return -1;
}
diff --git a/daemon/upload.c b/daemon/upload.c
index f8d312ff..2c429694 100644
--- a/daemon/upload.c
+++ b/daemon/upload.c
@@ -94,8 +94,11 @@ upload (const char *filename, int flags, int64_t offset)
return -1;
}
if (r == -2) { /* cancellation from library */
+ /* This error is ignored by the library since it initiated the
+ * cancel. Nevertheless we must send an error reply here.
+ */
+ reply_with_error ("file upload cancelled");
close (data.fd);
- /* Do NOT send any error. */
return -1;
}