aboutsummaryrefslogtreecommitdiff
path: root/sbin/sysctl
diff options
context:
space:
mode:
authorThomas Quinot <thomas@FreeBSD.org>2002-10-29 18:06:31 +0000
committerThomas Quinot <thomas@FreeBSD.org>2002-10-29 18:06:31 +0000
commit75a0cd567a42683a066e507960a6ac2dd7e80188 (patch)
treea13fb8de5b8dce354965baa180c08613d753ef83 /sbin/sysctl
parenta1f61f51d2a1c497f8f4d6a983f8b7932adb6b35 (diff)
Notes
Diffstat (limited to 'sbin/sysctl')
-rw-r--r--sbin/sysctl/sysctl.826
-rw-r--r--sbin/sysctl/sysctl.c47
2 files changed, 58 insertions, 15 deletions
diff --git a/sbin/sysctl/sysctl.8 b/sbin/sysctl/sysctl.8
index 9912b06fe256..18b405f95aa2 100644
--- a/sbin/sysctl/sysctl.8
+++ b/sbin/sysctl/sysctl.8
@@ -32,7 +32,7 @@
.\" From: @(#)sysctl.8 8.1 (Berkeley) 6/6/93
.\" $FreeBSD$
.\"
-.Dd May 28, 2001
+.Dd March 10, 2002
.Dt SYSCTL 8
.Os
.Sh NAME
@@ -118,7 +118,9 @@ few bytes.
.Pp
The information available from
.Nm
-consists of integers, strings, and opaques.
+consists of integers, strings, devices
+.Pq Vt dev_t ,
+and opaque types.
.Nm Sysctl
only knows about a couple of opaque types, and will resort to hexdumps
for the rest.
@@ -134,6 +136,17 @@ For a detailed description of these variable see
.Pp
The changeable column indicates whether a process with appropriate
privilege can change the value.
+String, integer, and devices values can be set using
+.Nm .
+For device values,
+.Ar value
+can be specified as a character device special file name.
+Special values
+.Ar off
+and
+.Ar none
+denote
+.Dq no device .
.Bl -column net.inet.ip.forwardingxxxxxx integerxxx
.It Sy "Name Type Changeable
.It "kern.ostype string no
@@ -162,6 +175,7 @@ privilege can change the value.
.It "kern.osreldate string no
.It "kern.bootfile string yes
.It "kern.corefile string yes
+.It "kern.dumpdev dev_t yes
.It "kern.logsigexit integer yes
.It "vm.loadavg struct no
.It "hw.machine string no
@@ -208,6 +222,14 @@ per uid to 1000, one would use the following request:
.Pp
.Dl "sysctl kern.maxprocperuid=1000"
.Pp
+The device used for crash dumps can be specified using:
+.Pp
+.Dl "sysctl kern.dumpdev=/dev/somedev"
+.Pp
+which is equivalent to
+.Pp
+.Dl "dumpon /dev/somedev"
+.Pp
Information about the system clock rate may be obtained with:
.Pp
.Dl "sysctl kern.clockrate"
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 2d8649827523..d19ab92fced2 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -53,6 +53,7 @@ static const char rcsid[] =
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/resource.h>
+#include <sys/param.h>
#include <ctype.h>
#include <err.h>
@@ -70,6 +71,8 @@ static int show_var(int *, int);
static int sysctl_all (int *oid, int len);
static int name2oid(char *, int *);
+static void set_T_dev_t (char *, void **, int *);
+
static void
usage(void)
{
@@ -157,7 +160,7 @@ parse(char *string)
size_t newsize = 0;
quad_t quadval;
int mib[CTL_MAXNAME];
- char *cp, *bufp, buf[BUFSIZ];
+ char *cp, *bufp, buf[BUFSIZ], fmt[BUFSIZ];
u_int kind;
bufp = buf;
@@ -175,7 +178,7 @@ parse(char *string)
if (len < 0)
errx(1, "unknown oid '%s'", bufp);
- if (oidfmt(mib, len, 0, &kind))
+ if (oidfmt(mib, len, fmt, &kind))
err(1, "couldn't find format of oid '%s'", bufp);
if (newval == NULL) {
@@ -217,11 +220,16 @@ parse(char *string)
case CTLTYPE_STRING:
break;
case CTLTYPE_QUAD:
- break;
sscanf(newval, "%qd", &quadval);
newval = &quadval;
newsize = sizeof(quadval);
break;
+ case CTLTYPE_OPAQUE:
+ if (strcmp(fmt, "T,dev_t") == 0) {
+ set_T_dev_t ((char*)newval, &newval, &newsize);
+ break;
+ }
+ /* FALLTHROUGH */
default:
errx(1, "oid '%s' is type %d,"
" cannot set that", bufp,
@@ -323,6 +331,27 @@ T_dev_t(int l2, void *p)
return (0);
}
+static void
+set_T_dev_t (char *path, void **val, int *size)
+{
+ static struct stat statb;
+
+ if (strcmp(path, "none") && strcmp(path, "off")) {
+ int rc = stat (path, &statb);
+ if (rc) {
+ err(1, "cannot stat %s", path);
+ }
+
+ if (!S_ISCHR(statb.st_mode)) {
+ errx(1, "must specify a device special file.");
+ }
+ } else {
+ statb.st_rdev = NODEV;
+ }
+ *val = (char*) &statb.st_rdev;
+ *size = sizeof statb.st_rdev;
+}
+
/*
* These functions uses a presently undocumented interface to the kernel
* to walk the tree and get the type so it can print the value.
@@ -478,16 +507,8 @@ show_var(int *oid, int nlen)
return (0);
}
- qoid[1] = 4;
- j = sizeof(buf);
- i = sysctl(qoid, nlen + 2, buf, &j, 0, 0);
- if (i || !j)
- err(1, "sysctl fmt %d %d %d", i, j, errno);
-
- kind = *(u_int *)buf;
-
- fmt = (char *)(buf + sizeof(u_int));
-
+ fmt = buf;
+ oidfmt(oid, nlen, fmt, &kind);
p = val;
switch (*fmt) {
case 'A':