https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=0674c2aa588c85b162e399ab691c53d3d52433d0 commit 0674c2aa588c85b162e399ab691c53d3d52433d0 Author: Zack Weinberg Date: Fri Aug 16 15:03:16 2019 -0400 Use clock_settime to implement stime. Similarly to the previous patch: use clock_settime to implement stime, not settimeofday or a direct syscall. This applies unconditionally to all ports. 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. Diff: --- 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(-) diff --git a/include/time.h b/include/time.h index ac3163c..c0421c7 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 891925a..9c4f4fb 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 b0809be..0000000 --- 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 d837e30..ef1512c 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 e374f97..f6cb655 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 de58c49..b4d692c 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)