Mon May 4 14:52:33 2009 UTC ()
sysctl_doeproc: fix a bug in rev.1.135.
don't forget to mark our marker process PK_MARKER.
this fixes crashes in sched_pstats, etc.


(yamt)
diff -r1.160 -r1.161 src/sys/kern/init_sysctl.c

cvs diff -r1.160 -r1.161 src/sys/kern/init_sysctl.c (expand / switch to unified diff)

--- src/sys/kern/init_sysctl.c 2009/03/29 01:02:50 1.160
+++ src/sys/kern/init_sysctl.c 2009/05/04 14:52:33 1.161
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init_sysctl.c,v 1.160 2009/03/29 01:02:50 mrg Exp $ */ 1/* $NetBSD: init_sysctl.c,v 1.161 2009/05/04 14:52:33 yamt Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Brown, and by Andrew Doran. 8 * by Andrew Brown, and by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.160 2009/03/29 01:02:50 mrg Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.161 2009/05/04 14:52:33 yamt Exp $");
34 34
35#include "opt_sysv.h" 35#include "opt_sysv.h"
36#include "opt_compat_netbsd32.h" 36#include "opt_compat_netbsd32.h"
37#include "opt_compat_netbsd.h" 37#include "opt_compat_netbsd.h"
38#include "opt_modular.h" 38#include "opt_modular.h"
39#include "opt_sa.h" 39#include "opt_sa.h"
40#include "opt_posix.h" 40#include "opt_posix.h"
41#include "pty.h" 41#include "pty.h"
42#include "rnd.h" 42#include "rnd.h"
43 43
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/sysctl.h> 46#include <sys/sysctl.h>
@@ -2220,26 +2220,27 @@ sysctl_doeproc(SYSCTLFN_ARGS) @@ -2220,26 +2220,27 @@ sysctl_doeproc(SYSCTLFN_ARGS)
2220 elem_count = name[3]; 2220 elem_count = name[3];
2221 } 2221 }
2222 2222
2223 sysctl_unlock(); 2223 sysctl_unlock();
2224 2224
2225 if (type == KERN_PROC) { 2225 if (type == KERN_PROC) {
2226 eproc = kmem_alloc(sizeof(*eproc), KM_SLEEP); 2226 eproc = kmem_alloc(sizeof(*eproc), KM_SLEEP);
2227 kproc2 = NULL; 2227 kproc2 = NULL;
2228 } else { 2228 } else {
2229 eproc = NULL; 2229 eproc = NULL;
2230 kproc2 = kmem_alloc(sizeof(*kproc2), KM_SLEEP); 2230 kproc2 = kmem_alloc(sizeof(*kproc2), KM_SLEEP);
2231 } 2231 }
2232 marker = kmem_alloc(sizeof(*marker), KM_SLEEP); 2232 marker = kmem_alloc(sizeof(*marker), KM_SLEEP);
 2233 marker->p_flag = PK_MARKER;
2233 2234
2234 mutex_enter(proc_lock); 2235 mutex_enter(proc_lock);
2235 mmmbrains = false; 2236 mmmbrains = false;
2236 for (p = LIST_FIRST(&allproc);; p = next) { 2237 for (p = LIST_FIRST(&allproc);; p = next) {
2237 if (p == NULL) { 2238 if (p == NULL) {
2238 if (!mmmbrains) { 2239 if (!mmmbrains) {
2239 p = LIST_FIRST(&zombproc); 2240 p = LIST_FIRST(&zombproc);
2240 mmmbrains = true; 2241 mmmbrains = true;
2241 } 2242 }
2242 if (p == NULL) 2243 if (p == NULL)
2243 break; 2244 break;
2244 } 2245 }
2245 next = LIST_NEXT(p, p_list); 2246 next = LIST_NEXT(p, p_list);