This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC 7/7] y2038: Introduce support for clock_settime() being Y2038 safe
- From: Lukasz Majewski <lukma at denx dot de>
- To: libc-alpha at sourceware dot org, Joseph Myers <joseph at codesourcery dot com>
- Cc: Paul Eggert <eggert at cs dot ucla dot edu>, Zack Weinberg <zackw at panix dot com>, Lukasz Majewski <lukma at denx dot de>
- Date: Wed, 27 Mar 2019 09:52:10 +0100
- Subject: [RFC 7/7] y2038: Introduce support for clock_settime() being Y2038 safe
- References: <20190327085210.22019-1-lukma@denx.de>
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(-)
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.
--
2.11.0