From owner-svn-src-all@FreeBSD.ORG Tue Dec 11 01:28:07 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 81E81695; Tue, 11 Dec 2012 01:28:07 +0000 (UTC) (envelope-from alfred@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 674768FC08; Tue, 11 Dec 2012 01:28:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id qBB1S7fo061275; Tue, 11 Dec 2012 01:28:07 GMT (envelope-from alfred@svn.freebsd.org) Received: (from alfred@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id qBB1S7rh061270; Tue, 11 Dec 2012 01:28:07 GMT (envelope-from alfred@svn.freebsd.org) Message-Id: <201212110128.qBB1S7rh061270@svn.freebsd.org> From: Alfred Perlstein Date: Tue, 11 Dec 2012 01:28:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r244106 - head/sbin/sysctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2012 01:28:07 -0000 Author: alfred Date: Tue Dec 11 01:28:06 2012 New Revision: 244106 URL: http://svnweb.freebsd.org/changeset/base/244106 Log: Allow sysctl to filter boot and runtime tunables. Add the following flags to sysctl: -W - show only writable sysctls -T - show only tuneable sysctls This can be used to create a /var/run/sysctl.boot to compare set tunables versus booted tunables. Sponsored by: iXsystems Modified: head/sbin/sysctl/sysctl.8 head/sbin/sysctl/sysctl.c Modified: head/sbin/sysctl/sysctl.8 ============================================================================== --- head/sbin/sysctl/sysctl.8 Tue Dec 11 01:23:50 2012 (r244105) +++ head/sbin/sysctl/sysctl.8 Tue Dec 11 01:28:06 2012 (r244106) @@ -36,11 +36,11 @@ .Nd get or set kernel state .Sh SYNOPSIS .Nm -.Op Fl bdehiNnoqx +.Op Fl bdehiNnoRTqx .Ar name Ns Op = Ns Ar value .Ar ... .Nm -.Op Fl bdehNnoqx +.Op Fl bdehNnoRTqx .Fl a .Sh DESCRIPTION The @@ -121,6 +121,11 @@ sixteen bytes of the value. Suppress some warnings generated by .Nm to standard error. +.It Fl T +Display only variables that are setable via loader (CTLFLAG_TUN). +.It Fl W +Display only wriable variables that are not statistical. +Useful for determining the set of runtime tunable sysctls. .It Fl X Equivalent to .Fl x a Modified: head/sbin/sysctl/sysctl.c ============================================================================== --- head/sbin/sysctl/sysctl.c Tue Dec 11 01:23:50 2012 (r244105) +++ head/sbin/sysctl/sysctl.c Tue Dec 11 01:28:06 2012 (r244106) @@ -59,7 +59,7 @@ static const char rcsid[] = #include static int aflag, bflag, dflag, eflag, hflag, iflag; -static int Nflag, nflag, oflag, qflag, xflag, warncount; +static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag, warncount; static int oidfmt(int *, int, char *, u_int *); static void parse(const char *); @@ -74,8 +74,8 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bdehiNnoqx] name[=value] ...", - " sysctl [-bdehNnoqx] -a"); + "usage: sysctl [-bdehiNnoqTWx] name[=value] ...", + " sysctl [-bdehNnoqTWx] -a"); exit(1); } @@ -88,7 +88,7 @@ main(int argc, char **argv) setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabdehiNnoqwxX")) != -1) { + while ((ch = getopt(argc, argv, "AabdehiNnoqTwWxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -124,10 +124,16 @@ main(int argc, char **argv) case 'q': qflag = 1; break; + case 'T': + Tflag = 1; + break; case 'w': /* compatibility */ /* ignored */ break; + case 'W': + Wflag = 1; + break; case 'X': /* compatibility */ aflag = xflag = 1; @@ -181,6 +187,11 @@ parse(const char *string) errx(1, "oid too long: '%s'", string); bufp = strsep(&cp, "="); if (cp != NULL) { + /* Tflag just lists tunables, do not allow assignment */ + if (Tflag || Wflag) { + warnx("Can't set variables when using -T or -W"); + usage(); + } while (isspace(*cp)) cp++; newval = cp; @@ -602,6 +613,14 @@ show_var(int *oid, int nlen) 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)