On Wed, Jun 23, 2010 at 10:37 PM, Eric Blake <eblake(a)redhat.com> wrote:
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.
Thank you for the confirmation.
Also, I missed it the first time, but you are leaking fd's - you called
grpdir=opendir(grppath), but never called closedir(grpdir).
Oops! I'll fix it as well.
Thanks!
ozaki-r
--
Eric Blake eblake(a)redhat.com +1-801-349-2682
Libvirt virtualization library
http://libvirt.org