Source-Changes-HG archive

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

[src/trunk]: src/sbin/sysctl Add a "-f file" flag to process directives from ...



details:   https://anonhg.NetBSD.org/src/rev/18ea130f2064
branches:  trunk
changeset: 483557:18ea130f2064
user:      tsarna <tsarna%NetBSD.org@localhost>
date:      Sun Mar 12 22:56:48 2000 +0000

description:
Add a "-f file" flag to process directives from a file.

diffstat:

 sbin/sysctl/Makefile |   5 ++++-
 sbin/sysctl/sysctl.8 |  20 +++++++++++++++++++-
 sbin/sysctl/sysctl.c |  41 +++++++++++++++++++++++++++++++++--------
 3 files changed, 56 insertions(+), 10 deletions(-)

diffs (150 lines):

diff -r c7beefdcbf02 -r 18ea130f2064 sbin/sysctl/Makefile
--- a/sbin/sysctl/Makefile      Sun Mar 12 21:57:50 2000 +0000
+++ b/sbin/sysctl/Makefile      Sun Mar 12 22:56:48 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.10 2000/01/17 04:23:00 itojun Exp $
+#      $NetBSD: Makefile,v 1.11 2000/03/12 22:56:48 tsarna Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/6/93
 
 PROG=  sysctl
@@ -7,4 +7,7 @@
 CPPFLAGS+=-DINET6 -DIPSEC
 #CPPFLAGS+=-DTCP6
 
+DPADD=  ${LIBUTIL}
+LDADD=  -lutil
+
 .include <bsd.prog.mk>
diff -r c7beefdcbf02 -r 18ea130f2064 sbin/sysctl/sysctl.8
--- a/sbin/sysctl/sysctl.8      Sun Mar 12 21:57:50 2000 +0000
+++ b/sbin/sysctl/sysctl.8      Sun Mar 12 22:56:48 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.8,v 1.44 2000/02/27 06:13:37 itojun Exp $
+.\"    $NetBSD: sysctl.8,v 1.45 2000/03/12 22:56:48 tsarna Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -50,6 +50,10 @@
 .Nm sysctl
 .Op Fl n
 .Fl aA
+.Nm sysctl
+.Op Fl n
+.Fl f
+.Ar file
 .Sh DESCRIPTION
 The
 .Nm sysctl
@@ -86,6 +90,20 @@
 flag must be specified and the MIB name followed
 by an equal sign and the new value to be used.
 .Pp
+The
+.Fl f
+flag specifies the name of a file to read and process.  Blank lines and
+comments (beginning with ``#'') are ignored.  Line continuations with
+``\\'' are permitted.  Remaining lines are processed similarly to
+command line arguments of the form
+.Ar name
+or
+.Ar name=value .
+The
+.Fl w
+flag is implied by
+.Fl f .
+.Pp
 The proc top-level MIB has a special semantic: it represent per-process values
 and as such may differ from one process to another. The second-level name
 is the pid of the process (in decimal form), or the special word 'curproc'.
diff -r c7beefdcbf02 -r 18ea130f2064 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c      Sun Mar 12 21:57:50 2000 +0000
+++ b/sbin/sysctl/sysctl.c      Sun Mar 12 22:56:48 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.26 2000/02/17 08:54:16 fvdl Exp $ */
+/*     $NetBSD: sysctl.c,v 1.27 2000/03/12 22:56:49 tsarna Exp $       */
 
 /*
  * Copyright (c) 1993
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.26 2000/02/17 08:54:16 fvdl Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.27 2000/03/12 22:56:49 tsarna Exp $");
 #endif
 #endif /* not lint */
 
@@ -107,6 +107,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <util.h>
 
 struct ctlname topname[] = CTL_NAMES;
 struct ctlname kernname[] = CTL_KERN_NAMES;
@@ -189,9 +190,10 @@
 {
        extern char *optarg;
        extern int optind;
+       char *fn = NULL;
        int ch, lvl1;
 
-       while ((ch = getopt(argc, argv, "Aanw")) != -1) {
+       while ((ch = getopt(argc, argv, "Aaf:nw")) != -1) {
                switch (ch) {
 
                case 'A':
@@ -202,6 +204,11 @@
                        aflag = 1;
                        break;
 
+               case 'f':
+                       fn = optarg;
+                       wflag = 1;
+                       break;
+
                case 'n':
                        nflag = 1;
                        break;
@@ -223,10 +230,28 @@
                        listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
                return 0;
        }
-       if (argc == 0)
-               usage();
-       while (argc-- > 0)
-               parse(*argv++, 1);
+
+       if (fn) {
+               FILE *fp;
+               char *l;
+               
+               fp = fopen(fn, "r");
+               if (fp == NULL) {
+                       err(1, "%s", fn);
+               } else {
+                       while (l = fparseln(fp, NULL, NULL, NULL, 0)) {
+                               if (*l) {
+                                       parse(l, 1);
+                               }
+                       }
+                       fclose(fp);
+               }
+       } else {
+               if (argc == 0)
+                       usage();
+               while (argc-- > 0)
+                       parse(*argv++, 1);
+       }
        return 0;
 }
 
@@ -298,7 +323,7 @@
                lp = &secondlevel[indx];
                if (lp->list == 0) {
                        warnx("Class `%s' is not implemented",
-                       topname[indx].ctl_name);
+                       topname[indx].ctl_name);
                        return;
                }
                if (bufp == NULL) {



Home | Main Index | Thread Index | Old Index