Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/sysctl/sysctl.c
Show First 20 Lines • Show All 946 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* Returns zero if anything was actually output. | * Returns zero if anything was actually output. | ||||
* Returns one if didn't know what to do with this. | * Returns one if didn't know what to do with this. | ||||
* Return minus one if we had errors. | * Return minus one if we had errors. | ||||
*/ | */ | ||||
static int | static int | ||||
show_var(int *oid, int nlen, bool honor_skip) | show_var(int *oid, int nlen, bool honor_skip) | ||||
{ | { | ||||
static int skip_len = 0, skip_oid[CTL_MAXNAME]; | |||||
u_char buf[BUFSIZ], *val, *oval, *p; | u_char buf[BUFSIZ], *val, *oval, *p; | ||||
char name[BUFSIZ], fmt[BUFSIZ]; | char name[BUFSIZ], fmt[BUFSIZ]; | ||||
const char *sep, *sep1, *prntype; | const char *sep, *sep1, *prntype; | ||||
int qoid[CTL_MAXNAME+2]; | int qoid[CTL_MAXNAME+2]; | ||||
uintmax_t umv; | uintmax_t umv; | ||||
intmax_t mv; | intmax_t mv; | ||||
int i, hexlen, sign, ctltype; | int i, hexlen, sign, ctltype; | ||||
size_t intlen; | size_t intlen; | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (tflag || dflag) { | ||||
} | } | ||||
qoid[1] = CTL_SYSCTL_OIDDESCR; | qoid[1] = CTL_SYSCTL_OIDDESCR; | ||||
j = sizeof(buf); | j = sizeof(buf); | ||||
i = sysctl(qoid, nlen + 2, buf, &j, 0, 0); | i = sysctl(qoid, nlen + 2, buf, &j, 0, 0); | ||||
printf("%s", buf); | printf("%s", buf); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* keep track of encountered skip nodes, ignoring descendants */ | |||||
if (skip_len == 0 && (kind & CTLFLAG_SKIP) != 0) { | |||||
/* Save this oid so we can skip descendants. */ | |||||
skip_len = nlen * sizeof(int); | |||||
memcpy(skip_oid, oid, skip_len); | |||||
} | |||||
/* bail before fetching the value if we're honoring skip */ | /* bail before fetching the value if we're honoring skip */ | ||||
if (honor_skip && (kind & CTLFLAG_SKIP) != 0) | if (honor_skip) { | ||||
if (0 < skip_len && skip_len <= nlen * (int)sizeof(int) && | |||||
memcmp(skip_oid, oid, skip_len) == 0) | |||||
return (1); | return (1); | ||||
/* Not a skip node or descendant of a skip node. */ | |||||
skip_len = 0; | |||||
} | |||||
/* don't fetch opaques that we don't know how to print */ | /* don't fetch opaques that we don't know how to print */ | ||||
if (ctltype == CTLTYPE_OPAQUE) { | if (ctltype == CTLTYPE_OPAQUE) { | ||||
if (strcmp(fmt, "S,clockinfo") == 0) | if (strcmp(fmt, "S,clockinfo") == 0) | ||||
func = S_clockinfo; | func = S_clockinfo; | ||||
else if (strcmp(fmt, "S,timeval") == 0) | else if (strcmp(fmt, "S,timeval") == 0) | ||||
func = S_timeval; | func = S_timeval; | ||||
else if (strcmp(fmt, "S,loadavg") == 0) | else if (strcmp(fmt, "S,loadavg") == 0) | ||||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |