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: 1150142 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104579-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="eGxA3OJ2"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CWg472frz9s00 for ; Tue, 20 Aug 2019 23:22:24 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=NW5qqbyIoVT9idW4t5P2BUuxWK50YRkk01KkfLOdI2A yZjsfDGj4aJS+PhbWy8G8us0mpMj+EIcwXUI8AYWWSqA/LvC9zTN8IH0iIXLmV3o 0N2Mpxa7Temt1+MPC1oGCBFAydeiz7A9zHFt1CCBLKnHVRRHtsD+zMVJtDrmUEqI = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=7dAVXmtrD2w4Q5P31f0RVS1cTb8=; b=eGxA3OJ2RYa4ytAW+ wCTG3a4q3yno35lVXQ4UaSbpwShz6702/MnowKOCOUyA5qPJzvrQ8BuaPbap25a0 WI6m730orHUtnEIN2j7uoYAyO54SRp/8gypjiVD/i/kL3d7Pp5SXWNlinYgmSTx3 B1OtxD22GpkGo8aAloKCLwBeEc= 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) From patchwork Tue Aug 20 13:21:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 1150143 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104580-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="YpJkeWCZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CWgG12tSz9s00 for ; Tue, 20 Aug 2019 23:22:33 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=ww3z9uZahPsyISh0Prd5/Rrpg4Us3nkXY5TRxcD0aUb oD9KcCblhhcCbxn7POAp/L+x6cxueDKL5DyONQFhQvWs0rUljq+PlkYStD7FDoTV df276JYdurUryficC3z9a7YMmG8QP3lyfcYDba8GLPByjdNzEfnyVZr2cKA+aJqo = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=CK+txz/vYUEKDQyZgV3cqe/S0qw=; b=YpJkeWCZKitAWB39y JEAEqZ0b+TZw7SU2p+Gz0EHUqDST/w3T2JSjb8k3PKNALMYp80Uuh7/fTgXgxFBH lUaCbE5v7FOuDw3R9zcOYB+d2yKswUem87l9YHKEEtPRLjCOWatytAqy8sLPr/QR mYg52HwmbunJr5slaEfOc5qAZg= Received: (qmail 48490 invoked by alias); 20 Aug 2019 13:22:02 -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 48386 invoked by uid 89); 20 Aug 2019 13:22:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.1 spammy=busy, MILLION, traces, BEFORE 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 02/12] Change most internal uses of __gettimeofday to __clock_gettime. Date: Tue, 20 Aug 2019 09:21:42 -0400 Message-Id: <20190820132152.24100-3-zackw@panix.com> In-Reply-To: <20190820132152.24100-1-zackw@panix.com> References: <20190820132152.24100-1-zackw@panix.com> MIME-Version: 1.0 Since gettimeofday will shortly be implemented in terms of clock_gettime on all platforms, internal code should use clock_gettime directly; in addition to removing a layer of indirection, this will allow us to remove the PLT-bypass gunk for gettimeofday. In many cases, the changed code does fewer conversions. A few Hurd-specific files were changed to use __host_get_time instead of __clock_gettime, as this seemed tidier. With the exception of support/support_test_main.c, test cases are not modified, mainly because I didn’t want to have to figure out which test cases were testing gettimeofday specifically. The definition of GETTIME in sysdeps/generic/memusage.h had a typo and was not reading tv_sec at all. I fixed this. It appears nobody has been generating malloc traces on a machine that doesn’t have a superseding definition. * inet/deadline.c (__deadline_current_time) * login/logout.c (logout) * login/logwtmp.c (logwtmp) * nis/nis_call.c (__nisfind_server) * nptl/pthread_join_common.c (timedwait_tid) * nptl/pthread_mutex_timedlock.c (__pthread_mutex_clocklock_common) * nscd/nscd_helper.c (wait_on_socket, open_socket) * resolv/gai_misc.c (handle_requests) * resolv/gai_suspend.c (gai_suspend) * resolv/res_send.c (evNowTime) * sunrpc/auth_des.c (authdes_marshal, authdes_destroy) * sunrpc/auth_unix.c (authunix_create, authunix_refresh) * sunrpc/create_xid.c (_create_xid) * sunrpc/svcauth_des.c (_svcauth_des) * sysdeps/generic/memusage.h (GETTIME) * sysdeps/mach/nanosleep.c (__libc_nanosleep) * sysdeps/posix/tempname.c (RANDOM_BITS) * sysdeps/pthread/aio_misc.c (handle_fildes_io) * sysdeps/pthread/aio_suspend.c (aio_suspend): Use __clock_gettime(CLOCK_REALTIME) instead of __gettimeofday. Include time.h if necessary. * sysdeps/mach/hurd/getitimer.c (__getitimer) * sysdeps/mach/hurd/setitimer.c (setitimer_locked) * sysdeps/mach/hurd/times.c (__times): Use __host_get_time instead of __gettimeofday. Include mach.h if necessary. * sysdeps/mach/usleep.c (usleep): Remove unnecessary calls to __gettimeofday. * support/support_test_main.c (print_timestamp): Take a struct timespec argument, not a struct timeval. (signal_handler): Update to match. Use clock_gettime(CLOCK_REALTIME) instead of gettimeofday. * sysdeps/generic/memusage.h (GETTIME): Correct typo causing the seconds field of each timestamp to be ignored. --- inet/deadline.c | 9 ++------- login/logout.c | 9 +++++---- login/logwtmp.c | 7 +++---- nis/nis_call.c | 4 +++- nptl/pthread_join_common.c | 7 +++---- nptl/pthread_mutex_timedlock.c | 7 +++---- nscd/nscd_helper.c | 24 ++++++++++++------------ resolv/gai_misc.c | 6 +++--- resolv/gai_suspend.c | 6 +++--- resolv/res_send.c | 6 +----- sunrpc/auth_des.c | 19 +++++++++++-------- sunrpc/auth_unix.c | 9 +++++---- sunrpc/create_xid.c | 6 +++--- sunrpc/svcauth_des.c | 7 ++++++- support/support_test_main.c | 14 ++++++-------- sysdeps/generic/memusage.h | 16 ++++++++-------- sysdeps/mach/hurd/getitimer.c | 3 ++- sysdeps/mach/hurd/setitimer.c | 3 ++- sysdeps/mach/hurd/times.c | 6 +++--- sysdeps/mach/nanosleep.c | 33 +++++++++++++++++++++------------ sysdeps/mach/usleep.c | 5 ----- sysdeps/posix/tempname.c | 9 ++++----- sysdeps/pthread/aio_misc.c | 6 +++--- sysdeps/pthread/aio_suspend.c | 6 +++--- 24 files changed, 115 insertions(+), 112 deletions(-) diff --git a/inet/deadline.c b/inet/deadline.c index ab275c266d..dee4637732 100644 --- a/inet/deadline.c +++ b/inet/deadline.c @@ -29,13 +29,8 @@ __deadline_current_time (void) { struct deadline_current_time result; if (__clock_gettime (CLOCK_MONOTONIC, &result.current) != 0) - { - struct timeval current_tv; - if (__gettimeofday (¤t_tv, NULL) == 0) - __libc_fatal ("Fatal error: gettimeofday system call failed\n"); - result.current.tv_sec = current_tv.tv_sec; - result.current.tv_nsec = current_tv.tv_usec * 1000; - } + if (__clock_gettime (CLOCK_REALTIME, &result.current) != 0) + __libc_fatal ("Fatal error: clock_gettime failed\n"); assert (result.current.tv_sec >= 0); return result; } diff --git a/login/logout.c b/login/logout.c index 5015c1af0b..f1313ded77 100644 --- a/login/logout.c +++ b/login/logout.c @@ -19,6 +19,7 @@ #include #include #include +#include #include int @@ -45,10 +46,10 @@ logout (const char *line) /* Clear information about who & from where. */ memset (ut->ut_name, '\0', sizeof ut->ut_name); memset (ut->ut_host, '\0', sizeof ut->ut_host); - struct timeval tv; - __gettimeofday (&tv, NULL); - ut->ut_tv.tv_sec = tv.tv_sec; - ut->ut_tv.tv_usec = tv.tv_usec; + + struct timespec ts; + __clock_gettime (CLOCK_REALTIME, &ts); + TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts); ut->ut_type = DEAD_PROCESS; if (pututline (ut) != NULL) diff --git a/login/logwtmp.c b/login/logwtmp.c index 50d14976c7..ec41375383 100644 --- a/login/logwtmp.c +++ b/login/logwtmp.c @@ -36,10 +36,9 @@ logwtmp (const char *line, const char *name, const char *host) strncpy (ut.ut_name, name, sizeof ut.ut_name); strncpy (ut.ut_host, host, sizeof ut.ut_host); - struct timeval tv; - __gettimeofday (&tv, NULL); - ut.ut_tv.tv_sec = tv.tv_sec; - ut.ut_tv.tv_usec = tv.tv_usec; + struct timespec ts; + __clock_gettime (CLOCK_REALTIME, &ts); + TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts); updwtmp (_PATH_WTMP, &ut); } diff --git a/nis/nis_call.c b/nis/nis_call.c index a48ecc39a8..db81fa3568 100644 --- a/nis/nis_call.c +++ b/nis/nis_call.c @@ -709,6 +709,7 @@ __nisfind_server (const_nis_name name, int search_parent, nis_error status; directory_obj *obj; struct timeval now; + struct timespec ts; unsigned int server_used = ~0; unsigned int current_ep = ~0; @@ -718,7 +719,8 @@ __nisfind_server (const_nis_name name, int search_parent, if (*dir != NULL) return NIS_SUCCESS; - (void) gettimeofday (&now, NULL); + __clock_gettime (CLOCK_REALTIME, &ts); + TIMESPEC_TO_TIMEVAL (&now, &ts); if ((flags & NO_CACHE) == 0) *dir = nis_server_cache_search (name, search_parent, &server_used, diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c index 5224ee2110..f1b14266de 100644 --- a/nptl/pthread_join_common.c +++ b/nptl/pthread_join_common.c @@ -46,15 +46,14 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime) /* Repeat until thread terminated. */ while ((tid = *tidp) != 0) { - struct timeval tv; struct timespec rt; /* Get the current time. */ - __gettimeofday (&tv, NULL); + __clock_gettime (CLOCK_REALTIME, &rt); /* Compute relative timeout. */ - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; + rt.tv_sec = abstime->tv_sec - rt.tv_sec; + rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec; if (rt.tv_nsec < 0) { rt.tv_nsec += 1000000000; diff --git a/nptl/pthread_mutex_timedlock.c b/nptl/pthread_mutex_timedlock.c index 52c258e33d..2b194e5bee 100644 --- a/nptl/pthread_mutex_timedlock.c +++ b/nptl/pthread_mutex_timedlock.c @@ -567,15 +567,14 @@ __pthread_mutex_clocklock_common (pthread_mutex_t *mutex, goto failpp; } - struct timeval tv; struct timespec rt; /* Get the current time. */ - (void) __gettimeofday (&tv, NULL); + __clock_gettime (CLOCK_REALTIME, &rt); /* Compute relative timeout. */ - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; + rt.tv_sec = abstime->tv_sec - rt.tv_sec; + rt.tv_nsec = abstime->tv_nsec - rt.tv_nsec; if (rt.tv_nsec < 0) { rt.tv_nsec += 1000000000; diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c index 733c2a60cd..e12769ba03 100644 --- a/nscd/nscd_helper.c +++ b/nscd/nscd_helper.c @@ -59,9 +59,10 @@ wait_on_socket (int sock, long int usectmo) /* Handle the case where the poll() call is interrupted by a signal. We cannot just use TEMP_FAILURE_RETRY since it might lead to infinite loops. */ - struct timeval now; - (void) __gettimeofday (&now, NULL); - long int end = now.tv_sec * 1000 + usectmo + (now.tv_usec + 500) / 1000; + struct timespec now; + __clock_gettime (CLOCK_REALTIME, &now); + long int end = (now.tv_sec * 1000 + usectmo + + (now.tv_nsec + 500000) / 1000000); long int timeout = usectmo; while (1) { @@ -70,8 +71,9 @@ wait_on_socket (int sock, long int usectmo) break; /* Recompute the timeout time. */ - (void) __gettimeofday (&now, NULL); - timeout = end - (now.tv_sec * 1000 + (now.tv_usec + 500) / 1000); + __clock_gettime (CLOCK_REALTIME, &now); + timeout = end - ((now.tv_sec * 1000 + + (now.tv_nsec + 500000) / 1000000)); } } @@ -191,9 +193,7 @@ open_socket (request_type type, const char *key, size_t keylen) memcpy (reqdata->key, key, keylen); bool first_try = true; - struct timeval tvend; - /* Fake initializing tvend. */ - asm ("" : "=m" (tvend)); + struct timespec tvend = { 0, 0 }; while (1) { #ifndef MSG_NOSIGNAL @@ -212,18 +212,18 @@ open_socket (request_type type, const char *key, size_t keylen) /* The daemon is busy wait for it. */ int to; - struct timeval now; - (void) __gettimeofday (&now, NULL); + struct timespec now; + __clock_gettime (CLOCK_REALTIME, &now); if (first_try) { - tvend.tv_usec = now.tv_usec; + tvend.tv_nsec = now.tv_nsec; tvend.tv_sec = now.tv_sec + 5; to = 5 * 1000; first_try = false; } else to = ((tvend.tv_sec - now.tv_sec) * 1000 - + (tvend.tv_usec - now.tv_usec) / 1000); + + (tvend.tv_nsec - now.tv_nsec) / 1000000); struct pollfd fds[1]; fds[0].fd = sock; diff --git a/resolv/gai_misc.c b/resolv/gai_misc.c index 69d7086ae6..5d1e310147 100644 --- a/resolv/gai_misc.c +++ b/resolv/gai_misc.c @@ -357,13 +357,13 @@ handle_requests (void *arg) something to arrive in it. */ if (runp == NULL && optim.gai_idle_time >= 0) { - struct timeval now; + struct timespec now; struct timespec wakeup_time; ++idle_thread_count; - gettimeofday (&now, NULL); + __clock_gettime (CLOCK_REALTIME, &now); wakeup_time.tv_sec = now.tv_sec + optim.gai_idle_time; - wakeup_time.tv_nsec = now.tv_usec * 1000; + wakeup_time.tv_nsec = now.tv_nsec; if (wakeup_time.tv_nsec >= 1000000000) { wakeup_time.tv_nsec -= 1000000000; diff --git a/resolv/gai_suspend.c b/resolv/gai_suspend.c index eee3bcebe9..8f81e5a3dd 100644 --- a/resolv/gai_suspend.c +++ b/resolv/gai_suspend.c @@ -91,11 +91,11 @@ gai_suspend (const struct gaicb *const list[], int ent, { /* We have to convert the relative timeout value into an absolute time value with pthread_cond_timedwait expects. */ - struct timeval now; + struct timespec now; struct timespec abstime; - __gettimeofday (&now, NULL); - abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000; + __clock_gettime (CLOCK_REALTIME, &now); + abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec; abstime.tv_sec = timeout->tv_sec + now.tv_sec; if (abstime.tv_nsec >= 1000000000) { diff --git a/resolv/res_send.c b/resolv/res_send.c index ed27f3abf8..0cd35f99d7 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -172,12 +172,8 @@ evCmpTime(struct timespec a, struct timespec b) { static void evNowTime(struct timespec *res) { - struct timeval now; - - if (gettimeofday(&now, NULL) < 0) + if (__clock_gettime(CLOCK_REALTIME, res) < 0) evConsTime(res, 0, 0); - else - TIMEVAL_TO_TIMESPEC (&now, res); } diff --git a/sunrpc/auth_des.c b/sunrpc/auth_des.c index 5b6f985bc2..9079b30397 100644 --- a/sunrpc/auth_des.c +++ b/sunrpc/auth_des.c @@ -41,6 +41,7 @@ #include #include /* XXX: just to get htonl() and ntohl() */ #include +#include #include #define MILLION 1000000L @@ -246,15 +247,15 @@ authdes_marshal (AUTH *auth, XDR *xdrs) int status; int len; register int32_t *ixdr; - struct timeval tval; + struct timespec now; /* * Figure out the "time", accounting for any time difference * with the server if necessary. */ - __gettimeofday (&tval, (struct timezone *) NULL); - ad->ad_timestamp.tv_sec = tval.tv_sec + ad->ad_timediff.tv_sec; - ad->ad_timestamp.tv_usec = tval.tv_usec + ad->ad_timediff.tv_usec; + __clock_gettime (CLOCK_REALTIME, &now); + ad->ad_timestamp.tv_sec = now.tv_sec + ad->ad_timediff.tv_sec; + ad->ad_timestamp.tv_usec = (now.tv_nsec / 1000) + ad->ad_timediff.tv_usec; if (ad->ad_timestamp.tv_usec >= MILLION) { ad->ad_timestamp.tv_usec -= MILLION; @@ -445,21 +446,23 @@ authdes_destroy (AUTH *auth) static bool_t synchronize (struct sockaddr *syncaddr, struct rpc_timeval *timep) { - struct timeval mytime; + struct timespec mytime; struct rpc_timeval timeout; + long myusec; timeout.tv_sec = RTIME_TIMEOUT; timeout.tv_usec = 0; if (rtime ((struct sockaddr_in *) syncaddr, timep, &timeout) < 0) return FALSE; - __gettimeofday (&mytime, (struct timezone *) NULL); + __clock_gettime (CLOCK_REALTIME, &mytime); timep->tv_sec -= mytime.tv_sec; - if (mytime.tv_usec > timep->tv_usec) + myusec = mytime.tv_nsec / 1000; + if (myusec > timep->tv_usec) { timep->tv_sec -= 1; timep->tv_usec += MILLION; } - timep->tv_usec -= mytime.tv_usec; + timep->tv_usec -= myusec; return TRUE; } diff --git a/sunrpc/auth_unix.c b/sunrpc/auth_unix.c index b035fdd870..ff0d2eb933 100644 --- a/sunrpc/auth_unix.c +++ b/sunrpc/auth_unix.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ authunix_create (char *machname, uid_t uid, gid_t gid, int len, { struct authunix_parms aup; char mymem[MAX_AUTH_BYTES]; - struct timeval now; + struct timespec now; XDR xdrs; AUTH *auth; struct audata *au; @@ -122,7 +123,7 @@ no_memory: /* * fill in param struct from the given params */ - (void) __gettimeofday (&now, (struct timezone *) 0); + __clock_gettime (CLOCK_REALTIME, &now); aup.aup_time = now.tv_sec; aup.aup_machname = machname; aup.aup_uid = uid; @@ -276,7 +277,7 @@ authunix_refresh (AUTH *auth) { struct audata *au = AUTH_PRIVATE (auth); struct authunix_parms aup; - struct timeval now; + struct timespec now; XDR xdrs; int stat; @@ -297,7 +298,7 @@ authunix_refresh (AUTH *auth) goto done; /* update the time and serialize in place */ - (void) __gettimeofday (&now, (struct timezone *) 0); + __clock_gettime (CLOCK_REALTIME, &now); aup.aup_time = now.tv_sec; xdrs.x_op = XDR_ENCODE; XDR_SETPOS (&xdrs, 0); diff --git a/sunrpc/create_xid.c b/sunrpc/create_xid.c index a44187f07c..8d1e722dad 100644 --- a/sunrpc/create_xid.c +++ b/sunrpc/create_xid.c @@ -39,10 +39,10 @@ _create_xid (void) pid_t pid = getpid (); if (is_initialized != pid) { - struct timeval now; + struct timespec now; - __gettimeofday (&now, (struct timezone *) 0); - __srand48_r (now.tv_sec ^ now.tv_usec ^ pid, + __clock_gettime (CLOCK_REALTIME, &now); + __srand48_r (now.tv_sec ^ now.tv_nsec ^ pid, &__rpc_lrand48_data); is_initialized = pid; } diff --git a/sunrpc/svcauth_des.c b/sunrpc/svcauth_des.c index c5a512d6f8..7607abc818 100644 --- a/sunrpc/svcauth_des.c +++ b/sunrpc/svcauth_des.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -295,7 +296,11 @@ _svcauth_des (register struct svc_req *rqst, register struct rpc_msg *msg) debug ("timestamp before last seen"); return AUTH_REJECTEDVERF; /* replay */ } - __gettimeofday (¤t, (struct timezone *) NULL); + { + struct timespec now; + __clock_gettime (CLOCK_REALTIME, &now); + TIMESPEC_TO_TIMEVAL (¤t, &now); + } current.tv_sec -= window; /* allow for expiration */ if (!BEFORE (¤t, ×tamp)) { diff --git a/support/support_test_main.c b/support/support_test_main.c index 7e7b9edbb0..bc4502c030 100644 --- a/support/support_test_main.c +++ b/support/support_test_main.c @@ -88,16 +88,16 @@ static pid_t test_pid; static void (*cleanup_function) (void); static void -print_timestamp (const char *what, struct timeval tv) +print_timestamp (const char *what, struct timespec tv) { struct tm tm; if (gmtime_r (&tv.tv_sec, &tm) == NULL) printf ("%s: %lld.%06d\n", - what, (long long int) tv.tv_sec, (int) tv.tv_usec); + what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000); else printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n", what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec); + tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000); } /* Timeout handler. We kill the child and exit with an error. */ @@ -110,8 +110,8 @@ signal_handler (int sig) /* Do this first to avoid further interference from the subprocess. */ - struct timeval now; - bool now_available = gettimeofday (&now, NULL) == 0; + struct timespec now; + bool now_available = clock_gettime (CLOCK_REALTIME, &now) == 0; struct stat64 st; bool st_available = fstat64 (STDOUT_FILENO, &st) == 0 && st.st_mtime != 0; @@ -168,9 +168,7 @@ signal_handler (int sig) if (now_available) print_timestamp ("Termination time", now); if (st_available) - print_timestamp ("Last write to standard output", - (struct timeval) { st.st_mtim.tv_sec, - st.st_mtim.tv_nsec / 1000 }); + print_timestamp ("Last write to standard output", st.st_mtim); /* Exit with an error. */ exit (1); diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h index 480bdf79ee..c29feb8edd 100644 --- a/sysdeps/generic/memusage.h +++ b/sysdeps/generic/memusage.h @@ -26,14 +26,14 @@ #endif #ifndef GETTIME -# define GETTIME(low,high) \ - { \ - struct timeval tval; \ - uint64_t usecs; \ - gettimeofday (&tval, NULL); \ - usecs = (uint64_t) tval.tv_usec + (uint64_t) tval.tv_usec * 1000000; \ - low = usecs & 0xffffffff; \ - high = usecs >> 32; \ +# define GETTIME(low,high) \ + { \ + struct timespec now; \ + uint64_t usecs; \ + __clock_gettime (CLOCK_REALTIME, &now); \ + usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \ + low = usecs & 0xffffffff; \ + high = usecs >> 32; \ } #endif diff --git a/sysdeps/mach/hurd/getitimer.c b/sysdeps/mach/hurd/getitimer.c index 69a0751ead..6a0fc3cb0d 100644 --- a/sysdeps/mach/hurd/getitimer.c +++ b/sysdeps/mach/hurd/getitimer.c @@ -19,6 +19,7 @@ #include #include #include +#include /* XXX Temporary cheezoid implementation; see __setitmr.c. */ @@ -61,7 +62,7 @@ __getitimer (enum __itimer_which which, struct itimerval *value) } /* Get the time now. */ - if (__gettimeofday (&elapsed, NULL) < 0) + if (__host_get_time (__mach_host_self (), (time_value_t *) &elapsed) < 0) return -1; /* Extract the current timer setting; and the time it was set, so we can diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c index 61e37c5f5d..c829a5869b 100644 --- a/sysdeps/mach/hurd/setitimer.c +++ b/sysdeps/mach/hurd/setitimer.c @@ -23,6 +23,7 @@ #include #include #include +#include #include /* XXX Temporary cheezoid implementation of ITIMER_REAL/SIGALRM. */ @@ -239,7 +240,7 @@ setitimer_locked (const struct itimerval *new, struct itimerval *old, if ((newval.it_value.tv_sec | newval.it_value.tv_usec) != 0 || old != NULL) { /* Calculate how much time is remaining for the pending alarm. */ - if (__gettimeofday (&now, NULL) < 0) + if (__host_get_time (__mach_host_self (), (time_value_t *) &now) < 0) { __spin_unlock (&_hurd_itimer_lock); _hurd_critical_section_unlock (crit); diff --git a/sysdeps/mach/hurd/times.c b/sysdeps/mach/hurd/times.c index 7758311d83..aafa7b15d9 100644 --- a/sysdeps/mach/hurd/times.c +++ b/sysdeps/mach/hurd/times.c @@ -42,7 +42,7 @@ __times (struct tms *tms) struct task_basic_info bi; struct task_thread_times_info tti; mach_msg_type_number_t count; - union { time_value_t tvt; struct timeval tv; } now; + time_value_t now; error_t err; count = TASK_BASIC_INFO_COUNT; @@ -65,10 +65,10 @@ __times (struct tms *tms) /* XXX This can't be implemented until getrusage(RUSAGE_CHILDREN) can be. */ tms->tms_cutime = tms->tms_cstime = 0; - if (__gettimeofday (&now.tv, NULL) < 0) + if (__host_get_time (__mach_host_self (), &now) < 0) return -1; - return (clock_from_time_value (&now.tvt) + return (clock_from_time_value (&now) - clock_from_time_value (&bi.creation_time)); } weak_alias (__times, times) diff --git a/sysdeps/mach/nanosleep.c b/sysdeps/mach/nanosleep.c index b4790aaf31..0be48db0d9 100644 --- a/sysdeps/mach/nanosleep.c +++ b/sysdeps/mach/nanosleep.c @@ -18,16 +18,26 @@ #include #include -#include #include #include +# define timespec_sub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_nsec = (a)->tv_nsec - (b)->tv_nsec; \ + if ((result)->tv_nsec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_nsec += 1000000000; \ + } \ + } while (0) + int __libc_nanosleep (const struct timespec *requested_time, - struct timespec *remaining) + struct timespec *remaining) { mach_port_t recv; - struct timeval before, after; + struct timespec before, after; + error_t err; if (requested_time->tv_sec < 0 || requested_time->tv_nsec < 0 @@ -43,20 +53,19 @@ __libc_nanosleep (const struct timespec *requested_time, recv = __mach_reply_port (); - if (remaining && __gettimeofday (&before, NULL) < 0) + if (remaining && __clock_gettime (CLOCK_REALTIME, &before) < 0) return -1; - error_t err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, - 0, 0, recv, ms, MACH_PORT_NULL); + + err = __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, + 0, 0, recv, ms, MACH_PORT_NULL); __mach_port_destroy (mach_task_self (), recv); if (err == EMACH_RCV_INTERRUPTED) { - if (remaining && __gettimeofday (&after, NULL) >= 0) + if (remaining && __clock_gettime (CLOCK_REALTIME, &after) >= 0) { - struct timeval req_time, elapsed, rem; - TIMESPEC_TO_TIMEVAL (&req_time, requested_time); - timersub (&after, &before, &elapsed); - timersub (&req_time, &elapsed, &rem); - TIMEVAL_TO_TIMESPEC (&rem, remaining); + struct timespec elapsed; + timespec_sub (&after, &before, &elapsed); + timespec_sub (requested_time, &elapsed, remaining); } errno = EINTR; diff --git a/sysdeps/mach/usleep.c b/sysdeps/mach/usleep.c index 5d4bd205e1..8428ace6ef 100644 --- a/sysdeps/mach/usleep.c +++ b/sysdeps/mach/usleep.c @@ -25,17 +25,12 @@ int usleep (useconds_t useconds) { mach_port_t recv; - struct timeval before, after; recv = __mach_reply_port (); - if (__gettimeofday (&before, NULL) < 0) - return -1; (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, 0, 0, recv, (useconds + 999) / 1000, MACH_PORT_NULL); __mach_port_destroy (mach_task_self (), recv); - if (__gettimeofday (&after, NULL) < 0) - return -1; return 0; } diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 310df3c4ca..c3956498ce 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -50,7 +50,7 @@ #include #include -#include +#include #include #include @@ -63,7 +63,6 @@ # define struct_stat64 struct stat # define __gen_tempname gen_tempname # define __getpid getpid -# define __gettimeofday gettimeofday # define __mkdir mkdir # define __open open # define __lxstat64(version, file, buf) lstat (file, buf) @@ -76,9 +75,9 @@ # else # define RANDOM_BITS(Var) \ { \ - struct timeval tv; \ - __gettimeofday (&tv, NULL); \ - (Var) = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \ + struct timespec ts; \ + clock_gettime (CLOCK_REALTIME, &ts); \ + (Var) = ((uint64_t) tv.tv_nsec << 16) ^ tv.tv_sec; \ } #endif diff --git a/sysdeps/pthread/aio_misc.c b/sysdeps/pthread/aio_misc.c index 0180ddb3c3..49ab08de3a 100644 --- a/sysdeps/pthread/aio_misc.c +++ b/sysdeps/pthread/aio_misc.c @@ -614,13 +614,13 @@ handle_fildes_io (void *arg) something to arrive in it. */ if (runp == NULL && optim.aio_idle_time >= 0) { - struct timeval now; + struct timespec now; struct timespec wakeup_time; ++idle_thread_count; - __gettimeofday (&now, NULL); + __clock_gettime (CLOCK_REALTIME, &now); wakeup_time.tv_sec = now.tv_sec + optim.aio_idle_time; - wakeup_time.tv_nsec = now.tv_usec * 1000; + wakeup_time.tv_nsec = now.tv_nsec; if (wakeup_time.tv_nsec >= 1000000000) { wakeup_time.tv_nsec -= 1000000000; diff --git a/sysdeps/pthread/aio_suspend.c b/sysdeps/pthread/aio_suspend.c index 06bd914672..fdd4087abb 100644 --- a/sysdeps/pthread/aio_suspend.c +++ b/sysdeps/pthread/aio_suspend.c @@ -183,11 +183,11 @@ aio_suspend (const struct aiocb *const list[], int nent, { /* We have to convert the relative timeout value into an absolute time value with pthread_cond_timedwait expects. */ - struct timeval now; + struct timespec now; struct timespec abstime; - __gettimeofday (&now, NULL); - abstime.tv_nsec = timeout->tv_nsec + now.tv_usec * 1000; + __clock_gettime (CLOCK_REALTIME, &now); + abstime.tv_nsec = timeout->tv_nsec + now.tv_nsec; abstime.tv_sec = timeout->tv_sec + now.tv_sec; if (abstime.tv_nsec >= 1000000000) { From patchwork Tue Aug 20 13:21:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 1150140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104577-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Ow0QdlqM"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CWfk59vRz9s00 for ; Tue, 20 Aug 2019 23:22:06 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=qWoYXHENohmRXR/MJYj4aaTMckhY/5VqG9AhCDkxKKq yhnYIb6N/5YbbxMrhrCXIwo4kuSCFVob3EJjrM943vlWeypO5Cj1X05IXDgrIatn 4vgvweJddhT5gUOOUyR8MHSC70RkFWb9XBi5AexwU1rck3zp6TDjgVA50eqkcktE = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=6HLA61Dt5T7R/He9i4FFhs9fza0=; b=Ow0QdlqMJ0vvZwv7b myZNRSmCRCYJVZEhwdVvQj3MRCuYBy8noud6hqBV9MCQRpIH7b0Ccp2KNI02WbYB kosS3KuDIFpVuAW15aIkahAPRqLUTtn9j3L8nCUVJVpnWI9qoz0uT5yGb0rnevn5 3FUxGbCbmFG4aeGn6IQhxntDGw= Received: (qmail 48066 invoked by alias); 20 Aug 2019 13:21:58 -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 48058 invoked by uid 89); 20 Aug 2019 13:21:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=day, HContent-Transfer-Encoding:8bit 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 03/12] =?utf-8?q?Don=E2=80=99t_use_the_argument_to_time=2E?= Date: Tue, 20 Aug 2019 09:21:43 -0400 Message-Id: <20190820132152.24100-4-zackw@panix.com> In-Reply-To: <20190820132152.24100-1-zackw@panix.com> References: <20190820132152.24100-1-zackw@panix.com> MIME-Version: 1.0 Unlike gettimeofday, I don’t think it makes sense to remove all the internal uses of time. Its callers don’t care about sub-second resolution and would be unnecessarily complicated if they had to declare a struct timespec instead of just a time_t. However, a handful of places were using the vestigial ‘result’ argument instead of the return value, which is ever so slightly less efficient and also looks weird. Correct this. * misc/syslog.c (__vsyslog_internal) * time/getdate.c (__getdate_r) * time/tst_wcsftime.c (main): Use return value of time, not its argument. * string/strfry.c (strfry) * sysdeps/mach/sleep.c (__sleep): Remove unnecessary casts of NULL. Reviewed-by: Adhemerval Zanella --- misc/syslog.c | 2 +- string/strfry.c | 2 +- sysdeps/mach/sleep.c | 4 ++-- time/getdate.c | 2 +- time/tst_wcsftime.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/misc/syslog.c b/misc/syslog.c index 3a15da41ce..cf2deef533 100644 --- a/misc/syslog.c +++ b/misc/syslog.c @@ -205,7 +205,7 @@ __vsyslog_internal(int pri, const char *fmt, va_list ap, { __fsetlocking (f, FSETLOCKING_BYCALLER); fprintf (f, "<%d>", pri); - (void) time (&now); + now = time (NULL); f->_IO_write_ptr += __strftime_l (f->_IO_write_ptr, f->_IO_write_end - f->_IO_write_ptr, diff --git a/string/strfry.c b/string/strfry.c index af6087bee5..71686d45c2 100644 --- a/string/strfry.c +++ b/string/strfry.c @@ -30,7 +30,7 @@ strfry (char *string) { static char state[32]; rdata.state = NULL; - __initstate_r (time ((time_t *) NULL) ^ getpid (), + __initstate_r (time (NULL) ^ getpid (), state, sizeof (state), &rdata); init = 1; } diff --git a/sysdeps/mach/sleep.c b/sysdeps/mach/sleep.c index 11e1bb87f3..c63ef926b7 100644 --- a/sysdeps/mach/sleep.c +++ b/sysdeps/mach/sleep.c @@ -33,10 +33,10 @@ __sleep (unsigned int seconds) recv = __mach_reply_port (); - before = time ((time_t *) NULL); + before = time (NULL); (void) __mach_msg (NULL, MACH_RCV_MSG|MACH_RCV_TIMEOUT|MACH_RCV_INTERRUPT, 0, 0, recv, seconds * 1000, MACH_PORT_NULL); - after = time ((time_t *) NULL); + after = time (NULL); __mach_port_destroy (__mach_task_self (), recv); return seconds - (after - before); diff --git a/time/getdate.c b/time/getdate.c index aee96f7163..8a567c3fcd 100644 --- a/time/getdate.c +++ b/time/getdate.c @@ -219,7 +219,7 @@ __getdate_r (const char *string, struct tm *tp) return 7; /* Get current time. */ - time (&timer); + timer = time (NULL); __localtime_r (&timer, &tm); /* If only the weekday is given, today is assumed if the given day diff --git a/time/tst_wcsftime.c b/time/tst_wcsftime.c index 3f6f0d9f77..55c45f6a81 100644 --- a/time/tst_wcsftime.c +++ b/time/tst_wcsftime.c @@ -10,7 +10,7 @@ main (int argc, char *argv[]) int result = 0; size_t n; - time (&t); + t = time (NULL); tp = gmtime (&t); n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]), From patchwork Tue Aug 20 13:21:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 1150141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104578-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="x+R8hdAA"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CWfv1Cgsz9sML for ; Tue, 20 Aug 2019 23:22:14 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=L1NHjwFf4wOhuA59v6fP98wR3sjrtH8yrJBxZKGOtsm ieNxB3mdtpZKxxPuAyvr/HZ3jljVvjRSboDgBYlfnxfm7NZS89bjuD0Q5Y/qCfNB mN5p/9MxYXWhoo6ROWAS2LwTLDUrlhyLhUTA9eAUiPs6mjGClbytMBCPwDeusOUI = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=99+OPdWSObWBfXX/u84boRUkl8U=; b=x+R8hdAAuqWGz3YVf Lx3UPb58IiXt30QCZAA4kL+NcgXMjhpT/U+DqtjbQsPOSeens+7oyyQw3SsGalS0 NlSBtBPZ7Fmctc+O50zzIDfQjhY4/C6AnQvejiv+b2jnWgdg46BcOSl5g/zcHVIh 5/JcvkqfBstgEWUx5Pgpk1WeV8= Received: (qmail 48159 invoked by alias); 20 Aug 2019 13:21:59 -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 48078 invoked by uid 89); 20 Aug 2019 13:21:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 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= 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 04/12] Use clock_settime to implement stime. Date: Tue, 20 Aug 2019 09:21:44 -0400 Message-Id: <20190820132152.24100-5-zackw@panix.com> In-Reply-To: <20190820132152.24100-1-zackw@panix.com> References: <20190820132152.24100-1-zackw@panix.com> MIME-Version: 1.0 Unconditionally, on all ports, use clock_settime to implement stime, not settimeofday or a direct syscall. Note that the former stub implementation of stime would return -1 with errno set to EINVAL if passed a null pointer. With this change, it instead unconditionally dereferences the pointer, so any hypothetical callers that passed NULL will now segfault. I don’t think this will break any non-contrived programs. * time/stime.c (stime): No longer a stub implementation. Call __clock_settime. * sysdeps/unix/stime.c: Delete file. * sysdeps/unix/sysv/linux/syscalls.list: Remove entry for stime. * include/time.h: Add libc_hidden_proto for __clock_settime. * rt/clock_settime.c, sysdeps/unix/sysv/linux/clock_settime.c: Add libc_hidden_def for __clock_settime. Reviewed-by: Adhemerval Zanella --- include/time.h | 1 + rt/clock_settime.c | 1 + sysdeps/unix/stime.c | 39 ------------------------- sysdeps/unix/sysv/linux/clock_settime.c | 1 + sysdeps/unix/sysv/linux/syscalls.list | 1 - time/stime.c | 15 +++------- 6 files changed, 7 insertions(+), 51 deletions(-) delete mode 100644 sysdeps/unix/stime.c diff --git a/include/time.h b/include/time.h index ac3163c2a5..c0421c7a28 100644 --- a/include/time.h +++ b/include/time.h @@ -22,6 +22,7 @@ extern __typeof (clock_getres) __clock_getres; extern __typeof (clock_gettime) __clock_gettime; libc_hidden_proto (__clock_gettime) extern __typeof (clock_settime) __clock_settime; +libc_hidden_proto (__clock_settime) extern __typeof (clock_nanosleep) __clock_nanosleep; extern __typeof (clock_getcpuclockid) __clock_getcpuclockid; diff --git a/rt/clock_settime.c b/rt/clock_settime.c index 891925ab2c..9c4f4fbc10 100644 --- a/rt/clock_settime.c +++ b/rt/clock_settime.c @@ -26,5 +26,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) __set_errno (ENOSYS); return -1; } +libc_hidden_def (__clock_settime) weak_alias (__clock_settime, clock_settime) stub_warning (clock_settime) diff --git a/sysdeps/unix/stime.c b/sysdeps/unix/stime.c deleted file mode 100644 index b0809be400..0000000000 --- a/sysdeps/unix/stime.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1992-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 /* For NULL. */ -#include -#include - -/* Set the system clock to *WHEN. */ - -int -stime (const time_t *when) -{ - struct timeval tv; - - if (when == NULL) - { - __set_errno (EINVAL); - return -1; - } - - tv.tv_sec = *when; - tv.tv_usec = 0; - return __settimeofday (&tv, (struct timezone *) 0); -} diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index d837e3019c..ef1512cc91 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -34,4 +34,5 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) return INLINE_SYSCALL_CALL (clock_settime, clock_id, tp); } +libc_hidden_def (__clock_settime) weak_alias (__clock_settime, clock_settime) diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index e374f97b5f..f6cb655e2c 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -62,7 +62,6 @@ setfsgid EXTRA setfsgid i:i setfsgid setfsuid EXTRA setfsuid i:i setfsuid setpgid - setpgid i:ii __setpgid setpgid sigaltstack - sigaltstack i:PP __sigaltstack sigaltstack -stime - stime i:p stime sysinfo EXTRA sysinfo i:p __sysinfo sysinfo swapon - swapon i:si __swapon swapon swapoff - swapoff i:s __swapoff swapoff diff --git a/time/stime.c b/time/stime.c index de58c49562..b4d692ca32 100644 --- a/time/stime.c +++ b/time/stime.c @@ -15,23 +15,16 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include /* Set the system clock to *WHEN. */ int stime (const time_t *when) { - if (when == NULL) - { - __set_errno (EINVAL); - return -1; - } + struct timespec ts; + ts.tv_sec = *when; + ts.tv_nsec = 0; - __set_errno (ENOSYS); - return -1; + return __clock_settime (CLOCK_REALTIME, &ts); } - -stub_warning (stime) From patchwork Tue Aug 20 13:21:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 1150144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-104581-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=panix.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="fyLJVj3Z"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CWgW32jfz9s00 for ; Tue, 20 Aug 2019 23:22:47 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=yoOm+4maYUfDMqokQJBSvvt8XfGb9kqeSLp2nbKIQjT jhOkOO1QDHCCPPl6APMfGeO+zl0NH/akMwYztGnWKN0AJhRllcRt6bifi7X9YN8e iXWG/1lI12w9+R0p5Yx6jMP7dlP6sYOAcWMqweSEipnLoJJ58cQK8McZqlc9E9Aw = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=Vo8+otMWOMf9u4SpV6BfkeMZuRo=; b=fyLJVj3Zu7exNruwU 9d3vu1uk0bT92j5xcNHIFxppK+TZ5TKCw2sStc39TxSr/B9jfJ4dQbFopKAUH6Zw oD00X0XzdT2V/+BDT9zY1TDRrP4oaOBe5+Lg6Qm7LSt0LPDM2K/o4xy85/8vG8g/ JvUlRUdHWXaL3wkMsWQoY3LDe8= Received: (qmail 48545 invoked by alias); 20 Aug 2019 13:22:02 -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 48410 invoked by uid 89); 20 Aug 2019 13:22:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=shutdown, era X-HELO: l2mail1.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 05/12] Use clock_settime to implement settimeofday. Date: Tue, 20 Aug 2019 09:21:45 -0400 Message-Id: <20190820132152.24100-6-zackw@panix.com> In-Reply-To: <20190820132152.24100-1-zackw@panix.com> References: <20190820132152.24100-1-zackw@panix.com> MIME-Version: 1.0 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. --- include/sys/time.h | 3 +- sysdeps/unix/syscalls.list | 1 - .../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(-) create mode 100644 sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c create mode 100644 sysdeps/unix/sysv/linux/settimezone.c create mode 100644 time/settimezone.c diff --git a/include/sys/time.h b/include/sys/time.h index 7ba0ca7c2d..a57752e8c7 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 61e5360b4d..5fedd5733d 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 0000000000..a61fcab482 --- /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 0000000000..36a6901e4e --- /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