mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
daemon/copy: Ensure errno is preserved along error paths.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user