summaryrefslogtreecommitdiffstats
path: root/sbin/sysctl/sysctl.c
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2012-12-11 01:28:06 +0000
committeralfred <alfred@FreeBSD.org>2012-12-11 01:28:06 +0000
commit2a065c7bf07356bbc84ff330f04ecf38d851febf (patch)
tree837ee4aba0e9bdea5797e911dbfb8c4477e390a1 /sbin/sysctl/sysctl.c
parentf63b721d8ae8f97828573d890c7de47e03cac25c (diff)
downloadFreeBSD-src-2a065c7bf07356bbc84ff330f04ecf38d851febf.zip
FreeBSD-src-2a065c7bf07356bbc84ff330f04ecf38d851febf.tar.gz
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
Diffstat (limited to 'sbin/sysctl/sysctl.c')
-rw-r--r--sbin/sysctl/sysctl.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 83e1337..a1acf88 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -59,7 +59,7 @@ static const char rcsid[] =
#include <unistd.h>
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)
OpenPOWER on IntegriCloud