Home | History | Annotate | Line # | Download | only in kern
init_main.c revision 1.201
      1 /*	$NetBSD: init_main.c,v 1.201 2002/06/17 16:22:50 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Christopher G. Demetriou.  All rights reserved.
      5  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  * (c) UNIX System Laboratories, Inc.
      8  * All or some portions of this file are derived from material licensed
      9  * to the University of California by American Telephone and Telegraph
     10  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     11  * the permission of UNIX System Laboratories, Inc.
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  * 3. All advertising materials mentioning features or use of this software
     22  *    must display the following acknowledgement:
     23  *	This product includes software developed by the University of
     24  *	California, Berkeley and its contributors.
     25  * 4. Neither the name of the University nor the names of its contributors
     26  *    may be used to endorse or promote products derived from this software
     27  *    without specific prior written permission.
     28  *
     29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39  * SUCH DAMAGE.
     40  *
     41  *	@(#)init_main.c	8.16 (Berkeley) 5/14/95
     42  */
     43 
     44 #include <sys/cdefs.h>
     45 __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.201 2002/06/17 16:22:50 christos Exp $");
     46 
     47 #include "fs_nfs.h"
     48 #include "opt_nfsserver.h"
     49 #include "opt_sysv.h"
     50 #include "opt_maxuprc.h"
     51 #include "opt_multiprocessor.h"
     52 #include "opt_pipe.h"
     53 #include "opt_syscall_debug.h"
     54 #include "opt_systrace.h"
     55 
     56 #include "rnd.h"
     57 
     58 #include <sys/param.h>
     59 #include <sys/acct.h>
     60 #include <sys/filedesc.h>
     61 #include <sys/file.h>
     62 #include <sys/errno.h>
     63 #include <sys/callout.h>
     64 #include <sys/kernel.h>
     65 #include <sys/mount.h>
     66 #include <sys/map.h>
     67 #include <sys/proc.h>
     68 #include <sys/kthread.h>
     69 #include <sys/resourcevar.h>
     70 #include <sys/signalvar.h>
     71 #include <sys/systm.h>
     72 #include <sys/vnode.h>
     73 #include <sys/tty.h>
     74 #include <sys/conf.h>
     75 #include <sys/disklabel.h>
     76 #include <sys/buf.h>
     77 #include <sys/device.h>
     78 #include <sys/disk.h>
     79 #include <sys/exec.h>
     80 #include <sys/socketvar.h>
     81 #include <sys/protosw.h>
     82 #include <sys/reboot.h>
     83 #include <sys/user.h>
     84 #include <sys/sysctl.h>
     85 #ifdef SYSVSHM
     86 #include <sys/shm.h>
     87 #endif
     88 #ifdef SYSVSEM
     89 #include <sys/sem.h>
     90 #endif
     91 #ifdef SYSVMSG
     92 #include <sys/msg.h>
     93 #endif
     94 #ifdef SYSTRACE
     95 #include <sys/systrace.h>
     96 #endif
     97 #include <sys/domain.h>
     98 #include <sys/mbuf.h>
     99 #include <sys/namei.h>
    100 #if NRND > 0
    101 #include <sys/rnd.h>
    102 #endif
    103 #ifndef PIPE_SOCKETPAIR
    104 #include <sys/pipe.h>
    105 #endif
    106 
    107 #include <sys/syscall.h>
    108 #include <sys/syscallargs.h>
    109 
    110 #include <ufs/ufs/quota.h>
    111 
    112 #include <miscfs/genfs/genfs.h>
    113 #include <miscfs/syncfs/syncfs.h>
    114 
    115 #include <machine/cpu.h>
    116 
    117 #include <uvm/uvm.h>
    118 
    119 #include <net/if.h>
    120 #include <net/raw_cb.h>
    121 
    122 const char copyright[] =
    123 "Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002\n"
    124 "    The NetBSD Foundation, Inc.  All rights reserved.\n"
    125 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
    126 "    The Regents of the University of California.  All rights reserved.\n"
    127 "\n";
    128 
    129 /* Components of the first process -- never freed. */
    130 struct	session session0;
    131 struct	pgrp pgrp0;
    132 struct	proc proc0;
    133 struct	pcred cred0;
    134 struct	filedesc0 filedesc0;
    135 struct	cwdinfo cwdi0;
    136 struct	plimit limit0;
    137 struct	vmspace vmspace0;
    138 struct	sigacts sigacts0;
    139 #ifndef curproc
    140 struct	proc *curproc = &proc0;
    141 #endif
    142 struct	proc *initproc;
    143 
    144 int	cmask = CMASK;
    145 extern	struct user *proc0paddr;
    146 
    147 struct	vnode *rootvp, *swapdev_vp;
    148 int	boothowto;
    149 int	cold = 1;			/* still working on startup */
    150 struct	timeval boottime;
    151 
    152 __volatile int start_init_exec;		/* semaphore for start_init() */
    153 
    154 static void check_console(struct proc *p);
    155 static void start_init(void *);
    156 void main(void);
    157 
    158 extern const struct emul emul_netbsd;	/* defined in kern_exec.c */
    159 
    160 /*
    161  * System startup; initialize the world, create process 0, mount root
    162  * filesystem, and fork to create init and pagedaemon.  Most of the
    163  * hard work is done in the lower-level initialization routines including
    164  * startup(), which does memory initialization and autoconfiguration.
    165  */
    166 void
    167 main(void)
    168 {
    169 	struct proc *p;
    170 	struct pdevinit *pdev;
    171 	int i, s, error;
    172 	rlim_t lim;
    173 	extern struct pdevinit pdevinit[];
    174 	extern void schedcpu(void *);
    175 #if defined(NFSSERVER) || defined(NFS)
    176 	extern void nfs_init(void);
    177 #endif
    178 #ifdef NVNODE_IMPLICIT
    179 	int usevnodes;
    180 #endif
    181 
    182 	/*
    183 	 * Initialize the current process pointer (curproc) before
    184 	 * any possible traps/probes to simplify trap processing.
    185 	 */
    186 	p = &proc0;
    187 	curproc = p;
    188 	p->p_cpu = curcpu();
    189 	/*
    190 	 * Attempt to find console and initialize
    191 	 * in case of early panic or other messages.
    192 	 */
    193 	consinit();
    194 	printf("%s", copyright);
    195 
    196 	KERNEL_LOCK_INIT();
    197 
    198 	uvm_init();
    199 
    200 	/* Do machine-dependent initialization. */
    201 	cpu_startup();
    202 
    203 	/* Initialize callouts. */
    204 	callout_startup();
    205 
    206 	/*
    207 	 * Initialize mbuf's.  Do this now because we might attempt to
    208 	 * allocate mbufs or mbuf clusters during autoconfiguration.
    209 	 */
    210 	mbinit();
    211 
    212 	/* Initialize sockets. */
    213 	soinit();
    214 
    215 	/*
    216 	 * The following 3 things must be done before autoconfiguration.
    217 	 */
    218 	disk_init();		/* initialize disk list */
    219 	tty_init();		/* initialize tty list */
    220 #if NRND > 0
    221 	rnd_init();		/* initialize RNG */
    222 #endif
    223 
    224 	/* Initialize the sysctl subsystem. */
    225 	sysctl_init();
    226 
    227 	/*
    228 	 * Initialize process and pgrp structures.
    229 	 */
    230 	procinit();
    231 
    232 	/*
    233 	 * Create process 0 (the swapper).
    234 	 */
    235 	s = proclist_lock_write();
    236 	LIST_INSERT_HEAD(&allproc, p, p_list);
    237 	LIST_INSERT_HEAD(PIDHASH(p->p_pid), p, p_hash);
    238 	proclist_unlock_write(s);
    239 
    240 	p->p_pgrp = &pgrp0;
    241 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
    242 	LIST_INIT(&pgrp0.pg_members);
    243 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
    244 
    245 	pgrp0.pg_session = &session0;
    246 	session0.s_count = 1;
    247 	session0.s_sid = p->p_pid;
    248 	session0.s_leader = p;
    249 
    250 	/*
    251 	 * Set P_NOCLDWAIT so that kernel threads are reparented to
    252 	 * init(8) when they exit.  init(8) can easily wait them out
    253 	 * for us.
    254 	 */
    255 	p->p_flag = P_INMEM | P_SYSTEM | P_NOCLDWAIT;
    256 	p->p_stat = SONPROC;
    257 	p->p_nice = NZERO;
    258 	p->p_emul = &emul_netbsd;
    259 #ifdef __HAVE_SYSCALL_INTERN
    260 	(*p->p_emul->e_syscall_intern)(p);
    261 #endif
    262 	strncpy(p->p_comm, "swapper", MAXCOMLEN);
    263 
    264 	callout_init(&p->p_realit_ch);
    265 	callout_init(&p->p_tsleep_ch);
    266 
    267 	/* Create credentials. */
    268 	cred0.p_refcnt = 1;
    269 	p->p_cred = &cred0;
    270 	p->p_ucred = crget();
    271 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
    272 
    273 	/* Create the file descriptor table. */
    274 	finit();
    275 	p->p_fd = &filedesc0.fd_fd;
    276 	fdinit1(&filedesc0);
    277 
    278 	/* Create the CWD info. */
    279 	p->p_cwdi = &cwdi0;
    280 	cwdi0.cwdi_cmask = cmask;
    281 	cwdi0.cwdi_refcnt = 1;
    282 
    283 	/* Create the limits structures. */
    284 	p->p_limit = &limit0;
    285 	for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
    286 		limit0.pl_rlimit[i].rlim_cur =
    287 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
    288 
    289 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
    290 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
    291 	    maxfiles < NOFILE ? maxfiles : NOFILE;
    292 
    293 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
    294 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
    295 	    maxproc < MAXUPRC ? maxproc : MAXUPRC;
    296 
    297 	lim = ptoa(uvmexp.free);
    298 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
    299 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
    300 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
    301 	limit0.pl_corename = defcorename;
    302 	limit0.p_refcnt = 1;
    303 
    304 	/*
    305 	 * Initialize proc0's vmspace, which uses the kernel pmap.
    306 	 * All kernel processes (which never have user space mappings)
    307 	 * share proc0's vmspace, and thus, the kernel pmap.
    308 	 */
    309 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
    310 	    trunc_page(VM_MAX_ADDRESS));
    311 	p->p_vmspace = &vmspace0;
    312 
    313 	p->p_addr = proc0paddr;				/* XXX */
    314 
    315 	/*
    316 	 * We continue to place resource usage info in the
    317 	 * user struct so they're pageable.
    318 	 */
    319 	p->p_stats = &p->p_addr->u_stats;
    320 
    321 	/*
    322 	 * Charge root for one process.
    323 	 */
    324 	(void)chgproccnt(0, 1);
    325 
    326 	rqinit();
    327 
    328 	/* Configure virtual memory system, set vm rlimits. */
    329 	uvm_init_limits(p);
    330 
    331 	/* Initialize the file systems. */
    332 #if defined(NFSSERVER) || defined(NFS)
    333 	nfs_init();			/* initialize server/shared data */
    334 #endif
    335 #ifdef NVNODE_IMPLICIT
    336 	/*
    337 	 * If maximum number of vnodes in namei vnode cache is not explicitly
    338 	 * defined in kernel config, adjust the number such as we use roughly
    339 	 * 0.5% of memory for vnode cache (but not less than NVNODE vnodes).
    340 	 */
    341 	usevnodes = (ptoa((unsigned)physmem) / 200) / sizeof(struct vnode);
    342 	if (usevnodes > desiredvnodes)
    343 		desiredvnodes = usevnodes;
    344 #endif
    345 	vfsinit();
    346 
    347 	/* Configure the system hardware.  This will enable interrupts. */
    348 	configure();
    349 
    350 	ubc_init();		/* must be after autoconfig */
    351 
    352 	/* Lock the kernel on behalf of proc0. */
    353 	KERNEL_PROC_LOCK(p);
    354 
    355 #ifdef SYSVSHM
    356 	/* Initialize System V style shared memory. */
    357 	shminit();
    358 #endif
    359 
    360 #ifdef SYSVSEM
    361 	/* Initialize System V style semaphores. */
    362 	seminit();
    363 #endif
    364 
    365 #ifdef SYSVMSG
    366 	/* Initialize System V style message queues. */
    367 	msginit();
    368 #endif
    369 
    370 	/* Attach pseudo-devices. */
    371 	for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
    372 		(*pdev->pdev_attach)(pdev->pdev_count);
    373 
    374 	/*
    375 	 * Initialize protocols.  Block reception of incoming packets
    376 	 * until everything is ready.
    377 	 */
    378 	s = splnet();
    379 	ifinit();
    380 	domaininit();
    381 	if_attachdomain();
    382 	splx(s);
    383 
    384 #ifdef GPROF
    385 	/* Initialize kernel profiling. */
    386 	kmstartup();
    387 #endif
    388 
    389 	/* Initialize system accouting. */
    390 	acct_init();
    391 
    392 #ifdef SYSTRACE
    393 	systrace_init();
    394 #endif
    395 	/*
    396 	 * Initialize signal-related data structures, and signal state
    397 	 * for proc0.
    398 	 */
    399 	signal_init();
    400 	p->p_sigacts = &sigacts0;
    401 	siginit(p);
    402 
    403 	/* Kick off timeout driven events by calling first time. */
    404 	schedcpu(NULL);
    405 
    406 	/*
    407 	 * Create process 1 (init(8)).  We do this now, as Unix has
    408 	 * historically had init be process 1, and changing this would
    409 	 * probably upset a lot of people.
    410 	 *
    411 	 * Note that process 1 won't immediately exec init(8), but will
    412 	 * wait for us to inform it that the root file system has been
    413 	 * mounted.
    414 	 */
    415 	if (fork1(p, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL, &initproc))
    416 		panic("fork init");
    417 
    418 	/*
    419 	 * Create any kernel threads who's creation was deferred because
    420 	 * initproc had not yet been created.
    421 	 */
    422 	kthread_run_deferred_queue();
    423 
    424 	/*
    425 	 * Now that device driver threads have been created, wait for
    426 	 * them to finish any deferred autoconfiguration.  Note we don't
    427 	 * need to lock this semaphore, since we haven't booted any
    428 	 * secondary processors, yet.
    429 	 */
    430 	while (config_pending)
    431 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
    432 
    433 	/*
    434 	 * Now that autoconfiguration has completed, we can determine
    435 	 * the root and dump devices.
    436 	 */
    437 	cpu_rootconf();
    438 	cpu_dumpconf();
    439 
    440 	/* Mount the root file system. */
    441 	do {
    442 		domountroothook();
    443 		if ((error = vfs_mountroot())) {
    444 			printf("cannot mount root, error = %d\n", error);
    445 			boothowto |= RB_ASKNAME;
    446 			setroot(root_device,
    447 			    (rootdev != NODEV) ? DISKPART(rootdev) : 0);
    448 		}
    449 	} while (error != 0);
    450 	mountroothook_destroy();
    451 
    452 	mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
    453 	mountlist.cqh_first->mnt_op->vfs_refcount++;
    454 
    455 	/*
    456 	 * Get the vnode for '/'.  Set filedesc0.fd_fd.fd_cdir to
    457 	 * reference it.
    458 	 */
    459 	if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
    460 		panic("cannot find root vnode");
    461 	cwdi0.cwdi_cdir = rootvnode;
    462 	VREF(cwdi0.cwdi_cdir);
    463 	VOP_UNLOCK(rootvnode, 0);
    464 	cwdi0.cwdi_rdir = NULL;
    465 
    466 	/*
    467 	 * Now that root is mounted, we can fixup initproc's CWD
    468 	 * info.  All other processes are kthreads, which merely
    469 	 * share proc0's CWD info.
    470 	 */
    471 	initproc->p_cwdi->cwdi_cdir = rootvnode;
    472 	VREF(initproc->p_cwdi->cwdi_cdir);
    473 	initproc->p_cwdi->cwdi_rdir = NULL;
    474 
    475 	/*
    476 	 * Now can look at time, having had a chance to verify the time
    477 	 * from the file system.  Reset p->p_rtime as it may have been
    478 	 * munched in mi_switch() after the time got set.
    479 	 */
    480 	proclist_lock_read();
    481 	s = splsched();
    482 	for (p = LIST_FIRST(&allproc); p != NULL;
    483 	     p = LIST_NEXT(p, p_list)) {
    484 		p->p_stats->p_start = mono_time = boottime = time;
    485 		if (p->p_cpu != NULL)
    486 			p->p_cpu->ci_schedstate.spc_runtime = time;
    487 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
    488 	}
    489 	splx(s);
    490 	proclist_unlock_read();
    491 
    492 	/* Create the pageout daemon kernel thread. */
    493 	uvm_swap_init();
    494 	if (kthread_create1(uvm_pageout, NULL, NULL, "pagedaemon"))
    495 		panic("fork pagedaemon");
    496 
    497 	/* Create the process reaper kernel thread. */
    498 	if (kthread_create1(reaper, NULL, NULL, "reaper"))
    499 		panic("fork reaper");
    500 
    501 	/* Create the filesystem syncer kernel thread. */
    502 	if (kthread_create1(sched_sync, NULL, NULL, "ioflush"))
    503 		panic("fork syncer");
    504 
    505 	/* Create the aiodone daemon kernel thread. */
    506 	if (kthread_create1(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
    507 		panic("fork aiodoned");
    508 
    509 #if defined(MULTIPROCESSOR)
    510 	/* Boot the secondary processors. */
    511 	cpu_boot_secondary_processors();
    512 #endif
    513 
    514 	/* Initialize exec structures */
    515 	exec_init(1);
    516 
    517 #ifndef PIPE_SOCKETPAIR
    518 	/* Initialize pipe structures */
    519 	pipe_init();
    520 #endif
    521 
    522 	/*
    523 	 * Okay, now we can let init(8) exec!  It's off to userland!
    524 	 */
    525 	start_init_exec = 1;
    526 	wakeup((void *)&start_init_exec);
    527 
    528 	/* The scheduler is an infinite loop. */
    529 	uvm_scheduler();
    530 	/* NOTREACHED */
    531 }
    532 
    533 static void
    534 check_console(struct proc *p)
    535 {
    536 	struct nameidata nd;
    537 	int error;
    538 
    539 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
    540 	error = namei(&nd);
    541 	if (error == 0)
    542 		vrele(nd.ni_vp);
    543 	else if (error == ENOENT)
    544 		printf("warning: no /dev/console\n");
    545 	else
    546 		printf("warning: lookup /dev/console: error %d\n", error);
    547 }
    548 
    549 /*
    550  * List of paths to try when searching for "init".
    551  */
    552 static const char *initpaths[] = {
    553 	"/sbin/init",
    554 	"/sbin/oinit",
    555 	"/sbin/init.bak",
    556 	NULL,
    557 };
    558 
    559 /*
    560  * Start the initial user process; try exec'ing each pathname in "initpaths".
    561  * The program is invoked with one argument containing the boot flags.
    562  */
    563 static void
    564 start_init(void *arg)
    565 {
    566 	struct proc *p = arg;
    567 	vaddr_t addr;
    568 	struct sys_execve_args /* {
    569 		syscallarg(const char *) path;
    570 		syscallarg(char * const *) argp;
    571 		syscallarg(char * const *) envp;
    572 	} */ args;
    573 	int options, i, error;
    574 	register_t retval[2];
    575 	char flags[4], *flagsp;
    576 	const char **pathp, *path, *slash;
    577 	char *ucp, **uap, *arg0, *arg1 = NULL;
    578 
    579 	/*
    580 	 * Now in process 1.
    581 	 */
    582 	strncpy(p->p_comm, "init", MAXCOMLEN);
    583 
    584 	/*
    585 	 * Wait for main() to tell us that it's safe to exec.
    586 	 */
    587 	while (start_init_exec == 0)
    588 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
    589 
    590 	/*
    591 	 * This is not the right way to do this.  We really should
    592 	 * hand-craft a descriptor onto /dev/console to hand to init,
    593 	 * but that's a _lot_ more work, and the benefit from this easy
    594 	 * hack makes up for the "good is the enemy of the best" effect.
    595 	 */
    596 	check_console(p);
    597 
    598 	/*
    599 	 * Need just enough stack to hold the faked-up "execve()" arguments.
    600 	 */
    601 	addr = USRSTACK - PAGE_SIZE;
    602 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
    603                     NULL, UVM_UNKNOWN_OFFSET, 0,
    604                     UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
    605 		    UVM_ADV_NORMAL,
    606                     UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0)
    607 		panic("init: couldn't allocate argument space");
    608 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
    609 
    610 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
    611 		ucp = (char *)(addr + PAGE_SIZE);
    612 
    613 		/*
    614 		 * Construct the boot flag argument.
    615 		 */
    616 		flagsp = flags;
    617 		*flagsp++ = '-';
    618 		options = 0;
    619 
    620 		if (boothowto & RB_SINGLE) {
    621 			*flagsp++ = 's';
    622 			options = 1;
    623 		}
    624 #ifdef notyet
    625 		if (boothowto & RB_FASTBOOT) {
    626 			*flagsp++ = 'f';
    627 			options = 1;
    628 		}
    629 #endif
    630 
    631 		/*
    632 		 * Move out the flags (arg 1), if necessary.
    633 		 */
    634 		if (options != 0) {
    635 			*flagsp++ = '\0';
    636 			i = flagsp - flags;
    637 #ifdef DEBUG
    638 			printf("init: copying out flags `%s' %d\n", flags, i);
    639 #endif
    640 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
    641 			arg1 = ucp;
    642 		}
    643 
    644 		/*
    645 		 * Move out the file name (also arg 0).
    646 		 */
    647 		i = strlen(path) + 1;
    648 #ifdef DEBUG
    649 		printf("init: copying out path `%s' %d\n", path, i);
    650 #endif
    651 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
    652 		arg0 = ucp;
    653 
    654 		/*
    655 		 * Move out the arg pointers.
    656 		 */
    657 		uap = (char **)((long)ucp & ~ALIGNBYTES);
    658 		(void)suword((caddr_t)--uap, 0);	/* terminator */
    659 		if (options != 0)
    660 			(void)suword((caddr_t)--uap, (long)arg1);
    661 		slash = strrchr(path, '/');
    662 		if (slash)
    663 			(void)suword((caddr_t)--uap,
    664 			    (long)arg0 + (slash + 1 - path));
    665 		else
    666 			(void)suword((caddr_t)--uap, (long)arg0);
    667 
    668 		/*
    669 		 * Point at the arguments.
    670 		 */
    671 		SCARG(&args, path) = arg0;
    672 		SCARG(&args, argp) = uap;
    673 		SCARG(&args, envp) = NULL;
    674 
    675 		/*
    676 		 * Now try to exec the program.  If can't for any reason
    677 		 * other than it doesn't exist, complain.
    678 		 */
    679 		error = sys_execve(p, &args, retval);
    680 		if (error == 0 || error == EJUSTRETURN) {
    681 			KERNEL_PROC_UNLOCK(p);
    682 			return;
    683 		}
    684 		if (error != ENOENT)
    685 			printf("exec %s: error %d\n", path, error);
    686 	}
    687 	printf("init: not found\n");
    688 	panic("no init");
    689 }
    690