diff options
author | jmg <jmg@FreeBSD.org> | 2015-02-13 01:20:37 +0000 |
---|---|---|
committer | jmg <jmg@FreeBSD.org> | 2015-02-13 01:20:37 +0000 |
commit | 4975cde94ae30e121d9ee2fec2456e4306011f72 (patch) | |
tree | 1b97d0d404030da1b55c4b7fe036f2ac9c90c1e2 /sbin/sysctl | |
parent | dd948d6f916470ac593900102223e47a4cd5ca3e (diff) | |
download | FreeBSD-src-4975cde94ae30e121d9ee2fec2456e4306011f72.zip FreeBSD-src-4975cde94ae30e121d9ee2fec2456e4306011f72.tar.gz |
add support for specifying an initial buffer size when fetching a
sysctl... This is useful for kern.arandom which (without -B) will
happily return 0 bytes, which isn't too useful or random...
fix spelling (thanks igor!) of settable while I'm here...
Diffstat (limited to 'sbin/sysctl')
-rw-r--r-- | sbin/sysctl/sysctl.8 | 15 | ||||
-rw-r--r-- | sbin/sysctl/sysctl.c | 23 |
2 files changed, 28 insertions, 10 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8 index b81de6e..cb8145e 100644 --- a/sbin/sysctl/sysctl.8 +++ b/sbin/sysctl/sysctl.8 @@ -28,7 +28,7 @@ .\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd December 13, 2012 +.Dd February 12, 2015 .Dt SYSCTL 8 .Os .Sh NAME @@ -37,11 +37,13 @@ .Sh SYNOPSIS .Nm .Op Fl bdehiNnoRTqx +.Op Fl B Ar bufsize .Op Fl f Ar filename .Ar name Ns Op = Ns Ar value .Ar ... .Nm .Op Fl bdehNnoRTqx +.Op Fl B Ar bufsize .Fl a .Sh DESCRIPTION The @@ -68,6 +70,15 @@ the command line. Force the value of the variable(s) to be output in raw, binary format. No names are printed and no terminating newlines are output. This is mostly useful with a single variable. +.It Fl B Ar bufsize +Set the buffer size to read from the +.Nm +to +.Ar bufsize . +This is necessary for a +.Nm +that has variable length, and the probe value of 0 is a valid length, such as +.Va kern.arandom . .It Fl d Print the description of the variable instead of its value. .It Fl e @@ -128,7 +139,7 @@ Suppress some warnings generated by .Nm to standard error. .It Fl T -Display only variables that are setable via loader (CTLFLAG_TUN). +Display only variables that are settable via loader (CTLFLAG_TUN). .It Fl W Display only writable variables that are not statistical. Useful for determining the set of runtime tunable sysctls. diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 6849b9e..f321120 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -71,7 +71,7 @@ static const char rcsid[] = static const char *conffile; -static int aflag, bflag, dflag, eflag, hflag, iflag; +static int aflag, bflag, Bflag, dflag, eflag, hflag, iflag; static int Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag; static int oidfmt(int *, int, char *, u_int *); @@ -112,8 +112,8 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: sysctl [-bdehiNnoqTWx] [-f filename] name[=value] ...", - " sysctl [-bdehNnoqTWx] -a"); + "usage: sysctl [-bdehiNnoqTWx] [ -B <bufsize> ] [-f filename] name[=value] ...", + " sysctl [-bdehNnoqTWx] [ -B <bufsize> ] -a"); exit(1); } @@ -127,7 +127,7 @@ main(int argc, char **argv) setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "Aabdef:hiNnoqTwWxX")) != -1) { + while ((ch = getopt(argc, argv, "AabB:def:hiNnoqTwWxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -139,6 +139,9 @@ main(int argc, char **argv) case 'b': bflag = 1; break; + case 'B': + Bflag = strtol(optarg, NULL, 0); + break; case 'd': dflag = 1; break; @@ -222,7 +225,7 @@ parse(const char *string, int lineno) unsigned int uintval; long longval; unsigned long ulongval; - size_t newsize = 0; + size_t newsize = Bflag; int64_t i64val; uint64_t u64val; int mib[CTL_MAXNAME]; @@ -815,9 +818,13 @@ show_var(int *oid, int nlen) return (0); } /* find an estimate of how much we need for this var */ - j = 0; - i = sysctl(oid, nlen, 0, &j, 0, 0); - j += j; /* we want to be sure :-) */ + if (Bflag) + j = Bflag; + else { + j = 0; + i = sysctl(oid, nlen, 0, &j, 0, 0); + j += j; /* we want to be sure :-) */ + } val = oval = malloc(j + 1); if (val == NULL) { |