From 5e0724b3f9dc9edc66648b427bc4f4c3ceaecc38 Mon Sep 17 00:00:00 2001 From: njoly Date: Sat, 4 Mar 2017 11:16:33 +0000 Subject: [PATCH] Fix {clock,pthread}_getcpuclockid to return an error number on failure, to match OpenGroup specifications. --- lib/libc/sys/clock_getcpuclockid.c | 14 +++++++++++--- lib/libc/sys/clock_getcpuclockid2.2 | 19 +++++++------------ lib/libpthread/pthread_getcpuclockid.3 | 9 +++------ lib/libpthread/pthread_getcpuclockid.c | 14 +++++++++++--- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/libc/sys/clock_getcpuclockid.c b/lib/libc/sys/clock_getcpuclockid.c index 3c5cec3af796..39a9cd1295ff 100644 --- a/lib/libc/sys/clock_getcpuclockid.c +++ b/lib/libc/sys/clock_getcpuclockid.c @@ -1,4 +1,4 @@ -/* $NetBSD: clock_getcpuclockid.c,v 1.1 2016/04/23 23:11:31 christos Exp $ */ +/* $NetBSD: clock_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -30,14 +30,22 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: clock_getcpuclockid.c,v 1.1 2016/04/23 23:11:31 christos Exp $"); +__RCSID("$NetBSD: clock_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $"); #endif /* LIBC_SCCS and not lint */ #include +#include #include int clock_getcpuclockid(pid_t pid, clockid_t *clock_id) { - return clock_getcpuclockid2(P_PID, (id_t)pid, clock_id); + int error = 0, saved_errno; + + saved_errno = errno; + if (clock_getcpuclockid2(P_PID, (id_t)pid, clock_id) == -1) + error = errno; + errno = saved_errno; + + return error; } diff --git a/lib/libc/sys/clock_getcpuclockid2.2 b/lib/libc/sys/clock_getcpuclockid2.2 index 85380581544b..78bc56c597bc 100644 --- a/lib/libc/sys/clock_getcpuclockid2.2 +++ b/lib/libc/sys/clock_getcpuclockid2.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: clock_getcpuclockid2.2,v 1.2 2016/04/24 08:59:30 wiz Exp $ +.\" $NetBSD: clock_getcpuclockid2.2,v 1.3 2017/03/04 11:16:33 njoly Exp $ .\" .\" Copyright (c) 2016 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 23, 2016 +.Dd March 3, 2017 .Dt CLOCK_GETCPUCLOCKID2 2 .Os .Sh NAME @@ -81,17 +81,12 @@ function can be used with the returned .Fa clock_id to retrieve process and LWP times. .Sh RETURN VALUES -The +.Rv -std clock_getcpuclockid2 +.Pp +If successful, the .Fn clock_getcpuclockid -and -.Fn clock_getcpuclockid2 -functions succeed and return 0, placing the requested -.Fa clock_id -in the argument. -On error, the value \-1 is returned -and the value of -.Va errno -is set to reflect what went wrong. +function will return 0. +Otherwise an error number will be returned. .Sh ERRORS These functions fail if: .Bl -tag -width Er diff --git a/lib/libpthread/pthread_getcpuclockid.3 b/lib/libpthread/pthread_getcpuclockid.3 index 73dce9ba2c9e..950ca9455622 100644 --- a/lib/libpthread/pthread_getcpuclockid.3 +++ b/lib/libpthread/pthread_getcpuclockid.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: pthread_getcpuclockid.3,v 1.3 2016/04/24 09:01:45 wiz Exp $ +.\" $NetBSD: pthread_getcpuclockid.3,v 1.4 2017/03/04 11:16:33 njoly Exp $ .\" .\" Copyright (c) 2016 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 23, 2016 +.Dd March 3, 2017 .Dt PTHREAD_GETCPUCLOCKID 3 .Os .Sh NAME @@ -58,10 +58,7 @@ On success the function returns 0, placing the requested .Fa clock_id in the argument. -On error, the value \-1 is returned -and the value of -.Va errno -is set to reflect what went wrong. +Otherwise an error number will be returned. .Sh ERRORS These functions fail if: .Bl -tag -width Er diff --git a/lib/libpthread/pthread_getcpuclockid.c b/lib/libpthread/pthread_getcpuclockid.c index 38d372221394..79c868f1b454 100644 --- a/lib/libpthread/pthread_getcpuclockid.c +++ b/lib/libpthread/pthread_getcpuclockid.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $ */ +/* $NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -30,10 +30,11 @@ */ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp $"); +__RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.2 2017/03/04 11:16:33 njoly Exp $"); #endif /* LIBC_SCCS and not lint */ #include +#include #include #include @@ -42,5 +43,12 @@ __RCSID("$NetBSD: pthread_getcpuclockid.c,v 1.1 2016/04/23 23:12:19 christos Exp int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id) { - return clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id); + int error = 0, saved_errno; + + saved_errno = errno; + if (clock_getcpuclockid2(P_LWPID, (id_t)thread->pt_lid, clock_id) == -1) + error = errno; + errno = saved_errno; + + return error; }