]>
git.saurik.com Git - apple/system_cmds.git/blob - sysctl.tproj/sysctl.c
fb0dbb4be12e198cf2c98aed22a2b9de30ca5f38
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 Modified November 1, 2000, by Ryan Rempel, ryan.rempel@utoronto.ca
60 The Darwin sysctl mechanism is in a state of flux. Parts of the kernel use the old
61 style of BSD sysctl definition, and other parts use the new style. The sysctl (8)
62 command that shipped with Darwin 1.2 (OS X PB) did not allow you to access
63 all possible sysctl values. In particular, it did not permit access to sysctl values
64 created by kernel extensions--hence my particular interest. The freeBSD sysctl (8)
65 command compiled and ran under Darwin 1.2, and it did permit access to
66 sysctl values created by kernel extensions, as well as several others. However, it
67 did not permit access to many other values which the Darwin 1.2 sysctl could access.
69 What I have done is merge the Darwin 1.2 sysctl and the freeBSD sysctl. Essentially,
70 there are two points of merger. When showing all values (i.e. -a, -A, or -X), sysctl now
71 runs the Darwin 1.2 routine to show all values, and then the freeBSD routine. This does
72 result in some duplication. When getting or setting a particular value, sysctl now tries
73 the freeBSD way first. If it cannot find the value, then it tries the Darwin 1.2 way.
75 There are a few oddities which this creates (aside from some duplication with -a, -A,
76 and -X). The freeBSD version of sysctl now supports two extra options, -b and -X.
77 In this syctl, those options are supported where the value is retrieved by the freeBSD
78 routine, and have no effect where the value is retrieved by the Darwin 1.2 routine.
79 The freeBSD sysctl uses a ':' to separate the name and the value, whereas Darwin 1.2's
80 sysctl uses a '='. I have left this way, as it lets you know which routine was used,
83 I have also fixed several lines which gave warnings previously, one of which appears
84 to have been an actual bug (bufp was dereferenced when it shouldn't have been).
85 I have also incoporated my previous patch to permit setting kern.hostid as an unsigned
86 integer. In the freeBSD side of the code, I have incorporated a general fix for
87 setting values where the format is specified as unsigned integer.
91 static char copyright
[] =
92 "@(#) Copyright (c) 1993\n\
93 The Regents of the University of California. All rights reserved.\n";
97 static char sccsid
[] = "@(#)sysctl.c 8.5 (Berkeley) 5/9/95";
100 #include <sys/param.h>
101 #include <sys/gmon.h>
102 #include <sys/mount.h>
103 #include <sys/stat.h>
104 #include <sys/sysctl.h>
105 #include <sys/socket.h>
107 #include <mach/machine/vm_param.h>
108 #include <mach/machine/vm_types.h>
109 #include <mach/mach_types.h>
111 #include <vm/vm_param.h>
112 #endif /* __APPLE__ */
113 #include <machine/cpu.h>
122 #include <sys/types.h>
123 #include <sys/resource.h>
126 struct ctlname topname
[] = CTL_NAMES
;
127 struct ctlname kernname
[] = CTL_KERN_NAMES
;
128 struct ctlname vmname
[] = CTL_VM_NAMES
;
129 struct ctlname hwname
[] = CTL_HW_NAMES
;
130 struct ctlname username
[] = CTL_USER_NAMES
;
131 struct ctlname debugname
[CTL_DEBUG_MAXID
];
132 struct ctlname
*vfsname
;
133 #ifdef CTL_MACHDEP_NAMES
134 struct ctlname machdepname
[] = CTL_MACHDEP_NAMES
;
140 struct ctlname
*list
;
143 struct list toplist
= { topname
, CTL_MAXID
};
144 struct list secondlevel
[] = {
145 { 0, 0 }, /* CTL_UNSPEC */
146 { kernname
, KERN_MAXID
}, /* CTL_KERN */
147 { vmname
, VM_MAXID
}, /* CTL_VM */
148 { 0, 0 }, /* CTL_VFS */
149 { 0, 0 }, /* CTL_NET */
150 { 0, CTL_DEBUG_MAXID
}, /* CTL_DEBUG */
151 { hwname
, HW_MAXID
}, /* CTL_HW */
152 #ifdef CTL_MACHDEP_NAMES
153 { machdepname
, CPU_MAXID
}, /* CTL_MACHDEP */
155 { 0, 0 }, /* CTL_MACHDEP */
157 { username
, USER_MAXID
}, /* CTL_USER_NAMES */
160 static int Aflag
, aflag
, bflag
, nflag
, wflag
, Xflag
;
161 static int foundSome
= 0;
163 void listall(char *prefix
, struct list
*lp
);
164 void old_parse(char *string
, int flags
);
167 int findname(char *string
, char *level
, char **bufp
, struct list
*namelist
);
170 static void parse(char *string
, int flags
);
171 static int oidfmt(int *, int, char *, u_int
*);
172 static int show_var(int *, int);
173 static int sysctl_all (int *oid
, int len
);
174 static int name2oid(char *, int *);
177 * Variables requiring special processing.
179 #define CLOCK 0x00000001
180 #define BOOTTIME 0x00000002
181 #define CONSDEV 0x00000004
188 // extern char *optarg; // unused
192 while ((ch
= getopt(argc
, argv
, "AabnwX")) != EOF
) {
194 case 'A': Aflag
= 1; break;
195 case 'a': aflag
= 1; break;
196 case 'b': bflag
= 1; break;
197 case 'n': nflag
= 1; break;
198 case 'w': wflag
= 1; break;
199 case 'X': Xflag
= Aflag
= 1; break;
206 if (argc
== 0 && (Aflag
|| aflag
)) {
209 for (lvl1
= 1; lvl1
< CTL_MAXID
; lvl1
++)
210 listall(topname
[lvl1
].ctl_name
, &secondlevel
[lvl1
]);
211 exit (sysctl_all(0, 0));
215 for (; *argv
!= NULL
; ++argv
)
221 * List all variables known to the system.
229 char *cp
, name
[BUFSIZ
];
233 strcpy(name
, prefix
);
234 cp
= &name
[strlen(name
)];
236 for (lvl2
= 0; lvl2
< lp
->size
; lvl2
++) {
237 if (lp
->list
[lvl2
].ctl_name
== 0)
239 strcpy(cp
, lp
->list
[lvl2
].ctl_name
);
240 old_parse(name
, Aflag
);
245 * Parse a name into a MIB entry.
246 * Lookup and print out the MIB entry if it exists.
247 * Set a new value if requested.
250 old_parse(string
, flags
)
254 int indx
, type
, state
, len
;
258 int intval
, newsize
= 0;
259 unsigned int uintval
;
260 int useUnsignedInt
= 0;
264 int mib
[CTL_MAXNAME
];
265 char *cp
, *bufp
, buf
[BUFSIZ
] /*, strval[BUFSIZ] */ ;
268 snprintf(buf
, BUFSIZ
, "%s", string
);
269 if ((cp
= strchr(string
, '=')) != NULL
) {
271 fprintf(stderr
, "Must specify -w to set variables\n");
274 *strchr(buf
, '=') = '\0';
279 newsize
= strlen(cp
);
281 if ((indx
= findname(string
, "top", &bufp
, &toplist
)) == -1)
286 if (indx
== CTL_DEBUG
)
288 lp
= &secondlevel
[indx
];
290 if (!foundSome
) fprintf(stderr
, "%s: class is not implemented\n",
291 topname
[indx
].ctl_name
);
295 listall(topname
[indx
].ctl_name
, lp
);
298 if ((indx
= findname(string
, "second", &bufp
, lp
)) == -1)
301 type
= lp
->list
[indx
].ctl_type
;
308 mib
[2] = GPROF_STATE
;
310 if (sysctl(mib
, 3, &state
, &size
, NULL
, 0) < 0) {
314 fprintf(stdout
, "%s: ", string
);
316 "kernel is not compiled for profiling\n");
320 fprintf(stdout
, "%s: %s\n", string
,
321 state
== GMON_PROF_OFF
? "off" : "running");
328 "Use pstat to view %s information\n", string
);
334 "Use ps to view %s information\n", string
);
352 if (mib
[1] == VM_LOADAVG
) {
355 getloadavg(loads
, 3);
357 fprintf(stdout
, "%s: ", string
);
358 fprintf(stdout
, "%.2f %.2f %.2f\n",
359 loads
[0], loads
[1], loads
[2]);
365 "Use vmstat or systat to view %s information\n", string
);
369 mib
[2] = CTL_DEBUG_VALUE
;
375 if (mib
[1] == CPU_CONSDEV
)
382 mib
[1] = VFS_GENERIC
;
386 if (sysctl(mib
, 4, &vfc
, &size
, (void *)0, (size_t)0) < 0) {
390 if (flags
== 0 && vfc
.vfc_refcount
== 0)
393 fprintf(stdout
, "%s has %d mounted instance%s\n",
394 string
, vfc
.vfc_refcount
,
395 vfc
.vfc_refcount
!= 1 ? "s" : "");
397 fprintf(stdout
, "%d\n", vfc
.vfc_refcount
);
404 fprintf(stderr
, "Illegal top level value: %d\n", mib
[0]);
409 fprintf(stderr
, "name %s in %s is unknown\n", bufp
, string
);
415 if (useUnsignedInt
) {
416 uintval
= strtoul(newval
, 0, 0);
418 newsize
= sizeof uintval
;
420 intval
= atoi(newval
);
422 newsize
= sizeof intval
;
427 sscanf(newval
, "%qd", &quadval
);
429 newsize
= sizeof quadval
;
434 if (sysctl(mib
, len
, buf
, &size
, newsize
? newval
: 0, newsize
) == -1) {
439 fprintf(stderr
, "%s: value is not available\n", string
);
442 fprintf(stderr
, "%s: specification is incomplete\n",
446 fprintf(stderr
, "%s: type is unknown to this program\n",
454 if (special
& CLOCK
) {
455 struct clockinfo
*clkp
= (struct clockinfo
*)buf
;
458 fprintf(stdout
, "%s: ", string
);
460 "hz = %d, tick = %d, profhz = %d, stathz = %d\n",
461 clkp
->hz
, clkp
->tick
, clkp
->profhz
, clkp
->stathz
);
464 if (special
& BOOTTIME
) {
465 struct timeval
*btp
= (struct timeval
*)buf
;
468 fprintf(stdout
, "%s = %s\n", string
,
469 ctime((time_t *) &btp
->tv_sec
));
471 fprintf(stdout
, "%d\n", btp
->tv_sec
);
474 if (special
& CONSDEV
) {
475 dev_t dev
= *(dev_t
*)buf
;
478 fprintf(stdout
, "%s = %s\n", string
,
479 devname(dev
, S_IFCHR
));
481 fprintf(stdout
, "0x%x\n", dev
);
488 fprintf(stdout
, "%s = ", string
);
489 fprintf(stdout
, useUnsignedInt
? "%u\n" : "%d\n", *(int *)buf
);
492 fprintf(stdout
, useUnsignedInt
? "%s: %u -> " : "%s: %d -> ",
493 string
, *(int *)buf
);
494 fprintf(stdout
, useUnsignedInt
? "%u\n" : "%d\n", *(int *)newval
);
501 fprintf(stdout
, "%s = ", string
);
502 fprintf(stdout
, "%s\n", buf
);
505 fprintf(stdout
, "%s: %s -> ", string
, buf
);
506 fprintf(stdout
, "%s\n", (char *) newval
);
513 fprintf(stdout
, "%s = ", string
);
514 fprintf(stdout
, "%qd\n", *(quad_t
*)buf
);
517 fprintf(stdout
, "%s: %qd -> ", string
,
519 fprintf(stdout
, "%qd\n", *(quad_t
*)newval
);
528 fprintf(stderr
, "%s: unknown type returned\n",
535 * Initialize the set of debugging names
542 if (secondlevel
[CTL_DEBUG
].list
!= 0)
544 secondlevel
[CTL_DEBUG
].list
= debugname
;
546 mib
[2] = CTL_DEBUG_NAME
;
547 for (loc
= lastused
, i
= 0; i
< CTL_DEBUG_MAXID
; i
++) {
550 if (sysctl(mib
, 3, &names
[loc
], &size
, NULL
, 0) == -1)
552 debugname
[i
].ctl_name
= &names
[loc
];
553 debugname
[i
].ctl_type
= CTLTYPE_INT
;
560 * Initialize the set of filesystem names
564 int mib
[4], maxtypenum
, cnt
, loc
, size
;
568 if (secondlevel
[CTL_VFS
].list
!= 0)
571 mib
[1] = VFS_GENERIC
;
572 mib
[2] = VFS_MAXTYPENUM
;
574 if (sysctl(mib
, 3, &maxtypenum
, &buflen
, (void *)0, (size_t)0) < 0)
576 if ((vfsname
= malloc(maxtypenum
* sizeof(*vfsname
))) == 0)
578 memset(vfsname
, 0, maxtypenum
* sizeof(*vfsname
));
581 for (loc
= lastused
, cnt
= 0; cnt
< maxtypenum
; cnt
++) {
583 if (sysctl(mib
, 4, &vfc
, &buflen
, (void *)0, (size_t)0) < 0) {
584 if (errno
== EOPNOTSUPP
)
590 strcat(&names
[loc
], vfc
.vfc_name
);
591 vfsname
[cnt
].ctl_name
= &names
[loc
];
592 vfsname
[cnt
].ctl_type
= CTLTYPE_INT
;
593 size
= strlen(vfc
.vfc_name
) + 1;
597 secondlevel
[CTL_VFS
].list
= vfsname
;
598 secondlevel
[CTL_VFS
].size
= maxtypenum
;
603 * Scan a list of names searching for a particular name.
606 findname(string
, level
, bufp
, namelist
)
610 struct list
*namelist
;
615 if (namelist
->list
== 0 || (name
= strsep(bufp
, ".")) == NULL
) {
616 fprintf(stderr
, "%s: incomplete specification\n", string
);
619 for (i
= 0; i
< namelist
->size
; i
++)
620 if (namelist
->list
[i
].ctl_name
!= NULL
&&
621 strcmp(name
, namelist
->list
[i
].ctl_name
) == 0)
623 if (i
== namelist
->size
) {
624 fprintf(stderr
, "%s level name %s in %s is invalid\n",
625 level
, name
, string
);
634 (void)fprintf(stderr
, "%s\n%s\n%s\n%s\n%s\n",
635 "usage: sysctl [-bn] variable ...",
636 " sysctl [-bn] -w variable=value ...",
644 * Parse a name into a MIB entry.
645 * Lookup and print out the MIB entry if it exists.
646 * Set a new value if requested.
649 parse(char *string
, int flags
)
653 int intval
, newsize
= 0;
654 unsigned int uintval
;
656 int mib
[CTL_MAXNAME
];
657 char *cp
, *bufp
, buf
[BUFSIZ
], fmt
[BUFSIZ
];
661 snprintf(buf
, BUFSIZ
, "%s", string
);
662 if ((cp
= strchr(string
, '=')) != NULL
) {
664 errx(2, "must specify -w to set variables");
665 *strchr(buf
, '=') = '\0';
670 newsize
= strlen(cp
);
675 len
= name2oid(bufp
, mib
);
679 while (*cp
!= '\0') cp
--;
682 old_parse (string
, flags
);
686 if (oidfmt(mib
, len
, fmt
, &kind
))
687 err(1, "couldn't find format of oid '%s'", bufp
);
690 if ((kind
& CTLTYPE
) == CTLTYPE_NODE
) {
691 sysctl_all(mib
, len
);
693 old_parse (string
, flags
);
695 i
= show_var(mib
, len
);
700 if ((kind
& CTLTYPE
) == CTLTYPE_NODE
)
701 errx(1, "oid '%s' isn't a leaf node", bufp
);
703 if (!(kind
&CTLFLAG_WR
))
704 errx(1, "oid '%s' is read only", bufp
);
706 switch (kind
& CTLTYPE
) {
708 if ((*fmt
== 'I') && (*(fmt
+ 1) == 'U')) {
709 uintval
= (unsigned int) strtoul (newval
, NULL
, 0);
711 newsize
= sizeof uintval
;
713 intval
= (int) strtol(newval
, NULL
, 0);
715 newsize
= sizeof intval
;
722 sscanf(newval
, "%qd", &quadval
);
724 newsize
= sizeof quadval
;
727 errx(1, "oid '%s' is type %d,"
728 " cannot set that", bufp
,
732 i
= show_var(mib
, len
);
733 if (sysctl(mib
, len
, 0, 0, newval
, newsize
) == -1) {
738 errx(1, "%s: value is not available",
741 errx(1, "%s: specification is incomplete",
744 errx(1, "%s: type is unknown to this program",
755 j
= show_var(mib
, len
);
762 /* These functions will dump out various interesting structures. */
765 S_clockinfo(int l2
, void *p
)
767 struct clockinfo
*ci
= (struct clockinfo
*)p
;
768 if (l2
!= sizeof *ci
)
769 err(1, "S_clockinfo %d != %d", l2
, sizeof *ci
);
770 printf("{ hz = %d, tick = %d, tickadj = %d, profhz = %d, stathz = %d }",
771 ci
->hz
, ci
->tick
, ci
->tickadj
, ci
->profhz
, ci
->stathz
);
776 S_loadavg(int l2
, void *p
)
778 struct loadavg
*tv
= (struct loadavg
*)p
;
780 if (l2
!= sizeof *tv
)
781 err(1, "S_loadavg %d != %d", l2
, sizeof *tv
);
783 printf("{ %.2f %.2f %.2f }",
784 (double)tv
->ldavg
[0]/(double)tv
->fscale
,
785 (double)tv
->ldavg
[1]/(double)tv
->fscale
,
786 (double)tv
->ldavg
[2]/(double)tv
->fscale
);
791 S_timeval(int l2
, void *p
)
793 struct timeval
*tv
= (struct timeval
*)p
;
797 if (l2
!= sizeof *tv
)
798 err(1, "S_timeval %d != %d", l2
, sizeof *tv
);
799 printf("{ sec = %ld, usec = %ld } ",
800 (long) tv
->tv_sec
, (long) tv
->tv_usec
);
802 p1
= strdup(ctime(&tv_sec
));
803 for (p2
=p1
; *p2
; p2
++)
811 T_dev_t(int l2
, void *p
)
813 dev_t
*d
= (dev_t
*)p
;
815 err(1, "T_dev_T %d != %d", l2
, sizeof *d
);
816 if ((int)(*d
) != -1) {
817 if (minor(*d
) > 255 || minor(*d
) < 0)
818 printf("{ major = %d, minor = 0x%x }",
819 major(*d
), minor(*d
));
821 printf("{ major = %d, minor = %d }",
822 major(*d
), minor(*d
));
828 * These functions uses a presently undocumented interface to the kernel
829 * to walk the tree and get the type so it can print the value.
830 * This interface is under work and consideration, and should probably
831 * be killed with a big axe by the first person who can find the time.
832 * (be aware though, that the proper interface isn't as obvious as it
833 * may seem, there are various conflicting requirements.
837 name2oid(char *name
, int *oidp
)
846 j
= CTL_MAXNAME
* sizeof (int);
847 i
= sysctl(oid
, 2, oidp
, &j
, name
, strlen(name
));
855 oidfmt(int *oid
, int len
, char *fmt
, u_int
*kind
)
857 int qoid
[CTL_MAXNAME
+2];
864 memcpy(qoid
+ 2, oid
, len
* sizeof(int));
867 i
= sysctl(qoid
, len
+ 2, buf
, &j
, 0, 0);
869 err(1, "sysctl fmt %d %d %d", i
, j
, errno
);
872 *kind
= *(u_int
*)buf
;
875 strcpy(fmt
, (char *)(buf
+ sizeof(u_int
)));
880 * This formats and outputs the value of one variable
882 * Returns zero if anything was actually output.
883 * Returns one if didn't know what to do with this.
884 * Return minus one if we had errors.
888 show_var(int *oid
, int nlen
)
890 u_char buf
[BUFSIZ
], *val
, *p
;
891 char name
[BUFSIZ
], /* descr[BUFSIZ], */ *fmt
;
892 int qoid
[CTL_MAXNAME
+2];
896 int (*func
)(int, void *) = 0;
899 memcpy(qoid
+ 2, oid
, nlen
* sizeof(int));
903 i
= sysctl(qoid
, nlen
+ 2, name
, &j
, 0, 0);
905 err(1, "sysctl name %d %d %d", i
, j
, errno
);
907 /* find an estimate of how much we need for this var */
909 i
= sysctl(oid
, nlen
, 0, &j
, 0, 0);
910 j
+= j
; /* we want to be sure :-) */
914 i
= sysctl(oid
, nlen
, val
, &len
, 0, 0);
919 fwrite(val
, 1, len
, stdout
);
925 i
= sysctl(qoid
, nlen
+ 2, buf
, &j
, 0, 0);
927 err(1, "sysctl fmt %d %d %d", i
, j
, errno
);
929 kind
= *(u_int
*)buf
;
931 fmt
= (char *)(buf
+ sizeof(u_int
));
937 printf("%s: ", name
);
943 printf("%s: ", name
);
946 while (len
>= sizeof(int)) {
948 printf("%s%u", val
, *(unsigned int *)p
);
950 printf("%s%d", val
, *(int *)p
);
959 printf("%s: ", name
);
962 while (len
>= sizeof(long)) {
964 printf("%s%lu", val
, *(unsigned long *)p
);
966 printf("%s%ld", val
, *(long *)p
);
968 len
-= sizeof (long);
975 printf("%s: ", name
);
976 printf("%p", *(void **)p
);
982 if (!strcmp(fmt
, "S,clockinfo")) func
= S_clockinfo
;
983 else if (!strcmp(fmt
, "S,timeval")) func
= S_timeval
;
984 else if (!strcmp(fmt
, "S,loadavg")) func
= S_loadavg
;
985 else if (!strcmp(fmt
, "T,dev_t")) func
= T_dev_t
;
988 printf("%s: ", name
);
989 return ((*func
)(len
, p
));
996 printf("%s: ", name
);
997 printf("Format:%s Length:%ld Dump:0x", fmt
, len
);
999 printf("%02x", *p
++);
1000 if (Xflag
|| p
< val
+16)
1011 sysctl_all (int *oid
, int len
)
1013 int name1
[22], name2
[22];
1021 memcpy(name1
+2, oid
, len
*sizeof (int));
1029 j
= sysctl(name1
, l1
, name2
, &l2
, 0, 0);
1031 if (errno
== ENOENT
)
1034 err(1, "sysctl(getnext) %d %d", j
, l2
);
1042 for (i
= 0; i
< len
; i
++)
1043 if (name2
[i
] != oid
[i
])
1046 i
= show_var(name2
, l2
);
1050 memcpy(name1
+2, name2
, l2
*sizeof (int));