Fri Sep 30 06:16:47 2016 UTC ()
Be consistent about returning -1 on error. Don't return random errnos
instead.


(dholland)
diff -r1.11 -r1.12 src/lib/libc/gen/sysctlgetmibinfo.c

cvs diff -r1.11 -r1.12 src/lib/libc/gen/sysctlgetmibinfo.c (expand / switch to unified diff)

--- src/lib/libc/gen/sysctlgetmibinfo.c 2014/05/16 12:22:32 1.11
+++ src/lib/libc/gen/sysctlgetmibinfo.c 2016/09/30 06:16:47 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sysctlgetmibinfo.c,v 1.11 2014/05/16 12:22:32 martin Exp $ */ 1/* $NetBSD: sysctlgetmibinfo.c,v 1.12 2016/09/30 06:16:47 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003,2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003,2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Brown. 8 * by Andrew Brown.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.11 2014/05/16 12:22:32 martin Exp $"); 34__RCSID("$NetBSD: sysctlgetmibinfo.c,v 1.12 2016/09/30 06:16:47 dholland Exp $");
35#endif /* LIBC_SCCS and not lint */ 35#endif /* LIBC_SCCS and not lint */
36 36
37#ifndef RUMP_ACTION 37#ifndef RUMP_ACTION
38#include "namespace.h" 38#include "namespace.h"
39#ifdef _REENTRANT 39#ifdef _REENTRANT
40#include "reentrant.h" 40#include "reentrant.h"
41#endif /* _REENTRANT */ 41#endif /* _REENTRANT */
42#endif /* RUMP_ACTION */ 42#endif /* RUMP_ACTION */
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/sysctl.h> 44#include <sys/sysctl.h>
45 45
46#include <assert.h> 46#include <assert.h>
47#include <errno.h> 47#include <errno.h>
@@ -411,40 +411,47 @@ sysctlgetmibinfo_unlocked(const char *gn @@ -411,40 +411,47 @@ sysctlgetmibinfo_unlocked(const char *gn
411 struct sysctlnode *pnode, *node; 411 struct sysctlnode *pnode, *node;
412 int name[CTL_MAXNAME], n, haven; 412 int name[CTL_MAXNAME], n, haven;
413 u_int ni, nl; 413 u_int ni, nl;
414 intmax_t q; 414 intmax_t q;
415 char sep[2], token[SYSCTL_NAMELEN], 415 char sep[2], token[SYSCTL_NAMELEN],
416 pname[SYSCTL_NAMELEN * CTL_MAXNAME + CTL_MAXNAME]; 416 pname[SYSCTL_NAMELEN * CTL_MAXNAME + CTL_MAXNAME];
417 const char *piece, *dot; 417 const char *piece, *dot;
418 char *t; 418 char *t;
419 size_t l; 419 size_t l;
420 420
421 if (rnode != NULL) { 421 if (rnode != NULL) {
422 if (*rnode == NULL) { 422 if (*rnode == NULL) {
423 /* XXX later deal with dealing back a sub version */ 423 /* XXX later deal with dealing back a sub version */
424 if (v != SYSCTL_VERSION) 424 if (v != SYSCTL_VERSION) {
425 return (EINVAL); 425 errno = EINVAL;
 426 return -1;
 427 }
426 428
427 pnode = &sysctl_mibroot; 429 pnode = &sysctl_mibroot;
428 } 430 }
429 else { 431 else {
430 /* this is just someone being silly */ 432 /* this is just someone being silly */
431 if (SYSCTL_VERS((*rnode)->sysctl_flags) != (uint32_t)v) 433 if (SYSCTL_VERS((*rnode)->sysctl_flags)
432 return (EINVAL); 434 != (uint32_t)v) {
 435 errno = EINVAL;
 436 return -1;
 437 }
433 438
434 /* XXX later deal with other people's trees */ 439 /* XXX later deal with other people's trees */
435 if (SYSCTL_VERS((*rnode)->sysctl_flags) != 440 if (SYSCTL_VERS((*rnode)->sysctl_flags) !=
436 SYSCTL_VERSION) 441 SYSCTL_VERSION) {
437 return (EINVAL); 442 errno = EINVAL;
 443 return -1;
 444 }
438 445
439 pnode = *rnode; 446 pnode = *rnode;
440 } 447 }
441 } 448 }
442 else 449 else
443 pnode = &sysctl_mibroot; 450 pnode = &sysctl_mibroot;
444 451
445 if (pnode == &sysctl_mibroot) 452 if (pnode == &sysctl_mibroot)
446 relearnhead(); 453 relearnhead();
447 454
448 nl = ni = 0; 455 nl = ni = 0;
449 token[0] = '\0'; 456 token[0] = '\0';
450 pname[0] = '\0'; 457 pname[0] = '\0';