[libvirt] [PATCH 15/18] Do not ignore hidden files in /sys and /proc

Ján Tomko jtomko at redhat.com
Tue Jun 21 16:05:38 UTC 2016


The directories we iterate over are unlikely to contain any entries
starting with a dot, other than '.' and '..' which is already skipped
by virDirRead.
---
 src/qemu/qemu_hostdev.c            | 4 ----
 src/storage/storage_backend_scsi.c | 3 ---
 src/util/vircgroup.c               | 1 -
 src/util/virnetdev.c               | 2 --
 src/util/virpci.c                  | 7 -------
 src/util/virprocess.c              | 4 ----
 src/util/virscsi.c                 | 6 ------
 src/util/virusb.c                  | 2 +-
 src/util/virutil.c                 | 8 +-------
 9 files changed, 2 insertions(+), 35 deletions(-)

diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 2fdfae9..dd3a3cf 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -115,10 +115,6 @@ qemuHostdevHostSupportsPassthroughVFIO(void)
         goto cleanup;
 
     while ((direrr = virDirRead(iommuDir, &iommuGroup, NULL)) > 0) {
-        /* skip ./ ../ */
-        if (STRPREFIX(iommuGroup->d_name, "."))
-            continue;
-
         /* assume we found a group */
         break;
     }
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index df683e4..558b3cf 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -269,9 +269,6 @@ getNewStyleBlockDevice(const char *lun_path,
         goto cleanup;
 
     while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
-        if (STREQLEN(block_dirent->d_name, ".", 1))
-            continue;
-
         if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0)
             goto cleanup;
 
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 971894a..04f3818 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3391,7 +3391,6 @@ virCgroupRemoveRecursively(char *grppath)
     while ((direrr = virDirRead(grpdir, &ent, NULL)) > 0) {
         char *path;
 
-        if (ent->d_name[0] == '.') continue;
         if (ent->d_type != DT_DIR) continue;
 
         if (virAsprintf(&path, "%s/%s", grppath, ent->d_name) == -1) {
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 84406de..cdbc41b 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -3168,8 +3168,6 @@ virNetDevRDMAFeature(const char *ifname,
         goto cleanup;
 
     while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) {
-        if (dp->d_name[0] == '.')
-            continue;
         if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resource",
                         dp->d_name) < 0)
             continue;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 948fdbf..04ff68b 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -468,10 +468,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
         virPCIDevicePtr check;
         char *tmp;
 
-        /* Ignore '.' and '..' */
-        if (entry->d_name[0] == '.')
-            continue;
-
         /* expected format: <domain>:<bus>:<slot>.<function> */
         if (/* domain */
             virStrToLong_ui(entry->d_name, &tmp, 16, &domain) < 0 || *tmp != ':' ||
@@ -2024,9 +2020,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
     while ((direrr = virDirRead(groupDir, &ent, groupPath)) > 0) {
         virPCIDeviceAddress newDev;
 
-        if (ent->d_name[0] == '.')
-            continue;
-
         if (virPCIDeviceAddressParse(ent->d_name, &newDev) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Found invalid device link '%s' in '%s'"),
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index a3e7f4e..09dd3c9 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -619,10 +619,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
         long long tmp;
         pid_t tmp_pid;
 
-        /* Skip . and .. */
-        if (STRPREFIX(ent->d_name, "."))
-            continue;
-
         if (virStrToLong_ll(ent->d_name, NULL, 10, &tmp) < 0)
             goto cleanup;
         tmp_pid = tmp;
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 0f57494..4843367 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -131,9 +131,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
         goto cleanup;
 
     while (virDirRead(dir, &entry, path) > 0) {
-        if (entry->d_name[0] == '.')
-            continue;
-
         /* Assume a single directory entry */
         ignore_value(VIR_STRDUP(sg, entry->d_name));
         break;
@@ -174,9 +171,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
         goto cleanup;
 
     while (virDirRead(dir, &entry, path) > 0) {
-        if (entry->d_name[0] == '.')
-            continue;
-
         ignore_value(VIR_STRDUP(name, entry->d_name));
         break;
     }
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 1db8173..6a001a7 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -145,7 +145,7 @@ virUSBDeviceSearch(unsigned int vendor,
         unsigned int found_prod, found_vend, found_bus, found_devno;
         char *tmpstr = de->d_name;
 
-        if (de->d_name[0] == '.' || strchr(de->d_name, ':'))
+        if (strchr(de->d_name, ':'))
             continue;
 
         if (virUSBSysReadFile("idVendor", de->d_name,
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 46313c2..170dd59 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1864,7 +1864,7 @@ virFindSCSIHostByPCI(const char *sysfs_prefix,
         return NULL;
 
     while (virDirRead(dir, &entry, prefix) > 0) {
-        if (entry->d_name[0] == '.' || !virFileIsLink(entry->d_name))
+        if (!virFileIsLink(entry->d_name))
             continue;
 
         if (virAsprintf(&host_link, "%s/%s", prefix, entry->d_name) < 0)
@@ -2210,9 +2210,6 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
     } while (0)
 
     while (virDirRead(dir, &entry, prefix) > 0) {
-        if (entry->d_name[0] == '.')
-            continue;
-
         if (virAsprintf(&wwnn_path, "%s/%s/node_name", prefix,
                         entry->d_name) < 0)
             goto cleanup;
@@ -2291,9 +2288,6 @@ virFindFCHostCapableVport(const char *sysfs_prefix)
         unsigned int host;
         char *p = NULL;
 
-        if (entry->d_name[0] == '.')
-            continue;
-
         p = entry->d_name + strlen("host");
         if (virStrToLong_ui(p, NULL, 10, &host) == -1) {
             VIR_DEBUG("Failed to parse host number from '%s'",
-- 
2.7.3




More information about the libvir-list mailing list