[PATCH 1/2] util: numa: Catch readdir errors in virNumaGetPages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't return possibly incomplete result if virDirRead fails.
---
 src/util/virnuma.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index c8e7f40..9cf5a75 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -728,6 +728,7 @@ virNumaGetPages(int node,
     int ret = -1;
     char *path = NULL;
     DIR *dir = NULL;
+    int direrr;
     struct dirent *entry;
     unsigned int *tmp_size = NULL, *tmp_avail = NULL, *tmp_free = NULL;
     unsigned int ntmp = 0;
@@ -768,7 +769,7 @@ virNumaGetPages(int node,
         goto cleanup;
     }

-    while (virDirRead(dir, &entry, path) > 0) {
+    while ((direrr = virDirRead(dir, &entry, path)) > 0) {
         const char *page_name = entry->d_name;
         unsigned int page_size, page_avail = 0, page_free = 0;
         char *end;
@@ -805,6 +806,9 @@ virNumaGetPages(int node,
         ntmp++;
     }

+    if (direrr < 0)
+        goto cleanup;
+
     /* Just to produce nice output, sort the arrays by increasing page size */
     do {
         exchange = false;
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]