about summary refs log tree commit diff
path: root/src/time
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-21 01:53:14 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-27 02:46:57 -0400
commit331993e3fc3623f111d95796d3d7f30b4f6552c1 (patch)
treee17e0f0717b1f2ac3e49491d171934e5056566b7 /src/time
parent0ce49d0a301b4142741b32773492af90f66ed3ca (diff)
downloadmusl-331993e3fc3623f111d95796d3d7f30b4f6552c1.tar.gz
musl-331993e3fc3623f111d95796d3d7f30b4f6552c1.tar.xz
musl-331993e3fc3623f111d95796d3d7f30b4f6552c1.zip
refactor thrd_sleep and nanosleep in terms of clock_nanosleep
for namespace-safety with thrd_sleep, this requires an alias, which is
also added. this eliminates all but one direct call point for
nanosleep syscalls, and arranges that 64-bit time_t conversion logic
will only need to exist in one file rather than three.

as a bonus, clock_nanosleep with CLOCK_REALTIME and empty flags is now
implemented as SYS_nanosleep, thereby working on older kernels that
may lack POSIX clocks functionality.
Diffstat (limited to 'src/time')
-rw-r--r--src/time/clock_nanosleep.c10
-rw-r--r--src/time/nanosleep.c2
2 files changed, 8 insertions, 4 deletions
diff --git a/src/time/clock_nanosleep.c b/src/time/clock_nanosleep.c
index 32f0c07e..1174f510 100644
--- a/src/time/clock_nanosleep.c
+++ b/src/time/clock_nanosleep.c
@@ -2,8 +2,12 @@
 #include <errno.h>
 #include "syscall.h"
 
-int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
+int __clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem)
 {
-	int r = -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem);
-	return clk == CLOCK_THREAD_CPUTIME_ID ? EINVAL : r;
+	if (clk == CLOCK_THREAD_CPUTIME_ID) return EINVAL;
+	if (clk == CLOCK_REALTIME && !flags)
+		return -__syscall_cp(SYS_nanosleep, req, rem);
+	return -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem);
 }
+
+weak_alias(__clock_nanosleep, clock_nanosleep);
diff --git a/src/time/nanosleep.c b/src/time/nanosleep.c
index 1e6f3922..bc9f7895 100644
--- a/src/time/nanosleep.c
+++ b/src/time/nanosleep.c
@@ -3,5 +3,5 @@
 
 int nanosleep(const struct timespec *req, struct timespec *rem)
 {
-	return syscall_cp(SYS_nanosleep, req, rem);
+	return __syscall_ret(-__clock_nanosleep(CLOCK_REALTIME, 0, req, rem));
 }