[libvirt] [PATCH] file: Log closing filedescriptors

Eric Blake eblake at redhat.com
Wed May 30 14:48:22 UTC 2012


On 05/30/2012 08:34 AM, Jiri Denemark wrote:
> ---
>  src/util/virfile.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index db3d737..bc7f2c9 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -35,6 +35,7 @@
>  #include "configmake.h"
>  #include "memory.h"
>  #include "virterror_internal.h"
> +#include "logging.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_NONE
>  #define virFileError(code, ...)                                   \
> @@ -51,6 +52,15 @@ int virFileClose(int *fdptr, bool preserve_errno)
>          if (preserve_errno)
>              saved_errno = errno;
>          rc = close(*fdptr);
> +        if (rc < 0) {
> +            if (errno != EBADF) {
> +                char ebuf[1024] ATTRIBUTE_UNUSED;
> +                VIR_DEBUG("Failed to close fd %d: %d",
> +                          *fdptr, virStrerror(errno, ebuf, sizeof(ebuf)));

I think we _also_ need to log EBADF errors, those are usually the sign
of developer bugs, as you are probably guilty of a double-close race.
In fact, I think EBADF should be logged with higher severity than
VIR_DEBUG, as we want to see that right away.

-- 
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/20120530/07b3e99d/attachment-0001.sig>


More information about the libvir-list mailing list