]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sbin/sysctl/sysctl.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sbin / sysctl / sysctl.c
1 /*
2  * Copyright (c) 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  */
29
30 #ifndef lint
31 static const char copyright[] =
32 "@(#) Copyright (c) 1993\n\
33         The Regents of the University of California.  All rights reserved.\n";
34 #endif /* not lint */
35
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)from: sysctl.c      8.1 (Berkeley) 6/6/93";
39 #endif
40 static const char rcsid[] =
41   "$FreeBSD$";
42 #endif /* not lint */
43
44 #include <sys/param.h>
45 #include <sys/time.h>
46 #include <sys/resource.h>
47 #include <sys/stat.h>
48 #include <sys/sysctl.h>
49 #include <sys/vmmeter.h>
50
51 #include <ctype.h>
52 #include <err.h>
53 #include <errno.h>
54 #include <inttypes.h>
55 #include <locale.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <unistd.h>
60
61 static int      aflag, bflag, dflag, eflag, hflag, iflag;
62 static int      Nflag, nflag, oflag, qflag, xflag, warncount;
63
64 static int      oidfmt(int *, int, char *, u_int *);
65 static void     parse(const char *);
66 static int      show_var(int *, int);
67 static int      sysctl_all(int *oid, int len);
68 static int      name2oid(char *, int *);
69
70 static int      set_IK(const char *, int *);
71
72 static void
73 usage(void)
74 {
75
76         (void)fprintf(stderr, "%s\n%s\n",
77             "usage: sysctl [-bdehiNnoqx] name[=value] ...",
78             "       sysctl [-bdehNnoqx] -a");
79         exit(1);
80 }
81
82 int
83 main(int argc, char **argv)
84 {
85         int ch;
86
87         setlocale(LC_NUMERIC, "");
88         setbuf(stdout,0);
89         setbuf(stderr,0);
90
91         while ((ch = getopt(argc, argv, "AabdehiNnoqwxX")) != -1) {
92                 switch (ch) {
93                 case 'A':
94                         /* compatibility */
95                         aflag = oflag = 1;
96                         break;
97                 case 'a':
98                         aflag = 1;
99                         break;
100                 case 'b':
101                         bflag = 1;
102                         break;
103                 case 'd':
104                         dflag = 1;
105                         break;
106                 case 'e':
107                         eflag = 1;
108                         break;
109                 case 'h':
110                         hflag = 1;
111                         break;
112                 case 'i':
113                         iflag = 1;
114                         break;
115                 case 'N':
116                         Nflag = 1;
117                         break;
118                 case 'n':
119                         nflag = 1;
120                         break;
121                 case 'o':
122                         oflag = 1;
123                         break;
124                 case 'q':
125                         qflag = 1;
126                         break;
127                 case 'w':
128                         /* compatibility */
129                         /* ignored */
130                         break;
131                 case 'X':
132                         /* compatibility */
133                         aflag = xflag = 1;
134                         break;
135                 case 'x':
136                         xflag = 1;
137                         break;
138                 default:
139                         usage();
140                 }
141         }
142         argc -= optind;
143         argv += optind;
144
145         if (Nflag && nflag)
146                 usage();
147         if (aflag && argc == 0)
148                 exit(sysctl_all(0, 0));
149         if (argc == 0)
150                 usage();
151
152         warncount = 0;
153         while (argc-- > 0)
154                 parse(*argv++);
155         exit(warncount);
156 }
157
158 /*
159  * Parse a name into a MIB entry.
160  * Lookup and print out the MIB entry if it exists.
161  * Set a new value if requested.
162  */
163 static void
164 parse(const char *string)
165 {
166         int len, i, j;
167         void *newval = 0;
168         int intval;
169         unsigned int uintval;
170         long longval;
171         unsigned long ulongval;
172         size_t newsize = 0;
173         int64_t i64val;
174         uint64_t u64val;
175         int mib[CTL_MAXNAME];
176         char *cp, *bufp, buf[BUFSIZ], *endptr, fmt[BUFSIZ];
177         u_int kind;
178
179         cp = buf;
180         if (snprintf(buf, BUFSIZ, "%s", string) >= BUFSIZ)
181                 errx(1, "oid too long: '%s'", string);
182         bufp = strsep(&cp, "=");
183         if (cp != NULL) {
184                 while (isspace(*cp))
185                         cp++;
186                 newval = cp;
187                 newsize = strlen(cp);
188         }
189         len = name2oid(bufp, mib);
190
191         if (len < 0) {
192                 if (iflag)
193                         return;
194                 if (qflag)
195                         exit(1);
196                 else
197                         errx(1, "unknown oid '%s'", bufp);
198         }
199
200         if (oidfmt(mib, len, fmt, &kind))
201                 err(1, "couldn't find format of oid '%s'", bufp);
202
203         if (newval == NULL || dflag) {
204                 if ((kind & CTLTYPE) == CTLTYPE_NODE) {
205                         if (dflag) {
206                                 i = show_var(mib, len);
207                                 if (!i && !bflag)
208                                         putchar('\n');
209                         }
210                         sysctl_all(mib, len);
211                 } else {
212                         i = show_var(mib, len);
213                         if (!i && !bflag)
214                                 putchar('\n');
215                 }
216         } else {
217                 if ((kind & CTLTYPE) == CTLTYPE_NODE)
218                         errx(1, "oid '%s' isn't a leaf node", bufp);
219
220                 if (!(kind & CTLFLAG_WR)) {
221                         if (kind & CTLFLAG_TUN) {
222                                 warnx("oid '%s' is a read only tunable", bufp);
223                                 errx(1, "Tunable values are set in /boot/loader.conf");
224                         } else {
225                                 errx(1, "oid '%s' is read only", bufp);
226                         }
227                 }
228
229                 if ((kind & CTLTYPE) == CTLTYPE_INT ||
230                     (kind & CTLTYPE) == CTLTYPE_UINT ||
231                     (kind & CTLTYPE) == CTLTYPE_LONG ||
232                     (kind & CTLTYPE) == CTLTYPE_ULONG ||
233                     (kind & CTLTYPE) == CTLTYPE_S64 ||
234                     (kind & CTLTYPE) == CTLTYPE_U64) {
235                         if (strlen(newval) == 0)
236                                 errx(1, "empty numeric value");
237                 }
238
239                 switch (kind & CTLTYPE) {
240                         case CTLTYPE_INT:
241                                 if (strcmp(fmt, "IK") == 0) {
242                                         if (!set_IK(newval, &intval))
243                                                 errx(1, "invalid value '%s'",
244                                                     (char *)newval);
245                                 } else {
246                                         intval = (int)strtol(newval, &endptr,
247                                             0);
248                                         if (endptr == newval || *endptr != '\0')
249                                                 errx(1, "invalid integer '%s'",
250                                                     (char *)newval);
251                                 }
252                                 newval = &intval;
253                                 newsize = sizeof(intval);
254                                 break;
255                         case CTLTYPE_UINT:
256                                 uintval = (int) strtoul(newval, &endptr, 0);
257                                 if (endptr == newval || *endptr != '\0')
258                                         errx(1, "invalid unsigned integer '%s'",
259                                             (char *)newval);
260                                 newval = &uintval;
261                                 newsize = sizeof(uintval);
262                                 break;
263                         case CTLTYPE_LONG:
264                                 longval = strtol(newval, &endptr, 0);
265                                 if (endptr == newval || *endptr != '\0')
266                                         errx(1, "invalid long integer '%s'",
267                                             (char *)newval);
268                                 newval = &longval;
269                                 newsize = sizeof(longval);
270                                 break;
271                         case CTLTYPE_ULONG:
272                                 ulongval = strtoul(newval, &endptr, 0);
273                                 if (endptr == newval || *endptr != '\0')
274                                         errx(1, "invalid unsigned long integer"
275                                             " '%s'", (char *)newval);
276                                 newval = &ulongval;
277                                 newsize = sizeof(ulongval);
278                                 break;
279                         case CTLTYPE_STRING:
280                                 break;
281                         case CTLTYPE_S64:
282                                 i64val = strtoimax(newval, &endptr, 0);
283                                 if (endptr == newval || *endptr != '\0')
284                                         errx(1, "invalid int64_t '%s'",
285                                             (char *)newval);
286                                 newval = &i64val;
287                                 newsize = sizeof(i64val);
288                                 break;
289                         case CTLTYPE_U64:
290                                 u64val = strtoumax(newval, &endptr, 0);
291                                 if (endptr == newval || *endptr != '\0')
292                                         errx(1, "invalid uint64_t '%s'",
293                                             (char *)newval);
294                                 newval = &u64val;
295                                 newsize = sizeof(u64val);
296                                 break;
297                         case CTLTYPE_OPAQUE:
298                                 /* FALLTHROUGH */
299                         default:
300                                 errx(1, "oid '%s' is type %d,"
301                                         " cannot set that", bufp,
302                                         kind & CTLTYPE);
303                 }
304
305                 i = show_var(mib, len);
306                 if (sysctl(mib, len, 0, 0, newval, newsize) == -1) {
307                         if (!i && !bflag)
308                                 putchar('\n');
309                         switch (errno) {
310                         case EOPNOTSUPP:
311                                 errx(1, "%s: value is not available",
312                                         string);
313                         case ENOTDIR:
314                                 errx(1, "%s: specification is incomplete",
315                                         string);
316                         case ENOMEM:
317                                 errx(1, "%s: type is unknown to this program",
318                                         string);
319                         default:
320                                 warn("%s", string);
321                                 warncount++;
322                                 return;
323                         }
324                 }
325                 if (!bflag)
326                         printf(" -> ");
327                 i = nflag;
328                 nflag = 1;
329                 j = show_var(mib, len);
330                 if (!j && !bflag)
331                         putchar('\n');
332                 nflag = i;
333         }
334 }
335
336 /* These functions will dump out various interesting structures. */
337
338 static int
339 S_clockinfo(int l2, void *p)
340 {
341         struct clockinfo *ci = (struct clockinfo*)p;
342
343         if (l2 != sizeof(*ci)) {
344                 warnx("S_clockinfo %d != %zu", l2, sizeof(*ci));
345                 return (1);
346         }
347         printf(hflag ? "{ hz = %'d, tick = %'d, profhz = %'d, stathz = %'d }" :
348                 "{ hz = %d, tick = %d, profhz = %d, stathz = %d }",
349                 ci->hz, ci->tick, ci->profhz, ci->stathz);
350         return (0);
351 }
352
353 static int
354 S_loadavg(int l2, void *p)
355 {
356         struct loadavg *tv = (struct loadavg*)p;
357
358         if (l2 != sizeof(*tv)) {
359                 warnx("S_loadavg %d != %zu", l2, sizeof(*tv));
360                 return (1);
361         }
362         printf(hflag ? "{ %'.2f %'.2f %'.2f }" : "{ %.2f %.2f %.2f }",
363                 (double)tv->ldavg[0]/(double)tv->fscale,
364                 (double)tv->ldavg[1]/(double)tv->fscale,
365                 (double)tv->ldavg[2]/(double)tv->fscale);
366         return (0);
367 }
368
369 static int
370 S_timeval(int l2, void *p)
371 {
372         struct timeval *tv = (struct timeval*)p;
373         time_t tv_sec;
374         char *p1, *p2;
375
376         if (l2 != sizeof(*tv)) {
377                 warnx("S_timeval %d != %zu", l2, sizeof(*tv));
378                 return (1);
379         }
380         printf(hflag ? "{ sec = %'jd, usec = %'ld } " :
381                 "{ sec = %jd, usec = %ld } ",
382                 (intmax_t)tv->tv_sec, tv->tv_usec);
383         tv_sec = tv->tv_sec;
384         p1 = strdup(ctime(&tv_sec));
385         for (p2=p1; *p2 ; p2++)
386                 if (*p2 == '\n')
387                         *p2 = '\0';
388         fputs(p1, stdout);
389         free(p1);
390         return (0);
391 }
392
393 static int
394 S_vmtotal(int l2, void *p)
395 {
396         struct vmtotal *v = (struct vmtotal *)p;
397         int pageKilo = getpagesize() / 1024;
398
399         if (l2 != sizeof(*v)) {
400                 warnx("S_vmtotal %d != %zu", l2, sizeof(*v));
401                 return (1);
402         }
403
404         printf(
405             "\nSystem wide totals computed every five seconds:"
406             " (values in kilobytes)\n");
407         printf("===============================================\n");
408         printf(
409             "Processes:\t\t(RUNQ: %hd Disk Wait: %hd Page Wait: "
410             "%hd Sleep: %hd)\n",
411             v->t_rq, v->t_dw, v->t_pw, v->t_sl);
412         printf(
413             "Virtual Memory:\t\t(Total: %dK Active: %dK)\n",
414             v->t_vm * pageKilo, v->t_avm * pageKilo);
415         printf("Real Memory:\t\t(Total: %dK Active: %dK)\n",
416             v->t_rm * pageKilo, v->t_arm * pageKilo);
417         printf("Shared Virtual Memory:\t(Total: %dK Active: %dK)\n",
418             v->t_vmshr * pageKilo, v->t_avmshr * pageKilo);
419         printf("Shared Real Memory:\t(Total: %dK Active: %dK)\n",
420             v->t_rmshr * pageKilo, v->t_armshr * pageKilo);
421         printf("Free Memory:\t%dK\n", v->t_free * pageKilo);
422
423         return (0);
424 }
425
426 static int
427 set_IK(const char *str, int *val)
428 {
429         float temp;
430         int len, kelv;
431         const char *p;
432         char *endptr;
433
434         if ((len = strlen(str)) == 0)
435                 return (0);
436         p = &str[len - 1];
437         if (*p == 'C' || *p == 'F') {
438                 temp = strtof(str, &endptr);
439                 if (endptr == str || endptr != p)
440                         return (0);
441                 if (*p == 'F')
442                         temp = (temp - 32) * 5 / 9;
443                 kelv = temp * 10 + 2732;
444         } else {
445                 kelv = (int)strtol(str, &endptr, 10);
446                 if (endptr == str || *endptr != '\0')
447                         return (0);
448         }
449         *val = kelv;
450         return (1);
451 }
452
453 /*
454  * These functions uses a presently undocumented interface to the kernel
455  * to walk the tree and get the type so it can print the value.
456  * This interface is under work and consideration, and should probably
457  * be killed with a big axe by the first person who can find the time.
458  * (be aware though, that the proper interface isn't as obvious as it
459  * may seem, there are various conflicting requirements.
460  */
461
462 static int
463 name2oid(char *name, int *oidp)
464 {
465         int oid[2];
466         int i;
467         size_t j;
468
469         oid[0] = 0;
470         oid[1] = 3;
471
472         j = CTL_MAXNAME * sizeof(int);
473         i = sysctl(oid, 2, oidp, &j, name, strlen(name));
474         if (i < 0)
475                 return (i);
476         j /= sizeof(int);
477         return (j);
478 }
479
480 static int
481 oidfmt(int *oid, int len, char *fmt, u_int *kind)
482 {
483         int qoid[CTL_MAXNAME+2];
484         u_char buf[BUFSIZ];
485         int i;
486         size_t j;
487
488         qoid[0] = 0;
489         qoid[1] = 4;
490         memcpy(qoid + 2, oid, len * sizeof(int));
491
492         j = sizeof(buf);
493         i = sysctl(qoid, len + 2, buf, &j, 0, 0);
494         if (i)
495                 err(1, "sysctl fmt %d %zu %d", i, j, errno);
496
497         if (kind)
498                 *kind = *(u_int *)buf;
499
500         if (fmt)
501                 strcpy(fmt, (char *)(buf + sizeof(u_int)));
502         return (0);
503 }
504
505 static int ctl_sign[CTLTYPE+1] = {
506         [CTLTYPE_INT] = 1,
507         [CTLTYPE_LONG] = 1,
508         [CTLTYPE_S64] = 1,
509 };
510
511 static int ctl_size[CTLTYPE+1] = {
512         [CTLTYPE_INT] = sizeof(int),
513         [CTLTYPE_UINT] = sizeof(u_int),
514         [CTLTYPE_LONG] = sizeof(long),
515         [CTLTYPE_ULONG] = sizeof(u_long),
516         [CTLTYPE_S64] = sizeof(int64_t),
517         [CTLTYPE_U64] = sizeof(int64_t),
518 };
519
520 /*
521  * This formats and outputs the value of one variable
522  *
523  * Returns zero if anything was actually output.
524  * Returns one if didn't know what to do with this.
525  * Return minus one if we had errors.
526  */
527 static int
528 show_var(int *oid, int nlen)
529 {
530         u_char buf[BUFSIZ], *val, *oval, *p;
531         char name[BUFSIZ], *fmt;
532         const char *sep, *sep1;
533         int qoid[CTL_MAXNAME+2];
534         uintmax_t umv;
535         intmax_t mv;
536         int i, hexlen, sign, ctltype;
537         size_t intlen;
538         size_t j, len;
539         u_int kind;
540         int (*func)(int, void *);
541
542         /* Silence GCC. */
543         umv = mv = intlen = 0;
544
545         bzero(buf, BUFSIZ);
546         bzero(name, BUFSIZ);
547         qoid[0] = 0;
548         memcpy(qoid + 2, oid, nlen * sizeof(int));
549
550         qoid[1] = 1;
551         j = sizeof(name);
552         i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
553         if (i || !j)
554                 err(1, "sysctl name %d %zu %d", i, j, errno);
555
556         if (Nflag) {
557                 printf("%s", name);
558                 return (0);
559         }
560
561         if (eflag)
562                 sep = "=";
563         else
564                 sep = ": ";
565
566         if (dflag) {    /* just print description */
567                 qoid[1] = 5;
568                 j = sizeof(buf);
569                 i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
570                 if (!nflag)
571                         printf("%s%s", name, sep);
572                 printf("%s", buf);
573                 return (0);
574         }
575         /* find an estimate of how much we need for this var */
576         j = 0;
577         i = sysctl(oid, nlen, 0, &j, 0, 0);
578         j += j; /* we want to be sure :-) */
579
580         val = oval = malloc(j + 1);
581         if (val == NULL) {
582                 warnx("malloc failed");
583                 return (1);
584         }
585         len = j;
586         i = sysctl(oid, nlen, val, &len, 0, 0);
587         if (i || !len) {
588                 free(oval);
589                 return (1);
590         }
591
592         if (bflag) {
593                 fwrite(val, 1, len, stdout);
594                 free(oval);
595                 return (0);
596         }
597         val[len] = '\0';
598         fmt = buf;
599         oidfmt(oid, nlen, fmt, &kind);
600         p = val;
601         ctltype = (kind & CTLTYPE);
602         sign = ctl_sign[ctltype];
603         intlen = ctl_size[ctltype];
604
605         switch (ctltype) {
606         case CTLTYPE_STRING:
607                 if (!nflag)
608                         printf("%s%s", name, sep);
609                 printf("%.*s", (int)len, p);
610                 free(oval);
611                 return (0);
612
613         case CTLTYPE_INT:
614         case CTLTYPE_UINT:
615         case CTLTYPE_LONG:
616         case CTLTYPE_ULONG:
617         case CTLTYPE_S64:
618         case CTLTYPE_U64:
619                 if (!nflag)
620                         printf("%s%s", name, sep);
621                 hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
622                 sep1 = "";
623                 while (len >= intlen) {
624                         switch (kind & CTLTYPE) {
625                         case CTLTYPE_INT:
626                         case CTLTYPE_UINT:
627                                 umv = *(u_int *)p;
628                                 mv = *(int *)p;
629                                 break;
630                         case CTLTYPE_LONG:
631                         case CTLTYPE_ULONG:
632                                 umv = *(u_long *)p;
633                                 mv = *(long *)p;
634                                 break;
635                         case CTLTYPE_S64:
636                         case CTLTYPE_U64:
637                                 umv = *(uint64_t *)p;
638                                 mv = *(int64_t *)p;
639                                 break;
640                         }
641                         fputs(sep1, stdout);
642                         if (xflag)
643                                 printf("%#0*jx", hexlen, umv);
644                         else if (!sign)
645                                 printf(hflag ? "%'ju" : "%ju", umv);
646                         else if (fmt[1] == 'K') {
647                                 if (mv < 0)
648                                         printf("%jd", mv);
649                                 else
650                                         printf("%.1fC", (mv - 2732.0) / 10);
651                         } else
652                                 printf(hflag ? "%'jd" : "%jd", mv);
653                         sep1 = " ";
654                         len -= intlen;
655                         p += intlen;
656                 }
657                 free(oval);
658                 return (0);
659
660         case CTLTYPE_OPAQUE:
661                 i = 0;
662                 if (strcmp(fmt, "S,clockinfo") == 0)
663                         func = S_clockinfo;
664                 else if (strcmp(fmt, "S,timeval") == 0)
665                         func = S_timeval;
666                 else if (strcmp(fmt, "S,loadavg") == 0)
667                         func = S_loadavg;
668                 else if (strcmp(fmt, "S,vmtotal") == 0)
669                         func = S_vmtotal;
670                 else
671                         func = NULL;
672                 if (func) {
673                         if (!nflag)
674                                 printf("%s%s", name, sep);
675                         i = (*func)(len, p);
676                         free(oval);
677                         return (i);
678                 }
679                 /* FALLTHROUGH */
680         default:
681                 if (!oflag && !xflag) {
682                         free(oval);
683                         return (1);
684                 }
685                 if (!nflag)
686                         printf("%s%s", name, sep);
687                 printf("Format:%s Length:%zu Dump:0x", fmt, len);
688                 while (len-- && (xflag || p < val + 16))
689                         printf("%02x", *p++);
690                 if (!xflag && len > 16)
691                         printf("...");
692                 free(oval);
693                 return (0);
694         }
695         free(oval);
696         return (1);
697 }
698
699 static int
700 sysctl_all(int *oid, int len)
701 {
702         int name1[22], name2[22];
703         int i, j;
704         size_t l1, l2;
705
706         name1[0] = 0;
707         name1[1] = 2;
708         l1 = 2;
709         if (len) {
710                 memcpy(name1+2, oid, len * sizeof(int));
711                 l1 += len;
712         } else {
713                 name1[2] = 1;
714                 l1++;
715         }
716         for (;;) {
717                 l2 = sizeof(name2);
718                 j = sysctl(name1, l1, name2, &l2, 0, 0);
719                 if (j < 0) {
720                         if (errno == ENOENT)
721                                 return (0);
722                         else
723                                 err(1, "sysctl(getnext) %d %zu", j, l2);
724                 }
725
726                 l2 /= sizeof(int);
727
728                 if (len < 0 || l2 < (unsigned int)len)
729                         return (0);
730
731                 for (i = 0; i < len; i++)
732                         if (name2[i] != oid[i])
733                                 return (0);
734
735                 i = show_var(name2, l2);
736                 if (!i && !bflag)
737                         putchar('\n');
738
739                 memcpy(name1+2, name2, l2 * sizeof(int));
740                 l1 = 2 + l2;
741         }
742 }