[01/12] Remove implementations of clock_[gs]ettime using [gs]ettimeofday.
Commit Message
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
Comments
On 20/08/2019 10:21, Zack Weinberg wrote:
> 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.)
I would prefer to avoid patch that might break the ABI, couldn't you
attach this change with the one that fix it for Hurd as well?
>
> * 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.
I would prefer to just use the full path (makes it more readable).
> * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
> and convert into an implementation of clock_settime.
Ditto.
> ---
> .../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 @@
> <http://www.gnu.org/licenses/>. */
>
> #include <errno.h>
> -#include <stddef.h>
> -#include <sys/time.h>
> +#include <time.h>
> #include <mach.h>
>
> -/* 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 @@
> <http://www.gnu.org/licenses/>. */
>
> #include <errno.h>
> +#include <time.h>
> #include <sys/time.h>
> #include <hurd.h>
> #include <hurd/port.h>
>
> -/* 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
> - <http://www.gnu.org/licenses/>. */
> -
> -#include <errno.h>
> -#include <stdint.h>
> -#include <time.h>
> -#include <sys/time.h>
> -#include <libc-internal.h>
> -#include <ldsodefs.h>
> -
> -
> -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
> - <http://www.gnu.org/licenses/>. */
> -
> -#include <errno.h>
> -#include <time.h>
> -#include <sys/time.h>
> -#include <ldsodefs.h>
> -
> -
> -/* 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)
>
On 8/20/19 2:06 PM, Adhemerval Zanella wrote:
>
>
> On 20/08/2019 10:21, Zack Weinberg wrote:
>> 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.)
>
> I would prefer to avoid patch that might break the ABI, couldn't you
> attach this change with the one that fix it for Hurd as well?
The changes that fix this for Hurd are the "use clock_gettime to
implement gettimeofday" and "use clock_settime to implement
settimeofday" patches. I think it will be easier to review the patch
series if I keep those separate, but I can reorganize it so that those
two patches happen immediately after this one, and squash them together
for final commit, does that plan work for you?
>>
>> * 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.
>
> I would prefer to just use the full path (makes it more readable).
>
>> * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
>> and convert into an implementation of clock_settime.
>
> Ditto.
Changed in my local copy.
zw
On 22/08/2019 09:54, Zack Weinberg wrote:
> On 8/20/19 2:06 PM, Adhemerval Zanella wrote:
>>
>>
>> On 20/08/2019 10:21, Zack Weinberg wrote:
>>> 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.)
>>
>> I would prefer to avoid patch that might break the ABI, couldn't you
>> attach this change with the one that fix it for Hurd as well?
>
> The changes that fix this for Hurd are the "use clock_gettime to
> implement gettimeofday" and "use clock_settime to implement
> settimeofday" patches. I think it will be easier to review the patch
> series if I keep those separate, but I can reorganize it so that those
> two patches happen immediately after this one, and squash them together
> for final commit, does that plan work for you?
I think it would better, thanks.
>
>>>
>>> * 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.
>>
>> I would prefer to just use the full path (makes it more readable).
>>
>>> * sysdeps/mach/hurd/settimeofday.c: Rename to .../clock_settime.c
>>> and convert into an implementation of clock_settime.
>>
>> Ditto.
>
> Changed in my local copy.
>
> zw
>
similarity index 67%
rename from sysdeps/mach/gettimeofday.c
rename to sysdeps/mach/clock_gettime.c
@@ -16,28 +16,31 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
-#include <stddef.h>
-#include <sys/time.h>
+#include <time.h>
#include <mach.h>
-/* 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)
similarity index 71%
rename from sysdeps/mach/hurd/settimeofday.c
rename to sysdeps/mach/hurd/clock_settime.c
@@ -16,37 +16,32 @@
<http://www.gnu.org/licenses/>. */
#include <errno.h>
+#include <time.h>
#include <sys/time.h>
#include <hurd.h>
#include <hurd/port.h>
-/* 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)
deleted file mode 100644
@@ -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
- <http://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <stdint.h>
-#include <time.h>
-#include <sys/time.h>
-#include <libc-internal.h>
-#include <ldsodefs.h>
-
-
-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)
deleted file mode 100644
@@ -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
- <http://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <time.h>
-#include <sys/time.h>
-#include <ldsodefs.h>
-
-
-/* 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)