From ebe9c6eab77e2da500c24430addfcd9f10b1676d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Tue, 2 Apr 2019 13:27:44 +0100 Subject: [PATCH] qemu: don't rely on the non-portable d_type field in dirent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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é --- src/qemu/qemu_firmware.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 4ce010caaa..787b76b531 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -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;