summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>1999-01-10 02:10:08 +0000
committerdes <des@FreeBSD.org>1999-01-10 02:10:08 +0000
commitcd585d50b4ac13d04faee5c4f5597b323fa5195b (patch)
treed579d686931fb86a54f5a2ecc27d9f0717ca23ae
parent9efaefb948b4c8c90de8b30691aad110bf960dc9 (diff)
downloadFreeBSD-src-cd585d50b4ac13d04faee5c4f5597b323fa5195b.zip
FreeBSD-src-cd585d50b4ac13d04faee5c4f5597b323fa5195b.tar.gz
Clean up option handling a little.
Add an option for showing sysctl descriptions instead of their values.
-rw-r--r--sbin/sysctl/sysctl.89
-rw-r--r--sbin/sysctl/sysctl.c52
-rw-r--r--usr.sbin/sysctl/sysctl.89
-rw-r--r--usr.sbin/sysctl/sysctl.c52
4 files changed, 80 insertions, 42 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8
index 455dcac..e959ecd 100644
--- a/sbin/sysctl/sysctl.8
+++ b/sbin/sysctl/sysctl.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
-.\" $Id: sysctl.8,v 1.16 1998/07/29 08:30:37 joerg Exp $
+.\" $Id: sysctl.8,v 1.17 1998/09/29 02:01:06 jkoshy Exp $
.\"
.Dd September 23, 1994
.Dt SYSCTL 8
@@ -40,14 +40,14 @@
.Nd get or set kernel state
.Sh SYNOPSIS
.Nm sysctl
-.Op Fl bn
+.Op Fl bdn
.Ar name ...
.Nm sysctl
.Op Fl bn
.Fl w
.Ar name=value ...
.Nm sysctl
-.Op Fl bn
+.Op Fl bdn
.Fl aAX
.Sh DESCRIPTION
The
@@ -85,6 +85,9 @@ set psize=`sysctl -n hw.pagesize`
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 d
+Display the description rather than the value of the requested
+variable(s).
.It Fl w Ar name=value ...
Set the MIB
.Ar name
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 94e630e..f264409 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)from: sysctl.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: sysctl.c,v 1.18 1998/08/25 07:38:19 dfr Exp $";
+ "$Id: sysctl.c,v 1.19 1998/11/08 19:27:43 phk Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -58,7 +58,7 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
-static int Aflag, aflag, nflag, wflag, Xflag, bflag;
+static int Aflag, aflag, bflag, dflag, nflag, wflag, Xflag;
static int oidfmt(int *, int, char *, u_int *);
static void parse(char *);
@@ -70,11 +70,12 @@ static void
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
- "usage: sysctl [-bnX] variable ...",
- " sysctl [-bnX] -w variable=value ...",
- " sysctl [-bnX] -a",
- " sysctl [-bnX] -A");
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+ "usage: sysctl [-bdn] variable ...",
+ " sysctl [-bn] -w variable=value ...",
+ " sysctl [-bdn] -a",
+ " sysctl [-bdn] -A",
+ " sysctl [-bdn] -X");
exit(1);
}
@@ -85,11 +86,12 @@ main(int argc, char **argv)
setbuf(stdout,0);
setbuf(stderr,0);
- while ((ch = getopt(argc, argv, "AabnwX")) != -1) {
+ while ((ch = getopt(argc, argv, "AabdnwX")) != -1) {
switch (ch) {
case 'A': Aflag = 1; break;
case 'a': aflag = 1; break;
case 'b': bflag = 1; break;
+ case 'd': dflag = 1; break;
case 'n': nflag = 1; break;
case 'w': wflag = 1; break;
case 'X': Xflag = Aflag = 1; break;
@@ -99,6 +101,8 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (wflag && (Aflag || aflag || dflag))
+ usage();
if (Aflag || aflag)
exit (sysctl_all(0, 0));
if (argc == 0)
@@ -336,13 +340,34 @@ static int
show_var(int *oid, int nlen)
{
u_char buf[BUFSIZ], *val, *p;
- char name[BUFSIZ], *fmt;
+ char name[BUFSIZ], descr[BUFSIZ], *fmt;
int qoid[CTL_MAXNAME+2];
int i;
size_t j, len;
u_int kind;
int (*func)(int, void *) = 0;
+ qoid[0] = 0;
+ memcpy(qoid + 2, oid, nlen * sizeof(int));
+
+ qoid[1] = 1;
+ j = sizeof name;
+ i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
+ if (i || !j)
+ err(1, "sysctl name %d %d %d", i, j, errno);
+
+ if (dflag) {
+ qoid[1] = 5;
+ j = sizeof descr;
+ i = sysctl(qoid, nlen + 2, descr, &j, 0, 0);
+ if (i || !j)
+ err(1, "sysctl name %d %d %d", i, j, errno);
+ if (!nflag)
+ printf("%s: ", name);
+ printf("%s", descr[0] ? descr : "[no description]");
+ return (0);
+ }
+
/* find an estimate of how much we need for this var */
j = 0;
i = sysctl(oid, nlen, 0, &j, 0, 0);
@@ -359,10 +384,7 @@ show_var(int *oid, int nlen)
return (0);
}
- qoid[0] = 0;
qoid[1] = 4;
- memcpy(qoid + 2, oid, nlen * sizeof(int));
-
j = sizeof buf;
i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
if (i || !j)
@@ -372,12 +394,6 @@ show_var(int *oid, int nlen)
fmt = (char *)(buf + sizeof(u_int));
- qoid[1] = 1;
- j = sizeof name;
- i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
- if (i || !j)
- err(1, "sysctl name %d %d %d", i, j, errno);
-
p = val;
switch (*fmt) {
case 'A':
diff --git a/usr.sbin/sysctl/sysctl.8 b/usr.sbin/sysctl/sysctl.8
index 455dcac..e959ecd 100644
--- a/usr.sbin/sysctl/sysctl.8
+++ b/usr.sbin/sysctl/sysctl.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
-.\" $Id: sysctl.8,v 1.16 1998/07/29 08:30:37 joerg Exp $
+.\" $Id: sysctl.8,v 1.17 1998/09/29 02:01:06 jkoshy Exp $
.\"
.Dd September 23, 1994
.Dt SYSCTL 8
@@ -40,14 +40,14 @@
.Nd get or set kernel state
.Sh SYNOPSIS
.Nm sysctl
-.Op Fl bn
+.Op Fl bdn
.Ar name ...
.Nm sysctl
.Op Fl bn
.Fl w
.Ar name=value ...
.Nm sysctl
-.Op Fl bn
+.Op Fl bdn
.Fl aAX
.Sh DESCRIPTION
The
@@ -85,6 +85,9 @@ set psize=`sysctl -n hw.pagesize`
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 d
+Display the description rather than the value of the requested
+variable(s).
.It Fl w Ar name=value ...
Set the MIB
.Ar name
diff --git a/usr.sbin/sysctl/sysctl.c b/usr.sbin/sysctl/sysctl.c
index 94e630e..f264409 100644
--- a/usr.sbin/sysctl/sysctl.c
+++ b/usr.sbin/sysctl/sysctl.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)from: sysctl.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: sysctl.c,v 1.18 1998/08/25 07:38:19 dfr Exp $";
+ "$Id: sysctl.c,v 1.19 1998/11/08 19:27:43 phk Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -58,7 +58,7 @@ static const char rcsid[] =
#include <string.h>
#include <unistd.h>
-static int Aflag, aflag, nflag, wflag, Xflag, bflag;
+static int Aflag, aflag, bflag, dflag, nflag, wflag, Xflag;
static int oidfmt(int *, int, char *, u_int *);
static void parse(char *);
@@ -70,11 +70,12 @@ static void
usage(void)
{
- (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
- "usage: sysctl [-bnX] variable ...",
- " sysctl [-bnX] -w variable=value ...",
- " sysctl [-bnX] -a",
- " sysctl [-bnX] -A");
+ (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n",
+ "usage: sysctl [-bdn] variable ...",
+ " sysctl [-bn] -w variable=value ...",
+ " sysctl [-bdn] -a",
+ " sysctl [-bdn] -A",
+ " sysctl [-bdn] -X");
exit(1);
}
@@ -85,11 +86,12 @@ main(int argc, char **argv)
setbuf(stdout,0);
setbuf(stderr,0);
- while ((ch = getopt(argc, argv, "AabnwX")) != -1) {
+ while ((ch = getopt(argc, argv, "AabdnwX")) != -1) {
switch (ch) {
case 'A': Aflag = 1; break;
case 'a': aflag = 1; break;
case 'b': bflag = 1; break;
+ case 'd': dflag = 1; break;
case 'n': nflag = 1; break;
case 'w': wflag = 1; break;
case 'X': Xflag = Aflag = 1; break;
@@ -99,6 +101,8 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ if (wflag && (Aflag || aflag || dflag))
+ usage();
if (Aflag || aflag)
exit (sysctl_all(0, 0));
if (argc == 0)
@@ -336,13 +340,34 @@ static int
show_var(int *oid, int nlen)
{
u_char buf[BUFSIZ], *val, *p;
- char name[BUFSIZ], *fmt;
+ char name[BUFSIZ], descr[BUFSIZ], *fmt;
int qoid[CTL_MAXNAME+2];
int i;
size_t j, len;
u_int kind;
int (*func)(int, void *) = 0;
+ qoid[0] = 0;
+ memcpy(qoid + 2, oid, nlen * sizeof(int));
+
+ qoid[1] = 1;
+ j = sizeof name;
+ i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
+ if (i || !j)
+ err(1, "sysctl name %d %d %d", i, j, errno);
+
+ if (dflag) {
+ qoid[1] = 5;
+ j = sizeof descr;
+ i = sysctl(qoid, nlen + 2, descr, &j, 0, 0);
+ if (i || !j)
+ err(1, "sysctl name %d %d %d", i, j, errno);
+ if (!nflag)
+ printf("%s: ", name);
+ printf("%s", descr[0] ? descr : "[no description]");
+ return (0);
+ }
+
/* find an estimate of how much we need for this var */
j = 0;
i = sysctl(oid, nlen, 0, &j, 0, 0);
@@ -359,10 +384,7 @@ show_var(int *oid, int nlen)
return (0);
}
- qoid[0] = 0;
qoid[1] = 4;
- memcpy(qoid + 2, oid, nlen * sizeof(int));
-
j = sizeof buf;
i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
if (i || !j)
@@ -372,12 +394,6 @@ show_var(int *oid, int nlen)
fmt = (char *)(buf + sizeof(u_int));
- qoid[1] = 1;
- j = sizeof name;
- i = sysctl(qoid, nlen + 2, name, &j, 0, 0);
- if (i || !j)
- err(1, "sysctl name %d %d %d", i, j, errno);
-
p = val;
switch (*fmt) {
case 'A':
OpenPOWER on IntegriCloud