Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Jul 2015 16:55:57 +0000 (UTC)
From:      Patrick Kelsey <pkelsey@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r285604 - stable/10/lib/libc/gen
Message-ID:  <201507151655.t6FGtvJx059189@svnmir.geo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pkelsey
Date: Wed Jul 15 16:55:56 2015
New Revision: 285604
URL: https://svnweb.freebsd.org/changeset/base/285604

Log:
  MFC r285188:
  
  Fix sysctl(3) so it returns the intended values for all mib names in
  the 'user' sysctl tree, which have all been coming back 0 or empty
  since r240176.
  
  Approved by: re

Modified:
  stable/10/lib/libc/gen/sysctl.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/gen/sysctl.c
==============================================================================
--- stable/10/lib/libc/gen/sysctl.c	Wed Jul 15 16:47:13 2015	(r285603)
+++ stable/10/lib/libc/gen/sysctl.c	Wed Jul 15 16:55:56 2015	(r285604)
@@ -51,9 +51,21 @@ sysctl(const int *name, u_int namelen, v
     const void *newp, size_t newlen)
 {
 	int retval;
+	size_t orig_oldlen;
 
+	orig_oldlen = oldlenp ? *oldlenp : 0;
 	retval = __sysctl(name, namelen, oldp, oldlenp, newp, newlen);
-	if (retval != -1 || errno != ENOENT || name[0] != CTL_USER)
+	/*
+	 * All valid names under CTL_USER have a dummy entry in the sysctl
+	 * tree (to support name lookups and enumerations) with an
+	 * empty/zero value, and the true value is supplied by this routine.
+	 * For all such names, __sysctl() is used solely to validate the
+	 * name.
+	 *
+	 * Return here unless there was a successful lookup for a CTL_USER
+	 * name.
+	 */
+	if (retval || name[0] != CTL_USER)
 		return (retval);
 
 	if (newp != NULL) {
@@ -67,7 +79,7 @@ sysctl(const int *name, u_int namelen, v
 
 	switch (name[1]) {
 	case USER_CS_PATH:
-		if (oldp && *oldlenp < sizeof(_PATH_STDPATH)) {
+		if (oldp && orig_oldlen < sizeof(_PATH_STDPATH)) {
 			errno = ENOMEM;
 			return -1;
 		}



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