diff options
author | araujo <araujo@FreeBSD.org> | 2015-12-10 02:11:42 +0000 |
---|---|---|
committer | araujo <araujo@FreeBSD.org> | 2015-12-10 02:11:42 +0000 |
commit | 9032c5bca2f4dcce582824f138e7629c3570a00a (patch) | |
tree | 8624e72d37984e4ca3b28d133d624996b9ca7b50 /sbin/sysctl | |
parent | 0a85f054bd5a318ab31fd192648b716a85572349 (diff) | |
download | FreeBSD-src-9032c5bca2f4dcce582824f138e7629c3570a00a.zip FreeBSD-src-9032c5bca2f4dcce582824f138e7629c3570a00a.tar.gz |
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
Diffstat (limited to 'sbin/sysctl')
-rw-r--r-- | sbin/sysctl/sysctl.8 | 8 | ||||
-rw-r--r-- | sbin/sysctl/sysctl.c | 34 |
2 files changed, 30 insertions, 12 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8 index cb8145e..8d2d316 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 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. diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 1cd31c0..6b493c6 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -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)) { |