From patchwork Fri Oct 25 12:08:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 177736 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3602583ill; Fri, 25 Oct 2019 05:09:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7GUB6QEtsP0RTG/aihFoa/hLFDzL4Truidlb9TdYtnoR/mVm0Cn+rRMSOgJPvDM2NEzIy X-Received: by 2002:a05:6402:21d6:: with SMTP id bi22mr3493244edb.19.1572005392197; Fri, 25 Oct 2019 05:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572005392; cv=none; d=google.com; s=arc-20160816; b=GhL6kX09k3knmrNPMuv/Y7LD301D4uJa/dUtNYw/4Vz6yK5YtC9zg/58TUor1OsGvi AKWT/oc8gHI3n6YGH/ADgDoay6I1d8fVAtwaY8kfnf6ephmKCYEUVWqKix4NkR4QACTM ZGDNlk8j5p1I1gBdH3ccdyzkU+UcXWr69sNMHNNxP4z9W9UYKinWwdAXWYGjnZrd73hl A9fPZhEXWBpJdd06O2Sq2MCUrnXp/vo8m8ZAN8RTwZV7z7Ju7g7mbhJISP24gsIe513o EU3HCeO7VE7KLK1PY3JDyQQ9b+JzOaQtB/Hdifw+6QtRiivw3FZfSOS4GS4zRvRQRFS6 hqwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=27hDrog4+twgSWKgM/faGX3uQpqarOtDmQrLHSbvgK0=; b=0JDze6t8VjS5pv0MbfI1dQ2e9m5wPfempDI0Zeo7D56G4fBTUlgTfNXPfVxpKEqxq9 D+zILeUzdAZ38DSZxLpZn9dHClzsz1SKxmLplWWGiLSPkOz/8u4ejepgEKaRHx0SscWW 7qJIiTezqAFzIp2jiRiNoWyfN0iwSlL6iEI49uwfx70DlmL0SCNGnumAr5tlMLdlnDt/ WLU5jgzWKEGCTfNcxU7bP765uvbI4llHpwIwo6dsjIjvCgFQ3Lf2Mwy08z4A1Av7Lb1S 8c7eeW0VM6/Ql+0RsqQMMyhhpJjPdoVEo0oXYh7FWpwvkx6JZKqx8BAmivH9NSaD0bo0 j0CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=H1bQC+jR; dkim=pass header.i=@linaro.org header.s=google header.b=VfxFL58S; spf=pass (google.com: domain of libc-alpha-return-106286-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106286-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id j24si1028615edt.259.2019.10.25.05.09.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Oct 2019 05:09:52 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-106286-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=H1bQC+jR; dkim=pass header.i=@linaro.org header.s=google header.b=VfxFL58S; spf=pass (google.com: domain of libc-alpha-return-106286-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-106286-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=UdbJF5hQ5ca4fNbCHRohy0+99E7a4nCwg53RJfWUdyx KtZpJnU/JEgVxcgEVJJ5K2PmMZWAQo1AvPVDMyP1Trl0dtbvvPcRwL3Qgrh9Bv3k KGFkFTduSczEzwA8WrxxpZZ65EztHEFFOtwhDwRUxMpIeqasKZoxWn9LayQz8g/U = 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=lL2VbeFn5PflmjnsOg5528z/i7A=; b=H1bQC+jRV+JBh+uck fmyFBuHCxHNB1hwrL9OQei7rqH18W4IN553IyJMFkuxmh+Ba99n1yS2HQZ5/4/co d3qznpoHx5GsWmJaeAY5ygaLh370LAxDxLc5rVkkmFMw5gMtqJKPLhNXAJi0eRjH WXKDz2//WHE4nNzrRAtUz+b5oc= Received: (qmail 77739 invoked by alias); 25 Oct 2019 12:08:56 -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 77647 invoked by uid 89); 25 Oct 2019 12:08:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=shutdown, prepared, accident X-HELO: mail-qk1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=27hDrog4+twgSWKgM/faGX3uQpqarOtDmQrLHSbvgK0=; b=VfxFL58Szq9lJe15+g5NpKJo/FKghyroNmvI+lr+cP87iIBkDxX7sWI5o0mlT7ptjJ yqnowDpKY8498nfJUQWfy5D/OxhhGRoWPLWNtzFIYq0mmEsDMhGd8G1Q/I3gdldBwG/H Q87fETWjZyGns8ZckdM/2GvbwfA22nfdCiPX9K4Sowx7Z2wD81K90Bq+7pht9VhJpcw7 VDp6a5njT8gmYGsHeV0bOnIEOcHHd+4MNsZYh+pvJLZquaWh0c/5KqBjq62KeU4HNwlz RKHMlUil1RhxTQnpfIkPEleoIskI72L6kxJq9LwPEe7lH5rZ1iIm+pG1ILLBShl0nhTw E8HA== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Lukasz Majewski , Zack Weinberg Subject: [PATCH v2 04/11] Use clock_settime to implement settimeofday. Date: Fri, 25 Oct 2019 09:08:25 -0300 Message-Id: <20191025120832.27667-5-adhemerval.zanella@linaro.org> In-Reply-To: <20191025120832.27667-1-adhemerval.zanella@linaro.org> References: <20191025120832.27667-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 From: Zack Weinberg Use clock_settime to implement settimeofday. Changes from previous version: - Added a NEWS entry. -- Unconditionally, on all ports, use clock_settime to implement settimeofday. Remove sysdeps/unix/clock_settime.c, which implemented clock_settime by calling settimeofday; new OS ports must henceforth provide a real implementation of clock_settime. Hurd had a real implementation of settimeofday but not of clock_settime; this patch converts it into an implementation of clock_settime. It only supports CLOCK_REALTIME and microsecond resolution; Hurd/Mach does not appear to have any support for finer-resolution clocks. The vestigial "set time zone" feature of settimeofday complicates the generic settimeofday implementation a little. 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). There currently isn't any other way to do this. However, the callers that do this 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. The settimeoday syscall is enabled on Linux by the flag COMPAT_32BIT_TIME, which is an option to either 32-bits ABIs or COMPAT builds (defined usually by 64-bit kernels that want to support 32-bit ABIs, such as x86). The idea to future 64-bit time_t only ABIs is to not provide settimeofday syscall. The same semantics are implemented for Linux/Alpha's GLIBC_2.0 compat symbol for settimeofday. There are no longer any internal callers of __settimeofday, so the internal prototype is removed. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu. Reviewed-by: Adhemerval Zanella --- NEWS | 24 +++++++++ include/sys/time.h | 3 +- sysdeps/{unix => mach/hurd}/clock_settime.c | 51 ++++++++----------- sysdeps/unix/syscalls.list | 1 - .../unix/sysv/linux/alpha/osf_settimeofday.c | 16 ++++-- sysdeps/unix/sysv/linux/alpha/settimeofday.c | 22 ++++++++ sysdeps/unix/sysv/linux/alpha/syscalls.list | 1 - sysdeps/unix/sysv/linux/settimezone.c | 36 +++++++++++++ time/Makefile | 8 +-- time/settimeofday.c | 24 +++++++-- .../hurd/settimeofday.c => time/settimezone.c | 34 ++----------- 11 files changed, 147 insertions(+), 73 deletions(-) rename sysdeps/{unix => mach/hurd}/clock_settime.c (65%) create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c create mode 100644 sysdeps/unix/sysv/linux/settimezone.c rename sysdeps/mach/hurd/settimeofday.c => time/settimezone.c (52%) -- 2.17.1 Reviewed-by: Lukasz Majewski diff --git a/NEWS b/NEWS index 8727b5e7f0..0b1476e745 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,30 @@ Deprecated and removed features, and other changes affecting compatibility: binaries and it has been removed from header. This function has been deprecated in favor of clock_settime. +* The settimeofday function can still be used to set a system-wide time + zone when the operating system supports it. This is because the Linux + kernel reused the API, on some architectures, to describe a system-wide + time-zone-like offset between the software clock maintained by the kernel, + and the “RTC” clock that keeps time when the system is shut down. + + However, to reduce the odds of this offset being set by accident, + settimeofday can no longer be used to set the time and the offset + simultaneously. If both of its two arguments are non-null, the call + will fail (setting errno to EINVAL). + + Callers attempting to set this offset should also be prepared for the call + to fail and set errno to ENOSYS; this already happens on the Hurd and on + some Linux architectures. The Linux kernel maintainers are discussing a + more principled replacement for the reused API. After a replacement + becomes available, we will change settimeofday to fail with ENOSYS on all + platforms when its ‘tzp’ argument is not a null pointer. + + Note that settimeofday itself is obsolescent according to POSIX. + Programs that set the system time should use clock_settime and/or + the adjtime family of functions instead. We may also cease to make + settimeofday available to newly linked binaries after there is a + replacement for Linux’s time-zone-like offset API. + Changes to build and runtime requirements: [Add changes to build and runtime requirements here] diff --git a/include/sys/time.h b/include/sys/time.h index 57208afa82..c0e30e70fb 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/clock_settime.c b/sysdeps/mach/hurd/clock_settime.c similarity index 65% rename from sysdeps/unix/clock_settime.c rename to sysdeps/mach/hurd/clock_settime.c index 18d7c99864..02239c097a 100644 --- a/sysdeps/unix/clock_settime.c +++ b/sysdeps/mach/hurd/clock_settime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1999-2019 Free Software Foundation, Inc. +/* Copyright (C) 1991-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 @@ -17,38 +17,31 @@ #include #include -#include +#include +#include #include -/* Set CLOCK to value TP. */ +/* Set the current time of day. + This call is restricted to the super-user. */ int -__clock_settime (clockid_t clock_id, const struct timespec *tp) +__clock_settime (clockid_t clock_id, const struct timespec *ts) { - 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; + error_t err; + mach_port_t hostpriv; + time_value_t tv; + + if (clock_id != CLOCK_REALTIME) + return __hurd_fail (EINVAL); + + err = __get_privileged_ports (&hostpriv, NULL); + if (err) + return __hurd_fail (EPERM); + + TIMESPEC_TO_TIME_VALUE (&tv, ts); + err = __host_set_time (hostpriv, tv); + __mach_port_deallocate (__mach_task_self (), hostpriv); + + return __hurd_fail (err); } libc_hidden_def (__clock_settime) 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 index fb2a36df19..914f5ac57b 100644 --- a/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c +++ b/sysdeps/unix/sysv/linux/alpha/osf_settimeofday.c @@ -32,9 +32,19 @@ attribute_compat_text_section __settimeofday_tv32 (const struct timeval32 *tv32, const struct timezone *tz) { - struct timeval tv; - tv32_to_tv64 (&tv, tv32); - return __settimeofday (&tv, tz); + if (__glibc_unlikely (tz != 0)) + { + if (tv32 != 0) + { + __set_errno (EINVAL); + return -1; + } + return __settimezone (tz); + } + + struct timespec ts; + tv32_to_ts64 (&ts, tv32); + return __clock_settime (CLOCK_REALTIME, &ts); } compat_symbol (libc, __settimeofday_tv32, settimeofday, GLIBC_2_0); 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