From c157a036a9cac44c843f2d89a42192db51c7ebef Mon Sep 17 00:00:00 2001 From: "David E. O'Brien" Date: Sat, 12 Aug 2006 23:33:10 +0000 Subject: [PATCH] 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. --- sbin/sysctl/sysctl.c | 12 ++++++++++-- share/man/man9/sysctl.9 | 27 +++++++++++++++++++++++++-- sys/sys/sysctl.h | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 09569c523298..d171ec94c131 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -578,7 +578,11 @@ show_var(int *oid, int nlen) while (len >= sizeof(int)) { fputs(val, stdout); 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') { if (*(long *)p < 0) printf("%ld", *(long *)p); @@ -601,7 +605,11 @@ show_var(int *oid, int nlen) while (len >= sizeof(long)) { fputs(val, stdout); 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') { if (*(long *)p < 0) printf("%ld", *(long *)p); diff --git a/share/man/man9/sysctl.9 b/share/man/man9/sysctl.9 index a9a07515afc5..9f5426a0badf 100644 --- a/share/man/man9/sysctl.9 +++ b/share/man/man9/sysctl.9 @@ -38,7 +38,9 @@ .Nm SYSCTL_STRING , .Nm SYSCTL_STRUCT , .Nm SYSCTL_UINT , -.Nm SYSCTL_ULONG +.Nm SYSCTL_ULONG , +.Nm SYSCTL_XINT , +.Nm SYSCTL_XLONG .Nd Static sysctl declaration functions .Sh SYNOPSIS .In sys/types.h @@ -129,6 +131,24 @@ .Fa "val" .Fa "descr" .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 The .Nm @@ -153,8 +173,10 @@ New nodes are declared using one of .Nm SYSCTL_STRING , .Nm SYSCTL_STRUCT , .Nm SYSCTL_UINT , +.Nm SYSCTL_ULONG , +.Nm SYSCTL_XINT , and -.Nm SYSCTL_ULONG . +.Nm SYSCTL_XLONG . Each macro accepts a parent name, as declared using .Nm SYSCTL_DECL , 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 * 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)"); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 7df7d68d4c6a..da17fdd7f815 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -259,6 +259,14 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_UINT|(access), \ 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. */ #define SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr) \ 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), \ 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. */ #define SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr) \ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \