From david@catwhisker.org  Tue May 13 22:42:32 2008
Return-Path: <david@catwhisker.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 93C1F106564A
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <david@catwhisker.org>
Reply-To: David Wolfskill <david@catwhisker.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Allow sysctl(8) to ignore unknown OIDs
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         123644
>Category:       bin
>Synopsis:       [patch] [sysctl] Allow sysctl(8) to ignore unknown OIDs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gavin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 13 22:50:01 UTC 2008
>Closed-Date:    Wed May 05 12:49:28 UTC 2010
>Last-Modified:  Wed May  5 12:50:03 UTC 2010
>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 <string.h>
 #include <unistd.h>
 
-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:
Responsible-Changed-From-To: freebsd-bugs->gavin 
Responsible-Changed-By: gavin 
Responsible-Changed-When: Sun Jan 31 10:41:20 UTC 2010 
Responsible-Changed-Why:  
Take 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123644 
State-Changed-From-To: open->patched 
State-Changed-By: gavin 
State-Changed-When: Sun Jan 31 19:35:07 UTC 2010 
State-Changed-Why:  
Fixed in head, MFC in 2 weeks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123644 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123644: commit references a PR
Date: Sun, 31 Jan 2010 19:33:35 +0000 (UTC)

 Author: gavin
 Date: Sun Jan 31 19:33:25 2010
 New Revision: 203310
 URL: http://svn.freebsd.org/changeset/base/203310
 
 Log:
   Implement the "-i" option to sysctl(8), to ignore failures while
   retrieving individual OIDs.  This allows the same list of OIDs to be
   passed to sysctl(8) across different systems where particular OIDs may not
   exist, and still get as much information as possible from them.
   
   PR:		bin/123644
   Submitted by:	dhw
   Approved by:	ed (mentor)
   MFC after:	2 weeks
 
 Modified:
   head/sbin/sysctl/sysctl.8
   head/sbin/sysctl/sysctl.c
 
 Modified: head/sbin/sysctl/sysctl.8
 ==============================================================================
 --- head/sbin/sysctl/sysctl.8	Sun Jan 31 19:30:47 2010	(r203309)
 +++ head/sbin/sysctl/sysctl.8	Sun Jan 31 19:33:25 2010	(r203310)
 @@ -28,7 +28,7 @@
  .\"	From: @(#)sysctl.8	8.1 (Berkeley) 6/6/93
  .\" $FreeBSD$
  .\"
 -.Dd November 28, 2007
 +.Dd January 31, 2010
  .Dt SYSCTL 8
  .Os
  .Sh NAME
 @@ -82,6 +82,12 @@ or
  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
 
 Modified: head/sbin/sysctl/sysctl.c
 ==============================================================================
 --- head/sbin/sysctl/sysctl.c	Sun Jan 31 19:30:47 2010	(r203309)
 +++ head/sbin/sysctl/sysctl.c	Sun Jan 31 19:33:25 2010	(r203310)
 @@ -58,8 +58,8 @@ static const char rcsid[] =
  #include <string.h>
  #include <unistd.h>
  
 -static int	aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
 -static int	qflag, xflag, warncount;
 +static int	aflag, bflag, dflag, eflag, hflag, iflag;
 +static int	Nflag, nflag, oflag, qflag, xflag, warncount;
  
  static int	oidfmt(int *, int, char *, u_int *);
  static void	parse(char *);
 @@ -89,7 +89,7 @@ main(int argc, char **argv)
  	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 @@ main(int argc, char **argv)
  		case 'h':
  			hflag = 1;
  			break;
 +		case 'i':
 +			iflag = 1;
 +			break;
  		case 'N':
  			Nflag = 1;
  			break;
 @@ -187,6 +190,8 @@ parse(char *string)
  	len = name2oid(bufp, mib);
  
  	if (len < 0) {
 +		if (iflag)
 +			return;
  		if (qflag)
  			exit(1);
  		else
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123644: commit references a PR
Date: Sun, 14 Feb 2010 09:49:26 +0000 (UTC)

 Author: gavin
 Date: Sun Feb 14 09:48:53 2010
 New Revision: 203858
 URL: http://svn.freebsd.org/changeset/base/203858
 
 Log:
   Merge r203310,203547,203717 from head:
   
     Implement the "-i" option to sysctl(8), to ignore failures while
     retrieving individual OIDs.  This allows the same list of OIDs to be
     passed to sysctl(8) across different systems where particular OIDs may
     not exist, and still get as much information as possible from them.
   
   PR:		bin/123644
   Submitted by:	dhw
 
 Modified:
   stable/8/sbin/sysctl/sysctl.8
   stable/8/sbin/sysctl/sysctl.c
 Directory Properties:
   stable/8/sbin/sysctl/   (props changed)
 
 Modified: stable/8/sbin/sysctl/sysctl.8
 ==============================================================================
 --- stable/8/sbin/sysctl/sysctl.8	Sun Feb 14 09:40:58 2010	(r203857)
 +++ stable/8/sbin/sysctl/sysctl.8	Sun Feb 14 09:48:53 2010	(r203858)
 @@ -28,7 +28,7 @@
  .\"	From: @(#)sysctl.8	8.1 (Berkeley) 6/6/93
  .\" $FreeBSD$
  .\"
 -.Dd November 28, 2007
 +.Dd February 6, 2010
  .Dt SYSCTL 8
  .Os
  .Sh NAME
 @@ -36,7 +36,7 @@
  .Nd get or set kernel state
  .Sh SYNOPSIS
  .Nm
 -.Op Fl bdehNnoqx
 +.Op Fl bdehiNnoqx
  .Ar name Ns Op = Ns Ar value
  .Ar ...
  .Nm
 @@ -82,6 +82,12 @@ or
  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
 
 Modified: stable/8/sbin/sysctl/sysctl.c
 ==============================================================================
 --- stable/8/sbin/sysctl/sysctl.c	Sun Feb 14 09:40:58 2010	(r203857)
 +++ stable/8/sbin/sysctl/sysctl.c	Sun Feb 14 09:48:53 2010	(r203858)
 @@ -58,8 +58,8 @@ static const char rcsid[] =
  #include <string.h>
  #include <unistd.h>
  
 -static int	aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
 -static int	qflag, xflag, warncount;
 +static int	aflag, bflag, dflag, eflag, hflag, iflag;
 +static int	Nflag, nflag, oflag, qflag, xflag, warncount;
  
  static int	oidfmt(int *, int, char *, u_int *);
  static void	parse(char *);
 @@ -75,7 +75,7 @@ usage(void)
  {
  
  	(void)fprintf(stderr, "%s\n%s\n",
 -	    "usage: sysctl [-bdehNnoqx] name[=value] ...",
 +	    "usage: sysctl [-bdehiNnoqx] name[=value] ...",
  	    "       sysctl [-bdehNnoqx] -a");
  	exit(1);
  }
 @@ -89,7 +89,7 @@ main(int argc, char **argv)
  	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 @@ main(int argc, char **argv)
  		case 'h':
  			hflag = 1;
  			break;
 +		case 'i':
 +			iflag = 1;
 +			break;
  		case 'N':
  			Nflag = 1;
  			break;
 @@ -187,6 +190,8 @@ parse(char *string)
  	len = name2oid(bufp, mib);
  
  	if (len < 0) {
 +		if (iflag)
 +			return;
  		if (qflag)
  			exit(1);
  		else
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: gavin 
State-Changed-When: Wed May 5 12:48:43 UTC 2010 
State-Changed-Why:  
Committed to head, stable/8 and stable/7.  Thanks for your 
submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=123644 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123644: commit references a PR
Date: Wed,  5 May 2010 12:48:45 +0000 (UTC)

 Author: gavin
 Date: Wed May  5 12:48:30 2010
 New Revision: 207658
 URL: http://svn.freebsd.org/changeset/base/207658
 
 Log:
   Merge r203310,203547,203717 from head:
   
     Implement the "-i" option to sysctl(8), to ignore failures while
     retrieving individual OIDs.  This allows the same list of OIDs to be
     passed to sysctl(8) across different systems where particular OIDs may
     not exist, and still get as much information as possible from them.
   
   PR:		bin/123644
   Submitted by:	dhw
 
 Modified:
   stable/7/sbin/sysctl/sysctl.8
   stable/7/sbin/sysctl/sysctl.c
 Directory Properties:
   stable/7/sbin/sysctl/   (props changed)
 
 Modified: stable/7/sbin/sysctl/sysctl.8
 ==============================================================================
 --- stable/7/sbin/sysctl/sysctl.8	Wed May  5 12:39:44 2010	(r207657)
 +++ stable/7/sbin/sysctl/sysctl.8	Wed May  5 12:48:30 2010	(r207658)
 @@ -28,7 +28,7 @@
  .\"	From: @(#)sysctl.8	8.1 (Berkeley) 6/6/93
  .\" $FreeBSD$
  .\"
 -.Dd November 28, 2007
 +.Dd February 6, 2010
  .Dt SYSCTL 8
  .Os
  .Sh NAME
 @@ -36,7 +36,7 @@
  .Nd get or set kernel state
  .Sh SYNOPSIS
  .Nm
 -.Op Fl bdehNnoqx
 +.Op Fl bdehiNnoqx
  .Ar name Ns Op = Ns Ar value
  .Ar ...
  .Nm
 @@ -82,6 +82,12 @@ or
  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
 
 Modified: stable/7/sbin/sysctl/sysctl.c
 ==============================================================================
 --- stable/7/sbin/sysctl/sysctl.c	Wed May  5 12:39:44 2010	(r207657)
 +++ stable/7/sbin/sysctl/sysctl.c	Wed May  5 12:48:30 2010	(r207658)
 @@ -58,8 +58,8 @@ static const char rcsid[] =
  #include <string.h>
  #include <unistd.h>
  
 -static int	aflag, bflag, dflag, eflag, hflag, Nflag, nflag, oflag;
 -static int	qflag, xflag;
 +static int	aflag, bflag, dflag, eflag, hflag, iflag,
 +static int	Nflag, nflag, oflag, qflag, xflag;
  
  static int	oidfmt(int *, int, char *, u_int *);
  static void	parse(char *);
 @@ -75,7 +75,7 @@ usage(void)
  {
  
  	(void)fprintf(stderr, "%s\n%s\n",
 -	    "usage: sysctl [-bdehNnoqx] name[=value] ...",
 +	    "usage: sysctl [-bdehiNnoqx] name[=value] ...",
  	    "       sysctl [-bdehNnoqx] -a");
  	exit(1);
  }
 @@ -89,7 +89,7 @@ main(int argc, char **argv)
  	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 @@ main(int argc, char **argv)
  		case 'h':
  			hflag = 1;
  			break;
 +		case 'i':
 +			iflag = 1;
 +			break;
  		case 'N':
  			Nflag = 1;
  			break;
 @@ -185,6 +188,8 @@ parse(char *string)
  	len = name2oid(bufp, mib);
  
  	if (len < 0) {
 +		if (iflag)
 +			return;
  		if (qflag)
  			exit(1);
  		else
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
