Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib Fix {clock, pthread}_getcpuclockid to return an error num...



details:   https://anonhg.NetBSD.org/src/rev/4841aa7c3d00
branches:  trunk
changeset: 822147:4841aa7c3d00
user:      njoly <njoly%NetBSD.org@localhost>
date:      Sat Mar 04 11:16:33 2017 +0000

description:
Fix {clock,pthread}_getcpuclockid to return an error number on
failure, to match OpenGroup specifications.

diffstat:

 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(-)

diffs (141 lines):

diff -r f40462f4d322 -r 4841aa7c3d00 lib/libc/sys/clock_getcpuclockid.c
--- a/lib/libc/sys/clock_getcpuclockid.c        Sat Mar 04 01:29:27 2017 +0000
+++ b/lib/libc/sys/clock_getcpuclockid.c        Sat Mar 04 11:16:33 2017 +0000
@@ -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 <sys/cdefs.h>
 #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 <sys/types.h>
+#include <errno.h>
 #include <time.h>
 
 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 -r f40462f4d322 -r 4841aa7c3d00 lib/libc/sys/clock_getcpuclockid2.2
--- a/lib/libc/sys/clock_getcpuclockid2.2       Sat Mar 04 01:29:27 2017 +0000
+++ b/lib/libc/sys/clock_getcpuclockid2.2       Sat Mar 04 11:16:33 2017 +0000
@@ -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 @@
 .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 -r f40462f4d322 -r 4841aa7c3d00 lib/libpthread/pthread_getcpuclockid.3
--- a/lib/libpthread/pthread_getcpuclockid.3    Sat Mar 04 01:29:27 2017 +0000
+++ b/lib/libpthread/pthread_getcpuclockid.3    Sat Mar 04 11:16:33 2017 +0000
@@ -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 @@
 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 -r f40462f4d322 -r 4841aa7c3d00 lib/libpthread/pthread_getcpuclockid.c
--- a/lib/libpthread/pthread_getcpuclockid.c    Sat Mar 04 01:29:27 2017 +0000
+++ b/lib/libpthread/pthread_getcpuclockid.c    Sat Mar 04 11:16:33 2017 +0000
@@ -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 <sys/cdefs.h>
 #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 <sys/types.h>
+#include <errno.h>
 #include <pthread.h>
 #include <time.h>
 
@@ -42,5 +43,12 @@
 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;
 }



Home | Main Index | Thread Index | Old Index