Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Apr 2003 15:12:28 +0100
From:      "Andy Gilligan" <andy@evo6.org>
To:        <stable@freebsd.org>
Subject:   MFC for sysctl descriptions
Message-ID:  <000801c3067d$b6379340$0a00000a@vx>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C30686.17AB1C20
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello everyone... :)

I liked the idea of having descriptions for various
sysctl oid's in -CURRENT, so I have created a patch
to merge these over to -STABLE.

I am unsure as to how much work has already gone into
bringing this to -STABLE, but as the descriptions
already exist in the source, I am fairly confident that
it was planned at some point.

All I can really ask is that someone with more knowledge
than myself about the sysctl internals have a brief look
at my patch to see if it is viable.

On my system (4.8-STABLE), everything seems to work, and
there have been no adverse effects from it.
(That I am aware of at least)

The patch is attached to this email, and is also available
at:  http://evo6.org/sysctl-mfc.patch

I hope someone may find this useful. :)

Very best regards,
Andy Gilligan
------=_NextPart_000_0005_01C30686.17AB1C20
Content-Type: application/octet-stream;
	name="sysctl-mfc.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="sysctl-mfc.patch"

Index: sbin/sysctl/sysctl.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /data/ncvs/src/sbin/sysctl/sysctl.c,v=0A=
retrieving revision 1.25.2.10=0A=
diff -u -r1.25.2.10 sysctl.c=0A=
--- sbin/sysctl/sysctl.c	22 Jan 2003 00:36:23 -0000	1.25.2.10=0A=
+++ sbin/sysctl/sysctl.c	19 Apr 2003 13:29:15 -0000=0A=
@@ -63,7 +63,7 @@=0A=
 #include <string.h>=0A=
 #include <unistd.h>=0A=
 =0A=
-static int	aflag, bflag, eflag, Nflag, nflag, oflag, xflag;=0A=
+static int	aflag, bflag, dflag, eflag, Nflag, nflag, oflag, xflag;=0A=
 =0A=
 static int	oidfmt(int *, int, char *, u_int *);=0A=
 static void	parse(char *);=0A=
@@ -78,8 +78,8 @@=0A=
 {=0A=
 =0A=
 	(void)fprintf(stderr, "%s\n%s\n",=0A=
-	    "usage: sysctl [-beNnox] variable[=3Dvalue] ...",=0A=
-	    "       sysctl [-beNnox] -a");=0A=
+	    "usage: sysctl [-bdeNnox] variable[=3Dvalue] ...",=0A=
+	    "       sysctl [-bdeNnox] -a");=0A=
 	exit(1);=0A=
 }=0A=
 =0A=
@@ -90,7 +90,7 @@=0A=
 	setbuf(stdout,0);=0A=
 	setbuf(stderr,0);=0A=
 =0A=
