From owner-cvs-all Tue Jan 5 06:32:49 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id GAA20679 for cvs-all-outgoing; Tue, 5 Jan 1999 06:32:49 -0800 (PST) (envelope-from owner-cvs-all@FreeBSD.ORG) Received: from niobe.ewox.org (ppp108.uio.no [129.240.240.113]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA20670 for ; Tue, 5 Jan 1999 06:32:45 -0800 (PST) (envelope-from des@niobe.ewox.org) Received: (from des@localhost) by niobe.ewox.org (8.9.1/8.9.1) id PAA11831; Tue, 5 Jan 1999 15:28:08 +0100 (CET) (envelope-from des) To: cvs-committers@FreeBSD.ORG Subject: sysctl(3) From: Dag-Erling Smorgrav Date: 05 Jan 1999 15:28:08 +0100 Message-ID: <86d84tztdz.fsf@niobe.ewox.org> Lines: 84 X-Mailer: Gnus v5.3/Emacs 19.34 Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk 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