[RFC,7/7] y2038: Introduce support for clock_settime() being Y2038 safe

Message ID 20190327085210.22019-8-lukma@denx.de
State Superseded
Headers

Commit Message

Lukasz Majewski March 27, 2019, 8:52 a.m. UTC
  This patch introduces the Y2038 specific code to make clock_settime()/
__clock_settime64() Y2038 safe on 32 bit systems.

* include/time.h:
  Remove libc_hidden_proto (__clock_settime64) - make the __clock_settime64
  publicly available for Y2038 safe system
* sysdeps/unix/sysv/linux/clock_settime.c:
  Use clock_settime64 kernel syscall (available from 5.1-rc1+ Linux) by
  32 bit Y2038 safe systems
* time/time.h: Redirect clock_settime call to __clock_settime64 on 32 bit
  Y2038 safe systems
---
 include/time.h                          |  4 +++-
 sysdeps/unix/sysv/linux/clock_settime.c | 11 +++++++++++
 time/time.h                             |  9 +++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
  

Comments

Joseph Myers March 27, 2019, 1:48 p.m. UTC | #1
On Wed, 27 Mar 2019, Lukasz Majewski wrote:

> +/* For Y2038 safe system the __clock_settime64 needs to be a visible
> +   symbol as a replacement for Y2038 unsafe clock_settime()
> +*/

Do not use () after a function name to indicate it's a function; see the 
GNU Coding Standards.  This applies to other comments in this patch series 
as well.
  

Patch

diff --git a/include/time.h b/include/time.h
index c8c0a6936e..25ddb70377 100644
--- a/include/time.h
+++ b/include/time.h
@@ -107,7 +107,9 @@  libc_hidden_proto (__timegm64)
 #else
 extern int __clock_settime64 (clockid_t clock_id,
                               const struct __timespec64 *tp);
-libc_hidden_proto (__clock_settime64)
+/* For Y2038 safe system the __clock_settime64 needs to be a visible
+   symbol as a replacement for Y2038 unsafe clock_settime()
+*/
 #endif
 
 /* Compute the `struct tm' representation of T,
diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
index 5b7ab7fcb3..3fcce623c9 100644
--- a/sysdeps/unix/sysv/linux/clock_settime.c
+++ b/sysdeps/unix/sysv/linux/clock_settime.c
@@ -29,6 +29,17 @@  __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
 			return -1;
 		}
 
+/* For being Y2038 safe we check if __TIMESIZE != 64 and run the
+   64 bit syscall only when supported by the kernel.
+   As __clock_settime64() may be also called by 32 bit machine (not Y2038
+   safe) - in case of error - the default kernel syscall (clock_settime)
+   is executed */
+#if defined __NR_clock_settime64 && defined __TIMESIZE != 64
+	int retval = INLINE_SYSCALL_CALL (clock_settime64, clock_id, tp);
+	if (! retval)
+		return retval;
+#endif
+
 	return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp);
 }
 
diff --git a/time/time.h b/time/time.h
index cba6d15260..c9c8aeccfa 100644
--- a/time/time.h
+++ b/time/time.h
@@ -222,6 +222,15 @@  extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
 extern int clock_settime (clockid_t __clock_id, const struct timespec *__tp)
      __THROW;
 
+#ifdef __USE_TIME_BITS64
+# if defined(__REDIRECT)
+extern int __REDIRECT (clock_settime, (clockid_t __clock_id, const struct
+     timespec *__tp), __clock_settime64) __THROW;
+# else
+# define clock_settime __clock_settime64
+# endif
+#endif
+
 # ifdef __USE_XOPEN2K
 /* High-resolution sleep with the specified clock.