Add a "-f file" flag to process directives from a file.
This commit is contained in:
parent
b8b53d87db
commit
4f90f5ce45
@ -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 @@ MAN= sysctl.8
|
||||
CPPFLAGS+=-DINET6 -DIPSEC
|
||||
#CPPFLAGS+=-DTCP6
|
||||
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -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 @@ If a value is to be set, the
|
||||
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'.
|
||||
|
@ -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 @@ __COPYRIGHT(
|
||||
#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 @@ __RCSID("$NetBSD: sysctl.c,v 1.26 2000/02/17 08:54:16 fvdl Exp $");
|
||||
#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 @@ main(argc, argv)
|
||||
{
|
||||
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 @@ main(argc, argv)
|
||||
aflag = 1;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
fn = optarg;
|
||||
wflag = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
break;
|
||||
@ -223,10 +230,28 @@ main(argc, argv)
|
||||
listall(topname[lvl1].ctl_name, &secondlevel[lvl1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user