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: 34184 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)