From owner-svn-src-head@freebsd.org Mon Jul 6 01:42:14 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C6DEE99A2; Mon, 6 Jul 2015 01:42:14 +0000 (UTC) (envelope-from pkelsey@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9C34311E9; Mon, 6 Jul 2015 01:42:14 +0000 (UTC) (envelope-from pkelsey@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t661gDRg001585; Mon, 6 Jul 2015 01:42:13 GMT (envelope-from pkelsey@FreeBSD.org) Received: (from pkelsey@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t661gDMi001581; Mon, 6 Jul 2015 01:42:13 GMT (envelope-from pkelsey@FreeBSD.org) Message-Id: <201507060142.t661gDMi001581@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pkelsey set sender to pkelsey@FreeBSD.org using -f From: Patrick Kelsey Date: Mon, 6 Jul 2015 01:42:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285188 - head/lib/libc/gen X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Jul 2015 01:42:14 -0000 Author: pkelsey Date: Mon Jul 6 01:42:12 2015 New Revision: 285188 URL: https://svnweb.freebsd.org/changeset/base/285188 Log: 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. Differential Revision: https://reviews.freebsd.org/D2945 Reviewed by: sbruno Approved by: jmallett (mentor) MFC after: 3 days Modified: head/lib/libc/gen/sysctl.c Modified: head/lib/libc/gen/sysctl.c ============================================================================== --- head/lib/libc/gen/sysctl.c Sun Jul 5 23:24:52 2015 (r285187) +++ head/lib/libc/gen/sysctl.c Mon Jul 6 01:42:12 2015 (r285188) @@ -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; }