From patchwork Tue Aug 20 13:21:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 34185 Received: (qmail 48208 invoked by alias); 20 Aug 2019 13:22:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 48079 invoked by uid 89); 20 Aug 2019 13:21:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=EPERM, 1000000000, eperm X-HELO: mailbackend.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Cc: Joseph Myers , Florian Weimer , Lukasz Majewski , Alistair Francis , Stepan Golosunov , Arnd Bergmann Subject: [PATCH 01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday. Date: Tue, 20 Aug 2019 09:21:41 -0400 Message-Id: <20190820132152.24100-2-zackw@panix.com> In-Reply-To: <20190820132152.24100-1-zackw@panix.com> References: <20190820132152.24100-1-zackw@panix.com> MIME-Version: 1.0 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. In preparation for implementing all the other time query/set interfaces using clock_gettime and clock_settime, remove the generic-Unix implementations of clock_gettime and clock_settime that forwarded to gettimeofday and settimeofday. Ports of glibc to historic Unixes that provided these functions, but not clock_gettime and clock_settime, are unlikely to be contributed anymore. The removed implementations *were* being used on the Hurd. Deal with this by converting the Hurd gettimeofday and settimeofday implementations into clock_gettime and clock_settime implementations, respectively. (They still only supply microsecond resolution. I don’t know enough about Hurd/Mach to know whether nanosecond- resolution clocks are even available.) This means Hurd temporarily has no implementation of gettimeofday or settimeofday; this will be corrected in subsequent patches. (glibc will not fail to build in the i386-gnu configuration, but gettimeofday and settimeofday will be ENOSYS stubs.) * 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. --- .../mach/{gettimeofday.c => clock_gettime.c} | 25 ++++---- .../hurd/{settimeofday.c => clock_settime.c} | 27 ++++---- sysdeps/unix/clock_gettime.c | 64 ------------------- sysdeps/unix/clock_settime.c | 54 ---------------- 4 files changed, 25 insertions(+), 145 deletions(-) rename sysdeps/mach/{gettimeofday.c => clock_gettime.c} (67%) rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (71%) delete mode 100644 sysdeps/unix/clock_gettime.c delete mode 100644 sysdeps/unix/clock_settime.c diff --git a/sysdeps/mach/gettimeofday.c b/sysdeps/mach/clock_gettime.c similarity index 67% rename from sysdeps/mach/gettimeofday.c rename to sysdeps/mach/clock_gettime.c index 8d0dfbb7dc..0fe0619aa5 100644 --- a/sysdeps/mach/gettimeofday.c +++ b/sysdeps/mach/clock_gettime.c @@ -16,28 +16,31 @@ . */ #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 (clock_id != CLOCK_REALTIME) + { + errno = EINVAL; + return -1; + } - if (err = __host_get_time (__mach_host_self (), (time_value_t *) tv)) + if (err = __host_get_time (__mach_host_self (), &tv)) { errno = err; return -1; } + + 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 bd0ffd64ac..a642b82b3e 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 10a6c96d9d..0000000000 --- a/sysdeps/unix/clock_gettime.c +++ /dev/null @@ -1,64 +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 -#include -#include - - -static inline int -realtime_gettime (struct timespec *tp) -{ - struct timeval tv; - int retval = __gettimeofday (&tv, NULL); - if (retval == 0) - /* Convert into `timespec'. */ - TIMEVAL_TO_TIMESPEC (&tv, tp); - return retval; -} - - -/* 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; -} -weak_alias (__clock_gettime, clock_gettime) -libc_hidden_def (__clock_gettime) diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c deleted file mode 100644 index 109a1ad872..0000000000 --- a/sysdeps/unix/clock_settime.c +++ /dev/null @@ -1,54 +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; -} -weak_alias (__clock_settime, clock_settime)