[RFC,7/7] y2038: Introduce support for clock_settime() being Y2038 safe
Commit Message
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
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.
@@ -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,
@@ -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);
}
@@ -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.