diff --git a/src/util/virfile.c b/src/util/virfile.c index e09992e41a..f6f01ec1e1 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -4072,11 +4072,18 @@ virFileInData(int fd, ret = 0; cleanup: /* At any rate, reposition back to where we started. */ - if (cur != (off_t) -1 && - lseek(fd, cur, SEEK_SET) == (off_t) -1) { - virReportSystemError(errno, "%s", - _("unable to restore position in file")); - ret = -1; + if (cur != (off_t) -1) { + int theerrno = errno; + + if (lseek(fd, cur, SEEK_SET) == (off_t) -1) { + virReportSystemError(errno, "%s", + _("unable to restore position in file")); + ret = -1; + if (theerrno == 0) + theerrno = errno; + } + + errno = theerrno; } return ret; }