Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/sysctl A little syntactic sugar
details: https://anonhg.NetBSD.org/src/rev/df1ca1d57221
branches: trunk
changeset: 559559:df1ca1d57221
user: atatat <atatat%NetBSD.org@localhost>
date: Sat Mar 20 05:22:41 2004 +0000
description:
A little syntactic sugar
diffstat:
sbin/sysctl/sysctl.c | 58 +++++++++++++++++++++++++++++++++------------------
1 files changed, 37 insertions(+), 21 deletions(-)
diffs (158 lines):
diff -r 5711c6f66f5d -r df1ca1d57221 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c Sat Mar 20 05:21:53 2004 +0000
+++ b/sbin/sysctl/sysctl.c Sat Mar 20 05:22:41 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysctl.c,v 1.81 2004/02/20 05:27:39 atatat Exp $ */
+/* $NetBSD: sysctl.c,v 1.82 2004/03/20 05:22:41 atatat Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@
#if 0
static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: sysctl.c,v 1.81 2004/02/20 05:27:39 atatat Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.82 2004/03/20 05:22:41 atatat Exp $");
#endif
#endif /* not lint */
@@ -138,8 +138,8 @@
static void hex_dump(const unsigned char *, size_t);
static void usage(void);
static void parse(char *);
-static void cparse(char *);
-static void dparse(char *);
+static void parse_create(char *);
+static void parse_destroy(char *);
static void sysctlerror(int);
/*
@@ -260,7 +260,7 @@
int name[CTL_MAXNAME];
int ch;
- while ((ch = getopt(argc, argv, "Aaef:Mnqrwx")) != -1) {
+ while ((ch = getopt(argc, argv, "Aabef:Mnqrwx")) != -1) {
switch (ch) {
case 'A':
Aflag++;
@@ -284,6 +284,7 @@
case 'q':
qflag++;
break;
+ case 'b': /* FreeBSD compat */
case 'r':
rflag++;
break;
@@ -693,15 +694,8 @@
req = 1;
key = l;
value = strchr(l, '=');
- if (value != NULL) {
- if (!wflag) {
- fprintf(warnfp,
- "%s: Must specify -w to set variables\n",
- getprogname());
- exit(1);
- }
+ if (value != NULL)
*value++ = '\0';
- }
if ((dot = strpbrk(key, "./")) == NULL)
sep[0] = '.';
@@ -709,13 +703,15 @@
sep[0] = dot[0];
sep[1] = '\0';
- if (key[0] == sep[0] && key[1] == sep[0]) {
+ while (key[0] == sep[0] && key[1] == sep[0]) {
if (value != NULL)
value[-1] = '=';
- if (strncmp(key + 2, "create=", 7) == 0)
- cparse(key + 9);
- else if (strncmp(key + 2, "destroy=", 8) == 0)
- dparse(key + 10);
+ if (strncmp(key + 2, "create", 6) == 0 &&
+ (key[8] == '=' || key[8] == sep[0]))
+ parse_create(key + 8 + (key[8] == '='));
+ else if (strncmp(key + 2, "destroy", 7) == 0 &&
+ (key[9] == '=' || key[9] == sep[0]))
+ parse_destroy(key + 9 + (key[9] == '='));
else
fprintf(warnfp, "%s: unable to parse '%s'\n",
getprogname(), key);
@@ -741,6 +737,12 @@
return;
}
+ if (!wflag) {
+ fprintf(warnfp, "%s: Must specify -w to set variables\n",
+ getprogname());
+ exit(1);
+ }
+
if (type != CTLTYPE_NODE && (w = findwriter(name, namelen)) != NULL) {
(*w->ps_w)(gsname, gdname, value, name, namelen, node, type,
w->ps_d);
@@ -780,7 +782,7 @@
[type=(int|quad|string|struct|node),]
[size=###,]
[n=###,]
- [flags=(tiohxparw12),]
+ [flags=(iohxparw12),]
[addr=0x####,|symbol=...|value=...]
size is optional for some types. type must be set before anything
@@ -796,7 +798,7 @@
*/
static void
-cparse(char *l)
+parse_create(char *l)
{
struct sysctlnode node;
size_t sz;
@@ -806,6 +808,12 @@
u_quad_t q;
long li, lo;
+ if (!wflag) {
+ fprintf(warnfp, "%s: Must specify -w to create nodes\n",
+ getprogname());
+ exit(1);
+ }
+
/*
* these are the pieces that make up the description of a new
* node
@@ -1190,6 +1198,8 @@
strlcpy(node.sysctl_name, t + 1, sizeof(node.sysctl_name));
else
strlcpy(node.sysctl_name, nname, sizeof(node.sysctl_name));
+ if (t == nname)
+ t = NULL;
/*
* if this is a new top-level node, then we don't need to find
@@ -1240,13 +1250,19 @@
}
static void
-dparse(char *l)
+parse_destroy(char *l)
{
struct sysctlnode node;
size_t sz;
int name[CTL_MAXNAME], rc;
u_int namelen;
+ if (!wflag) {
+ fprintf(warnfp, "%s: Must specify -w to destroy nodes\n",
+ getprogname());
+ exit(1);
+ }
+
memset(name, 0, sizeof(name));
namelen = sizeof(name) / sizeof(name[0]);
sz = sizeof(gsname);
Home |
Main Index |
Thread Index |
Old Index