Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Dec 2012 02:55:41 +0000 (UTC)
From:      Alfred Perlstein <alfred@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r244133 - head/sbin/sysctl
Message-ID:  <201212120255.qBC2tfj2045784@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212120255.qBC2tfj2045784>