Linux: Use AT_FDCWD in utime, utimes when calling utimensat

Message ID 87sgin9fqf.fsf@oldenburg2.str.redhat.com
State New
Headers show
Series
  • Linux: Use AT_FDCWD in utime, utimes when calling utimensat
Related show

Commit Message

Florian Weimer March 5, 2020, 11:57 a.m.
0 is a valid descriptor without any special meaning.

-----
 sysdeps/unix/sysv/linux/utime.c  | 2 +-
 sysdeps/unix/sysv/linux/utimes.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Florian Weimer March 5, 2020, 12:30 p.m. | #1
* Florian Weimer:

> 0 is a valid descriptor without any special meaning.

>

> -----

>  sysdeps/unix/sysv/linux/utime.c  | 2 +-

>  sysdeps/unix/sysv/linux/utimes.c | 2 +-

>  2 files changed, 2 insertions(+), 2 deletions(-)

>

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

> index 2cd9334a6f..6516344adc 100644

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

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

> @@ -32,7 +32,7 @@ __utime64 (const char *file, const struct __utimbuf64 *times)

>        ts64[1].tv_nsec = 0LL;

>      }

>  

> -  return __utimensat64_helper (0, file, times ? ts64 : NULL, 0);

> +  return __utimensat64_helper (AT_FDCWD, file, times ? ts64 : NULL, 0);

>  }

>  

>  #if __TIMESIZE != 64

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

> index 75927b6ec6..02a5e91415 100644

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

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

> @@ -29,7 +29,7 @@ __utimes64 (const char *file, const struct __timeval64 tvp[2])

>        ts64[1] = timeval64_to_timespec64 (tvp[1]);

>      }

>  

> -  return __utimensat64_helper (0, file, tvp ? ts64 : NULL, 0);

> +  return __utimensat64_helper (AT_FDCWD, file, tvp ? ts64 : NULL, 0);

>  }

>  

>  #if __TIMESIZE != 64


There's a missing <fcntl.h> in this patch, it should read:

diff --git a/sysdeps/unix/sysv/linux/utime.c b/sysdeps/unix/sysv/linux/utime.c
index 2cd9334a6f..8665ef2636 100644
--- a/sysdeps/unix/sysv/linux/utime.c
+++ b/sysdeps/unix/sysv/linux/utime.c
@@ -18,6 +18,7 @@
 
 #include <utime.h>
 #include <time.h>
+#include <fcntl.h>
 
 int
 __utime64 (const char *file, const struct __utimbuf64 *times)
@@ -32,7 +33,7 @@ __utime64 (const char *file, const struct __utimbuf64 *times)
       ts64[1].tv_nsec = 0LL;
     }
 
-  return __utimensat64_helper (0, file, times ? ts64 : NULL, 0);
+  return __utimensat64_helper (AT_FDCWD, file, times ? ts64 : NULL, 0);
 }
 
 #if __TIMESIZE != 64
diff --git a/sysdeps/unix/sysv/linux/utimes.c b/sysdeps/unix/sysv/linux/utimes.c
index 75927b6ec6..a6809876fd 100644
--- a/sysdeps/unix/sysv/linux/utimes.c
+++ b/sysdeps/unix/sysv/linux/utimes.c
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <time.h>
+#include <fcntl.h>
 
 int
 __utimes64 (const char *file, const struct __timeval64 tvp[2])
@@ -29,7 +30,7 @@ __utimes64 (const char *file, const struct __timeval64 tvp[2])
       ts64[1] = timeval64_to_timespec64 (tvp[1]);
     }
 
-  return __utimensat64_helper (0, file, tvp ? ts64 : NULL, 0);
+  return __utimensat64_helper (AT_FDCWD, file, tvp ? ts64 : NULL, 0);
 }
 
 #if __TIMESIZE != 64

Florian
Lukasz Majewski March 5, 2020, 12:56 p.m. | #2
Hi Florian,

> * Florian Weimer:

> 

> > 0 is a valid descriptor without any special meaning.

> >

> > -----

> >  sysdeps/unix/sysv/linux/utime.c  | 2 +-

> >  sysdeps/unix/sysv/linux/utimes.c | 2 +-

> >  2 files changed, 2 insertions(+), 2 deletions(-)

> >

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

> > b/sysdeps/unix/sysv/linux/utime.c index 2cd9334a6f..6516344adc

> > 100644 --- a/sysdeps/unix/sysv/linux/utime.c

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

> > @@ -32,7 +32,7 @@ __utime64 (const char *file, const struct

> > __utimbuf64 *times) ts64[1].tv_nsec = 0LL;

> >      }

> >  

> > -  return __utimensat64_helper (0, file, times ? ts64 : NULL, 0);

> > +  return __utimensat64_helper (AT_FDCWD, file, times ? ts64 :

> > NULL, 0); }

> >  

