daemon/copy: Ensure errno is preserved along error paths.

This commit is contained in:
Richard W.M. Jones
2013-04-04 14:15:44 +01:00
parent 33c087ea9c
commit 3cdca7616a

View File

@@ -49,6 +49,7 @@ copy (const char *src, const char *src_display,
char buf[BUFSIZ];
size_t n;
ssize_t r;
int err;
if ((optargs_bitmask & GUESTFS_COPY_DEVICE_TO_DEVICE_SRCOFFSET_BITMASK)) {
if (srcoffset < 0) {
@@ -119,8 +120,10 @@ copy (const char *src, const char *src_display,
r = read (src_fd, buf, n);
if (r == -1) {
err = errno;
if (size == -1)
pulse_mode_cancel ();
errno = err;
reply_with_perror ("read: %s", src_display);
close (src_fd);
close (dest_fd);
@@ -138,8 +141,10 @@ copy (const char *src, const char *src_display,
if (sparse && is_zero (buf, r)) {
if (lseek (dest_fd, r, SEEK_CUR) == -1) {
err = errno;
if (size == -1)
pulse_mode_cancel ();
errno = err;
reply_with_perror ("%s: seek (because of sparse flag)", dest_display);
close (src_fd);
close (dest_fd);
@@ -149,8 +154,10 @@ copy (const char *src, const char *src_display,
}
if (xwrite (dest_fd, buf, r) == -1) {
err = errno;
if (size == -1)
pulse_mode_cancel ();
errno = err;
reply_with_perror ("%s: write", dest_display);
close (src_fd);
close (dest_fd);