[PATCH] nodeinfo: Make sure we always reset errno before calling readdir

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

 



We must always reset errno to 0 even if we do 'continue'.

This fixes runtime with musl libc which will set errno on sscanf.

Signed-off-by: Natanael Copa <ncopa@xxxxxxxxxxxxxxx>
---
 src/nodeinfo.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 53ba716..8d3214e 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -452,8 +452,7 @@ virNodeParseNode(const char *node,
 
     /* enumerate sockets in the node */
     CPU_ZERO(&sock_map);
-    errno = 0;
-    while ((cpudirent = readdir(cpudir))) {
+    for (errno = 0; (cpudirent = readdir(cpudir)); errno = 0) {
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
             continue;
 
@@ -470,8 +469,6 @@ virNodeParseNode(const char *node,
 
         if (sock > sock_max)
             sock_max = sock;
-
-        errno = 0;
     }
 
     if (errno) {
@@ -490,8 +487,7 @@ virNodeParseNode(const char *node,
 
     /* iterate over all CPU's in the node */
     rewinddir(cpudir);
-    errno = 0;
-    while ((cpudirent = readdir(cpudir))) {
+    for (errno = 0; (cpudirent = readdir(cpudir)); errno = 0) {
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
             continue;
 
@@ -530,8 +526,6 @@ virNodeParseNode(const char *node,
 
         if (siblings > *threads)
             *threads = siblings;
-
-        errno = 0;
     }
 
     if (errno) {
@@ -672,8 +666,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
         goto fallback;
     }
 
-    errno = 0;
-    while ((nodedirent = readdir(nodedir))) {
+    for (errno = 0; (nodedirent = readdir(nodedir)); errno = 0) {
         if (sscanf(nodedirent->d_name, "node%u", &node) != 1)
             continue;
 
@@ -699,8 +692,6 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
 
         if (threads > nodeinfo->threads)
             nodeinfo->threads = threads;
-
-        errno = 0;
     }
 
     if (errno) {
-- 
1.9.1

--
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]