mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
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...
This commit is contained in:
parent
01f66c0831
commit
7582000531
@ -28,7 +28,7 @@
|
|||||||
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
|
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd December 13, 2012
|
.Dd February 12, 2015
|
||||||
.Dt SYSCTL 8
|
.Dt SYSCTL 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -37,11 +37,13 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl bdehiNnoRTqx
|
.Op Fl bdehiNnoRTqx
|
||||||
|
.Op Fl B Ar bufsize
|
||||||
.Op Fl f Ar filename
|
.Op Fl f Ar filename
|
||||||
.Ar name Ns Op = Ns Ar value
|
.Ar name Ns Op = Ns Ar value
|
||||||
.Ar ...
|
.Ar ...
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl bdehNnoRTqx
|
.Op Fl bdehNnoRTqx
|
||||||
|
.Op Fl B Ar bufsize
|
||||||
.Fl a
|
.Fl a
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
@ -68,6 +70,15 @@ the command line.
|
|||||||
Force the value of the variable(s) to be output in raw, binary format.
|
Force the value of the variable(s) to be output in raw, binary format.
|
||||||
No names are printed and no terminating newlines are output.
|
No names are printed and no terminating newlines are output.
|
||||||
This is mostly useful with a single variable.
|
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
|
.It Fl d
|
||||||
Print the description of the variable instead of its value.
|
Print the description of the variable instead of its value.
|
||||||
.It Fl e
|
.It Fl e
|
||||||
@ -128,7 +139,7 @@ Suppress some warnings generated by
|
|||||||
.Nm
|
.Nm
|
||||||
to standard error.
|
to standard error.
|
||||||
.It Fl T
|
.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
|
.It Fl W
|
||||||
Display only writable variables that are not statistical.
|
Display only writable variables that are not statistical.
|
||||||
Useful for determining the set of runtime tunable sysctls.
|
Useful for determining the set of runtime tunable sysctls.
|
||||||
|
@ -71,7 +71,7 @@ static const char rcsid[] =
|
|||||||
|
|
||||||
static const char *conffile;
|
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 Nflag, nflag, oflag, qflag, Tflag, Wflag, xflag;
|
||||||
|
|
||||||
static int oidfmt(int *, int, char *, u_int *);
|
static int oidfmt(int *, int, char *, u_int *);
|
||||||
@ -112,8 +112,8 @@ usage(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: sysctl [-bdehiNnoqTWx] [-f filename] name[=value] ...",
|
"usage: sysctl [-bdehiNnoqTWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
|
||||||
" sysctl [-bdehNnoqTWx] -a");
|
" sysctl [-bdehNnoqTWx] [ -B <bufsize> ] -a");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ main(int argc, char **argv)
|
|||||||
setbuf(stdout,0);
|
setbuf(stdout,0);
|
||||||
setbuf(stderr,0);
|
setbuf(stderr,0);
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "Aabdef:hiNnoqTwWxX")) != -1) {
|
while ((ch = getopt(argc, argv, "AabB:def:hiNnoqTwWxX")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'A':
|
case 'A':
|
||||||
/* compatibility */
|
/* compatibility */
|
||||||
@ -139,6 +139,9 @@ main(int argc, char **argv)
|
|||||||
case 'b':
|
case 'b':
|
||||||
bflag = 1;
|
bflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'B':
|
||||||
|
Bflag = strtol(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
dflag = 1;
|
dflag = 1;
|
||||||
break;
|
break;
|
||||||
@ -222,7 +225,7 @@ parse(const char *string, int lineno)
|
|||||||
unsigned int uintval;
|
unsigned int uintval;
|
||||||
long longval;
|
long longval;
|
||||||
unsigned long ulongval;
|
unsigned long ulongval;
|
||||||
size_t newsize = 0;
|
size_t newsize = Bflag;
|
||||||
int64_t i64val;
|
int64_t i64val;
|
||||||
uint64_t u64val;
|
uint64_t u64val;
|
||||||
int mib[CTL_MAXNAME];
|
int mib[CTL_MAXNAME];
|
||||||
@ -815,9 +818,13 @@ show_var(int *oid, int nlen)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
/* find an estimate of how much we need for this var */
|
/* find an estimate of how much we need for this var */
|
||||||
j = 0;
|
if (Bflag)
|
||||||
i = sysctl(oid, nlen, 0, &j, 0, 0);
|
j = Bflag;
|
||||||
j += j; /* we want to be sure :-) */
|
else {
|
||||||
|
j = 0;
|
||||||
|
i = sysctl(oid, nlen, 0, &j, 0, 0);
|
||||||
|
j += j; /* we want to be sure :-) */
|
||||||
|
}
|
||||||
|
|
||||||
val = oval = malloc(j + 1);
|
val = oval = malloc(j + 1);
|
||||||
if (val == NULL) {
|
if (val == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user