Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jul 2001 09:30:41 +0300
From:      Peter Pentchev <roam@orbitel.bg>
To:        arch@FreeBSD.org
Cc:        audit@FreeBSD.org
Subject:   Re: kern/29131: Current hungs in sysctl -a while booting + patch
Message-ID:  <20010723093041.A1201@ringworld.oblivion.bg>
In-Reply-To: <20010722235934.G882@ringworld.oblivion.bg>; from roam@orbitel.bg on Sun, Jul 22, 2001 at 11:59:34PM %2B0300
References:  <200107220334.f6M3YRe01219@kan.dnsalias.net> <20010722110626.A819@ringworld.oblivion.bg> <20010722034233.B49508@sneakerz.org> <20010722235934.G882@ringworld.oblivion.bg>

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

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Jul 22, 2001 at 11:59:34PM +0300, Peter Pentchev wrote:
> On Sun, Jul 22, 2001 at 03:42:33AM -0500, Alfred Perlstein wrote:
> > * Peter Pentchev <roam@orbitel.bg> [010722 03:02] wrote:
> > > Hi,
> > > 
> > > Can anyone envision any side effects from committing the patch
> > > in this PR?  Seems like a trivial fix for a typo to me..
> > 
> > Shouldn't "magic" constants be put into the sysctl.h header?
> 
> Good call!
> 
> Attached are two patches: one to make sys/kern/kern_sysctl.c a bit
> more style(9)-compliant (what made me do it was the failed search
> for /^sysctl_register_oid/ when I saw it referenced), and one to put
> a magic constant into sysctl.h and make kern_sysctl.c use it and
> complain (albeit a bit harshly ;) about misbehaving static sysctl's.

Here are the patches again (for -audit review).

The second patch was modified after a suggestion from Dima - the comment
about OID_AUTO in kern_sysctl.c was improved a bit.

G'luck,
Peter

-- 
This would easier understand fewer had omitted.

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="kern_sysctl.c-style.patch"

Index: src/sys/kern/kern_sysctl.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.110
diff -u -r1.110 kern_sysctl.c
--- src/sys/kern/kern_sysctl.c	2001/06/22 19:54:38	1.110
+++ src/sys/kern/kern_sysctl.c	2001/07/22 20:38:15
@@ -87,7 +87,8 @@
  * Order by number in each list.
  */
 
-void sysctl_register_oid(struct sysctl_oid *oidp)
+void
+sysctl_register_oid(struct sysctl_oid *oidp)
 {
 	struct sysctl_oid_list *parent = oidp->oid_parent;
 	struct sysctl_oid *p;
@@ -135,7 +136,8 @@
 		SLIST_INSERT_HEAD(parent, oidp, oid_link);
 }
 
-void sysctl_unregister_oid(struct sysctl_oid *oidp)
+void
+sysctl_unregister_oid(struct sysctl_oid *oidp)
 {
 	SLIST_REMOVE(oidp->oid_parent, oidp, sysctl_oid, oid_link);
 }
@@ -371,7 +373,8 @@
  */
 SET_DECLARE(sysctl_set, struct sysctl_oid);
 
-static void sysctl_register_all(void *arg)
+static void
+sysctl_register_all(void *arg)
 {
 	struct sysctl_oid **oidp;
 
@@ -1084,7 +1087,8 @@
  * must be in kernel space.
  */
 int
-userland_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval)
+userland_sysctl(struct proc *p, int *name, u_int namelen, void *old,
+    size_t *oldlenp, int inkernel, void *new, size_t newlen, size_t *retval)
 {
 	int error = 0;
 	struct sysctl_req req, req2;

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sysctl-auto-start.patch"

Index: src/sys/kern/kern_sysctl.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_sysctl.c,v
retrieving revision 1.110
diff -u -r1.110 kern_sysctl.c
--- src/sys/kern/kern_sysctl.c	2001/06/22 19:54:38	1.110
+++ src/sys/kern/kern_sysctl.c	2001/07/23 06:26:42
@@ -109,15 +109,19 @@
 	}
 	/*
 	 * If this oid has a number OID_AUTO, give it a number which
-	 * is greater than any current oid.  Make sure it is at least
-	 * 100 to leave space for pre-assigned oid numbers.
+	 * is greater than any current oid.
+	 * NOTE: DO NOT change the starting value here, change it in
+	 * <sys/sysctl.h>, and make sure it is at least 256 to
+	 * accomodate e.g. net.inet.raw as a static sysctl node.
 	 */
 	if (oidp->oid_number == OID_AUTO) {
-		static int newoid = 100;
+		static int newoid = CTL_AUTO_START;
 
 		oidp->oid_number = newoid++;
 		if (newoid == 0x7fffffff)
 			panic("out of oids");
+	} else if (oidp->oid_number >= CTL_AUTO_START) {
+		panic("static sysctl oid too high: %d", oidp->oid_number);
 	}
 
 	/*
Index: src/sys/sys/sysctl.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/sysctl.h,v
retrieving revision 1.97
diff -u -r1.97 sysctl.h
--- src/sys/sys/sysctl.h	2001/06/22 06:35:19	1.97
+++ src/sys/sys/sysctl.h	2001/07/23 06:26:42
@@ -95,6 +95,12 @@
  */ 
 #define OID_AUTO	(-1)
 
+/*
+ * The starting number for dynamically-assigned entries.  WARNING!
+ * ALL static sysctl entries should have numbers LESS than this!
+ */
+#define CTL_AUTO_START	0x100
+
 #ifdef _KERNEL
 #define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \
 	struct sysctl_req *req

--PEIAKu/WMn1b1Hv9--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010723093041.A1201>