[5/6] Handle DT_UNKNOWN in gconv-modules.d

Message ID 20210610111853.2286873-6-siddhesh@sourceware.org
State Superseded
Delegated to: DJ Delorie
Headers
Series gconv configuration parsing cleanups |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Siddhesh Poyarekar June 10, 2021, 11:18 a.m. UTC
  On filesystems that do not support dt_type, a regular file shows up as
DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
such cases.
---
 iconv/gconv_parseconfdir.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
  

Comments

DJ Delorie June 22, 2021, 4:03 a.m. UTC | #1
Siddhesh Poyarekar <siddhesh@sourceware.org> writes:
> On filesystems that do not support dt_type, a regular file shows up as
> DT_UNKNOWN.  Fall back to using lstat64 to read file properties in
> such cases.
> ---
>  iconv/gconv_parseconfdir.h | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h
> index 3d4d58d4be..e73ea0ff5c 100644
> --- a/iconv/gconv_parseconfdir.h
> +++ b/iconv/gconv_parseconfdir.h
> @@ -32,6 +32,7 @@
>  # define readdir __readdir
>  # define closedir __closedir
>  # define mempcpy __mempcpy
> +# define lstat64 __lstat64
>  #endif

Ok.

>  /* Name of the file containing the module information in the directories
> @@ -138,7 +139,7 @@ gconv_parseconfdir (const char *dir, size_t dir_len)
>        struct dirent *ent;
>        while ((ent = readdir (confdir)) != NULL)
>  	{
> -	  if (ent->d_type != DT_REG)
> +	  if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
>  	    continue;

Ok.

> @@ -148,8 +149,14 @@ gconv_parseconfdir (const char *dir, size_t dir_len)
>  	      && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
>  	    {
>  	      char *conf;
> +	      struct stat64 st;
>  	      if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0)
>  		continue;
> +	      if (ent->d_type == DT_UNKNOWN
> +		  && (lstat64 (conf, &st) == -1
> +		      || !S_ISREG (st.st_mode)))
> +		continue;

Skip non-regular files that weren't reported earlier (or other errors); ok.


LGTM
Reviewed-by: DJ Delorie <dj@redhat.com>
  

Patch

diff --git a/iconv/gconv_parseconfdir.h b/iconv/gconv_parseconfdir.h
index 3d4d58d4be..e73ea0ff5c 100644
--- a/iconv/gconv_parseconfdir.h
+++ b/iconv/gconv_parseconfdir.h
@@ -32,6 +32,7 @@ 
 # define readdir __readdir
 # define closedir __closedir
 # define mempcpy __mempcpy
+# define lstat64 __lstat64
 #endif
 
 /* Name of the file containing the module information in the directories
@@ -138,7 +139,7 @@  gconv_parseconfdir (const char *dir, size_t dir_len)
       struct dirent *ent;
       while ((ent = readdir (confdir)) != NULL)
 	{
-	  if (ent->d_type != DT_REG)
+	  if (ent->d_type != DT_REG && ent->d_type != DT_UNKNOWN)
 	    continue;
 
 	  size_t len = strlen (ent->d_name);
@@ -148,8 +149,14 @@  gconv_parseconfdir (const char *dir, size_t dir_len)
 	      && strcmp (ent->d_name + len - strlen (suffix), suffix) == 0)
 	    {
 	      char *conf;
+	      struct stat64 st;
 	      if (asprintf (&conf, "%s/%s", buf, ent->d_name) < 0)
 		continue;
+	      if (ent->d_type == DT_UNKNOWN
+		  && (lstat64 (conf, &st) == -1
+		      || !S_ISREG (st.st_mode)))
+		continue;
+
 	      found |= read_conf_file (conf, dir, dir_len);
 	      free (conf);
 	    }