Date: Mon, 24 Dec 2001 15:42:48 +0100 (CET) From: Thomas Quinot <thomas@cuivre.fr.eu.org> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/33150: sbin/sysctl: allow setting dev_t values [patch included] Message-ID: <20011224144248.A91547B@melusine.cuivre.fr.eu.org>
next in thread | raw e-mail | index | archive | help
>Number: 33150 >Category: bin >Synopsis: sbin/sysctl: allow setting dev_t values [patch included] >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Dec 24 06:50:00 PST 2001 >Closed-Date: >Last-Modified: >Originator: Thomas Quinot >Release: FreeBSD 4.4-STABLE i386 >Organization: >Environment: System: FreeBSD melusine.cuivre.fr.eu.org 4.4-STABLE FreeBSD 4.4-STABLE #3: Mon Dec 17 01:07:53 CET 2001 root@melusine.cuivre.fr.eu.org:/usr/obj/usr/src/sys/MELUSINE i386 >Description: The enclosed patch adds a new functionality to sbin/sysctl: it allows setting of variables of type dev_t by indicating the name of a special file on the command line, eg: sysctl kern.dumpdev=/dev/ad1s1b (same effect as dumpon /dev/ad1s1b). This would come in handy for controlling any other sysctl variable that is supposed to designate a device. >How-To-Repeat: >Fix: --- sysctl.c.dist Mon Dec 24 15:39:37 2001 +++ sysctl.c Mon Dec 24 15:36:18 2001 @@ -49,6 +49,7 @@ #include <sys/stat.h> #include <sys/sysctl.h> #include <sys/resource.h> +#include <sys/param.h> #include <ctype.h> #include <err.h> @@ -66,6 +67,8 @@ 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) { @@ -153,7 +156,7 @@ 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; @@ -171,7 +174,7 @@ 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,6 +220,12 @@ 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, @@ -316,6 +325,27 @@ major(*d), minor(*d)); } 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; } /* >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011224144248.A91547B>