Module: Mesa Branch: main Commit: 0ae1231879b729e4bd3dc92149f41aceebdd594a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0ae1231879b729e4bd3dc92149f41aceebdd594a
Author: Ryan Houdek <[email protected]> Date: Fri Nov 5 23:41:39 2021 -0700 util/xmlconfig: Allow DT_UNKNOWN files Some filesystems don't fill in d_type in dirent. Resulting in DT_UNKNOWN. Pass this entry through to the next step and use stat on the full filepath to determine if it is a file. sshfs is known to not fill d_type. This resolves an issue where driconf living on an sshfs path wasn't working. Reviewed-by: Adam Jackson <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13697> --- src/util/xmlconfig.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/util/xmlconfig.c b/src/util/xmlconfig.c index 8614497ac3f..ec2aa291b97 100644 --- a/src/util/xmlconfig.c +++ b/src/util/xmlconfig.c @@ -1009,7 +1009,10 @@ scandir_filter(const struct dirent *ent) (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode))) return 0; #else - if (ent->d_type != DT_REG && ent->d_type != DT_LNK) + /* Allow through unknown file types for filesystems that don't support d_type + * The full filepath isn't available here to stat the file + */ + if (ent->d_type != DT_REG && ent->d_type != DT_LNK && ent->d_type != DT_UNKNOWN) return 0; #endif @@ -1033,10 +1036,26 @@ parseConfigDir(struct OptConfData *data, const char *dirname) for (i = 0; i < count; i++) { char filename[PATH_MAX]; +#ifdef DT_REG + unsigned char d_type = entries[i]->d_type; +#endif snprintf(filename, PATH_MAX, "%s/%s", dirname, entries[i]->d_name); free(entries[i]); +#ifdef DT_REG + /* In the case of unknown d_type, ensure it is a regular file + * This can be accomplished with stat on the full filepath + */ + if (d_type == DT_UNKNOWN) { + struct stat st; + if (stat(filename, &st) != 0 || + !S_ISREG(st.st_mode)) { + continue; + } + } +#endif + parseOneConfigFile(data, filename); }
