Module Name:    src
Committed By:   kamil
Date:           Wed Jan 23 13:38:30 UTC 2019

Modified Files:
        src/sys/kern: init_main.c

Log Message:
Change the place of initproc initialization

The initproc variable cannot be initialized in start_init as there
is a race between vfs_mountroot and start_init.

PR kern/53817 by Andreas Gustafsson


To generate a diff of this commit:
cvs rdiff -u -r1.501 -r1.502 src/sys/kern/init_main.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.501 src/sys/kern/init_main.c:1.502
--- src/sys/kern/init_main.c:1.501	Wed Dec 26 22:16:26 2018
+++ src/sys/kern/init_main.c	Wed Jan 23 13:38:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.501 2018/12/26 22:16:26 thorpej Exp $	*/
+/*	$NetBSD: init_main.c,v 1.502 2019/01/23 13:38:30 kamil Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.501 2018/12/26 22:16:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.502 2019/01/23 13:38:30 kamil Exp $");
 
 #include "opt_ddb.h"
 #include "opt_inet.h"
@@ -617,6 +617,14 @@ main(void)
 		panic("fork init");
 
 	/*
+	 * The initproc variable cannot be initialized in start_init as there
+	 * is a race between vfs_mountroot and start_init.
+	 */
+	mutex_enter(proc_lock);
+	initproc = proc_find_raw(1);
+	mutex_exit(proc_lock);
+
+	/*
 	 * Load any remaining builtin modules, and hand back temporary
 	 * storage to the VM system.  Then require force when loading any
 	 * remaining un-init'ed built-in modules to avoid later surprises.
@@ -946,8 +954,6 @@ start_init(void *arg)
 	char ipath[129];
 	int ipx, len;
 
-	initproc = p;
-
 	/*
 	 * Now in process 1.
 	 */

Reply via email to