xref: /openbsd-src/sys/kern/init_main.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: init_main.c,v 1.159 2009/04/19 17:53:38 deraadt Exp $	*/
2 /*	$NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $	*/
3 
4 /*
5  * Copyright (c) 1995 Christopher G. Demetriou.  All rights reserved.
6  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  * (c) UNIX System Laboratories, Inc.
9  * All or some portions of this file are derived from material licensed
10  * to the University of California by American Telephone and Telegraph
11  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
12  * the permission of UNIX System Laboratories, Inc.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)init_main.c	8.9 (Berkeley) 1/21/94
39  */
40 
41 #include <sys/param.h>
42 #include <sys/core.h>
43 #include <sys/filedesc.h>
44 #include <sys/file.h>
45 #include <sys/errno.h>
46 #include <sys/exec.h>
47 #include <sys/kernel.h>
48 #include <sys/kthread.h>
49 #include <sys/mount.h>
50 #include <sys/proc.h>
51 #include <sys/resourcevar.h>
52 #include <sys/signalvar.h>
53 #include <sys/systm.h>
54 #include <sys/namei.h>
55 #include <sys/vnode.h>
56 #include <sys/tty.h>
57 #include <sys/conf.h>
58 #include <sys/buf.h>
59 #include <sys/device.h>
60 #include <sys/socketvar.h>
61 #include <sys/lockf.h>
62 #include <sys/protosw.h>
63 #include <sys/reboot.h>
64 #include <sys/user.h>
65 #ifdef SYSVSHM
66 #include <sys/shm.h>
67 #endif
68 #ifdef SYSVSEM
69 #include <sys/sem.h>
70 #endif
71 #ifdef SYSVMSG
72 #include <sys/msg.h>
73 #endif
74 #include <sys/domain.h>
75 #include <sys/mbuf.h>
76 #include <sys/pipe.h>
77 #include <sys/workq.h>
78 
79 #include <sys/syscall.h>
80 #include <sys/syscallargs.h>
81 
82 #include <dev/rndvar.h>
83 
84 #include <ufs/ufs/quota.h>
85 
86 #include <machine/cpu.h>
87 
88 #include <uvm/uvm.h>
89 
90 #include <net/if.h>
91 #include <net/raw_cb.h>
92 
93 #if defined(CRYPTO)
94 #include <crypto/cryptodev.h>
95 #include <crypto/cryptosoft.h>
96 #endif
97 
98 #if defined(NFSSERVER) || defined(NFSCLIENT)
99 extern void nfs_init(void);
100 #endif
101 
102 #include "vscsi.h"
103 #include "softraid.h"
104 
105 const char	copyright[] =
106 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
107 "\tThe Regents of the University of California.  All rights reserved.\n"
108 "Copyright (c) 1995-2009 OpenBSD. All rights reserved.  http://www.OpenBSD.org\n";
109 
110 /* Components of the first process -- never freed. */
111 struct	session session0;
112 struct	pgrp pgrp0;
113 struct	proc proc0;
114 struct	process process0;
115 struct	pcred cred0;
116 struct	plimit limit0;
117 struct	vmspace vmspace0;
118 struct	sigacts sigacts0;
119 struct	proc *initproc;
120 
121 int	cmask = CMASK;
122 extern	struct user *proc0paddr;
123 
124 struct	vnode *rootvp, *swapdev_vp;
125 int	boothowto;
126 struct	timeval boottime;
127 int	ncpus =  1;
128 int	ncpusfound = 1;			/* number of cpus we find */
129 __volatile int start_init_exec;		/* semaphore for start_init() */
130 
131 #if !defined(NO_PROPOLICE)
132 long	__guard[8];
133 #endif
134 
135 /* XXX return int so gcc -Werror won't complain */
136 int	main(void *);
137 void	check_console(struct proc *);
138 void	start_init(void *);
139 void	start_cleaner(void *);
140 void	start_update(void *);
141 void	start_reaper(void *);
142 void	init_crypto(void);
143 void	init_exec(void);
144 void	kqueue_init(void);
145 void	workq_init(void);
146 
147 extern char sigcode[], esigcode[];
148 #ifdef SYSCALL_DEBUG
149 extern char *syscallnames[];
150 #endif
151 
152 struct emul emul_native = {
153 	"native",
154 	NULL,
155 	sendsig,
156 	SYS_syscall,
157 	SYS_MAXSYSCALL,
158 	sysent,
159 #ifdef SYSCALL_DEBUG
160 	syscallnames,
161 #else
162 	NULL,
163 #endif
164 	0,
165 	copyargs,
166 	setregs,
167 	NULL,
168 	coredump_trad,
169 	sigcode,
170 	esigcode,
171 	EMUL_ENABLED | EMUL_NATIVE,
172 };
173 
174 
175 /*
176  * System startup; initialize the world, create process 0, mount root
177  * filesystem, and fork to create init and pagedaemon.  Most of the
178  * hard work is done in the lower-level initialization routines including
179  * startup(), which does memory initialization and autoconfiguration.
180  */
181 /* XXX return int, so gcc -Werror won't complain */
182 int
183 main(void *framep)
184 {
185 	struct proc *p;
186 	struct pdevinit *pdev;
187 	struct timeval rtv;
188 	quad_t lim;
189 	int s, i;
190 	extern struct pdevinit pdevinit[];
191 	extern void scheduler_start(void);
192 	extern void disk_init(void);
193 	extern void endtsleep(void *);
194 	extern void realitexpire(void *);
195 
196 	/*
197 	 * Initialize the current process pointer (curproc) before
198 	 * any possible traps/probes to simplify trap processing.
199 	 */
200 	curproc = p = &proc0;
201 	p->p_cpu = curcpu();
202 
203 	/*
204 	 * Initialize timeouts.
205 	 */
206 	timeout_startup();
207 
208 	/*
209 	 * Attempt to find console and initialize
210 	 * in case of early panic or other messages.
211 	 */
212 	config_init();		/* init autoconfiguration data structures */
213 	consinit();
214 
215 	printf("%s\n", copyright);
216 
217 	KERNEL_LOCK_INIT();
218 
219 	uvm_init();
220 	disk_init();		/* must come before autoconfiguration */
221 	tty_init();		/* initialise tty's */
222 	cpu_startup();
223 
224 	/*
225 	 * Initialize mbuf's.  Do this now because we might attempt to
226 	 * allocate mbufs or mbuf clusters during autoconfiguration.
227 	 */
228 	mbinit();
229 
230 	/* Initialize sockets. */
231 	soinit();
232 
233 	/*
234 	 * Initialize process and pgrp structures.
235 	 */
236 	procinit();
237 
238 	/* Initialize file locking. */
239 	lf_init();
240 
241 	/*
242 	 * Initialize filedescriptors.
243 	 */
244 	filedesc_init();
245 
246 	/*
247 	 * Initialize pipes.
248 	 */
249 	pipe_init();
250 
251 	/*
252 	 * Initialize kqueues.
253 	 */
254 	kqueue_init();
255 
256 	/*
257 	 * Create process 0 (the swapper).
258 	 */
259 
260 	process0.ps_mainproc = p;
261 	TAILQ_INIT(&process0.ps_threads);
262 	TAILQ_INSERT_TAIL(&process0.ps_threads, p, p_thr_link);
263 	process0.ps_refcnt = 1;
264 	p->p_p = &process0;
265 
266 	LIST_INSERT_HEAD(&allproc, p, p_list);
267 	p->p_pgrp = &pgrp0;
268 	LIST_INSERT_HEAD(PIDHASH(0), p, p_hash);
269 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
270 	LIST_INIT(&pgrp0.pg_members);
271 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
272 
273 	pgrp0.pg_session = &session0;
274 	session0.s_count = 1;
275 	session0.s_leader = p;
276 
277 	atomic_setbits_int(&p->p_flag, P_SYSTEM | P_NOCLDWAIT);
278 	p->p_stat = SONPROC;
279 	p->p_nice = NZERO;
280 	p->p_emul = &emul_native;
281 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
282 
283 	/* Init timeouts. */
284 	timeout_set(&p->p_sleep_to, endtsleep, p);
285 	timeout_set(&p->p_realit_to, realitexpire, p);
286 
287 	/* Create credentials. */
288 	cred0.p_refcnt = 1;
289 	p->p_cred = &cred0;
290 	p->p_ucred = crget();
291 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
292 
293 	/* Initialize signal state for process 0. */
294 	signal_init();
295 	p->p_sigacts = &sigacts0;
296 	siginit(p);
297 
298 	/* Create the file descriptor table. */
299 	p->p_fd = fdinit(NULL);
300 
301 	/* Create the limits structures. */
302 	p->p_p->ps_limit = &limit0;
303 	for (i = 0; i < nitems(p->p_rlimit); i++)
304 		limit0.pl_rlimit[i].rlim_cur =
305 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
306 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur = NOFILE;
307 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = MIN(NOFILE_MAX,
308 	    (maxfiles - NOFILE > NOFILE) ?  maxfiles - NOFILE : NOFILE);
309 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur = MAXUPRC;
310 	lim = ptoa(uvmexp.free);
311 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
312 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
313 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
314 	limit0.p_refcnt = 1;
315 
316 	/* Allocate a prototype map so we have something to fork. */
317 	uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
318 	    trunc_page(VM_MAX_ADDRESS), TRUE, TRUE);
319 	p->p_vmspace = &vmspace0;
320 
321 	p->p_addr = proc0paddr;				/* XXX */
322 
323 	/*
324 	 * We continue to place resource usage info in the
325 	 * user struct so they're pageable.
326 	 */
327 	p->p_stats = &p->p_addr->u_stats;
328 
329 	/*
330 	 * Charge root for one process.
331 	 */
332 	(void)chgproccnt(0, 1);
333 
334 	/* Initialize run queues */
335 	sched_init_runqueues();
336 	sleep_queue_init();
337 	sched_init_cpu(curcpu());
338 
339 	/* Initialize work queues */
340 	workq_init();
341 
342 	/* Configure the devices */
343 	cpu_configure();
344 
345 	/* Configure virtual memory system, set vm rlimits. */
346 	uvm_init_limits(p);
347 
348 	/* Initialize the file systems. */
349 #if defined(NFSSERVER) || defined(NFSCLIENT)
350 	nfs_init();			/* initialize server/shared data */
351 #endif
352 	vfsinit();
353 
354 	/* Start real time and statistics clocks. */
355 	initclocks();
356 
357 	/* Lock the kernel on behalf of proc0. */
358 	KERNEL_PROC_LOCK(p);
359 
360 #ifdef SYSVSHM
361 	/* Initialize System V style shared memory. */
362 	shminit();
363 #endif
364 
365 #ifdef SYSVSEM
366 	/* Initialize System V style semaphores. */
367 	seminit();
368 #endif
369 
370 #ifdef SYSVMSG
371 	/* Initialize System V style message queues. */
372 	msginit();
373 #endif
374 
375 	/* Attach pseudo-devices. */
376 	randomattach();
377 	for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
378 		if (pdev->pdev_count > 0)
379 			(*pdev->pdev_attach)(pdev->pdev_count);
380 
381 #ifdef CRYPTO
382 	swcr_init();
383 #endif /* CRYPTO */
384 
385 	/*
386 	 * Initialize protocols.  Block reception of incoming packets
387 	 * until everything is ready.
388 	 */
389 	s = splnet();
390 	ifinit();
391 	domaininit();
392 	if_attachdomain();
393 	splx(s);
394 
395 #ifdef GPROF
396 	/* Initialize kernel profiling. */
397 	kmstartup();
398 #endif
399 
400 #if !defined(NO_PROPOLICE)
401 	{
402 		volatile long newguard[8];
403 
404 		arc4random_buf((long *)newguard, sizeof(newguard));
405 
406 		for (i = nitems(__guard) - 1; i; i--)
407 			__guard[i] = newguard[i];
408 	}
409 #endif
410 
411 	/* init exec and emul */
412 	init_exec();
413 
414 	/* Start the scheduler */
415 	scheduler_start();
416 
417 	/*
418 	 * Create process 1 (init(8)).  We do this now, as Unix has
419 	 * historically had init be process 1, and changing this would
420 	 * probably upset a lot of people.
421 	 *
422 	 * Note that process 1 won't immediately exec init(8), but will
423 	 * wait for us to inform it that the root file system has been
424 	 * mounted.
425 	 */
426 	if (fork1(p, SIGCHLD, FORK_FORK, NULL, 0, start_init, NULL, NULL,
427 	    &initproc))
428 		panic("fork init");
429 
430 	/*
431 	 * Create any kernel threads whose creation was deferred because
432 	 * initproc had not yet been created.
433 	 */
434 	kthread_run_deferred_queue();
435 
436 	/*
437 	 * Now that device driver threads have been created, wait for
438 	 * them to finish any deferred autoconfiguration.  Note we don't
439 	 * need to lock this semaphore, since we haven't booted any
440 	 * secondary processors, yet.
441 	 */
442 	while (config_pending)
443 		(void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
444 
445 	dostartuphooks();
446 
447 #if NVSCSI > 0
448 	config_rootfound("vscsi", NULL);
449 #endif
450 #if NSOFTRAID > 0
451 	config_rootfound("softraid", NULL);
452 #endif
453 
454 	/* Configure root/swap devices */
455 	diskconf();
456 
457 	if (mountroot == NULL || ((*mountroot)() != 0))
458 		panic("cannot mount root");
459 
460 	CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
461 
462 	/* Get the vnode for '/'.  Set p->p_fd->fd_cdir to reference it. */
463 	if (VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode))
464 		panic("cannot find root vnode");
465 	p->p_fd->fd_cdir = rootvnode;
466 	VREF(p->p_fd->fd_cdir);
467 	VOP_UNLOCK(rootvnode, 0, p);
468 	p->p_fd->fd_rdir = NULL;
469 
470 	/*
471 	 * Now that root is mounted, we can fixup initproc's CWD
472 	 * info.  All other processes are kthreads, which merely
473 	 * share proc0's CWD info.
474 	 */
475 	initproc->p_fd->fd_cdir = rootvnode;
476 	VREF(initproc->p_fd->fd_cdir);
477 	initproc->p_fd->fd_rdir = NULL;
478 
479 	/*
480 	 * Now can look at time, having had a chance to verify the time
481 	 * from the file system.  Reset p->p_rtime as it may have been
482 	 * munched in mi_switch() after the time got set.
483 	 */
484 #ifdef __HAVE_TIMECOUNTER
485 	microtime(&boottime);
486 #else
487 	boottime = mono_time = time;
488 #endif
489 	LIST_FOREACH(p, &allproc, p_list) {
490 		p->p_stats->p_start = boottime;
491 		microuptime(&p->p_cpu->ci_schedstate.spc_runtime);
492 		p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
493 	}
494 
495 	uvm_swap_init();
496 
497 	/* Create the pageout daemon kernel thread. */
498 	if (kthread_create(uvm_pageout, NULL, NULL, "pagedaemon"))
499 		panic("fork pagedaemon");
500 
501 	/* Create the reaper daemon kernel thread. */
502 	if (kthread_create(start_reaper, NULL, NULL, "reaper"))
503 		panic("fork reaper");
504 
505 	/* Create the cleaner daemon kernel thread. */
506 	if (kthread_create(start_cleaner, NULL, NULL, "cleaner"))
507 		panic("fork cleaner");
508 
509 	/* Create the update daemon kernel thread. */
510 	if (kthread_create(start_update, NULL, NULL, "update"))
511 		panic("fork update");
512 
513 	/* Create the aiodone daemon kernel thread. */
514 	if (kthread_create(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
515 		panic("fork aiodoned");
516 
517 #ifdef CRYPTO
518 	/* Create the crypto kernel thread. */
519 	init_crypto();
520 #endif /* CRYPTO */
521 
522 	microtime(&rtv);
523 	srandom((u_int32_t)(rtv.tv_sec ^ rtv.tv_usec) ^ arc4random());
524 
525 	randompid = 1;
526 
527 #if defined(MULTIPROCESSOR)
528 	/* Boot the secondary processors. */
529 	cpu_boot_secondary_processors();
530 #endif
531 
532 	domountroothooks();
533 
534 	/*
535 	 * Okay, now we can let init(8) exec!  It's off to userland!
536 	 */
537 	start_init_exec = 1;
538 	wakeup((void *)&start_init_exec);
539 
540 	/* The scheduler is an infinite loop. */
541 	uvm_scheduler();
542 	/* NOTREACHED */
543 }
544 
545 /*
546  * List of paths to try when searching for "init".
547  */
548 static char *initpaths[] = {
549 	"/sbin/init",
550 	"/sbin/oinit",
551 	"/sbin/init.bak",
552 	NULL,
553 };
554 
555 void
556 check_console(struct proc *p)
557 {
558 	struct nameidata nd;
559 	int error;
560 
561 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p);
562 	error = namei(&nd);
563 	if (error) {
564 		if (error == ENOENT)
565 			printf("warning: /dev/console does not exist\n");
566 		else
567 			printf("warning: /dev/console error %d\n", error);
568 	} else
569 		vrele(nd.ni_vp);
570 }
571 
572 /*
573  * Start the initial user process; try exec'ing each pathname in "initpaths".
574  * The program is invoked with one argument containing the boot flags.
575  */
576 void
577 start_init(void *arg)
578 {
579 	struct proc *p = arg;
580 	vaddr_t addr;
581 	struct sys_execve_args /* {
582 		syscallarg(const char *) path;
583 		syscallarg(char *const *) argp;
584 		syscallarg(char *const *) envp;
585 	} */ args;
586 	int options, error;
587 	long i;
588 	register_t retval[2];
589 	char flags[4], *flagsp;
590 	char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL;
591 
592 	/*
593 	 * Now in process 1.
594 	 */
595 
596 	/*
597 	 * Wait for main() to tell us that it's safe to exec.
598 	 */
599 	while (start_init_exec == 0)
600 		(void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
601 
602 	check_console(p);
603 
604 	/*
605 	 * Need just enough stack to hold the faked-up "execve()" arguments.
606 	 */
607 #ifdef MACHINE_STACK_GROWS_UP
608 	addr = USRSTACK;
609 #else
610 	addr = USRSTACK - PAGE_SIZE;
611 #endif
612 	if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
613 	    NULL, UVM_UNKNOWN_OFFSET, 0,
614 	    UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_ALL, UVM_INH_COPY,
615 	    UVM_ADV_NORMAL, UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)))
616 		panic("init: couldn't allocate argument space");
617 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
618 
619 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
620 #ifdef MACHINE_STACK_GROWS_UP
621 		ucp = (char *)addr;
622 #else
623 		ucp = (char *)(addr + PAGE_SIZE);
624 #endif
625 		/*
626 		 * Construct the boot flag argument.
627 		 */
628 		flagsp = flags;
629 		*flagsp++ = '-';
630 		options = 0;
631 
632 		if (boothowto & RB_SINGLE) {
633 			*flagsp++ = 's';
634 			options = 1;
635 		}
636 #ifdef notyet
637 		if (boothowto & RB_FASTBOOT) {
638 			*flagsp++ = 'f';
639 			options = 1;
640 		}
641 #endif
642 
643 		/*
644 		 * Move out the flags (arg 1), if necessary.
645 		 */
646 		if (options != 0) {
647 			*flagsp++ = '\0';
648 			i = flagsp - flags;
649 #ifdef DEBUG
650 			printf("init: copying out flags `%s' %d\n", flags, i);
651 #endif
652 #ifdef MACHINE_STACK_GROWS_UP
653 			arg1 = ucp;
654 			(void)copyout((caddr_t)flags, (caddr_t)ucp, i);
655 			ucp += i;
656 #else
657 			(void)copyout((caddr_t)flags, (caddr_t)(ucp -= i), i);
658 			arg1 = ucp;
659 #endif
660 		}
661 
662 		/*
663 		 * Move out the file name (also arg 0).
664 		 */
665 		i = strlen(path) + 1;
666 #ifdef DEBUG
667 		printf("init: copying out path `%s' %d\n", path, i);
668 #endif
669 #ifdef MACHINE_STACK_GROWS_UP
670 		arg0 = ucp;
671 		(void)copyout((caddr_t)path, (caddr_t)ucp, i);
672 		ucp += i;
673 		ucp = (caddr_t)ALIGN((u_long)ucp);
674 		uap = (char **)ucp + 3;
675 #else
676 		(void)copyout((caddr_t)path, (caddr_t)(ucp -= i), i);
677 		arg0 = ucp;
678 		uap = (char **)((u_long)ucp & ~ALIGNBYTES);
679 #endif
680 
681 		/*
682 		 * Move out the arg pointers.
683 		 */
684 		i = 0;
685 		copyout(&i, (caddr_t)--uap, sizeof(register_t)); /* terminator */
686 		if (options != 0)
687 			copyout(&arg1, (caddr_t)--uap, sizeof(register_t));
688 		copyout(&arg0, (caddr_t)--uap, sizeof(register_t));
689 
690 		/*
691 		 * Point at the arguments.
692 		 */
693 		SCARG(&args, path) = arg0;
694 		SCARG(&args, argp) = uap;
695 		SCARG(&args, envp) = NULL;
696 
697 		/*
698 		 * Now try to exec the program.  If can't for any reason
699 		 * other than it doesn't exist, complain.
700 		 */
701 		if ((error = sys_execve(p, &args, retval)) == 0) {
702 			KERNEL_PROC_UNLOCK(p);
703 			return;
704 		}
705 		if (error != ENOENT)
706 			printf("exec %s: error %d\n", path, error);
707 	}
708 	printf("init: not found\n");
709 	panic("no init");
710 }
711 
712 void
713 start_update(void *arg)
714 {
715 	sched_sync(curproc);
716 	/* NOTREACHED */
717 }
718 
719 void
720 start_cleaner(void *arg)
721 {
722 	buf_daemon(curproc);
723 	/* NOTREACHED */
724 }
725 
726 void
727 start_reaper(void *arg)
728 {
729 	reaper();
730 	/* NOTREACHED */
731 }
732