summaryrefslogtreecommitdiff
path: root/src/time
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2013-06-08 11:36:41 -0400
committerRich Felker <dalias@aerifal.cx>2013-06-08 11:36:41 -0400
commitea200e38bd79723054c7ad97cbf87911eac5b7f5 (patch)
treeb4e065a5ed23be930dcf3ca33cf08d3f9a7ce023 /src/time
parent0996faa3d789dd69e4c1c022757f0623908b0df5 (diff)
downloadmusl-ea200e38bd79723054c7ad97cbf87911eac5b7f5.tar.gz
support cputime clocks for processes/threads other than self
apparently these features have been in Linux for a while now, so it makes sense to support them. the bit twiddling seems utterly illogical and wasteful, especially the negation, but that's how the kernel folks chose to encode pids/tids into the clock id.
Diffstat (limited to 'src/time')
-rw-r--r--src/time/clock_getcpuclockid.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/time/clock_getcpuclockid.c b/src/time/clock_getcpuclockid.c
index 723840b0..8a0e2d4c 100644
--- a/src/time/clock_getcpuclockid.c
+++ b/src/time/clock_getcpuclockid.c
@@ -5,7 +5,10 @@
int clock_getcpuclockid(pid_t pid, clockid_t *clk)
{
- if (pid && pid != getpid()) return EPERM;
- *clk = CLOCK_PROCESS_CPUTIME_ID;
+ struct timespec ts;
+ clockid_t id = (-pid-1)*8U + 2;
+ int ret = __syscall(SYS_clock_getres, id, &ts);
+ if (ret) return -ret;
+ *clk = id;
return 0;
}