]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: don't rely on the non-portable d_type field in dirent
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 2 Apr 2019 12:27:44 +0000 (13:27 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 3 Apr 2019 10:31:38 +0000 (11:31 +0100)
d_type is a non-portable extension to the struct dirent and even if it
exists, its value may be DT_UNKNOWN if the filesystem doesn't support
it. This is common with older versions of XFS which have ftype=0
feature.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_firmware.c

index 4ce010caaa1163bf403315ade2e5d92c2ca4cf20..787b76b531314e6a050d9b5ac8bca06a59dd4d7d 100644 (file)
@@ -924,9 +924,7 @@ qemuFirmwareBuildFileList(virHashTablePtr files, const char *dir)
     while ((rc = virDirRead(dirp, &ent, dir)) > 0) {
         VIR_AUTOFREE(char *) filename = NULL;
         VIR_AUTOFREE(char *) path = NULL;
-
-        if (ent->d_type != DT_REG && ent->d_type != DT_LNK)
-            continue;
+        struct stat sb;
 
         if (STRPREFIX(ent->d_name, "."))
             continue;
@@ -937,6 +935,14 @@ qemuFirmwareBuildFileList(virHashTablePtr files, const char *dir)
         if (virAsprintf(&path, "%s/%s", dir, filename) < 0)
             goto cleanup;
 
+        if (stat(path, &sb) < 0) {
+            virReportSystemError(errno, _("Unable to access %s"), path);
+            goto cleanup;
+        }
+
+        if (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))
+            continue;
+
         if (virHashUpdateEntry(files, filename, path) < 0)
             goto cleanup;