Author: alfred
Date: Wed Dec 12 02:55:40 2012
New Revision: 244133
URL: http://svnweb.freebsd.org/changeset/base/244133

Log:
  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.

Modified:
  head/sbin/sysctl/sysctl.c

Modified: head/sbin/sysctl/sysctl.c
==============================================================================
--- head/sbin/sysctl/sysctl.c   Wed Dec 12 01:50:58 2012        (r244132)
+++ head/sbin/sysctl/sysctl.c   Wed Dec 12 02:55:40 2012        (r244133)
@@ -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)
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to