Skip site navigation (1)Skip section navigation (2)
Date:      05 Jan 1999 15:28:08 +0100
From:      Dag-Erling Smorgrav <des@flood.ping.uio.no>
To:        cvs-committers@FreeBSD.ORG
Subject:   sysctl(3)
Message-ID:  <86d84tztdz.fsf@niobe.ewox.org>

next in thread | raw e-mail | index | archive | help
I'm about to commit the attached patch to src/libc/gen/sysctl.c, which
makes sysctl(3) behave as documented (i.e. set errno and return -1).
If anyone knows of live code that relies on its current (buggy)
behaviour, please fix it or let me know so I can fix it.

Note that the sysctl syscall still returns the error code directly
instead of setting errno. Apart from sysctl(3), only IBCS2 and libmsun
use it directly. IBCS2 expects it to behave as it currently does,
while libmsun expects it to behave as it does not (but should?):

(from src/lib/msun/src/get_hw_float.c)

	if (__sysctl(mib, 2, &hw_float, &len, (void *)0, 0) == -1)
		hw_float = 0;	/* shouldn't happen; assume the worst */

The test should be != 0 instead of == -1, or the sysctl syscall should
be fixed to return -1 and set errno instead of returning the error
directly.

DES
-- 
Dag-Erling Smørgrav - des@flood.ping.uio.no

Index: sysctl.3
===================================================================
RCS file: /home/ncvs/src/lib/libc/gen/sysctl.3,v
retrieving revision 1.23
diff -u -r1.23 sysctl.3
--- sysctl.3	1998/09/29 05:16:45	1.23
+++ sysctl.3	1999/01/05 14:05:58
@@ -669,6 +669,8 @@
 .Sh RETURN VALUES
 If the call to
 .Fn sysctl
+or
+.Fn sysctlbyname
 is successful, the number of bytes copied out is returned.
 Otherwise \-1 is returned and
 .Va errno
Index: sysctl.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/gen/sysctl.c,v
retrieving revision 1.2
diff -u -r1.2 sysctl.c
--- sysctl.c	1995/10/22 14:37:05	1.2
+++ sysctl.c	1999/01/05 14:03:54
@@ -52,8 +52,10 @@
 	void *oldp, *newp;
 	size_t *oldlenp, newlen;
 {
-	if (name[0] != CTL_USER)
-		return (__sysctl(name, namelen, oldp, oldlenp, newp, newlen));
+	if (name[0] != CTL_USER) {
+		errno = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
+		return (errno ? -1 : 0);
+	}
 
 	if (newp != NULL) {
 		errno = EPERM;
@@ -66,16 +68,20 @@
 
 	switch (name[1]) {
 	case USER_CS_PATH:
-		if (oldp && *oldlenp < sizeof(_PATH_STDPATH))
-			return (ENOMEM);
+		if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) {
+			errno = ENOMEM;
+			return -1;
+		}
 		*oldlenp = sizeof(_PATH_STDPATH);
 		if (oldp != NULL)
 			memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH));
 		return (0);
 	}
 
-	if (oldp && *oldlenp < sizeof(int))
-		return (ENOMEM);
+	if (oldp && *oldlenp < sizeof(int)) {
+		errno = ENOMEM;
+		return (-1);
+	}
 	*oldlenp = sizeof(int);
 	if (oldp == NULL)
 		return (0);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86d84tztdz.fsf>