[libvirt] [PATCHv3 2/4] nodeinfo: Fix gathering of nodeinfo data structure

Eric Blake eblake at redhat.com
Tue Jul 10 12:55:42 UTC 2012


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 at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120710/cca0f39d/attachment-0001.sig>


More information about the libvir-list mailing list