提交 e37bcbd9 编写于 作者: J Ján Tomko

Report errors in virNodeCountThreadSiblings

Use virFileReadAll which reports an error when the file is larger
than the specified maximum.

https://bugzilla.redhat.com/show_bug.cgi?id=1207849
上级 815dc963
...@@ -344,7 +344,6 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu) ...@@ -344,7 +344,6 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
{ {
unsigned long ret = 0; unsigned long ret = 0;
char *path; char *path;
FILE *pathfp;
char *str = NULL; char *str = NULL;
size_t i; size_t i;
...@@ -352,26 +351,15 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu) ...@@ -352,26 +351,15 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
dir, cpu) < 0) dir, cpu) < 0)
return 0; return 0;
pathfp = fopen(path, "r"); if (!virFileExists(path)) {
if (pathfp == NULL) {
/* If file doesn't exist, then pretend our only /* If file doesn't exist, then pretend our only
* sibling is ourself */ * sibling is ourself */
if (errno == ENOENT) { ret = 1;
VIR_FREE(path);
return 1;
}
virReportSystemError(errno, _("cannot open %s"), path);
VIR_FREE(path);
return 0;
}
if (VIR_ALLOC_N(str, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX) < 0)
goto cleanup; goto cleanup;
}
if (fgets(str, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, pathfp) == NULL) { if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &str) < 0)
virReportSystemError(errno, _("cannot read from %s"), path);
goto cleanup; goto cleanup;
}
i = 0; i = 0;
while (str[i] != '\0') { while (str[i] != '\0') {
...@@ -386,9 +374,7 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu) ...@@ -386,9 +374,7 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
cleanup: cleanup:
VIR_FREE(str); VIR_FREE(str);
VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path); VIR_FREE(path);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册