From f97c062bec223fe6716fac1497b773e0deac83a1 Mon Sep 17 00:00:00 2001 From: alfred Date: Wed, 12 Dec 2012 02:55:40 +0000 Subject: 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. --- sbin/sysctl/sysctl.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'sbin/sysctl') 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) -- cgit v1.1