On 06/23/2010 05:51 AM, Ryota Ozaki wrote:
> Technically, any loop over readdir must first set errno to 0,
then call
> readdir, and if it is NULL, check if errno is still 0. Otherwise, you
> can miss subtle readdir failures.
Oh, right. So revised version will be like this:
for (;;) {
errno = 0;
ent = readdir(grpdir);
if (ent == NULL) {
if (errno)
VIR_ERROR(_("Failed to readdir for %s (%d)")_, grppath, errno);
break;
}
...
}
If I miss something, please let me know.
Yes, that is a correct usage pattern for readdir.
Also, I missed it the first time, but you are leaking fd's - you called
grpdir=opendir(grppath), but never called closedir(grpdir).
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org