Re: [PATCH 3/6] Fix error handling of readdir() in virFileLoopDeviceOpen

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

 



On 03.05.2013 15:49, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
> 
> To correctly handle errors from readdir() you must set 'errno'
> to zero before invoking it & check its value afterwards to
> distinguish error from EOF.
> 
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  src/util/virfile.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index 25a0501..9363468 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -531,6 +531,7 @@ static int virFileLoopDeviceOpen(char **dev_name)
>          goto cleanup;
>      }
>  
> +    errno = 0;
>      while ((de = readdir(dh)) != NULL) {
>          if (!STRPREFIX(de->d_name, "loop"))
>              continue;
> @@ -562,10 +563,15 @@ static int virFileLoopDeviceOpen(char **dev_name)
>          /* Oh well, try the next device */
>          VIR_FORCE_CLOSE(fd);
>          VIR_FREE(looppath);
> +        errno = 0;
>      }
>  
> -    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                   _("Unable to find a free loop device in /dev"));
> +    if (errno != 0)
> +        virReportSystemError(errno, "%s",
> +                             _("Unable to iterate over loop devices"));
> +    else
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                       _("Unable to find a free loop device in /dev"));
>  
>  cleanup:
>      if (fd != -1) {
> 

ACK

Michal

--
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]