summaryrefslogtreecommitdiffstats
path: root/sys/kern/init_main.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1999-07-01 13:21:46 +0000
committerpeter <peter@FreeBSD.org>1999-07-01 13:21:46 +0000
commit6cb5fe6c6bfe3fbe7878f6c055e0deb2ad86d77c (patch)
tree3d833b579e08cb5e2dc4561ebb531129df5f2eb3 /sys/kern/init_main.c
parente671ad02ffd3e5dedda4576976c1952f1f8d8fe3 (diff)
downloadFreeBSD-src-6cb5fe6c6bfe3fbe7878f6c055e0deb2ad86d77c.zip
FreeBSD-src-6cb5fe6c6bfe3fbe7878f6c055e0deb2ad86d77c.tar.gz
Slight reorganization of kernel thread/process creation. Instead of using
SYSINIT_KT() etc (which is a static, compile-time procedure), use a NetBSD-style kthread_create() interface. kproc_start is still available as a SYSINIT() hook. This allowed simplification of chunks of the sysinit code in the process. This kthread_create() is our old kproc_start internals, with the SYSINIT_KT fork hooks grafted in and tweaked to work the same as the NetBSD one. One thing I'd like to do shortly is get rid of nfsiod as a user initiated process. It makes sense for the nfs client code to create them on the fly as needed up to a user settable limit. This means that nfsiod doesn't need to be in /sbin and is always "available". This is a fair bit easier to do outside of the SYSINIT_KT() framework.
Diffstat (limited to 'sys/kern/init_main.c')
-rw-r--r--sys/kern/init_main.c110
1 files changed, 27 insertions, 83 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index f988887..bcc7c86 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -39,7 +39,7 @@
* SUCH DAMAGE.
*
* @(#)init_main.c 8.9 (Berkeley) 1/21/94
- * $Id: init_main.c,v 1.122 1999/05/11 10:08:10 jb Exp $
+ * $Id: init_main.c,v 1.123 1999/06/30 15:33:32 peter Exp $
*/
#include "opt_devfs.h"
@@ -52,6 +52,7 @@
#include <sys/mount.h>
#include <sys/sysctl.h>
#include <sys/proc.h>
+#include <sys/kthread.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/systm.h>
@@ -180,7 +181,6 @@ mi_startup(framep)
register struct sysinit **sipp; /* system initialization*/
register struct sysinit **xipp; /* interior loop of sort*/
register struct sysinit *save; /* bubble*/
- struct proc *p2;
/*
* Copy the locore.s frame pointer for proc0, this is forked into
@@ -220,28 +220,8 @@ restart:
if ((*sipp)->subsystem == SI_SUB_DONE)
continue;
- switch( (*sipp)->type) {
- case SI_TYPE_DEFAULT:
- /* no special processing*/
- (*((*sipp)->func))((*sipp)->udata);
- break;
-
- case SI_TYPE_KTHREAD:
- /* kernel thread*/
- if (fork1(&proc0, RFMEM|RFFDG|RFPROC, &p2))
- panic("fork kernel thread");
- cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
- break;
-
- case SI_TYPE_KPROCESS:
- if (fork1(&proc0, RFFDG|RFPROC, &p2))
- panic("fork kernel process");
- cpu_set_fork_handler(p2, (*sipp)->func, (*sipp)->udata);
- break;
-
- default:
- panic("init_main: unrecognized init type");
- }
+ /* Call function */
+ (*((*sipp)->func))((*sipp)->udata);
/* Check off the one we're just done */
(*sipp)->subsystem = SI_SUB_DONE;
@@ -262,42 +242,6 @@ restart:
/*
- * Start a kernel process. This is called after a fork() call in
- * mi_startup() in the file kern/init_main.c.
- *
- * This function is used to start "internal" daemons.
- */
-/* ARGSUSED*/
-void
-kproc_start(udata)
- const void *udata;
-{
- const struct kproc_desc *kp = udata;
- struct proc *p = curproc;
-
-#ifdef DIAGNOSTIC
- printf("Start pid=%d <%s>\n",p->p_pid, kp->arg0);
-#endif
-
- /* save a global descriptor, if desired*/
- if( kp->global_procpp != NULL)
- *kp->global_procpp = p;
-
- /* this is a non-swapped system process*/
- p->p_flag |= P_INMEM | P_SYSTEM;
-
- /* set up arg0 for 'ps', et al*/
- strcpy( p->p_comm, kp->arg0);
-
- /* call the processes' main()...*/
- (*kp->func)();
-
- /* NOTREACHED */
- panic("kproc_start: %s", kp->arg0);
-}
-
-
-/*
***************************************************************************
****
**** The following SYSINIT's belong elsewhere, but have not yet
@@ -551,30 +495,27 @@ SYSINIT(retrofit, SI_SUB_ROOT_FDTAB, SI_ORDER_FIRST, xxx_vfs_root_fdtab, NULL)
***************************************************************************
*/
-static void kthread_init __P((const void *dummy));
-SYSINIT_KP(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kthread_init, NULL)
-
-
extern void prepare_usermode __P((void));
-static void start_init __P((struct proc *p));
+static void create_init __P((const void *dummy));
+static void start_init __P((void *dummy));
+SYSINIT(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, create_init, NULL)
-/* ARGSUSED*/
+/*
+ * Like kthread_create(), but runs in it's own address space.
+ */
static void
-kthread_init(dummy)
- const void *dummy;
+create_init(udata)
+ const void *udata;
{
- /* Create process 1 (init(8)). */
- start_init(curproc);
-
- prepare_usermode();
+ int error;
- /*
- * This returns to the fork trampoline, then to user mode.
- */
- return;
+ error = fork1(&proc0, RFFDG | RFPROC, &initproc);
+ if (error)
+ panic("cannot fork init: %d\n", error);
+ initproc->p_flag |= P_INMEM | P_SYSTEM;
+ cpu_set_fork_handler(initproc, start_init, NULL);
}
-
/*
* List of paths to try when searching for "init".
*/
@@ -591,16 +532,17 @@ SYSCTL_STRING(_kern, OID_AUTO, init_path, CTLFLAG_RD, init_path, 0, "");
* The program is invoked with one argument containing the boot flags.
*/
static void
-start_init(p)
- struct proc *p;
+start_init(dummy)
+ void *dummy;
{
vm_offset_t addr;
struct execve_args args;
int options, error;
char *var, *path, *next, *s;
char *ucp, **uap, *arg0, *arg1;
+ struct proc *p;
- initproc = p;
+ p = curproc;
/*
* Need just enough stack to hold the faked-up "execve()" arguments.
@@ -681,11 +623,13 @@ start_init(p)
* Now try to exec the program. If can't for any reason
* other than it doesn't exist, complain.
*
- * Otherwise return to mi_startup() which returns to btext
- * which completes the system startup.
+ * Otherwise, return via the fork trampoline all the way
+ * to user mode as init!
*/
- if ((error = execve(p, &args)) == 0)
+ if ((error = execve(p, &args)) == 0) {
+ prepare_usermode();
return;
+ }
if (error != ENOENT)
printf("exec %.*s: error %d\n", (int)(next - path),
path, error);
OpenPOWER on IntegriCloud