[04/10] linux: Use internal DIR locks when accessing filepos on telldir

Message ID 20200417132209.22065-4-adhemerval.zanella@linaro.org
State New
Headers show
Series
  • [01/10] linux: Move posix dir implementations to Linux
Related show

Commit Message

Since it might change during a readdir call.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/unix/sysv/linux/telldir.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.17.1

Comments

Florian Weimer April 21, 2020, 10:33 a.m. | #1
* Adhemerval Zanella via Libc-alpha:

> Since it might change during a readdir call.

>

> Checked on x86_64-linux-gnu and i686-linux-gnu.

> ---

>  sysdeps/unix/sysv/linux/telldir.c | 8 +++++++-

>  1 file changed, 7 insertions(+), 1 deletion(-)

>

> diff --git a/sysdeps/unix/sysv/linux/telldir.c b/sysdeps/unix/sysv/linux/telldir.c

> index 1bb822c807..57d435ed21 100644

> --- a/sysdeps/unix/sysv/linux/telldir.c

> +++ b/sysdeps/unix/sysv/linux/telldir.c

> @@ -23,5 +23,11 @@

>  long int

>  telldir (DIR *dirp)

>  {

> -  return dirp->filepos;

> +  long int ret;

> +

> +  __libc_lock_lock (dirp->lock);

> +  ret = dirp->filepos;

> +  __libc_lock_unlock (dirp->lock);

> +

> +  return ret;

>  }


This looks okay to me.

Patch

diff --git a/sysdeps/unix/sysv/linux/telldir.c b/sysdeps/unix/sysv/linux/telldir.c
index 1bb822c807..57d435ed21 100644
--- a/sysdeps/unix/sysv/linux/telldir.c
+++ b/sysdeps/unix/sysv/linux/telldir.c
@@ -23,5 +23,11 @@ 
 long int
 telldir (DIR *dirp)
 {
-  return dirp->filepos;
+  long int ret;
+
+  __libc_lock_lock (dirp->lock);
+  ret = dirp->filepos;
+  __libc_lock_unlock (dirp->lock);
+
+  return ret;
 }