提交 1eeff53d 编写于 作者: D Daniel P. Berrange

Fix error handling of readdir() in virFileLoopDeviceOpen

To correctly handle errors from readdir() you must set 'errno'
to zero before invoking it & check its value afterwards to
distinguish error from EOF.
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 c8fa7e8c
......@@ -546,6 +546,7 @@ static int virFileLoopDeviceOpen(char **dev_name)
goto cleanup;
}
errno = 0;
while ((de = readdir(dh)) != NULL) {
if (!STRPREFIX(de->d_name, "loop"))
continue;
......@@ -577,8 +578,13 @@ static int virFileLoopDeviceOpen(char **dev_name)
/* Oh well, try the next device */
VIR_FORCE_CLOSE(fd);
VIR_FREE(looppath);
errno = 0;
}
if (errno != 0)
virReportSystemError(errno, "%s",
_("Unable to iterate over loop devices"));
else
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find a free loop device in /dev"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册