提交 f4966b85 编写于 作者: M Michal Privoznik

virFileInData: Preserve errno on error

The virFileInData() function should return to the caller if the
current position the passed file is in is a data section or a
hole (and also how long the current section is). At any rate,
upon return from this function (be it successful or not) the
original position in the file is restored. This may mess up with
errno which might have been set earlier. Save the errno into a
local variable so it can be restored for the caller's sake.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NMartin Kletzander <mkletzan@redhat.com>
上级 808e27a1
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册