mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
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
This commit is contained in:
parent
815dc963ee
commit
e37bcbd9b8
@ -344,7 +344,6 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
|
||||
{
|
||||
unsigned long ret = 0;
|
||||
char *path;
|
||||
FILE *pathfp;
|
||||
char *str = NULL;
|
||||
size_t i;
|
||||
|
||||
@ -352,27 +351,16 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
|
||||
dir, cpu) < 0)
|
||||
return 0;
|
||||
|
||||
pathfp = fopen(path, "r");
|
||||
if (pathfp == NULL) {
|
||||
if (!virFileExists(path)) {
|
||||
/* If file doesn't exist, then pretend our only
|
||||
* sibling is ourself */
|
||||
if (errno == ENOENT) {
|
||||
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;
|
||||
|
||||
if (fgets(str, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, pathfp) == NULL) {
|
||||
virReportSystemError(errno, _("cannot read from %s"), path);
|
||||
ret = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virFileReadAll(path, SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX, &str) < 0)
|
||||
goto cleanup;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0') {
|
||||
if (c_isdigit(str[i]))
|
||||
@ -386,9 +374,7 @@ virNodeCountThreadSiblings(const char *dir, unsigned int cpu)
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(str);
|
||||
VIR_FORCE_FCLOSE(pathfp);
|
||||
VIR_FREE(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user