From owner-freebsd-bugs@FreeBSD.ORG Tue May 13 22:50:02 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F21F5106567E for ; Tue, 13 May 2008 22:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id CD33E8FC12 for ; Tue, 13 May 2008 22:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m4DMo1NN053389 for ; Tue, 13 May 2008 22:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m4DMo1BD053388; Tue, 13 May 2008 22:50:01 GMT (envelope-from gnats) Resent-Date: Tue, 13 May 2008 22:50:01 GMT Resent-Message-Id: <200805132250.m4DMo1BD053388@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, David Wolfskill Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 93C1F106564A for ; Tue, 13 May 2008 22:42:32 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from bunrab.catwhisker.org (adsl-63-193-123-122.dsl.snfc21.pacbell.net [63.193.123.122]) by mx1.freebsd.org (Postfix) with ESMTP id 54C1F8FC12 for ; Tue, 13 May 2008 22:42:32 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from bunrab.catwhisker.org (localhost [127.0.0.1]) by bunrab.catwhisker.org (8.13.3/8.13.3) with ESMTP id m4DMgV6a005026 for ; Tue, 13 May 2008 15:42:31 -0700 (PDT) (envelope-from david@bunrab.catwhisker.org) Received: (from david@localhost) by bunrab.catwhisker.org (8.13.3/8.13.1/Submit) id m4DMgVWF005025; Tue, 13 May 2008 15:42:31 -0700 (PDT) (envelope-from david) Message-Id: <200805132242.m4DMgVWF005025@bunrab.catwhisker.org> Date: Tue, 13 May 2008 15:42:31 -0700 (PDT) From: David Wolfskill To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/123644: Allow sysctl(8) to ignore unknown OIDs X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: David Wolfskill List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 May 2008 22:50:02 -0000 >Number: 123644 >Category: bin >Synopsis: Allow sysctl(8) to ignore unknown OIDs >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue May 13 22:50:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: David Wolfskill >Release: FreeBSD 8.0-CURRENT i386 >Organization: Wolfskill & Dowling Residence >Environment: FreeBSD localhost 8.0-CURRENT FreeBSD 8.0-CURRENT #769: Mon May 12 07:17:44 PDT 2008 root@g1-37.catwhisker.org:/common/S4/obj/usr/src/sys/CANARY i386 >Description: Generally, requesting that sysctl(8) report the value of an OID it doesn't know causes the program to exit without attempting to process any additional OIDs. there is a -q option, but that does not control whether or not sysctl(8) exits -- merely whether or not it whines in the process. I propose the addition of a flag (the below patch uses "-i," but I don't care which letter is used) to specify that sysctl(8) should silently ignore the specification of any unknown OIDs. The reason for this is that I have been using sysctl(8) to retrieve information on resource usage on various machines. I find that if I try to use a single list of OIDs for all of the machines I'm querying, it's fairly probable that my OID list includes an OID that isn't supported by at least one of the systems. I realize that in an ideal world, it may be reasonable to expect me to use a separate, machine-specific list of OIDs for each such system, but in practice, this is quite counter-productive. By using the patched version of the code (which, IMO, should be a candidate for MFC if it's committed to HEAD), I transform sysctl(8) into a "best effort" OID-reporting tool. And if I don't get values for some OID, my scripts know how to handle that easily enough. >How-To-Repeat: On a FreeBSD 8-CURRENT system: localhost(8.0-C)[2] sysctl hw.ncpu kern.sched.quantum net.inet.ip.fw.enable hw.ncpu: 1 sysctl: unknown oid 'kern.sched.quantum' localhost(8.0-C)[3] Notice that we didn't get a report for "net.inet.ip.fw.enable". Now, after applying the patch, then rebuilding & re-installing sysctl(8): localhost(8.0-C)[3] sysctl -i hw.ncpu kern.sched.quantum net.inet.ip.fw.enable hw.ncpu: 1 net.inet.ip.fw.enable: 1 localhost(8.0-C)[4] We now get the value for net.inet.ip.fw.enable; the request for kern.sched.quantum is silently ignored. >Fix: Index: sysctl.8 =================================================================== RCS file: /cvs/freebsd/src/sbin/sysctl/sysctl.8,v retrieving revision 1.64 diff -u -r1.64 sysctl.8 --- sysctl.8 28 Nov 2007 14:48:30 -0000 1.64 +++ sysctl.8 12 May 2008 19:14:08 -0000 @@ -82,6 +82,12 @@ is specified, or a variable is being set. .It Fl h Format output for human, rather than machine, readability. +.It Fl i +Ignore unknown OIDs. +The purpose is to make use of +.Nm +for collecting data from a variety of machines (not all of which +are necessarily running exactly the same software) easier. .It Fl N Show only variable names, not their values. This is particularly useful with shells that offer programmable Index: sysctl.c =================================================================== RCS file: /cvs/freebsd/src/sbin/sysctl/sysctl.c,v retrieving revision 1.88 diff -u -r1.88 sysctl.c --- sysctl.c 15 Oct 2007 20:00:19 -0000 1.88 +++ sysctl.c 12 May 2008 19:07:34 -0000 @@ -58,8 +58,8 @@ #include #include -static int aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag; -static int qflag, xflag; +static int aflag, bflag, dflag, eflag, hflag, iflag, Nflag, nflag; +static int oflag, qflag, xflag; static int oidfmt(int *, int, char *, u_int *); static void parse(char *); @@ -89,7 +89,7 @@ setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabdehNnoqwxX")) != -1) { + while ((ch = getopt(argc, argv, "AabdehiNnoqwxX")) != -1) { switch (ch) { case 'A': /* compatibility */ @@ -110,6 +110,9 @@ case 'h': hflag = 1; break; + case 'i': + iflag = 1; + break; case 'N': Nflag = 1; break; @@ -185,6 +188,8 @@ len = name2oid(bufp, mib); if (len < 0) { + if (iflag) + return; if (qflag) exit(1); else >Release-Note: >Audit-Trail: >Unformatted: