From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8527 invoked by alias); 22 Aug 2019 23:03:55 -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 8510 invoked by uid 9014); 22 Aug 2019 23:03:55 -0000 Date: Thu, 22 Aug 2019 23:03:00 -0000 Message-ID: <20190822230355.8509.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Zack Weinberg To: glibc-cvs@sourceware.org Subject: [glibc/zack/y2038-preliminaries] Remove implementations of clock_[gs]ettime using [gs]ettimeofday. X-Act-Checkin: glibc X-Git-Author: Zack Weinberg X-Git-Refname: refs/heads/zack/y2038-preliminaries X-Git-Oldrev: c38d9652e3b147fd1c99d2e3972e57bc1289b5ab X-Git-Newrev: 5509f57349a19bd4fe1bb71fd51b8a560698f3dd X-SW-Source: 2019-q3/txt/msg00384.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5509f57349a19bd4fe1bb71fd51b8a560698f3dd commit 5509f57349a19bd4fe1bb71fd51b8a560698f3dd Author: Zack Weinberg Date: Fri Aug 16 15:11:47 2019 -0400 Remove implementations of clock_[gs]ettime using [gs]ettimeofday. gettimeofday and settimeofday are obsolete in POSIX and will not be provided by Linux for future new architectures. The preferred interfaces are clock_gettime and clock_settime. Ports of glibc to historic Unixes that provided these functions, but not clock_gettime and clock_settime, are unlikely to be contributed anymore. Accordingly, remove the generic-Unix implementations of clock_gettime and clock_settime that forwarded to gettimeofday and settimeofday. New OS ports must henceforth provide some implementation of clock_gettime and clock_settime. The generic-Unix implementations *were* being used on the Hurd. This patch therefore also converts the Hurd gettimeofday and settimeofday implementations into clock_gettime and clock_settime implementations. They only support CLOCK_REALTIME, and they only supply microsecond resolution. Hurd/Mach does not appear to have any support for finer-resolution or monotonic clocks. Relatedly, Hurd is currently using sysdeps/posix/clock_getres.c for clock_getres; its output for CLOCK_REALTIME is based on sysconf (_SC_CLK_TCK), and I do not know whether that gives the correct result. This means Hurd temporarily has only ENOSYS stubs for gettimeofday and settimeofday; this will be corrected in the next two patches, which will be squashed together with this one after review. * sysdeps/unix/clock_gettime.c, sysdeps/unix/clock_settime.c: Delete file. * sysdeps/mach/gettimeofday.c: Rename to .../clock_gettime.c and convert into an implementation of clock_gettime. * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c and convert into an implementation of clock_settime. Diff: --- sysdeps/mach/{gettimeofday.c => clock_gettime.c} | 26 ++++----- .../mach/hurd/{settimeofday.c => clock_settime.c} | 27 ++++------ sysdeps/unix/clock_gettime.c | 56 -------------------- sysdeps/unix/clock_settime.c | 61 ---------------------- 4 files changed, 24 insertions(+), 146 deletions(-) diff --git a/sysdeps/mach/gettimeofday.c b/sysdeps/mach/clock_gettime.c similarity index 65% rename from sysdeps/mach/gettimeofday.c rename to sysdeps/mach/clock_gettime.c index 8d0dfbb..8e3675e 100644 --- a/sysdeps/mach/gettimeofday.c +++ b/sysdeps/mach/clock_gettime.c @@ -16,28 +16,28 @@ . */ #include -#include -#include +#include #include -/* Get the current time of day and timezone information, - putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. +/* Get the current time of day, putting it into *TS. Returns 0 on success, -1 on errors. */ int -__gettimeofday (struct timeval *tv, struct timezone *tz) +__clock_gettime (clockid_t clock_id, struct timespec *ts) { kern_return_t err; + time_value_t tv; - if (tz != NULL) - *tz = (struct timezone){0, 0}; /* XXX */ - - if (err = __host_get_time (__mach_host_self (), (time_value_t *) tv)) + if (clock_id != CLOCK_REALTIME) { - errno = err; + errno = EINVAL; return -1; } + + /* Could theoretically fail if __mach_host_self fails due to + resource exhaustion, but we assume this will never happen. */ + __host_get_time (__mach_host_self (), &tv); + TIME_VALUE_TO_TIMESPEC (&tv, ts); return 0; } -libc_hidden_def (__gettimeofday) -weak_alias (__gettimeofday, gettimeofday) -libc_hidden_weak (gettimeofday) +weak_alias (__clock_gettime, clock_gettime) +libc_hidden_def (__clock_gettime) diff --git a/sysdeps/mach/hurd/settimeofday.c b/sysdeps/mach/hurd/clock_settime.c similarity index 71% rename from sysdeps/mach/hurd/settimeofday.c rename to sysdeps/mach/hurd/clock_settime.c index bd0ffd6..a642b82 100644 --- a/sysdeps/mach/hurd/settimeofday.c +++ b/sysdeps/mach/hurd/clock_settime.c @@ -16,37 +16,32 @@ . */ #include +#include #include #include #include -/* Set the current time of day and timezone information. +/* Set the current time of day. This call is restricted to the super-user. */ int -__settimeofday (const struct timeval *tv, const struct timezone *tz) +__clock_settime (clockid_t clock_id, const struct timespec *ts) { error_t err; mach_port_t hostpriv; + time_value_t tv; - if (tz != NULL) - { - errno = ENOSYS; - return -1; - } + if (clock_id != CLOCK_REALTIME) + return __hurd_fail (EINVAL); err = __get_privileged_ports (&hostpriv, NULL); if (err) return __hurd_fail (EPERM); - /* `time_value_t' and `struct timeval' are in fact identical with the - names changed. */ - err = __host_set_time (hostpriv, *(time_value_t *) tv); + TIMESPEC_TO_TIME_VALUE (&tv, ts); + err = __host_set_time (hostpriv, tv); __mach_port_deallocate (__mach_task_self (), hostpriv); - if (err) - return __hurd_fail (err); - - return 0; + return __hurd_fail (err); } - -weak_alias (__settimeofday, settimeofday) +libc_hidden_def (__clock_settime) +weak_alias (__clock_settime, clock_settime) diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c deleted file mode 100644 index 2a82fc1..0000000 --- a/sysdeps/unix/clock_gettime.c +++ /dev/null @@ -1,56 +0,0 @@ -/* clock_gettime -- Get the current time from a POSIX clockid_t. Unix version. - Copyright (C) 1999-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 - -/* Get current value of CLOCK and store it in TP. */ -int -__clock_gettime (clockid_t clock_id, struct timespec *tp) -{ - int retval = -1; - - switch (clock_id) - { - case CLOCK_REALTIME: - { - struct timeval tv; - retval = __gettimeofday (&tv, NULL); - if (retval == 0) - TIMEVAL_TO_TIMESPEC (&tv, tp); - } - break; - - default: - __set_errno (EINVAL); - break; - } - - return retval; -} -libc_hidden_def (__clock_gettime) - -versioned_symbol (libc, __clock_gettime, clock_gettime, GLIBC_2_17); -/* clock_gettime moved to libc in version 2.17; - old binaries may expect the symbol version it had in librt. */ -#if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17) -strong_alias (__clock_gettime, __clock_gettime_2); -compat_symbol (libc, __clock_gettime_2, clock_gettime, GLIBC_2_2); -#endif diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c deleted file mode 100644 index 5b39849..0000000 --- a/sysdeps/unix/clock_settime.c +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright (C) 1999-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 - -/* Set CLOCK to value TP. */ -int -__clock_settime (clockid_t clock_id, const struct timespec *tp) -{ - int retval = -1; - - /* Make sure the time cvalue is OK. */ - if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) - { - __set_errno (EINVAL); - return -1; - } - - switch (clock_id) - { - case CLOCK_REALTIME: - { - struct timeval tv; - TIMESPEC_TO_TIMEVAL (&tv, tp); - retval = __settimeofday (&tv, NULL); - } - break; - - default: - __set_errno (EINVAL); - break; - } - - return retval; -} -libc_hidden_def (__clock_settime) - -versioned_symbol (libc, __clock_settime, clock_settime, GLIBC_2_17); -/* clock_settime moved to libc in version 2.17; - old binaries may expect the symbol version it had in librt. */ -#if SHLIB_COMPAT (libc, GLIBC_2_2, GLIBC_2_17) -strong_alias (__clock_settime, __clock_settime_2); -compat_symbol (libc, __clock_settime_2, clock_settime, GLIBC_2_2); -#endif