-	while ((ch =3D getopt(argc, argv, "AabeNnowxX")) !=3D -1) {=0A=
+	while ((ch =3D getopt(argc, argv, "AabdeNnowxX")) !=3D -1) {=0A=
 		switch (ch) {=0A=
 		case 'A':=0A=
 			/* compatibility */=0A=
@@ -102,6 +102,9 @@=0A=
 		case 'b':=0A=
 			bflag =3D 1;=0A=
 			break;=0A=
+		case 'd':=0A=
+			dflag =3D 1;=0A=
+			break;=0A=
 		case 'e':=0A=
 			eflag =3D 1;=0A=
 			break;=0A=
@@ -491,6 +494,15 @@=0A=
 	else=0A=
 		sep =3D ": ";=0A=
 =0A=
+	if (dflag) {	/* just print description */=0A=
+		qoid[1] =3D 5;=0A=
+		j =3D sizeof(buf);=0A=
+		i =3D sysctl(qoid, nlen + 2, buf, &j, 0, 0);=0A=
+		if (!nflag)=0A=
+			printf("%s%s", name, sep);=0A=
+		printf("%s", buf);=0A=
+		return(0);=0A=
+	}=0A=
 	/* find an estimate of how much we need for this var */=0A=
 	j =3D 0;=0A=
 	i =3D sysctl(oid, nlen, 0, &j, 0, 0);=0A=
Index: sys/kern/kern_sysctl.c=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /data/ncvs/src/sys/kern/kern_sysctl.c,v=0A=
retrieving revision 1.92.2.8=0A=
diff -u -r1.92.2.8 kern_sysctl.c=0A=
--- sys/kern/kern_sysctl.c	9 Sep 2002 19:27:58 -0000	1.92.2.8=0A=
+++ sys/kern/kern_sysctl.c	19 Apr 2003 13:52:00 -0000=0A=
@@ -303,6 +303,8 @@=0A=
 		}=0A=
 		sysctl_unregister_oid(oidp);=0A=
 		if (del) {=0A=
+			if (oidp->descr)=0A=
+				free((void *)(uintptr_t)(const void *)oidp->descr, M_SYSCTLOID);=0A=
 			free((void *)(uintptr_t)(const void *)oidp->oid_name,=0A=
 			     M_SYSCTLOID);=0A=
 			free(oidp, M_SYSCTLOID);=0A=
@@ -364,6 +366,12 @@=0A=
 		oidp->oid_arg2 =3D arg2;=0A=
 	}=0A=
 	oidp->oid_fmt =3D fmt;=0A=
+	if (descr) {=0A=
+		int len =3D strlen(descr) + 1;=0A=
+		oidp->descr =3D malloc(len, M_SYSCTLOID, M_WAITOK);=0A=
+		if (oidp->descr)=0A=
+			strcpy((char *)(uintptr_t)(const void *)oidp->descr, descr);=0A=
+	};=0A=
 	/* Update the context, if used */=0A=
 	if (clist !=3D NULL)=0A=
 		sysctl_ctx_entry_add(clist, oidp);=0A=
@@ -718,6 +726,24 @@=0A=
 =0A=
 =0A=
 SYSCTL_NODE(_sysctl, 4, oidfmt, CTLFLAG_RD, sysctl_sysctl_oidfmt, "");=0A=
+=0A=
+static int=0A=
+sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS)=0A=
+{=0A=
+	struct sysctl_oid *oid;=0A=
+	int error;=0A=
+=0A=
+	error =3D sysctl_find_oid(arg1, arg2, &oid, NULL, req);=0A=
+	if (error)=0A=
+		return (error);=0A=
+	=0A=
+	if (!oid->descr)=0A=
+		return (ENOENT);=0A=
+	error =3D SYSCTL_OUT(req, oid->descr, strlen(oid->descr) + 1);=0A=
+	return (error);=0A=
+}=0A=
+=0A=
+SYSCTL_NODE(_sysctl, 5, oiddescr, CTLFLAG_RD, sysctl_sysctl_oiddescr, =
"");=0A=
 =0A=
 /*=0A=
  * Default "handler" functions.=0A=
Index: sys/sys/sysctl.h=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /data/ncvs/src/sys/sys/sysctl.h,v=0A=
retrieving revision 1.81.2.9=0A=
diff -u -r1.81.2.9 sysctl.h=0A=
--- sys/sys/sysctl.h	9 Sep 2002 19:27:54 -0000	1.81.2.9=0A=
+++ sys/sys/sysctl.h	19 Apr 2003 13:24:38 -0000=0A=
@@ -133,6 +133,7 @@=0A=
 	int 		(*oid_handler)(SYSCTL_HANDLER_ARGS);=0A=
 	const char	*oid_fmt;=0A=
 	int		oid_refcnt;=0A=
+	const char	*descr;=0A=
 };=0A=
 =0A=
 #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)=0A=
@@ -174,7 +175,7 @@=0A=
 #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, =
descr) \=0A=
 	static struct sysctl_oid sysctl__##parent##_##name =3D {		 \=0A=
 		&sysctl_##parent##_children, { 0 },			 \=0A=
-		nbr, kind, a1, a2, #name, handler, fmt, 0 };		 \=0A=
+		nbr, kind, a1, a2, #name, handler, fmt, 0, descr };		 \=0A=
 	DATA_SET(sysctl_set, sysctl__##parent##_##name);=0A=
 =0A=
 #define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, =
fmt, descr) \=0A=

------=_NextPart_000_0005_01C30686.17AB1C20--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000801c3067d$b6379340$0a00000a>