Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Apr 2003 16:03:07 +0100
From:      "Andy Gilligan" <andy@evo6.org>
To:        "Simon L. Nielsen" <simon@nitro.dk>
Cc:        stable@freebsd.org
Subject:   Re: MFC for sysctl descriptions
Message-ID:  <004401c30684$c92f35f0$0a00000a@vx>
References:  <000801c3067d$b6379340$0a00000a@vx> <002101c30681$0d9c97e0$0a00000a@vx> <20030419145427.GC15529@nitro.dk>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Sorry, my bad :)

Patch updated to include SYNOPSIS changes.

- Andy

----- Original Message ----- 
From: "Simon L. Nielsen" <simon@nitro.dk>
To: "Andy Gilligan" <andy@evo6.org>
Cc: <stable@freebsd.org>
Sent: Saturday, April 19, 2003 3:54 PM
Subject: Re: MFC for sysctl descriptions

On 2003.04.19 15:36:24 +0100, Andy Gilligan wrote:
> The patch attached to the previous email did not include
> the updated sysctl.8 manpage (although the link was correct).

The patch for the manpage seems to be missing the update to the SYNOPSIS
section.

I'm waiting for my build world/kernel to finish building to test the
patch...

-- 
Simon L. Nielsen

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

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