Add -t option to display field types.

PR:		bin/203918
Submitted by:	ota <ota@j.email.ne.jp>
Reviewed by:	cem
Approved by:	bapt (mentor)
Differential Revision:	https://reviews.freebsd.org/D4451
This commit is contained in:
Marcelo Araujo 2015-12-10 02:11:42 +00:00
parent 6a301ac85a
commit 8020192d7b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=292045
2 changed files with 30 additions and 12 deletions

View File

@ -28,7 +28,7 @@
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
.Dd February 12, 2015
.Dd December 10, 2015
.Dt SYSCTL 8
.Os
.Sh NAME
@ -36,13 +36,13 @@
.Nd get or set kernel state
.Sh SYNOPSIS
.Nm
.Op Fl bdehiNnoRTqx
.Op Fl bdehiNnoRTtqx
.Op Fl B Ar bufsize
.Op Fl f Ar filename
.Ar name Ns Op = Ns Ar value
.Ar ...
.Nm
.Op Fl bdehNnoRTqx
.Op Fl bdehNnoRTtqx
.Op Fl B Ar bufsize
.Fl a
.Sh DESCRIPTION
@ -140,6 +140,8 @@ Suppress some warnings generated by
to standard error.
.It Fl T
Display only variables that are settable via loader (CTLFLAG_TUN).
.It Fl t
Print the type of the variable.
.It Fl W
Display only writable variables that are not statistical.
Useful for determining the set of runtime tunable sysctls.

View File

@ -72,7 +72,7 @@ static const char rcsid[] =
static const char *conffile;
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, Tflag, Wflag, xflag;
static int oidfmt(int *, int, char *, u_int *);
static int parsefile(const char *);
@ -120,6 +120,9 @@ static const char *ctl_typename[CTLTYPE+1] = {
[CTLTYPE_S16] = "int16_t",
[CTLTYPE_S32] = "int32_t",
[CTLTYPE_S64] = "int64_t",
[CTLTYPE_NODE] = "node",
[CTLTYPE_STRING] = "string",
[CTLTYPE_OPAQUE] = "opaque",
};
static void
@ -127,8 +130,8 @@ usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: sysctl [-bdehiNnoqTWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
" sysctl [-bdehNnoqTWx] [ -B <bufsize> ] -a");
"usage: sysctl [-bdehiNnoqTtWx] [ -B <bufsize> ] [-f filename] name[=value] ...",
" sysctl [-bdehNnoqTtWx] [ -B <bufsize> ] -a");
exit(1);
}
@ -142,7 +145,7 @@ main(int argc, char **argv)
setbuf(stdout,0);
setbuf(stderr,0);
while ((ch = getopt(argc, argv, "AabB:def:hiNnoqTwWxX")) != -1) {
while ((ch = getopt(argc, argv, "AabB:def:hiNnoqtTwWxX")) != -1) {
switch (ch) {
case 'A':
/* compatibility */
@ -184,6 +187,9 @@ main(int argc, char **argv)
case 'q':
qflag = 1;
break;
case 't':
tflag = 1;
break;
case 'T':
Tflag = 1;
break;
@ -856,7 +862,7 @@ show_var(int *oid, int nlen)
{
u_char buf[BUFSIZ], *val, *oval, *p;
char name[BUFSIZ], fmt[BUFSIZ];
const char *sep, *sep1;
const char *sep, *sep1, *prntype;
int qoid[CTL_MAXNAME+2];
uintmax_t umv;
intmax_t mv;
@ -902,12 +908,23 @@ show_var(int *oid, int nlen)
else
sep = ": ";
if (dflag) { /* just print description */
ctltype = (kind & CTLTYPE);
if (tflag || dflag) {
if (!nflag)
printf("%s%s", name, sep);
if (ctl_typename[ctltype] != NULL)
prntype = ctl_typename[ctltype];
else
prntype = "unknown";
if (tflag && dflag)
printf("%s%s", prntype, sep);
else if (tflag) {
printf("%s", prntype);
return (0);
}
qoid[1] = 5;
j = sizeof(buf);
i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
if (!nflag)
printf("%s%s", name, sep);
printf("%s", buf);
return (0);
}
@ -925,7 +942,6 @@ show_var(int *oid, int nlen)
warnx("malloc failed");
return (1);
}
ctltype = (kind & CTLTYPE);
len = j;
i = sysctl(oid, nlen, val, &len, 0, 0);
if (i != 0 || (len == 0 && ctltype != CTLTYPE_STRING)) {