Add an extension to the UINT & ULONG types. The XINT & XLONG types behave

the same, except sysctl(8) will print out the values in hex.
This commit is contained in:
David E. O'Brien 2006-08-12 23:33:10 +00:00
parent 65a963b762
commit c157a036a9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=161256
3 changed files with 51 additions and 4 deletions

View File

@ -578,7 +578,11 @@ show_var(int *oid, int nlen)
while (len >= sizeof(int)) { while (len >= sizeof(int)) {
fputs(val, stdout); fputs(val, stdout);
if (*fmt == 'U') if (*fmt == 'U')
printf(hflag ? "%'u" : "%u", *(unsigned int *)p); printf(hflag ? "%'u" : "%u",
*(unsigned int *)p);
else if (*fmt == 'X')
printf(hflag ? "%'#010x" : "%#010x",
*(unsigned int *)p);
else if (*fmt == 'K') { else if (*fmt == 'K') {
if (*(long *)p < 0) if (*(long *)p < 0)
printf("%ld", *(long *)p); printf("%ld", *(long *)p);
@ -601,7 +605,11 @@ show_var(int *oid, int nlen)
while (len >= sizeof(long)) { while (len >= sizeof(long)) {
fputs(val, stdout); fputs(val, stdout);
if (*fmt == 'U') if (*fmt == 'U')
printf(hflag ? "%'lu" : "%lu", *(unsigned long *)p); printf(hflag ? "%'lu" : "%lu",
*(unsigned long *)p);
else if (*fmt == 'X')
printf(hflag ? "%'#018lx" : "%#018lx",
*(unsigned long *)p);
else if (*fmt == 'K') { else if (*fmt == 'K') {
if (*(long *)p < 0) if (*(long *)p < 0)
printf("%ld", *(long *)p); printf("%ld", *(long *)p);

View File

@ -38,7 +38,9 @@
.Nm SYSCTL_STRING , .Nm SYSCTL_STRING ,
.Nm SYSCTL_STRUCT , .Nm SYSCTL_STRUCT ,
.Nm SYSCTL_UINT , .Nm SYSCTL_UINT ,
.Nm SYSCTL_ULONG .Nm SYSCTL_ULONG ,
.Nm SYSCTL_XINT ,
.Nm SYSCTL_XLONG
.Nd Static sysctl declaration functions .Nd Static sysctl declaration functions
.Sh SYNOPSIS .Sh SYNOPSIS
.In sys/types.h .In sys/types.h
@ -129,6 +131,24 @@
.Fa "val" .Fa "val"
.Fa "descr" .Fa "descr"
.Fc .Fc
.Fo SYSCTL_XINT
.Fa "parent"
.Fa "nbr"
.Fa "name"
.Fa "access"
.Fa "ptr"
.Fa "val"
.Fa "descr"
.Fc
.Fo SYSCTL_XLONG
.Fa "parent"
.Fa "nbr"
.Fa "name"
.Fa "access"
.Fa "ptr"
.Fa "val"
.Fa "descr"
.Fc
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .Nm
@ -153,8 +173,10 @@ New nodes are declared using one of
.Nm SYSCTL_STRING , .Nm SYSCTL_STRING ,
.Nm SYSCTL_STRUCT , .Nm SYSCTL_STRUCT ,
.Nm SYSCTL_UINT , .Nm SYSCTL_UINT ,
.Nm SYSCTL_ULONG ,
.Nm SYSCTL_XINT ,
and and
.Nm SYSCTL_ULONG . .Nm SYSCTL_XLONG .
Each macro accepts a parent name, as declared using Each macro accepts a parent name, as declared using
.Nm SYSCTL_DECL , .Nm SYSCTL_DECL ,
an OID number, typically an OID number, typically
@ -271,6 +293,7 @@ Examples of integer, opaque, string, and procedure sysctls follow:
* Example of a constant integer value. Notice that the control * Example of a constant integer value. Notice that the control
* flags are CTLFLAG_RD, the variable pointer is NULL, and the * flags are CTLFLAG_RD, the variable pointer is NULL, and the
* value is declared. * 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, SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD, NULL,
sizeof(struct bio), "sizeof(struct bio)"); sizeof(struct bio), "sizeof(struct bio)");

View File

@ -259,6 +259,14 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \
ptr, val, sysctl_handle_int, "IU", __DESCR(descr)) ptr, val, sysctl_handle_int, "IU", __DESCR(descr))
#define SYSCTL_XINT(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_UINT|(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|(access), \
ptr, val, sysctl_handle_int, "IX", __DESCR(descr))
/* Oid for a long. The pointer must be non NULL. */ /* Oid for a long. The pointer must be non NULL. */
#define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \ #define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_LONG|(access), \ SYSCTL_OID(parent, nbr, name, CTLTYPE_LONG|(access), \
@ -277,6 +285,14 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \
ptr, 0, sysctl_handle_long, "LU", __DESCR(descr)) ptr, 0, sysctl_handle_long, "LU", __DESCR(descr))
#define SYSCTL_XLONG(parent, nbr, name, access, ptr, val, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_ULONG|(access), \
ptr, val, sysctl_handle_long, "LX", __DESCR(descr))
#define SYSCTL_ADD_XLONG(ctx, parent, nbr, name, access, ptr, descr) \
sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_ULONG|(access), \
ptr, 0, sysctl_handle_long, "LX", __DESCR(descr))
/* Oid for an opaque object. Specified by a pointer and a length. */ /* Oid for an opaque object. Specified by a pointer and a length. */
#define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \
SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \