tech-kern archive

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

Re: {clock,pthread}_getcpuclockid return values



On Mon, Feb 27, 2017 at 08:58:55PM +0000, Christos Zoulas wrote:
> In article <20170227153935.GA9153%issan.sis.pasteur.fr@localhost>,
> Nicolas Joly  <njoly%pasteur.fr@localhost> wrote:
> >
> >Hi,
> >
> >Checking the Opengroup online specifications, i noticed that both
> >clock_getcpuclockid[1] and pthread_getcpuclockid[2] should return 0 on
> >success and an error number otherwise. But our implementation does not
> >follow that and returns -1 and set errno on failure. Both functions
> >are wrappers around clock_getcpuclockid2 syscall.
> >
> >Unless there is a specific reason for this behaviour, we'll have to
> >fix them for follow the standard ... but where. Both wrappers, or the
> >underling syscall ?
> >
> >Thanks.
> >
> >[1]
> >http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getcpuclockid.html
> >[2]
> >http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getcpuclockid.html
> 
> I am torn; on one side making it NOERR makes clock_getcpuclockid
> and clock_getcpuclockid2 returns consistent, but the NOERR syscalls
> are inconsistent amongst themselves (for some non-zero returns means
> error, others return values that need more examination to see if it
> was an error, and some can never return an error). These fall in the
> first category, so it is not a big deal.
> 
> You choose :-)

Here is a patch, for review, that fix them on the wrapper side ... I
prefer keeping the never failing syscalls as an exception.

I'll do a second pass later on the man pages as ERRORS section seems
wrong. clock_getcpuclockid2 can fail with EFAULT (copyout) or EINVAL
(invalid idtype); but wrappers have valid fixed idtype argument
leaving only EFAULT.

Thanks.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
Index: lib/libc/sys/clock_getcpuclockid.c
===================================================================
RCS file: /cvsroot/src/lib/libc/sys/clock_getcpuclockid.c,v
retrieving revision 1.1
diff -u -p -r1.1 clock_getcpuclockid.c
--- lib/libc/sys/clock_getcpuclockid.c	23 Apr 2016 23:11:31 -0000	1.1
+++ lib/libc/sys/clock_getcpuclockid.c	3 Mar 2017 07:38:03 -0000
@@ -34,10 +34,18 @@ __RCSID("$NetBSD: clock_getcpuclockid.c,
 #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;
 }
Index: lib/libc/sys/clock_getcpuclockid2.2
===================================================================
RCS file: /cvsroot/src/lib/libc/sys/clock_getcpuclockid2.2,v
retrieving revision 1.2
diff -u -p -r1.2 clock_getcpuclockid2.2
--- lib/libc/sys/clock_getcpuclockid2.2	24 Apr 2016 08:59:30 -0000	1.2
+++ lib/libc/sys/clock_getcpuclockid2.2	3 Mar 2017 07:38:03 -0000
@@ -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
Index: lib/libpthread/pthread_getcpuclockid.3
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_getcpuclockid.3,v
retrieving revision 1.3
diff -u -p -r1.3 pthread_getcpuclockid.3
--- lib/libpthread/pthread_getcpuclockid.3	24 Apr 2016 09:01:45 -0000	1.3
+++ lib/libpthread/pthread_getcpuclockid.3	3 Mar 2017 07:38:03 -0000
@@ -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
Index: lib/libpthread/pthread_getcpuclockid.c
===================================================================
RCS file: /cvsroot/src/lib/libpthread/pthread_getcpuclockid.c,v
retrieving revision 1.1
diff -u -p -r1.1 pthread_getcpuclockid.c
--- lib/libpthread/pthread_getcpuclockid.c	23 Apr 2016 23:12:19 -0000	1.1
+++ lib/libpthread/pthread_getcpuclockid.c	3 Mar 2017 07:38:03 -0000
@@ -34,6 +34,7 @@ __RCSID("$NetBSD: pthread_getcpuclockid.
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
+#include <errno.h>
 #include <pthread.h>
 #include <time.h>
 
@@ -42,5 +43,12 @@ __RCSID("$NetBSD: pthread_getcpuclockid.
 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