clock_nanosleep: add CLOCK_THREAD_CPUTIME_ID special case

POSIX makes "the CPU-time clock of the calling thread" (i.e.,
CLOCK_THREAD_CPUTIME_ID) a special case which returns EINVAL instead of
ENOTSUP.

However, the clock_nanosleep syscall treats this clock just like any
other, and returns -EOPNOTSUPP to indicate an unimplemented nanosleep
handler.  So we need to handle this ourselves in userspace.

This change fixes the LTP clock_nanosleep01 testcase.

Change-Id: If3bed940d276834bcd114d8c17f96197e9384711
Signed-off-by: Greg Hackmann <ghackmann@google.com>
This commit is contained in:
Greg Hackmann 2016-03-26 11:37:55 -07:00
parent 7c59c70200
commit d15dfb2ff5
2 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,8 @@
extern "C" int ___clock_nanosleep(clockid_t, int, const timespec*, timespec*);
int clock_nanosleep(clockid_t clock_id, int flags, const timespec* in, timespec* out) {
if (clock_id == CLOCK_THREAD_CPUTIME_ID) return EINVAL;
ErrnoRestorer errno_restorer;
return (___clock_nanosleep(clock_id, flags, in, out) == 0) ? 0 : errno;
}

View File

@ -573,3 +573,10 @@ TEST(time, clock_nanosleep) {
timespec out;
ASSERT_EQ(EINVAL, clock_nanosleep(-1, 0, &in, &out));
}
TEST(time, clock_nanosleep_thread_cputime_id) {
timespec in;
in.tv_sec = 1;
in.tv_nsec = 0;
ASSERT_EQ(EINVAL, clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, 0, &in, nullptr));
}