Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/sysctl implement CTLTYPE_BOOL support. it was entirely...
details: https://anonhg.NetBSD.org/src/rev/6d3897f2eeb7
branches: trunk
changeset: 753813:6d3897f2eeb7
user: mrg <mrg%NetBSD.org@localhost>
date: Sun Apr 11 01:52:10 2010 +0000
description:
implement CTLTYPE_BOOL support. it was entirely missing. HI MATT!
diffstat:
sbin/sysctl/sysctl.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 66 insertions(+), 5 deletions(-)
diffs (188 lines):
diff -r 57563900f217 -r 6d3897f2eeb7 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c Sun Apr 11 01:50:25 2010 +0000
+++ b/sbin/sysctl/sysctl.c Sun Apr 11 01:52:10 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysctl.c,v 1.130 2009/09/30 04:30:50 elad Exp $ */
+/* $NetBSD: sysctl.c,v 1.131 2010/04/11 01:52:10 mrg 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.130 2009/09/30 04:30:50 elad Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.131 2010/04/11 01:52:10 mrg Exp $");
#endif
#endif /* not lint */
@@ -502,6 +502,8 @@
return "QUAD";
case CTLTYPE_STRUCT:
return "STRUCT";
+ case CTLTYPE_BOOL:
+ return "BOOL";
}
return "???";
@@ -712,6 +714,16 @@
display_number(pnode, gsname, &i, sizeof(i), DISPLAY_VALUE);
break;
}
+ case CTLTYPE_BOOL: {
+ bool b;
+ rc = sysctl(name, namelen, &b, &sz, NULL, 0);
+ if (rc == -1) {
+ sysctlerror(1);
+ break;
+ }
+ display_number(pnode, gsname, &b, sizeof(b), DISPLAY_VALUE);
+ break;
+ }
case CTLTYPE_STRING: {
unsigned char buf[1024], *tbuf;
tbuf = buf;
@@ -884,14 +896,13 @@
print_tree(&name[0], namelen, node, CTLTYPE_NODE, 1);
break;
case CTLTYPE_INT:
+ case CTLTYPE_BOOL:
+ case CTLTYPE_QUAD:
write_number(&name[0], namelen, node, value);
break;
case CTLTYPE_STRING:
write_string(&name[0], namelen, node, value);
break;
- case CTLTYPE_QUAD:
- write_number(&name[0], namelen, node, value);
- break;
case CTLTYPE_STRUCT:
/*
* XXX old behavior is to print. should we error instead?
@@ -932,6 +943,7 @@
u_int namelen, type;
u_quad_t uq;
quad_t q;
+ bool b;
if (!wflag) {
sysctlperror("Must specify -w to create nodes\n");
@@ -957,6 +969,7 @@
* misc stuff used when constructing
*/
i = 0;
+ b = false;
uq = 0;
key = NULL;
value = NULL;
@@ -1053,6 +1066,10 @@
sz = sizeof(int);
type = CTLTYPE_INT;
}
+ else if (strcmp(value, "bool") == 0) {
+ sz = sizeof(bool);
+ type = CTLTYPE_BOOL;
+ }
else if (strcmp(value, "string") == 0)
type = CTLTYPE_STRING;
else if (strcmp(value, "quad") == 0) {
@@ -1192,6 +1209,26 @@
if (sz == 0)
sz = sizeof(int);
break;
+ case CTLTYPE_BOOL:
+ errno = 0;
+ q = strtoll(data, &t, 0);
+ if (t == data || *t != '\0' || errno != 0 ||
+ (q != 0 && q != 1)) {
+ sysctlperror(
+ "%s: '%s' is not a valid bool\n",
+ nname, value);
+ EXIT(1);
+ }
+ b = q == 1;
+ if (!(flags & CTLFLAG_OWNDATA)) {
+ flags |= CTLFLAG_IMMEDIATE;
+ node.sysctl_idata = b;
+ }
+ else
+ node.sysctl_data = &b;
+ if (sz == 0)
+ sz = sizeof(bool);
+ break;
case CTLTYPE_STRING:
flags |= CTLFLAG_OWNDATA;
node.sysctl_data = data;
@@ -1277,6 +1314,7 @@
*/
if (sz != 0) {
if ((type == CTLTYPE_INT && sz != sizeof(int)) ||
+ (type == CTLTYPE_BOOL && sz != sizeof(bool)) ||
(type == CTLTYPE_QUAD && sz != sizeof(u_quad_t)) ||
(type == CTLTYPE_NODE && sz != 0)) {
sysctlperror("%s: wrong size for type\n", nname);
@@ -1664,6 +1702,7 @@
u_int ii, io;
u_quad_t qi, qo;
size_t si, so;
+ bool bi, bo;
int rc;
void *i, *o;
char *t;
@@ -1673,6 +1712,7 @@
si = so = 0;
i = o = NULL;
+ bi = bo = false;
errno = 0;
qi = strtouq(value, &t, 0);
if (qi == UQUAD_MAX && errno == ERANGE) {
@@ -1697,6 +1737,13 @@
i = ⅈ
si = sizeof(ii);
break;
+ case CTLTYPE_BOOL:
+ bi = (bool)qi;
+ o = &bo;
+ so = sizeof(bo);
+ i = &bi;
+ si = sizeof(bi);
+ break;
case CTLTYPE_QUAD:
o = &qo;
so = sizeof(qo);
@@ -1716,6 +1763,10 @@
display_number(node, gsname, &io, sizeof(io), DISPLAY_OLD);
display_number(node, gsname, &ii, sizeof(ii), DISPLAY_NEW);
break;
+ case CTLTYPE_BOOL:
+ display_number(node, gsname, &bo, sizeof(bo), DISPLAY_OLD);
+ display_number(node, gsname, &bi, sizeof(bi), DISPLAY_NEW);
+ break;
case CTLTYPE_QUAD:
display_number(node, gsname, &qo, sizeof(qo), DISPLAY_OLD);
display_number(node, gsname, &qi, sizeof(qi), DISPLAY_NEW);
@@ -1764,6 +1815,7 @@
const void *data, size_t sz, int n)
{
u_quad_t q;
+ bool b;
int i;
if (qflag)
@@ -1800,6 +1852,15 @@
else
printf("%d", i);
break;
+ case CTLTYPE_BOOL:
+ memcpy(&b, data, sz);
+ if (xflag)
+ printf("0x%0*x", (int)sz * 2, b);
+ else if (node->sysctl_flags & CTLFLAG_HEX)
+ printf("%#x", b);
+ else
+ printf("%d", b);
+ break;
case CTLTYPE_QUAD:
memcpy(&q, data, sz);
if (xflag)
Home |
Main Index |
Thread Index |
Old Index