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