From owner-freebsd-bugs Mon Dec 24 6:50:13 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id F132337B41D for ; Mon, 24 Dec 2001 06:50:00 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id fBOEo0x70477; Mon, 24 Dec 2001 06:50:00 -0800 (PST) (envelope-from gnats) Received: from melchior.cuivre.fr.eu.org (melchior.enst.fr [137.194.161.6]) by hub.freebsd.org (Postfix) with ESMTP id 798D337B405 for ; Mon, 24 Dec 2001 06:42:53 -0800 (PST) Received: from melusine.cuivre.fr.eu.org (melusine.enst.fr [137.194.160.34]) by melchior.cuivre.fr.eu.org (Postfix) with ESMTP id EC7E97A3F for ; Mon, 24 Dec 2001 15:42:49 +0100 (CET) Received: by melusine.cuivre.fr.eu.org (Postfix, from userid 1000) id A91547B; Mon, 24 Dec 2001 15:42:48 +0100 (CET) Message-Id: <20011224144248.A91547B@melusine.cuivre.fr.eu.org> Date: Mon, 24 Dec 2001 15:42:48 +0100 (CET) From: Thomas Quinot Reply-To: Thomas Quinot To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: bin/33150: sbin/sysctl: allow setting dev_t values [patch included] Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 #include #include +#include #include #include @@ -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