- }
- }
- size = BUFSIZ;
- if (sysctl(mib, len, buf, &size, newsize ? newval : 0, newsize) == -1) {
- if (flags == 0)
- return;
- switch (errno) {
- case ENOTSUP:
- fprintf(stderr, "%s: value is not available\n", string);
- return;
- case ENOTDIR:
- fprintf(stderr, "%s: specification is incomplete\n",
- string);
- return;
- case ENOMEM:
- fprintf(stderr, "%s: type is unknown to this program\n",
- string);
- return;
- case ENOENT:
- fprintf(stderr, "%s: no such MIB\n",
- string);
- return;
- default:
- perror(string);
- return;
- }
- }
- if (special & CLOCK) {
- struct clockinfo *clkp = (struct clockinfo *)buf;
-
- if (!nflag)
- fprintf(stdout, "%s: ", string);
- fprintf(stdout,
- "hz = %d, tick = %d, profhz = %d, stathz = %d\n",
- clkp->hz, clkp->tick, clkp->profhz, clkp->stathz);
- return;
- }
- if (special & BOOTTIME) {
- struct timeval *btp = (struct timeval *)buf;
-
- if (!nflag)
- fprintf(stdout, "%s = %s\n", string,
- ctime((time_t *) &btp->tv_sec));
- else
- fprintf(stdout, "%ld\n", btp->tv_sec);
- return;
- }
- if (special & CONSDEV) {
- dev_t dev = *(dev_t *)buf;
-
- if (!nflag)
- fprintf(stdout, "%s = %s\n", string,
- devname(dev, S_IFCHR));
- else
- fprintf(stdout, "0x%x\n", dev);
- return;
- }
- switch (type) {
- case CTLTYPE_INT:
- if (newsize == 0) {
- if (!nflag)
- fprintf(stdout, "%s = ", string);
- fprintf(stdout, useUnsignedInt ? "%u\n" : "%d\n", *(int *)buf);
- } else {
- if (!nflag)
- fprintf(stdout, useUnsignedInt ? "%s: %u -> " : "%s: %d -> ",
- string, *(int *)buf);
- fprintf(stdout, useUnsignedInt ? "%u\n" : "%d\n", *(int *)newval);
- }
- return;
-
- case CTLTYPE_STRING:
- if (newsize == 0) {
- if (!nflag)
- fprintf(stdout, "%s = ", string);
- fprintf(stdout, "%s\n", buf);
- } else {
- if (!nflag)
- fprintf(stdout, "%s: %s -> ", string, buf);
- fprintf(stdout, "%s\n", (char *) newval);
- }
- return;
-
- case CTLTYPE_QUAD:
- if (newsize == 0) {
- if (!nflag)
- fprintf(stdout, "%s = ", string);
- fprintf(stdout, "%qd\n", *(quad_t *)buf);
- } else {
- if (!nflag)
- fprintf(stdout, "%s: %qd -> ", string,
- *(quad_t *)buf);
- fprintf(stdout, "%qd\n", *(quad_t *)newval);
- }
- return;
-
- case CTLTYPE_NODE:
- case CTLTYPE_STRUCT:
- return;
-
- default:
- fprintf(stderr, "%s: unknown type returned\n",
- string);
- return;
- }
-}
-
-/*
- * Initialize the set of debugging names
- */
-void debuginit()
-{
- int mib[3], loc, i;
- size_t size;
-
- if (secondlevel[CTL_DEBUG].list != 0)
- return;
- secondlevel[CTL_DEBUG].list = debugname;
- mib[0] = CTL_DEBUG;
- mib[2] = CTL_DEBUG_NAME;
- for (loc = lastused, i = 0; i < CTL_DEBUG_MAXID; i++) {
- mib[1] = i;
- size = BUFSIZ - loc;
- if (sysctl(mib, 3, &names[loc], &size, NULL, 0) == -1)
- continue;
- debugname[i].ctl_name = &names[loc];
- debugname[i].ctl_type = CTLTYPE_INT;
- loc += size;
- }
- lastused = loc;
-}
-
-/*
- * Initialize the set of filesystem names
- */
-void vfsinit()
-{
- int mib[4], maxtypenum, cnt, loc, size;
- struct vfsconf vfc;
- size_t buflen;
-
- if (secondlevel[CTL_VFS].list != 0)
- return;
- mib[0] = CTL_VFS;
- mib[1] = VFS_GENERIC;
- mib[2] = VFS_MAXTYPENUM;
- buflen = 4;
- if (sysctl(mib, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0)
- return;
- if ((vfsname = malloc(maxtypenum * sizeof(*vfsname))) == 0)
- return;
- memset(vfsname, 0, maxtypenum * sizeof(*vfsname));
- mib[2] = VFS_CONF;
- buflen = sizeof vfc;
- for (loc = lastused, cnt = 0; cnt < maxtypenum; cnt++) {
- mib[3] = cnt;
- if (sysctl(mib, 4, &vfc, &buflen, (void *)0, (size_t)0) < 0) {
- if (errno == ENOTSUP)
- continue;
- perror("vfsinit");
- free(vfsname);
- return;
- }
- strcat(&names[loc], vfc.vfc_name);
- vfsname[cnt].ctl_name = &names[loc];
- vfsname[cnt].ctl_type = CTLTYPE_INT;
- size = strlen(vfc.vfc_name) + 1;
- loc += size;
- }
- lastused = loc;
- secondlevel[CTL_VFS].list = vfsname;
- secondlevel[CTL_VFS].size = maxtypenum;
- return;
-}
-
-/*
- * Scan a list of names searching for a particular name.
- */
-int
-findname(string, level, bufp, namelist)
- char *string;
- char *level;
- char **bufp;
- struct list *namelist;
-{
- char *name;
- int i;
-
- /* Make 'sysctl kern.' style behave the same as 'sysctl kern' 3360872*/
- if (bufp[0][strlen(*bufp)-1] == '.')
- bufp[0][strlen(*bufp)-1]='\0';
- if (namelist->list == 0 || (name = strsep(bufp, ".")) == NULL) {
- if (!foundSome) {
- fprintf(stderr, "%s: incomplete specification\n", string);
- invalid_name_used = 1;
- }
- return (-1);
- }
- for (i = 0; i < namelist->size; i++)
- if (namelist->list[i].ctl_name != NULL &&
- strcmp(name, namelist->list[i].ctl_name) == 0)