Re: [PATCH] nodeinfo: Make sure we always reset errno before calling readdir

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 10 Apr 2014 09:22:42 -0600
Eric Blake <eblake@xxxxxxxxxx> wrote:

> On 04/10/2014 08:38 AM, Natanael Copa wrote:
> 
> >>> -    errno = 0;
> >>> -    while ((cpudirent = readdir(cpudir))) {
> >>> +    for (errno = 0; (cpudirent = readdir(cpudir)); errno = 0) {
> >>>          if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
> >>>              continue;
> >>
... 
> > 
> > I suppose we could use helper function to make it more readable:
> > 
> > static struct dirent *virReaddir(DIR *dirp)
> > {
> >     errno = 0;
> >     return readdir(dirp);
> > }
> 
> Or maybe:
> 
> int virReaddir(DIR *dirp, struct dirent **ent)
> {
>     errno = 0;
>     *ent = readdir(dirp);
>     if (!*ent && errno) {
>         virReportSystemError(errno, _("unable to read directory"))
>         return -1;
>     }
>     return *ent ? 1 : 0;
> }
> 
> and used as:
> 
> while ((ret = virReaddir(dirp, &entry)) > 0) {
>     process entry
> }
> if (ret < 0)
>     goto error;

This looks better yes.

Should I prepare a new patch with this? And grep for more readdirs?

-nc

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]