mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
nodeinfo: use virDirRead API
This makes sure that errno is reset before readdir is called, even if the loop does a 'continue'. This fixes issue with musl libc which sets errno on sscanf. The following 'continue' makes the errno be set before calling readdir. Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
1ce2f1a434
commit
92cf75df8e
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* nodeinfo.c: Helper routines for OS specific node information
|
* nodeinfo.c: Helper routines for OS specific node information
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2008, 2010-2013 Red Hat, Inc.
|
* Copyright (C) 2006-2008, 2010-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2006 Daniel P. Berrange
|
* Copyright (C) 2006 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -440,6 +440,7 @@ virNodeParseNode(const char *node,
|
|||||||
int siblings;
|
int siblings;
|
||||||
unsigned int cpu;
|
unsigned int cpu;
|
||||||
int online;
|
int online;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
*threads = 0;
|
*threads = 0;
|
||||||
*cores = 0;
|
*cores = 0;
|
||||||
@ -452,8 +453,7 @@ virNodeParseNode(const char *node,
|
|||||||
|
|
||||||
/* enumerate sockets in the node */
|
/* enumerate sockets in the node */
|
||||||
CPU_ZERO(&sock_map);
|
CPU_ZERO(&sock_map);
|
||||||
errno = 0;
|
while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
|
||||||
while ((cpudirent = readdir(cpudir))) {
|
|
||||||
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -470,14 +470,10 @@ virNodeParseNode(const char *node,
|
|||||||
|
|
||||||
if (sock > sock_max)
|
if (sock > sock_max)
|
||||||
sock_max = sock;
|
sock_max = sock;
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno) {
|
if (direrr < 0)
|
||||||
virReportSystemError(errno, _("problem reading %s"), node);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
sock_max++;
|
sock_max++;
|
||||||
|
|
||||||
@ -490,8 +486,7 @@ virNodeParseNode(const char *node,
|
|||||||
|
|
||||||
/* iterate over all CPU's in the node */
|
/* iterate over all CPU's in the node */
|
||||||
rewinddir(cpudir);
|
rewinddir(cpudir);
|
||||||
errno = 0;
|
while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
|
||||||
while ((cpudirent = readdir(cpudir))) {
|
|
||||||
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -530,14 +525,10 @@ virNodeParseNode(const char *node,
|
|||||||
|
|
||||||
if (siblings > *threads)
|
if (siblings > *threads)
|
||||||
*threads = siblings;
|
*threads = siblings;
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno) {
|
if (direrr < 0)
|
||||||
virReportSystemError(errno, _("problem reading %s"), node);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/* finalize the returned data */
|
/* finalize the returned data */
|
||||||
*sockets = CPU_COUNT(&sock_map);
|
*sockets = CPU_COUNT(&sock_map);
|
||||||
@ -576,6 +567,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *sysfs_nodedir = NULL;
|
char *sysfs_nodedir = NULL;
|
||||||
char *sysfs_cpudir = NULL;
|
char *sysfs_cpudir = NULL;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
/* Start with parsing CPU clock speed from /proc/cpuinfo */
|
/* Start with parsing CPU clock speed from /proc/cpuinfo */
|
||||||
while (fgets(line, sizeof(line), cpuinfo) != NULL) {
|
while (fgets(line, sizeof(line), cpuinfo) != NULL) {
|
||||||
@ -672,8 +664,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
|
|||||||
goto fallback;
|
goto fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
while ((direrr = virDirRead(nodedir, &nodedirent, sysfs_nodedir)) > 0) {
|
||||||
while ((nodedirent = readdir(nodedir))) {
|
|
||||||
if (sscanf(nodedirent->d_name, "node%u", &node) != 1)
|
if (sscanf(nodedirent->d_name, "node%u", &node) != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -699,14 +690,10 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
|
|||||||
|
|
||||||
if (threads > nodeinfo->threads)
|
if (threads > nodeinfo->threads)
|
||||||
nodeinfo->threads = threads;
|
nodeinfo->threads = threads;
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errno) {
|
if (direrr < 0)
|
||||||
virReportSystemError(errno, _("problem reading %s"), sysfs_nodedir);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (nodeinfo->cpus && nodeinfo->nodes)
|
if (nodeinfo->cpus && nodeinfo->nodes)
|
||||||
goto done;
|
goto done;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user