diff options
-rw-r--r-- | sys/kern/init_main.c | 5 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 31 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 5 |
3 files changed, 21 insertions, 20 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 919bcf2be12..b309b6f8d8a 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.58 2001/02/05 21:28:06 mickey Exp $ */ +/* $OpenBSD: init_main.c,v 1.59 2001/03/16 08:49:09 art Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -222,6 +222,9 @@ main(framep) tty_init(); /* initialise tty's */ cpu_startup(); + /* Initialize sysctls (must be done before any processes run) */ + sysctl_init(); + /* * Initialize process and pgrp structures. */ diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 1a049ad54d0..1af6d28fd50 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.38 2001/01/31 09:59:51 deraadt Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.39 2001/03/16 08:49:09 art Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -74,13 +74,16 @@ #endif /* - * Locking and stats + * Lock to avoid too many processes vslocking a large amount of memory + * at the same time. */ -static struct sysctl_lock { - int sl_lock; - int sl_want; - int sl_locked; -} memlock; +struct lock sysctl_lock; + +void +sysctl_init() +{ + lockinit(&sysctl_lock, PLOCK|PCATCH, "sysctl", 0, 0); +} int sys___sysctl(p, v, retval) @@ -166,12 +169,8 @@ sys___sysctl(p, v, retval) if (!useracc(SCARG(uap, old), oldlen, B_WRITE)) #endif return (EFAULT); - while (memlock.sl_lock) { - memlock.sl_want = 1; - sleep((caddr_t)&memlock, PRIBIO+1); - memlock.sl_locked++; - } - memlock.sl_lock = 1; + if ((error = lockmgr(&sysctl_lock, LK_EXCLUSIVE, NULL, p)) != 0) + return (error); if (dolock) #if defined(UVM) uvm_vslock(p, SCARG(uap, old), oldlen, VM_PROT_NONE); @@ -189,11 +188,7 @@ sys___sysctl(p, v, retval) #else vsunlock(SCARG(uap, old), savelen); #endif - memlock.sl_lock = 0; - if (memlock.sl_want) { - memlock.sl_want = 0; - wakeup((caddr_t)&memlock); - } + lockmgr(&sysctl_lock, LK_RELEASE, NULL, p); } if (error) return (error); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index a842f83af6c..f68d920ca51 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.34 2001/01/31 09:59:50 deraadt Exp $ */ +/* $OpenBSD: sysctl.h,v 1.35 2001/03/16 08:49:08 art Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -437,6 +437,9 @@ int cpu_sysctl __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *)); int vfs_sysctl __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *)); + +void sysctl_init __P((void)); + #else /* !_KERNEL */ #include <sys/cdefs.h> |