sysctl(8) should use the CTLTYPE to determine the type of data when

reading.  (This was already done for writing to a sysctl).  This
requires all SYSCTL setups to specify a type.  Most of them are now
checked at compile-time.

Remove SYSCTL_*X* sysctl additions as the print being in hex should be
controlled by the -x flag to sysctl(8).

Succested by:	bde
This commit is contained in:
Matthew D Fleming 2011-01-19 17:04:07 +00:00
parent 08b1d53573
commit f8e4b4ef49
9 changed files with 41 additions and 82 deletions

View File

@ -510,7 +510,7 @@ show_var(int *oid, int nlen)
int qoid[CTL_MAXNAME+2];
uintmax_t umv;
intmax_t mv;
int i, hexlen;
int i, hexlen, sign, ctltype;
size_t intlen;
size_t j, len;
u_int kind;
@ -575,46 +575,57 @@ show_var(int *oid, int nlen)
fmt = buf;
oidfmt(oid, nlen, fmt, &kind);
p = val;
switch (*fmt) {
case 'A':
ctltype = (kind & CTLTYPE);
sign = (ctltype == CTLTYPE_INT || ctltype == CTLTYPE_LONG) ? 1 : 0;
switch (ctltype) {
case CTLTYPE_STRING:
if (!nflag)
printf("%s%s", name, sep);
printf("%.*s", (int)len, p);
free(oval);
return (0);
case 'I':
case 'L':
case 'Q':
case CTLTYPE_INT:
case CTLTYPE_UINT:
case CTLTYPE_LONG:
case CTLTYPE_ULONG:
case CTLTYPE_QUAD:
if (!nflag)
printf("%s%s", name, sep);
switch (*fmt) {
case 'I': intlen = sizeof(int); break;
case 'L': intlen = sizeof(long); break;
case 'Q': intlen = sizeof(quad_t); break;
switch (kind & CTLTYPE) {
case CTLTYPE_INT:
case CTLTYPE_UINT:
intlen = sizeof(int); break;
case CTLTYPE_LONG:
case CTLTYPE_ULONG:
intlen = sizeof(long); break;
case CTLTYPE_QUAD:
intlen = sizeof(quad_t); break;
}
hexlen = 2 + (intlen * CHAR_BIT + 3) / 4;
sep1 = "";
while (len >= intlen) {
switch (*fmt) {
case 'I':
switch (kind & CTLTYPE) {
case CTLTYPE_INT:
case CTLTYPE_UINT:
umv = *(u_int *)p;
mv = *(int *)p;
break;
case 'L':
case CTLTYPE_LONG:
case CTLTYPE_ULONG:
umv = *(u_long *)p;
mv = *(long *)p;
break;
case 'Q':
case CTLTYPE_QUAD:
umv = *(u_quad_t *)p;
mv = *(quad_t *)p;
break;
}
fputs(sep1, stdout);
if (fmt[1] == 'U')
printf(hflag ? "%'ju" : "%ju", umv);
else if (fmt[1] == 'X')
if (xflag)
printf("%#0*jx", hexlen, umv);
else if (!sign)
printf(hflag ? "%'ju" : "%ju", umv);
else if (fmt[1] == 'K') {
if (mv < 0)
printf("%jd", mv);
@ -629,14 +640,7 @@ show_var(int *oid, int nlen)
free(oval);
return (0);
case 'P':
if (!nflag)
printf("%s%s", name, sep);
printf("%p", *(void **)p);
free(oval);
return (0);
case 'S':
case CTLTYPE_OPAQUE:
i = 0;
if (strcmp(fmt, "S,clockinfo") == 0)
func = S_clockinfo;

View File

@ -1193,8 +1193,7 @@ MLINKS+=sysctl.9 SYSCTL_DECL.9 \
sysctl.9 SYSCTL_STRUCT.9 \
sysctl.9 SYSCTL_UINT.9 \
sysctl.9 SYSCTL_ULONG.9 \
sysctl.9 SYSCTL_XINT.9 \
sysctl.9 SYSCTL_XLONG.9
sysctl.9 SYSCTL_QUAD.9
MLINKS+=sysctl_add_oid.9 SYSCTL_ADD_INT.9 \
sysctl_add_oid.9 SYSCTL_ADD_LONG.9 \
sysctl_add_oid.9 SYSCTL_ADD_NODE.9 \
@ -1205,6 +1204,7 @@ MLINKS+=sysctl_add_oid.9 SYSCTL_ADD_INT.9 \
sysctl_add_oid.9 SYSCTL_ADD_STRUCT.9 \
sysctl_add_oid.9 SYSCTL_ADD_UINT.9 \
sysctl_add_oid.9 SYSCTL_ADD_ULONG.9 \
sysctl_add_oid.9 SYSCTL_ADD_QUAD.9 \
sysctl_add_oid.9 SYSCTL_CHILDREN.9 \
sysctl_add_oid.9 sysctl_move_oid.9 \
sysctl_add_oid.9 sysctl_remove_oid.9 \

View File

@ -39,8 +39,6 @@
.Nm SYSCTL_STRUCT ,
.Nm SYSCTL_UINT ,
.Nm SYSCTL_ULONG ,
.Nm SYSCTL_XINT ,
.Nm SYSCTL_XLONG ,
.Nm SYSCTL_QUAD
.Nd Static sysctl declaration functions
.Sh SYNOPSIS
@ -56,8 +54,6 @@
.Fn SYSCTL_STRUCT parent nbr name access ptr type descr
.Fn SYSCTL_UINT parent nbr name access ptr val descr
.Fn SYSCTL_ULONG parent nbr name access ptr val descr
.Fn SYSCTL_XINT parent nbr name access ptr val descr
.Fn SYSCTL_XLONG parent nbr name access ptr val descr
.Fn SYSCTL_QUAD parent nbr name access ptr val descr
.Sh DESCRIPTION
The
@ -84,8 +80,6 @@ New nodes are declared using one of
.Fn SYSCTL_STRUCT ,
.Fn SYSCTL_UINT ,
.Fn SYSCTL_ULONG ,
.Fn SYSCTL_XINT ,
.Fn SYSCTL_XLONG ,
and
.Fn SYSCTL_QUAD .
Each macro accepts a parent name, as declared using
@ -206,7 +200,6 @@ Examples of integer, opaque, string, and procedure sysctls follow:
* Example of a constant integer value. Notice that the control
* flags are CTLFLAG_RD, the variable pointer is NULL, and the
* value is declared.
* If sysctl(8) should print this value in hex, use 'SYSCTL_XINT'.
*/
SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
sizeof(struct bio), "sizeof(struct bio)");

View File

@ -1127,7 +1127,7 @@ dasysctlinit(void *context, int pending)
struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
if (fc->valid & CTS_FC_VALID_WWPN) {
softc->wwpn = fc->wwpn;
SYSCTL_ADD_X64(&softc->sysctl_ctx,
SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
SYSCTL_CHILDREN(softc->sysctl_tree),
OID_AUTO, "wwpn", CTLFLAG_RD,
&softc->wwpn, "World Wide Port Name");

View File

@ -3630,7 +3630,7 @@ t3_add_configured_sysctls(adapter_t *sc)
SYSCTL_ADD_UINT(ctx, rspqpoidlist, OID_AUTO, "starved",
CTLFLAG_RD, &qs->rspq.starved,
0, "#times starved");
SYSCTL_ADD_XLONG(ctx, rspqpoidlist, OID_AUTO, "phys_addr",
SYSCTL_ADD_ULONG(ctx, rspqpoidlist, OID_AUTO, "phys_addr",
CTLFLAG_RD, &qs->rspq.phys_addr,
"physical_address_of the queue");
SYSCTL_ADD_UINT(ctx, rspqpoidlist, OID_AUTO, "dump_start",
@ -3681,7 +3681,7 @@ t3_add_configured_sysctls(adapter_t *sc)
SYSCTL_ADD_UINT(ctx, txqpoidlist, OID_AUTO, "stopped_flags",
CTLFLAG_RD, &qs->txq_stopped,
0, "tx queues stopped");
SYSCTL_ADD_XLONG(ctx, txqpoidlist, OID_AUTO, "phys_addr",
SYSCTL_ADD_ULONG(ctx, txqpoidlist, OID_AUTO, "phys_addr",
CTLFLAG_RD, &txq->phys_addr,
"physical_address_of the queue");
SYSCTL_ADD_UINT(ctx, txqpoidlist, OID_AUTO, "qgen",

View File

@ -295,7 +295,7 @@ wi_attach(device_t dev)
SYSCTL_ADD_INT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO,
"pri_version", CTLFLAG_RD, &sc->sc_pri_firmware_ver, 0,
"Primary Firmware version");
SYSCTL_ADD_XINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "nic_id",
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "nic_id",
CTLFLAG_RD, &sc->sc_nic_id, 0, "NIC id");
SYSCTL_ADD_STRING(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "nic_name",
CTLFLAG_RD, sc->sc_nic_name, 0, "NIC name");

View File

@ -104,18 +104,18 @@ SYSCTL_NODE(_net, OID_AUTO, enc, CTLFLAG_RW, 0, "enc sysctl");
SYSCTL_NODE(_net_enc, OID_AUTO, in, CTLFLAG_RW, 0, "enc input sysctl");
static int ipsec_filter_mask_in = ENC_BEFORE;
SYSCTL_XINT(_net_enc_in, OID_AUTO, ipsec_filter_mask, CTLFLAG_RW,
SYSCTL_INT(_net_enc_in, OID_AUTO, ipsec_filter_mask, CTLFLAG_RW,
&ipsec_filter_mask_in, 0, "IPsec input firewall filter mask");
static int ipsec_bpf_mask_in = ENC_BEFORE;
SYSCTL_XINT(_net_enc_in, OID_AUTO, ipsec_bpf_mask, CTLFLAG_RW,
SYSCTL_INT(_net_enc_in, OID_AUTO, ipsec_bpf_mask, CTLFLAG_RW,
&ipsec_bpf_mask_in, 0, "IPsec input bpf mask");
SYSCTL_NODE(_net_enc, OID_AUTO, out, CTLFLAG_RW, 0, "enc output sysctl");
static int ipsec_filter_mask_out = ENC_BEFORE;
SYSCTL_XINT(_net_enc_out, OID_AUTO, ipsec_filter_mask, CTLFLAG_RW,
SYSCTL_INT(_net_enc_out, OID_AUTO, ipsec_filter_mask, CTLFLAG_RW,
&ipsec_filter_mask_out, 0, "IPsec output firewall filter mask");
static int ipsec_bpf_mask_out = ENC_BEFORE|ENC_AFTER;
SYSCTL_XINT(_net_enc_out, OID_AUTO, ipsec_bpf_mask, CTLFLAG_RW,
SYSCTL_INT(_net_enc_out, OID_AUTO, ipsec_bpf_mask, CTLFLAG_RW,
&ipsec_bpf_mask_out, 0, "IPsec output bpf mask");
static void

View File

@ -236,6 +236,7 @@ int vnet_sysctl_handle_uint(SYSCTL_HANDLER_ARGS);
ptr, val, vnet_sysctl_handle_int, "I", descr)
#define SYSCTL_VNET_PROC(parent, nbr, name, access, ptr, arg, handler, \
fmt, descr) \
CTASSERT(((access) & CTLTYPE) != 0); \
SYSCTL_OID(parent, nbr, name, CTLFLAG_VNET|(access), ptr, arg, \
handler, fmt, descr)
#define SYSCTL_VNET_OPAQUE(parent, nbr, name, access, ptr, len, fmt, \

View File

@ -239,14 +239,10 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
SYSCTL_ALLOWED_TYPES(INT, int *a; );
SYSCTL_ALLOWED_TYPES(UINT, unsigned int *a; );
SYSCTL_ALLOWED_TYPES(XINT, unsigned int *a; int *b; );
SYSCTL_ALLOWED_TYPES(LONG, long *a; );
SYSCTL_ALLOWED_TYPES(ULONG, unsigned long *a; );
SYSCTL_ALLOWED_TYPES(XLONG, unsigned long *a; long *b; );
SYSCTL_ALLOWED_TYPES(INT64, int64_t *a; long long *b; );
SYSCTL_ALLOWED_TYPES(UINT64, uint64_t *a; unsigned long long *b; );
SYSCTL_ALLOWED_TYPES(XINT64, uint64_t *a; int64_t *b;
unsigned long long *c; long long *d; );
#ifdef notyet
#define SYSCTL_ADD_ASSERT_TYPE(type, ptr) \
@ -328,18 +324,6 @@ SYSCTL_ALLOWED_TYPES(XINT64, uint64_t *a; int64_t *b;
SYSCTL_ADD_ASSERT_TYPE(UINT, ptr), val, \
sysctl_handle_int, "IU", __DESCR(descr))
#define SYSCTL_XINT(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_ASSERT_TYPE(XINT, ptr, parent, name); \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_int, "IX", descr)
#define SYSCTL_ADD_XINT(ctx, parent, nbr, name, access, ptr, val, descr) \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \
SYSCTL_ADD_ASSERT_TYPE(XINT, ptr), val, \
sysctl_handle_int, "IX", __DESCR(descr))
/* Oid for a long. The pointer must be non NULL. */
#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_ASSERT_TYPE(LONG, ptr, parent, name); \
@ -366,18 +350,6 @@ SYSCTL_ALLOWED_TYPES(XINT64, uint64_t *a; int64_t *b;
SYSCTL_ADD_ASSERT_TYPE(ULONG, ptr), 0, \
sysctl_handle_long, "LU", __DESCR(descr))
#define SYSCTL_XLONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_ASSERT_TYPE(XLONG, ptr, parent, name); \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_long, "LX", descr)
#define SYSCTL_ADD_XLONG(ctx, parent, nbr, name, access, ptr, descr) \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \
SYSCTL_ADD_ASSERT_TYPE(XLONG, ptr), 0, \
sysctl_handle_long, "LX", __DESCR(descr))
/* Oid for a quad. The pointer must be non NULL. */
#define SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_ASSERT_TYPE(INT64, ptr, parent, name); \
@ -403,18 +375,6 @@ SYSCTL_ALLOWED_TYPES(XINT64, uint64_t *a; int64_t *b;
SYSCTL_ADD_ASSERT_TYPE(UINT64, ptr), 0, \
sysctl_handle_quad, "QU", __DESCR(descr))
#define SYSCTL_X64(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_ASSERT_TYPE(XINT64, ptr, parent, name); \
SYSCTL_OID(parent, nbr, name, \
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
ptr, val, sysctl_handle_quad, "QX", descr)
#define SYSCTL_ADD_X64(ctx, parent, nbr, name, access, ptr, descr) \
sysctl_add_oid(ctx, parent, nbr, name, \
CTLTYPE_QUAD | CTLFLAG_MPSAFE | (access), \
SYSCTL_ADD_ASSERT_TYPE(XINT64, ptr), 0, \
sysctl_handle_quad, "QX", __DESCR(descr))
/* Oid for an opaque object. Specified by a pointer and a length. */
#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \
@ -436,6 +396,7 @@ SYSCTL_ALLOWED_TYPES(XINT64, uint64_t *a; int64_t *b;
/* Oid for a procedure. Specified by a pointer and an arg. */
#define SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
CTASSERT(((access) & CTLTYPE) != 0); \
SYSCTL_OID(parent, nbr, name, (access), \
ptr, arg, handler, fmt, descr)