ac1d42a util: use virDirRead API

Authored and Committed by ericb 10 years ago
    util: use virDirRead API
    
    In making the conversion to the new API, I fixed a couple bugs:
    virSCSIDeviceGetSgName would leak memory if a directory
    unexpectedly contained multiple entries;
    virNetDevTapGetRealDeviceName could report a spurious error
    from a stale errno inherited before starting the readdir search.
    
    The decision on whether to store the result of virDirRead into
    a variable is based on whether the end of the loop falls through
    to cleanup code automatically.  In some cases, we have loops that
    are documented to return NULL on failure, and which raise an
    error on most failure paths but not in the case where the directory
    was unexpectedly empty; it may be worth a followup patch to
    explicitly report an error if readdir was successful but the
    directory was empty, so that a NULL return always has an error set.
    
    * src/util/vircgroup.c (virCgroupRemoveRecursively): Use new
    interface.
    (virCgroupKillRecursiveInternal, virCgroupSetOwner): Report
    readdir failures.
    * src/util/virfile.c (virFileLoopDeviceOpenSearch)
    (virFileNBDDeviceFindUnused, virFileDeleteTree): Use new
    interface.
    * src/util/virnetdevtap.c (virNetDevTapGetRealDeviceName):
    Properly check readdir errors.
    * src/util/virpci.c (virPCIDeviceIterDevices)
    (virPCIDeviceFileIterate, virPCIGetNetName): Report readdir
    failures.
    (virPCIDeviceAddressIOMMUGroupIterate): Use new interface.
    * src/util/virscsi.c (virSCSIDeviceGetSgName): Report readdir
    failures, and avoid memory leak.
    (virSCSIDeviceGetDevName): Report readdir failures.
    * src/util/virusb.c (virUSBDeviceSearch): Report readdir
    failures.
    * src/util/virutil.c (virGetFCHostNameByWWN)
    (virFindFCHostCapableVport): Report readdir failures.
    
    Signed-off-by: Eric Blake <eblake@redhat.com>
    
        
file modified
+17 -11
file modified
+15 -28
file modified
+2 -8
file modified
+10 -10
file modified
+5 -4
file modified
+5 -2
file modified
+2 -2