3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char copyright[] =
32 "@(#) Copyright (c) 1993\n\
33 The Regents of the University of California. All rights reserved.\n";
38 static char sccsid[] = "@(#)from: sysctl.c 8.1 (Berkeley) 6/6/93";
40 static const char rcsid[] =
44 #include <sys/param.h>
46 #include <sys/resource.h>
48 #include <sys/sysctl.h>
49 #include <sys/vmmeter.h>
50 #include <dev/evdev/input.h>
54 #include <machine/metadata.h>
57 #if defined(__amd64__) || defined(__i386__)
58 #include <machine/pc/bios.h>
74 static const char *conffile;
76 static int aflag, bflag, Bflag, dflag, eflag, hflag, iflag;
77 static int Nflag, nflag, oflag, qflag, tflag, Tflag, Wflag, xflag;
79 static int oidfmt(int *, int, char *, u_int *);
80 static int parsefile(const char *);
81 static int parse(const char *, int);
82 static int show_var(int *, int);
83 static int sysctl_all(int *oid, int len);
84 static int name2oid(const char *, int *);
86 static int strIKtoi(const char *, char **, const char *);
88 static int ctl_sign[CTLTYPE+1] = {
97 static int ctl_size[CTLTYPE+1] = {
98 [CTLTYPE_INT] = sizeof(int),
99 [CTLTYPE_UINT] = sizeof(u_int),
100 [CTLTYPE_LONG] = sizeof(long),
101 [CTLTYPE_ULONG] = sizeof(u_long),
102 [CTLTYPE_S8] = sizeof(int8_t),
103 [CTLTYPE_S16] = sizeof(int16_t),
104 [CTLTYPE_S32] = sizeof(int32_t),
105 [CTLTYPE_S64] = sizeof(int64_t),
106 [CTLTYPE_U8] = sizeof(uint8_t),
107 [CTLTYPE_U16] = sizeof(uint16_t),
108 [CTLTYPE_U32] = sizeof(uint32_t),
109 [CTLTYPE_U64] = sizeof(uint64_t),
112 static const char *ctl_typename[CTLTYPE+1] = {
113 [CTLTYPE_INT] = "integer",
114 [CTLTYPE_UINT] = "unsigned integer",
115 [CTLTYPE_LONG] = "long integer",
116 [CTLTYPE_ULONG] = "unsigned long",
117 [CTLTYPE_U8] = "uint8_t",
118 [CTLTYPE_U16] = "uint16_t",
119 [CTLTYPE_U32] = "uint32_t",
120 [CTLTYPE_U64] = "uint64_t",
121 [CTLTYPE_S8] = "int8_t",
122 [CTLTYPE_S16] = "int16_t",
123 [CTLTYPE_S32] = "int32_t",
124 [CTLTYPE_S64] = "int64_t",
125 [CTLTYPE_NODE] = "node",
126 [CTLTYPE_STRING] = "string",
127 [CTLTYPE_OPAQUE] = "opaque",
134 (void)fprintf(stderr, "%s\n%s\n",
135 "usage: sysctl [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
136 " sysctl [-bdehNnoqTtWx] [ -B <bufsize> ] -a");
141 main(int argc, char **argv)
146 setlocale(LC_NUMERIC, "");
150 while ((ch = getopt(argc, argv, "AabB:def:hiNnoqtTwWxX")) != -1) {
163 Bflag = strtol(optarg, NULL, 0);
221 if (aflag && argc == 0)
222 exit(sysctl_all(0, 0));
223 if (argc == 0 && conffile == NULL)
227 if (conffile != NULL)
228 warncount += parsefile(conffile);
231 warncount += parse(*argv++, 0);
237 * Parse a single numeric value, append it to 'newbuf', and update
238 * 'newsize'. Returns true if the value was parsed and false if the
239 * value was invalid. Non-numeric types (strings) are handled
240 * directly in parse().
243 parse_numeric(const char *newvalstr, const char *fmt, u_int kind,
244 void **newbufp, size_t *newsizep)
255 unsigned int uintval;
257 unsigned long ulongval;
265 switch (kind & CTLTYPE) {
267 if (strncmp(fmt, "IK", 2) == 0)
268 intval = strIKtoi(newvalstr, &endptr, fmt);
270 intval = (int)strtol(newvalstr, &endptr, 0);
272 valsize = sizeof(intval);
275 uintval = (int) strtoul(newvalstr, &endptr, 0);
277 valsize = sizeof(uintval);
280 longval = strtol(newvalstr, &endptr, 0);
282 valsize = sizeof(longval);
285 ulongval = strtoul(newvalstr, &endptr, 0);
287 valsize = sizeof(ulongval);
290 i8val = (int8_t)strtol(newvalstr, &endptr, 0);
292 valsize = sizeof(i8val);
295 i16val = (int16_t)strtol(newvalstr, &endptr, 0);
297 valsize = sizeof(i16val);
300 i32val = (int32_t)strtol(newvalstr, &endptr, 0);
302 valsize = sizeof(i32val);
305 i64val = strtoimax(newvalstr, &endptr, 0);
307 valsize = sizeof(i64val);
310 u8val = (uint8_t)strtoul(newvalstr, &endptr, 0);
312 valsize = sizeof(u8val);
315 u16val = (uint16_t)strtoul(newvalstr, &endptr, 0);
317 valsize = sizeof(u16val);
320 u32val = (uint32_t)strtoul(newvalstr, &endptr, 0);
322 valsize = sizeof(u32val);
325 u64val = strtoumax(newvalstr, &endptr, 0);
327 valsize = sizeof(u64val);
334 if (errno != 0 || endptr == newvalstr ||
335 (endptr != NULL && *endptr != '\0'))
338 newbuf = realloc(*newbufp, *newsizep + valsize);
340 err(1, "out of memory");
341 memcpy((char *)newbuf + *newsizep, newval, valsize);
343 *newsizep += valsize;
349 * Parse a name into a MIB entry.
350 * Lookup and print out the MIB entry if it exists.
351 * Set a new value if requested.
354 parse(const char *string, int lineno)
358 char *newvalstr = NULL;
360 size_t newsize = Bflag;
361 int mib[CTL_MAXNAME];
362 char *cp, *bufp, buf[BUFSIZ], fmt[BUFSIZ], line[BUFSIZ];
366 snprintf(line, sizeof(line), " at line %d", lineno);
371 if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ) {
372 warnx("oid too long: '%s'%s", string, line);
375 bufp = strsep(&cp, "=:");
377 /* Tflag just lists tunables, do not allow assignment */
378 if (Tflag || Wflag) {
379 warnx("Can't set variables when using -T or -W");
384 /* Strip a pair of " or ' if any. */
388 if (cp[strlen(cp) - 1] == *cp)
389 cp[strlen(cp) - 1] = '\0';
393 newsize = strlen(cp);
396 cp = bufp + strlen(bufp) - 1;
397 while (cp >= bufp && isspace((int)*cp)) {
401 len = name2oid(bufp, mib);
409 if (errno == ENOENT) {
410 warnx("unknown oid '%s'%s", bufp, line);
412 warn("unknown oid '%s'%s", bufp, line);
418 if (oidfmt(mib, len, fmt, &kind)) {
419 warn("couldn't find format of oid '%s'%s", bufp, line);
426 if (newvalstr == NULL || dflag) {
427 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
429 i = show_var(mib, len);
433 sysctl_all(mib, len);
435 i = show_var(mib, len);
440 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
441 warnx("oid '%s' isn't a leaf node%s", bufp, line);
445 if (!(kind & CTLFLAG_WR)) {
446 if (kind & CTLFLAG_TUN) {
447 warnx("oid '%s' is a read only tunable%s", bufp, line);
448 warnx("Tunable values are set in /boot/loader.conf");
450 warnx("oid '%s' is read only%s", bufp, line);
454 switch (kind & CTLTYPE) {
467 if (strlen(newvalstr) == 0) {
468 warnx("empty numeric value");
475 warnx("oid '%s' is type %d,"
476 " cannot set that%s", bufp,
477 kind & CTLTYPE, line);
483 switch (kind & CTLTYPE) {
489 while ((cp = strsep(&newvalstr, " ,")) != NULL) {
492 if (!parse_numeric(cp, fmt, kind, &newbuf,
494 warnx("invalid %s '%s'%s",
495 ctl_typename[kind & CTLTYPE],
505 i = show_var(mib, len);
506 if (sysctl(mib, len, 0, 0, newval, newsize) == -1) {
512 warnx("%s: value is not available%s",
516 warnx("%s: specification is incomplete%s",
520 warnx("%s: type is unknown to this program%s",
524 warn("%s%s", string, line);
533 j = show_var(mib, len);
543 parsefile(const char *filename)
546 char line[BUFSIZ], *p, *pq, *pdq;
547 int warncount = 0, lineno = 0;
549 file = fopen(filename, "r");
551 err(EX_NOINPUT, "%s", filename);
552 while (fgets(line, sizeof(line), file) != NULL) {
555 pq = strchr(line, '\'');
556 pdq = strchr(line, '\"');
557 /* Replace the first # with \0. */
558 while((p = strchr(p, '#')) != NULL) {
559 if (pq != NULL && p > pq) {
560 if ((p = strchr(pq+1, '\'')) != NULL)
563 } else if (pdq != NULL && p > pdq) {
564 if ((p = strchr(pdq+1, '\"')) != NULL)
567 } else if (p == line || *(p-1) != '\\') {
574 p = line + strlen(line) - 1;
575 while (p >= line && isspace((int)*p)) {
580 while (isspace((int)*p))
585 warncount += parse(p, lineno);
592 /* These functions will dump out various interesting structures. */
595 S_clockinfo(size_t l2, void *p)
597 struct clockinfo *ci = (struct clockinfo*)p;
599 if (l2 != sizeof(*ci)) {
600 warnx("S_clockinfo %zu != %zu", l2, sizeof(*ci));
603 printf(hflag ? "{ hz = %'d, tick = %'d, profhz = %'d, stathz = %'d }" :
604 "{ hz = %d, tick = %d, profhz = %d, stathz = %d }",
605 ci->hz, ci->tick, ci->profhz, ci->stathz);
610 S_loadavg(size_t l2, void *p)
612 struct loadavg *tv = (struct loadavg*)p;
614 if (l2 != sizeof(*tv)) {
615 warnx("S_loadavg %zu != %zu", l2, sizeof(*tv));
618 printf(hflag ? "{ %'.2f %'.2f %'.2f }" : "{ %.2f %.2f %.2f }",
619 (double)tv->ldavg[0]/(double)tv->fscale,
620 (double)tv->ldavg[1]/(double)tv->fscale,
621 (double)tv->ldavg[2]/(double)tv->fscale);
626 S_timeval(size_t l2, void *p)
628 struct timeval *tv = (struct timeval*)p;
632 if (l2 != sizeof(*tv)) {
633 warnx("S_timeval %zu != %zu", l2, sizeof(*tv));
636 printf(hflag ? "{ sec = %'jd, usec = %'ld } " :
637 "{ sec = %jd, usec = %ld } ",
638 (intmax_t)tv->tv_sec, tv->tv_usec);
640 p1 = strdup(ctime(&tv_sec));
641 for (p2=p1; *p2 ; p2++)
650 S_vmtotal(size_t l2, void *p)
652 struct vmtotal *v = (struct vmtotal *)p;
653 int pageKilo = getpagesize() / 1024;
655 if (l2 != sizeof(*v)) {
656 warnx("S_vmtotal %zu != %zu", l2, sizeof(*v));
661 "\nSystem wide totals computed every five seconds:"
662 " (values in kilobytes)\n");
663 printf("===============================================\n");
665 "Processes:\t\t(RUNQ: %hd Disk Wait: %hd Page Wait: "
667 v->t_rq, v->t_dw, v->t_pw, v->t_sl);
669 "Virtual Memory:\t\t(Total: %jdK Active: %jdK)\n",
670 (intmax_t)v->t_vm * pageKilo, (intmax_t)v->t_avm * pageKilo);
671 printf("Real Memory:\t\t(Total: %jdK Active: %jdK)\n",
672 (intmax_t)v->t_rm * pageKilo, (intmax_t)v->t_arm * pageKilo);
673 printf("Shared Virtual Memory:\t(Total: %jdK Active: %jdK)\n",
674 (intmax_t)v->t_vmshr * pageKilo, (intmax_t)v->t_avmshr * pageKilo);
675 printf("Shared Real Memory:\t(Total: %jdK Active: %jdK)\n",
676 (intmax_t)v->t_rmshr * pageKilo, (intmax_t)v->t_armshr * pageKilo);
677 printf("Free Memory:\t%jdK", (intmax_t)v->t_free * pageKilo);
683 S_input_id(size_t l2, void *p)
685 struct input_id *id = p;
687 if (l2 != sizeof(*id)) {
688 warnx("S_input_id %zu != %zu", l2, sizeof(*id));
692 printf("{ bustype = 0x%04x, vendor = 0x%04x, "
693 "product = 0x%04x, version = 0x%04x }",
694 id->bustype, id->vendor, id->product, id->version);
700 S_efi_map(size_t l2, void *p)
702 struct efi_map_header *efihdr;
708 static const char * const types[] = {
709 [EFI_MD_TYPE_NULL] = "Reserved",
710 [EFI_MD_TYPE_CODE] = "LoaderCode",
711 [EFI_MD_TYPE_DATA] = "LoaderData",
712 [EFI_MD_TYPE_BS_CODE] = "BootServicesCode",
713 [EFI_MD_TYPE_BS_DATA] = "BootServicesData",
714 [EFI_MD_TYPE_RT_CODE] = "RuntimeServicesCode",
715 [EFI_MD_TYPE_RT_DATA] = "RuntimeServicesData",
716 [EFI_MD_TYPE_FREE] = "ConventionalMemory",
717 [EFI_MD_TYPE_BAD] = "UnusableMemory",
718 [EFI_MD_TYPE_RECLAIM] = "ACPIReclaimMemory",
719 [EFI_MD_TYPE_FIRMWARE] = "ACPIMemoryNVS",
720 [EFI_MD_TYPE_IOMEM] = "MemoryMappedIO",
721 [EFI_MD_TYPE_IOPORT] = "MemoryMappedIOPortSpace",
722 [EFI_MD_TYPE_PALCODE] = "PalCode",
723 [EFI_MD_TYPE_PERSISTENT] = "PersistentMemory",
727 * Memory map data provided by UEFI via the GetMemoryMap
730 if (l2 < sizeof(*efihdr)) {
731 warnx("S_efi_map length less than header");
735 efisz = (sizeof(struct efi_map_header) + 0xf) & ~0xf;
736 map = (struct efi_md *)((uint8_t *)efihdr + efisz);
738 if (efihdr->descriptor_size == 0)
740 if (l2 != efisz + efihdr->memory_size) {
741 warnx("S_efi_map length mismatch %zu vs %zu", l2, efisz +
742 efihdr->memory_size);
745 ndesc = efihdr->memory_size / efihdr->descriptor_size;
747 printf("\n%23s %12s %12s %8s %4s",
748 "Type", "Physical", "Virtual", "#Pages", "Attr");
750 for (i = 0; i < ndesc; i++,
751 map = efi_next_descriptor(map, efihdr->descriptor_size)) {
753 if (map->md_type < nitems(types))
754 type = types[map->md_type];
757 printf("\n%23s %012lx %12p %08lx ", type, map->md_phys,
758 map->md_virt, map->md_pages);
759 if (map->md_attr & EFI_MD_ATTR_UC)
761 if (map->md_attr & EFI_MD_ATTR_WC)
763 if (map->md_attr & EFI_MD_ATTR_WT)
765 if (map->md_attr & EFI_MD_ATTR_WB)
767 if (map->md_attr & EFI_MD_ATTR_UCE)
769 if (map->md_attr & EFI_MD_ATTR_WP)
771 if (map->md_attr & EFI_MD_ATTR_RP)
773 if (map->md_attr & EFI_MD_ATTR_XP)
775 if (map->md_attr & EFI_MD_ATTR_RT)
782 #if defined(__amd64__) || defined(__i386__)
784 S_bios_smap_xattr(size_t l2, void *p)
786 struct bios_smap_xattr *smap, *end;
788 if (l2 % sizeof(*smap) != 0) {
789 warnx("S_bios_smap_xattr %zu is not a multiple of %zu", l2,
794 end = (struct bios_smap_xattr *)((char *)p + l2);
795 for (smap = p; smap < end; smap++)
796 printf("\nSMAP type=%02x, xattr=%02x, base=%016jx, len=%016jx",
797 smap->type, smap->xattr, (uintmax_t)smap->base,
798 (uintmax_t)smap->length);
804 strIKtoi(const char *str, char **endptrp, const char *fmt)
815 /* caller already checked this */
819 * A format of "IK" is in deciKelvin. A format of "IK3" is in
820 * milliKelvin. The single digit following IK is log10 of the
821 * multiplying factor to convert Kelvin into the untis of this sysctl,
822 * or the dividing factor to convert the sysctl value to Kelvin. Numbers
823 * larger than 6 will run into precision issues with 32-bit integers.
824 * Characters that aren't ASCII digits after the 'K' are ignored. No
825 * localization is present because this is an interface from the kernel
826 * to this program (eg not an end-user interface), so isdigit() isn't
829 if (fmt[2] != '\0' && fmt[2] >= '0' && fmt[2] <= '9')
834 if (*p == 'C' || *p == 'F' || *p == 'K') {
835 temp = strtof(str, endptrp);
836 if (*endptrp != str && *endptrp == p && errno == 0) {
838 temp = (temp - 32) * 5 / 9;
842 for (i = 0; i < prec; i++)
844 return ((int)(temp + 0.5));
847 /* No unit specified -> treat it as a raw number */
848 kelv = (int)strtol(str, endptrp, 10);
849 if (*endptrp != str && *endptrp == p && errno == 0) {
860 * These functions uses a presently undocumented interface to the kernel
861 * to walk the tree and get the type so it can print the value.
862 * This interface is under work and consideration, and should probably
863 * be killed with a big axe by the first person who can find the time.
864 * (be aware though, that the proper interface isn't as obvious as it
865 * may seem, there are various conflicting requirements.
869 name2oid(const char *name, int *oidp)
878 j = CTL_MAXNAME * sizeof(int);
879 i = sysctl(oid, 2, oidp, &j, name, strlen(name));
887 oidfmt(int *oid, int len, char *fmt, u_int *kind)
889 int qoid[CTL_MAXNAME+2];
896 memcpy(qoid + 2, oid, len * sizeof(int));
899 i = sysctl(qoid, len + 2, buf, &j, 0, 0);
901 err(1, "sysctl fmt %d %zu %d", i, j, errno);
904 *kind = *(u_int *)buf;
907 strcpy(fmt, (char *)(buf + sizeof(u_int)));
912 * This formats and outputs the value of one variable
914 * Returns zero if anything was actually output.
915 * Returns one if didn't know what to do with this.
916 * Return minus one if we had errors.
919 show_var(int *oid, int nlen)
921 u_char buf[BUFSIZ], *val, *oval, *p;
922 char name[BUFSIZ], fmt[BUFSIZ];
923 const char *sep, *sep1, *prntype;
924 int qoid[CTL_MAXNAME+2];
927 int i, hexlen, sign, ctltype;
932 int (*func)(size_t, void *);
936 umv = mv = intlen = 0;
942 memcpy(qoid + 2, oid, nlen * sizeof(int));
946 i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
948 err(1, "sysctl name %d %zu %d", i, j, errno);
950 oidfmt(oid, nlen, fmt, &kind);
951 /* if Wflag then only list sysctls that are writeable and not stats. */
952 if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0))
955 /* if Tflag then only list sysctls that are tuneables. */
956 if (Tflag && (kind & CTLFLAG_TUN) == 0)
969 ctltype = (kind & CTLTYPE);
970 if (tflag || dflag) {
972 printf("%s%s", name, sep);
973 if (ctl_typename[ctltype] != NULL)
974 prntype = ctl_typename[ctltype];
978 printf("%s%s", prntype, sep);
980 printf("%s", prntype);
985 i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
989 /* find an estimate of how much we need for this var */
994 i = sysctl(oid, nlen, 0, &j, 0, 0);
995 j += j; /* we want to be sure :-) */
998 val = oval = malloc(j + 1);
1000 warnx("malloc failed");
1004 i = sysctl(oid, nlen, val, &len, 0, 0);
1005 if (i != 0 || (len == 0 && ctltype != CTLTYPE_STRING)) {
1011 fwrite(val, 1, len, stdout);
1017 sign = ctl_sign[ctltype];
1018 intlen = ctl_size[ctltype];
1021 case CTLTYPE_STRING:
1023 printf("%s%s", name, sep);
1024 printf("%.*s", (int)len, p);
1041 printf("%s%s", name, sep);
1042 hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
1044 while (len >= intlen) {
1045 switch (kind & CTLTYPE) {
1058 umv = *(uint8_t *)p;
1063 umv = *(uint16_t *)p;
1068 umv = *(uint32_t *)p;
1073 umv = *(uint64_t *)p;
1077 fputs(sep1, stdout);
1079 printf("%#0*jx", hexlen, umv);
1081 printf(hflag ? "%'ju" : "%ju", umv);
1082 else if (fmt[1] == 'K') {
1087 * See strIKtoi for details on fmt.
1091 prec = fmt[2] - '0';
1093 for (int i = 0; i < prec; i++)
1095 printf("%.*fC", prec,
1096 (float)mv / base - 273.15);
1099 printf(hflag ? "%'jd" : "%jd", mv);
1107 case CTLTYPE_OPAQUE:
1109 if (strcmp(fmt, "S,clockinfo") == 0)
1111 else if (strcmp(fmt, "S,timeval") == 0)
1113 else if (strcmp(fmt, "S,loadavg") == 0)
1115 else if (strcmp(fmt, "S,vmtotal") == 0)
1117 else if (strcmp(fmt, "S,input_id") == 0)
1120 else if (strcmp(fmt, "S,efi_map_header") == 0)
1123 #if defined(__amd64__) || defined(__i386__)
1124 else if (strcmp(fmt, "S,bios_smap_xattr") == 0)
1125 func = S_bios_smap_xattr;
1131 printf("%s%s", name, sep);
1132 i = (*func)(len, p);
1138 if (!oflag && !xflag) {
1143 printf("%s%s", name, sep);
1144 printf("Format:%s Length:%zu Dump:0x", fmt, len);
1145 while (len-- && (xflag || p < val + 16))
1146 printf("%02x", *p++);
1147 if (!xflag && len > 16)
1157 sysctl_all(int *oid, int len)
1159 int name1[22], name2[22];
1167 memcpy(name1+2, oid, len * sizeof(int));
1175 j = sysctl(name1, l1, name2, &l2, 0, 0);
1177 if (errno == ENOENT)
1180 err(1, "sysctl(getnext) %d %zu", j, l2);
1185 if (len < 0 || l2 < (unsigned int)len)
1188 for (i = 0; i < len; i++)
1189 if (name2[i] != oid[i])
1192 i = show_var(name2, l2);
1196 memcpy(name1+2, name2, l2 * sizeof(int));