From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15504 invoked by alias); 21 Aug 2019 12:28:11 -0000 Mailing-List: contact glibc-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: glibc-cvs-owner@sourceware.org List-Subscribe: Received: (qmail 15487 invoked by uid 9014); 21 Aug 2019 12:28:10 -0000 Date: Wed, 21 Aug 2019 12:28:00 -0000 Message-ID: <20190821122810.15486.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zack Weinberg To: glibc-cvs@sourceware.org Subject: [glibc/zack/y2038-preliminaries] Use clock_settime to implement settimeofday. X-Act-Checkin: glibc X-Git-Author: Zack Weinberg X-Git-Refname: refs/heads/zack/y2038-preliminaries X-Git-Oldrev: e15799360056223b21b037221a3c60c6d83be00a X-Git-Newrev: dc6c34fbdafa4e30a73390b641489921e075abed X-SW-Source: 2019-q3/txt/msg00361.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=dc6c34fbdafa4e30a73390b641489921e075abed commit dc6c34fbdafa4e30a73390b641489921e075abed Author: Zack Weinberg Date: Fri Aug 16 16:21:13 2019 -0400 Use clock_settime to implement settimeofday. Unconditionally, on all ports, use clock_settime to implement settimeofday. This is a little different from using clock_settime to implement stime, because the vestigial “set time zone” feature of settimeofday complicates matters. The only remaining uses of this feature that aren’t just bugs are using it to inform the Linux kernel of the offset between the hardware clock and UTC, on systems where the hardware clock doesn’t run in UTC (usually because of dual-booting with Windows). They call settimeofday with _only_ the timezone argument non-NULL. Therefore, glibc’s new behavior is: callers of settimeofday must supply one and only one of the two arguments. If both arguments are non-NULL, or both arguments are NULL, the call fails and sets errno to EINVAL. When only the timeval argument is supplied, settimeofday calls __clock_settime(CLOCK_REALTIME), same as stime. When only the timezone argument is supplied, settimeofday calls a new internal function called __settimezone. On Linux, only, this function will pass the timezone structure to the settimeofday system call. On all other operating systems, and on Linux architectures that don’t define __NR_settimeofday, __settimezone is a stub that always sets errno to ENOSYS and returns -1. Another complication is that the alpha-linux-gnu configuration has two versions of settimeofday, GLIBC_2.0 and GLIBC_2.1, with the older symbol using 32-bit time_t (yes, really). The older symbol is reimplemented from scratch (with the same semantics); the newer symbol uses the generic implementation with some #ifdeffage to get the versioning right. Henceforth, __NR_osf_settimeofday will never be used, and __NR_settimeofday only for the timezone feature. There are no longer any internal callers of __settimeofday, so the internal prototype is removed. * time/settimeofday.c (settimeofday): No longer a stub implementation. Call __clock_settime or __settimezone depending on arguments. Optionally override the default symbol version for settimeofday. * include/sys/time.h: Remove prototype for __settimeofday. Add prototype for __settimezone. * sysdeps/unix/syscalls.list: Remove entry for settimeofday. * time/settimezone.c: New file. (__settimezone): New stub implementation. * sysdeps/unix/sysv/linux/settimezone.c: New file. (__settimezone): Implement using settimeofday system call, if available. * time/Makefile (routines): Add settimezone. * sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove entries for settimeofday and osf_settimeofday. * sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c New file, defines settimeofday@GLIBC_2.0. * sysdeps/unix/sysv/linux/alpha/settimeofday.c: New file, defines settimeofday@@GLIBC_2.1. Diff: --- include/sys/time.h | 3 +- sysdeps/unix/syscalls.list | 1 - sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c | 55 ++++++++++++++++++++++++ sysdeps/unix/sysv/linux/alpha/settimeofday.c | 22 ++++++++++ sysdeps/unix/sysv/linux/alpha/syscalls.list | 2 - sysdeps/unix/sysv/linux/settimezone.c | 39 +++++++++++++++++ time/Makefile | 2 +- time/settimeofday.c | 24 +++++++++-- time/settimezone.c | 28 ++++++++++++ 9 files changed, 166 insertions(+), 10 deletions(-) diff --git a/include/sys/time.h b/include/sys/time.h index 7ba0ca7..a57752e 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -24,8 +24,7 @@ extern int __gettimeofday (struct timeval *__tv, struct timezone *__tz); libc_hidden_proto (__gettimeofday) libc_hidden_proto (gettimeofday) -extern int __settimeofday (const struct timeval *__tv, - const struct timezone *__tz) +extern int __settimezone (const struct timezone *__tz) attribute_hidden; extern int __adjtime (const struct timeval *__delta, struct timeval *__olddelta); diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list index 61e5360..5fedd57 100644 --- a/sysdeps/unix/syscalls.list +++ b/sysdeps/unix/syscalls.list @@ -76,7 +76,6 @@ setreuid - setreuid i:ii __setreuid setreuid setrlimit - setrlimit i:ip __setrlimit setrlimit setsid - setsid i: __setsid setsid setsockopt - setsockopt i:iiibn setsockopt __setsockopt -settimeofday - settimeofday i:PP __settimeofday settimeofday setuid - setuid i:i __setuid setuid shutdown - shutdown i:ii shutdown sigaction - sigaction i:ipp __sigaction sigaction diff --git a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c new file mode 100644 index 0000000..a61fcab --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c @@ -0,0 +1,55 @@ +/* settimeofday -- Set the current time of day. Linux/Alpha/tv32 version. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) + +struct timeval32 +{ + int tv_sec, tv_usec; +}; + +/* Set the current time of day and timezone information. + This call is restricted to the super-user. */ +int +attribute_compat_text_section +__settimeofday_tv32 (const struct timeval32 *tv32, + const struct timezone *tz) +{ + if (__glibc_unlikely (tz != 0)) + { + if (tv32 != 0) + { + __set_errno (EINVAL); + return -1; + } + return __settimezone (tz); + } + + struct timespec ts; + ts.tv_sec = tv32->tv_sec; + ts.tv_nsec = tv32->tv_usec * 1000; + return __clock_settime (CLOCK_REALTIME, &ts); +} + +compat_symbol (libc, __settimeofday_tv32, settimeofday, GLIBC_2_0); +#endif diff --git a/sysdeps/unix/sysv/linux/alpha/settimeofday.c b/sysdeps/unix/sysv/linux/alpha/settimeofday.c new file mode 100644 index 0000000..36a6901 --- /dev/null +++ b/sysdeps/unix/sysv/linux/alpha/settimeofday.c @@ -0,0 +1,22 @@ +/* settimeofday -- Set the current time of day. Linux/Alpha/tv64 version. + Copyright (C) 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* We can use the generic implementation, but we have to override its + default symbol version. */ +#define VERSION_settimeofday GLIBC_2.1 +#include