> >  #if __TIMESIZE != 64

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

> > b/sysdeps/unix/sysv/linux/utimes.c index 75927b6ec6..02a5e91415

> > 100644 --- a/sysdeps/unix/sysv/linux/utimes.c

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

> > @@ -29,7 +29,7 @@ __utimes64 (const char *file, const struct

> > __timeval64 tvp[2]) ts64[1] = timeval64_to_timespec64 (tvp[1]);

> >      }

> >  

> > -  return __utimensat64_helper (0, file, tvp ? ts64 : NULL, 0);

> > +  return __utimensat64_helper (AT_FDCWD, file, tvp ? ts64 : NULL,

> > 0); }

> >  

> >  #if __TIMESIZE != 64  

> 

> There's a missing <fcntl.h> in this patch, it should read:

> 

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

> b/sysdeps/unix/sysv/linux/utime.c index 2cd9334a6f..8665ef2636 100644

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

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

> @@ -18,6 +18,7 @@

>  

>  #include <utime.h>

>  #include <time.h>

> +#include <fcntl.h>

>  

>  int

>  __utime64 (const char *file, const struct __utimbuf64 *times)

> @@ -32,7 +33,7 @@ __utime64 (const char *file, const struct

> __utimbuf64 *times) ts64[1].tv_nsec = 0LL;

>      }

>  

> -  return __utimensat64_helper (0, file, times ? ts64 : NULL, 0);

> +  return __utimensat64_helper (AT_FDCWD, file, times ? ts64 : NULL,

> 0); }

>  

>  #if __TIMESIZE != 64

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

> b/sysdeps/unix/sysv/linux/utimes.c index 75927b6ec6..a6809876fd 100644

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

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

> @@ -17,6 +17,7 @@

>     <https://www.gnu.org/licenses/>.  */

>  

>  #include <time.h>

> +#include <fcntl.h>

>  

>  int

>  __utimes64 (const char *file, const struct __timeval64 tvp[2])

> @@ -29,7 +30,7 @@ __utimes64 (const char *file, const struct

> __timeval64 tvp[2]) ts64[1] = timeval64_to_timespec64 (tvp[1]);

>      }

>  

> -  return __utimensat64_helper (0, file, tvp ? ts64 : NULL, 0);

> +  return __utimensat64_helper (AT_FDCWD, file, tvp ? ts64 : NULL, 0);

>  }

>  

>  #if __TIMESIZE != 64

> 

> Florian

> 


Thanks for spotting this. 

Indeed - I've overlooked the missing AT_FDCWD. The AT_FDCWD is
necessary to use utimensat_time{64} syscall to be replacement of utimes
(and utime).


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
Florian Weimer March 5, 2020, 12:57 p.m. | #3
* Lukasz Majewski:

> Indeed - I've overlooked the missing AT_FDCWD. The AT_FDCWD is

> necessary to use utimensat_time{64} syscall to be replacement of utimes

> (and utime).


May I consider this a patch review?

Thanks,
Florian
Lukasz Majewski March 5, 2020, 1:26 p.m. | #4
Hi Florian,

> * Lukasz Majewski:

> 

> > Indeed - I've overlooked the missing AT_FDCWD. The AT_FDCWD is

> > necessary to use utimensat_time{64} syscall to be replacement of

> > utimes (and utime).  

> 

> May I consider this a patch review?

> 

> Thanks,

> Florian

> 


Reviewed-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

Patch

diff --git a/sysdeps/unix/sysv/linux/utime.c b/sysdeps/unix/sysv/linux/utime.c
index 2cd9334a6f..6516344adc 100644
--- a/sysdeps/unix/sysv/linux/utime.c
+++ b/sysdeps/unix/sysv/linux/utime.c
@@ -32,7 +32,7 @@  __utime64 (const char *file, const struct __utimbuf64 *times)
       ts64[1].tv_nsec = 0LL;
     }
 
-  return __utimensat64_helper (0, file, times ? ts64 : NULL, 0);
+  return __utimensat64_helper (AT_FDCWD, file, times ? ts64 : NULL, 0);
 }
 
 #if __TIMESIZE != 64
diff --git a/sysdeps/unix/sysv/linux/utimes.c b/sysdeps/unix/sysv/linux/utimes.c
index 75927b6ec6..02a5e91415 100644
--- a/sysdeps/unix/sysv/linux/utimes.c
+++ b/sysdeps/unix/sysv/linux/utimes.c
@@ -29,7 +29,7 @@  __utimes64 (const char *file, const struct __timeval64 tvp[2])
       ts64[1] = timeval64_to_timespec64 (tvp[1]);
     }
 
-  return __utimensat64_helper (0, file, tvp ? ts64 : NULL, 0);
+  return __utimensat64_helper (AT_FDCWD, file, tvp ? ts64 : NULL, 0);
 }
 
 #if __TIMESIZE != 64