Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/sysctl allow -q flag to work for reads.



details:   https://anonhg.NetBSD.org/src/rev/48e3a64e145a
branches:  trunk
changeset: 767909:48e3a64e145a
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Aug 03 01:47:40 2011 +0000

description:
allow -q flag to work for reads.

diffstat:

 sbin/sysctl/sysctl.8 |  11 +++++++----
 sbin/sysctl/sysctl.c |  12 +++++++-----
 2 files changed, 14 insertions(+), 9 deletions(-)

diffs (87 lines):

diff -r ec9d4b9c9ed3 -r 48e3a64e145a sbin/sysctl/sysctl.8
--- a/sbin/sysctl/sysctl.8      Wed Aug 03 01:43:25 2011 +0000
+++ b/sbin/sysctl/sysctl.8      Wed Aug 03 01:47:40 2011 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.8,v 1.161 2009/09/30 04:30:50 elad Exp $
+.\"    $NetBSD: sysctl.8,v 1.162 2011/08/03 01:47:40 christos Exp $
 .\"
 .\" Copyright (c) 2004 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -54,7 +54,7 @@
 .\"
 .\"    @(#)sysctl.8    8.1 (Berkeley) 6/6/93
 .\"
-.Dd September 30, 2009
+.Dd August 2, 2011
 .Dt SYSCTL 8
 .Os
 .Sh NAME
@@ -62,7 +62,7 @@
 .Nd get or set kernel state
 .Sh SYNOPSIS
 .Nm sysctl
-.Op Fl AdeMn
+.Op Fl AdeMnq
 .Oo
 .Fl r |
 .Fl x
@@ -185,8 +185,11 @@
 set psize=`sysctl -n hw.pagesize`
 .Ed
 .It Fl q
-Used to indicate that nothing should be printed for writes unless an
+Used to indicate that nothing should be printed for reads or writes unless an
 error is detected.
+For reads, not finding a variable does not print an error, but exits with
+an error code.
+This is useful just for testing that a variable exists.
 .It Fl r
 Raw output form.
 Values printed are in their raw binary forms as retrieved directly
diff -r ec9d4b9c9ed3 -r 48e3a64e145a sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c      Wed Aug 03 01:43:25 2011 +0000
+++ b/sbin/sysctl/sysctl.c      Wed Aug 03 01:47:40 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.134 2011/04/16 01:15:54 christos Exp $ */
+/*     $NetBSD: sysctl.c,v 1.135 2011/08/03 01:47:40 christos Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.134 2011/04/16 01:15:54 christos Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.135 2011/08/03 01:47:40 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -321,8 +321,6 @@
        argc -= optind;
        argv += optind;
 
-       if (qflag && !wflag)
-               usage();
        if (xflag && rflag)
                usage();
        /* if ((xflag || rflag) && wflag)
@@ -1540,7 +1538,7 @@
                      "\t%s %s\n"
                      "\t%s %s\n"
                      "\t%s %s\n",
-                     progname, "[-dne] [-x[x]|-r] variable ...",
+                     progname, "[-dneq] [-x[x]|-r] variable ...",
                      progname, "[-ne] [-q] -w variable=value ...",
                      progname, "[-dne] -a",
                      progname, "[-dne] -A",
@@ -1688,6 +1686,10 @@
 sysctlparseerror(u_int namelen, const char *pname)
 {
 
+       if (qflag) {
+               errs++;
+               return;
+       }
        sysctlperror("%s level name '%s' in '%s' is invalid\n",
                     lname[namelen], gsname, pname);
 }



Home | Main Index | Thread Index | Old Index