On 07/10/2012 04:56 AM, Michal Privoznik wrote:
> +
> + /* enumerate sockets in the node */
> + CPU_ZERO(&sock_map);
> + while ((cpudirent = readdir(cpudir))) {
I guess we want reentrant version of readdir here, don't we?
readdir_r() is a GNU extension not provided by gnulib, so we can't use
it. Furthermore, readdir() is thread-safe if you have only one thread
traversing a given DIR*; readdir_r() is only useful if you want to have
multiple threads visit the same DIR* (which is not what we are doing
here). For that reason, our syntax check does not forbid readdir, and
we don't need to use readdir_r.
> + if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
> + continue;
> +
> + /* Parse socket */
> + sock = virNodeParseSocket(node, cpu);
> + CPU_SET(sock, &sock_map);
> +
> + if (sock > sock_max)
> + sock_max = sock;
> + }
> +
> + if (errno) {
You should have reset errno before while() loop.
That part is true - you MUST reset errno before every call to readdir(),
as it is the only way to tell errors apart from end-of-iteration.
> + /* iterate over all CPU's in the node */
> + rewinddir(cpudir);
> + while ((cpudirent = readdir(cpudir))) {
Again, s/readdir/readdir_r/
Overkill, not necessary.
--
Eric Blake eblake(a)redhat.com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org