This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 04/12] Use clock_settime to implement stime.
- From: Zack Weinberg <zackw at panix dot com>
- To: libc-alpha at sourceware dot org
- Cc: Joseph Myers <joseph at codesourcery dot com>, Florian Weimer <fweimer at redhat dot com>, Lukasz Majewski <lukma at denx dot de>, Alistair Francis <alistair23 at gmail dot com>, Stepan Golosunov <stepan at golosunov dot pp dot ru>, Arnd Bergmann <arnd at arndb dot de>
- Date: Tue, 20 Aug 2019 09:21:44 -0400
- Subject: [PATCH 04/12] Use clock_settime to implement stime.
- References: <20190820132152.24100-1-zackw@panix.com>
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.
---
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
- <http://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <stddef.h> /* For NULL. */
-#include <sys/time.h>
-#include <time.h>
-
-/* 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
<http://www.gnu.org/licenses/>. */
-#include <errno.h>
#include <time.h>
-#include <stddef.h>
/* 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)
--
2.23.0.rc1