diff options
author | alfred <alfred@FreeBSD.org> | 2012-12-12 02:55:40 +0000 |
---|---|---|
committer | alfred <alfred@FreeBSD.org> | 2012-12-12 02:55:40 +0000 |
commit | f97c062bec223fe6716fac1497b773e0deac83a1 (patch) | |
tree | 67366cf021b1a64368c78470789a10dcd39b40c6 /sbin/sysctl | |
parent | a23c0ad41dbeb143459da5e55eb43f9f8aa991c5 (diff) | |
download | FreeBSD-src-f97c062bec223fe6716fac1497b773e0deac83a1.zip FreeBSD-src-f97c062bec223fe6716fac1497b773e0deac83a1.tar.gz |
Make Tflag and Wflag filters work for more sysctl options.
To do this move the Tflag and Wflag checks earlier in show_var() so
we bail earlier for variables not matching our query.
Diffstat (limited to 'sbin/sysctl')
-rw-r--r-- | sbin/sysctl/sysctl.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index a1acf88..a9c2b7a 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -539,7 +539,7 @@ static int show_var(int *oid, int nlen) { u_char buf[BUFSIZ], *val, *oval, *p; - char name[BUFSIZ], *fmt; + char name[BUFSIZ], fmt[BUFSIZ]; const char *sep, *sep1; int qoid[CTL_MAXNAME+2]; uintmax_t umv; @@ -554,6 +554,7 @@ show_var(int *oid, int nlen) umv = mv = intlen = 0; bzero(buf, BUFSIZ); + bzero(fmt, BUFSIZ); bzero(name, BUFSIZ); qoid[0] = 0; memcpy(qoid + 2, oid, nlen * sizeof(int)); @@ -564,6 +565,15 @@ show_var(int *oid, int nlen) if (i || !j) err(1, "sysctl name %d %zu %d", i, j, errno); + oidfmt(oid, nlen, fmt, &kind); + /* if Wflag then only list sysctls that are writeable and not stats. */ + if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0)) + return 1; + + /* if Tflag then only list sysctls that are tuneables. */ + if (Tflag && (kind & CTLFLAG_TUN) == 0) + return 1; + if (Nflag) { printf("%s", name); return (0); @@ -606,21 +616,11 @@ show_var(int *oid, int nlen) return (0); } val[len] = '\0'; - fmt = buf; - oidfmt(oid, nlen, fmt, &kind); p = val; ctltype = (kind & CTLTYPE); sign = ctl_sign[ctltype]; intlen = ctl_size[ctltype]; - /* if Wflag then only list sysctls that are writeable and not stats. */ - if (Wflag && ((kind & CTLFLAG_WR) == 0 || (kind & CTLFLAG_STATS) != 0)) - return 1; - - /* if Tflag then only list sysctls that are tuneables. */ - if (Tflag && (kind & CTLFLAG_TUN) == 0) - return 1; - switch (ctltype) { case CTLTYPE_STRING: if (!nflag) |