init_main.c revision 1.211 1 /* $NetBSD: init_main.c,v 1.211 2002/11/17 22:53:46 chs 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.211 2002/11/17 22:53:46 chs 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/proc.h>
67 #include <sys/kthread.h>
68 #include <sys/resourcevar.h>
69 #include <sys/signalvar.h>
70 #include <sys/systm.h>
71 #include <sys/vnode.h>
72 #include <sys/tty.h>
73 #include <sys/conf.h>
74 #include <sys/disklabel.h>
75 #include <sys/buf.h>
76 #include <sys/device.h>
77 #include <sys/disk.h>
78 #include <sys/exec.h>
79 #include <sys/socketvar.h>
80 #include <sys/protosw.h>
81 #include <sys/reboot.h>
82 #include <sys/user.h>
83 #include <sys/sysctl.h>
84 #include <sys/event.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 #ifdef LKM
107 #include <sys/lkm.h>
108 #endif
109
110 #include <sys/syscall.h>
111 #include <sys/syscallargs.h>
112
113 #include <ufs/ufs/quota.h>
114
115 #include <miscfs/genfs/genfs.h>
116 #include <miscfs/syncfs/syncfs.h>
117
118 #include <machine/cpu.h>
119
120 #include <uvm/uvm.h>
121
122 #include <dev/cons.h>
123
124 #include <net/if.h>
125 #include <net/raw_cb.h>
126
127 const char copyright[] =
128 "Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002\n"
129 " The NetBSD Foundation, Inc. All rights reserved.\n"
130 "Copyright (c) 1982, 1986, 1989, 1991, 1993\n"
131 " The Regents of the University of California. All rights reserved.\n"
132 "\n";
133
134 /* Components of the first process -- never freed. */
135 struct session session0;
136 struct pgrp pgrp0;
137 struct proc proc0;
138 struct pcred cred0;
139 struct filedesc0 filedesc0;
140 struct cwdinfo cwdi0;
141 struct plimit limit0;
142 struct vmspace vmspace0;
143 struct sigacts sigacts0;
144 #ifndef curproc
145 struct proc *curproc = &proc0;
146 #endif
147 struct proc *initproc;
148
149 int cmask = CMASK;
150 extern struct user *proc0paddr;
151
152 struct vnode *rootvp, *swapdev_vp;
153 int boothowto;
154 int cold = 1; /* still working on startup */
155 struct timeval boottime;
156
157 __volatile int start_init_exec; /* semaphore for start_init() */
158
159 static void check_console(struct proc *p);
160 static void start_init(void *);
161 void main(void);
162
163 extern const struct emul emul_netbsd; /* defined in kern_exec.c */
164
165 /*
166 * System startup; initialize the world, create process 0, mount root
167 * filesystem, and fork to create init and pagedaemon. Most of the
168 * hard work is done in the lower-level initialization routines including
169 * startup(), which does memory initialization and autoconfiguration.
170 */
171 void
172 main(void)
173 {
174 struct proc *p;
175 struct pdevinit *pdev;
176 int s, error;
177 u_int i;
178 rlim_t lim;
179 extern struct pdevinit pdevinit[];
180 extern void schedcpu(void *);
181 #if defined(NFSSERVER) || defined(NFS)
182 extern void nfs_init(void);
183 #endif
184 #ifdef NVNODE_IMPLICIT
185 int usevnodes;
186 #endif
187
188 /*
189 * Initialize the current process pointer (curproc) before
190 * any possible traps/probes to simplify trap processing.
191 */
192 simple_lock_init(&proc0.p_raslock);
193 p = &proc0;
194 curproc = p;
195 p->p_cpu = curcpu();
196 /*
197 * Attempt to find console and initialize
198 * in case of early panic or other messages.
199 */
200 consinit();
201 printf("%s", copyright);
202
203 KERNEL_LOCK_INIT();
204
205 uvm_init();
206
207 /* Do machine-dependent initialization. */
208 cpu_startup();
209
210 /* Initialize callouts. */
211 callout_startup();
212
213 /*
214 * Initialize mbuf's. Do this now because we might attempt to
215 * allocate mbufs or mbuf clusters during autoconfiguration.
216 */
217 mbinit();
218
219 /* Initialize kqueues. */
220 kqueue_init();
221
222 /* Initialize sockets. */
223 soinit();
224
225 /*
226 * The following 3 things must be done before autoconfiguration.
227 */
228 disk_init(); /* initialize disk list */
229 tty_init(); /* initialize tty list */
230 #if NRND > 0
231 rnd_init(); /* initialize RNG */
232 #endif
233
234 /* Initialize the sysctl subsystem. */
235 sysctl_init();
236
237 /*
238 * Initialize process and pgrp structures.
239 */
240 procinit();
241
242 #ifdef LKM
243 /* Initialize the LKM system. */
244 lkm_init();
245 #endif
246
247 /*
248 * Create process 0 (the swapper).
249 */
250 s = proclist_lock_write();
251 LIST_INSERT_HEAD(&allproc, p, p_list);
252 LIST_INSERT_HEAD(PIDHASH(p->p_pid), p, p_hash);
253 proclist_unlock_write(s);
254
255 p->p_pgrp = &pgrp0;
256 LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
257 LIST_INIT(&pgrp0.pg_members);
258 LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
259
260 pgrp0.pg_session = &session0;
261 session0.s_count = 1;
262 session0.s_sid = p->p_pid;
263 session0.s_leader = p;
264
265 /*
266 * Set P_NOCLDWAIT so that kernel threads are reparented to
267 * init(8) when they exit. init(8) can easily wait them out
268 * for us.
269 */
270 p->p_flag = P_INMEM | P_SYSTEM | P_NOCLDWAIT;
271 p->p_stat = SONPROC;
272 p->p_nice = NZERO;
273 p->p_emul = &emul_netbsd;
274 #ifdef __HAVE_SYSCALL_INTERN
275 (*p->p_emul->e_syscall_intern)(p);
276 #endif
277 strncpy(p->p_comm, "swapper", MAXCOMLEN);
278
279 callout_init(&p->p_realit_ch);
280 callout_init(&p->p_tsleep_ch);
281
282 /* Create credentials. */
283 cred0.p_refcnt = 1;
284 p->p_cred = &cred0;
285 p->p_ucred = crget();
286 p->p_ucred->cr_ngroups = 1; /* group 0 */
287
288 /* Create the file descriptor table. */
289 finit();
290 p->p_fd = &filedesc0.fd_fd;
291 fdinit1(&filedesc0);
292
293 /* Create the CWD info. */
294 p->p_cwdi = &cwdi0;
295 cwdi0.cwdi_cmask = cmask;
296 cwdi0.cwdi_refcnt = 1;
297
298 /* Create the limits structures. */
299 p->p_limit = &limit0;
300 for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
301 limit0.pl_rlimit[i].rlim_cur =
302 limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
303
304 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
305 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
306 maxfiles < NOFILE ? maxfiles : NOFILE;
307
308 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
309 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
310 maxproc < MAXUPRC ? maxproc : MAXUPRC;
311
312 lim = ptoa(uvmexp.free);
313 limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
314 limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
315 limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
316 limit0.pl_corename = defcorename;
317 limit0.p_refcnt = 1;
318
319 /*
320 * Initialize proc0's vmspace, which uses the kernel pmap.
321 * All kernel processes (which never have user space mappings)
322 * share proc0's vmspace, and thus, the kernel pmap.
323 */
324 uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
325 trunc_page(VM_MAX_ADDRESS));
326 p->p_vmspace = &vmspace0;
327
328 p->p_addr = proc0paddr; /* XXX */
329
330 /*
331 * We continue to place resource usage info in the
332 * user struct so they're pageable.
333 */
334 p->p_stats = &p->p_addr->u_stats;
335
336 /*
337 * Charge root for one process.
338 */
339 (void)chgproccnt(0, 1);
340
341 rqinit();
342
343 /* Configure virtual memory system, set vm rlimits. */
344 uvm_init_limits(p);
345
346 /* Initialize the file systems. */
347 #if defined(NFSSERVER) || defined(NFS)
348 nfs_init(); /* initialize server/shared data */
349 #endif
350 #ifdef NVNODE_IMPLICIT
351 /*
352 * If maximum number of vnodes in namei vnode cache is not explicitly
353 * defined in kernel config, adjust the number such as we use roughly
354 * 0.5% of memory for vnode cache (but not less than NVNODE vnodes).
355 */
356 usevnodes = (ptoa((unsigned)physmem) / 200) / sizeof(struct vnode);
357 if (usevnodes > desiredvnodes)
358 desiredvnodes = usevnodes;
359 #endif
360 vfsinit();
361
362 /* Configure the system hardware. This will enable interrupts. */
363 configure();
364
365 ubc_init(); /* must be after autoconfig */
366
367 /* Lock the kernel on behalf of proc0. */
368 KERNEL_PROC_LOCK(p);
369
370 #ifdef SYSVSHM
371 /* Initialize System V style shared memory. */
372 shminit();
373 #endif
374
375 #ifdef SYSVSEM
376 /* Initialize System V style semaphores. */
377 seminit();
378 #endif
379
380 #ifdef SYSVMSG
381 /* Initialize System V style message queues. */
382 msginit();
383 #endif
384
385 /* Attach pseudo-devices. */
386 for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
387 (*pdev->pdev_attach)(pdev->pdev_count);
388
389 /*
390 * Initialize protocols. Block reception of incoming packets
391 * until everything is ready.
392 */
393 s = splnet();
394 ifinit();
395 domaininit();
396 if_attachdomain();
397 splx(s);
398
399 #ifdef GPROF
400 /* Initialize kernel profiling. */
401 kmstartup();
402 #endif
403
404 /* Initialize system accouting. */
405 acct_init();
406
407 #ifdef SYSTRACE
408 systrace_init();
409 #endif
410 /*
411 * Initialize signal-related data structures, and signal state
412 * for proc0.
413 */
414 signal_init();
415 p->p_sigacts = &sigacts0;
416 siginit(p);
417
418 /* Kick off timeout driven events by calling first time. */
419 schedcpu(NULL);
420
421 /*
422 * Create process 1 (init(8)). We do this now, as Unix has
423 * historically had init be process 1, and changing this would
424 * probably upset a lot of people.
425 *
426 * Note that process 1 won't immediately exec init(8), but will
427 * wait for us to inform it that the root file system has been
428 * mounted.
429 */
430 if (fork1(p, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL, &initproc))
431 panic("fork init");
432
433 /*
434 * Create any kernel threads who's creation was deferred because
435 * initproc had not yet been created.
436 */
437 kthread_run_deferred_queue();
438
439 /*
440 * Now that device driver threads have been created, wait for
441 * them to finish any deferred autoconfiguration. Note we don't
442 * need to lock this semaphore, since we haven't booted any
443 * secondary processors, yet.
444 */
445 while (config_pending)
446 (void) tsleep((void *)&config_pending, PWAIT, "cfpend", 0);
447
448 /*
449 * Finalize configuration now that all real devices have been
450 * found. This needs to be done before the root device is
451 * selected, since finalization may create the root device.
452 */
453 config_finalize();
454
455 /*
456 * Now that autoconfiguration has completed, we can determine
457 * the root and dump devices.
458 */
459 cpu_rootconf();
460 cpu_dumpconf();
461
462 /* Mount the root file system. */
463 do {
464 domountroothook();
465 if ((error = vfs_mountroot())) {
466 printf("cannot mount root, error = %d\n", error);
467 boothowto |= RB_ASKNAME;
468 setroot(root_device,
469 (rootdev != NODEV) ? DISKPART(rootdev) : 0);
470 }
471 } while (error != 0);
472 mountroothook_destroy();
473
474 CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
475 CIRCLEQ_FIRST(&mountlist)->mnt_op->vfs_refcount++;
476
477 /*
478 * Get the vnode for '/'. Set filedesc0.fd_fd.fd_cdir to
479 * reference it.
480 */
481 if (VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode))
482 panic("cannot find root vnode");
483 cwdi0.cwdi_cdir = rootvnode;
484 VREF(cwdi0.cwdi_cdir);
485 VOP_UNLOCK(rootvnode, 0);
486 cwdi0.cwdi_rdir = NULL;
487
488 /*
489 * Now that root is mounted, we can fixup initproc's CWD
490 * info. All other processes are kthreads, which merely
491 * share proc0's CWD info.
492 */
493 initproc->p_cwdi->cwdi_cdir = rootvnode;
494 VREF(initproc->p_cwdi->cwdi_cdir);
495 initproc->p_cwdi->cwdi_rdir = NULL;
496
497 /*
498 * Now can look at time, having had a chance to verify the time
499 * from the file system. Reset p->p_rtime as it may have been
500 * munched in mi_switch() after the time got set.
501 */
502 proclist_lock_read();
503 s = splsched();
504 for (p = LIST_FIRST(&allproc); p != NULL;
505 p = LIST_NEXT(p, p_list)) {
506 p->p_stats->p_start = mono_time = boottime = time;
507 if (p->p_cpu != NULL)
508 p->p_cpu->ci_schedstate.spc_runtime = time;
509 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
510 }
511 splx(s);
512 proclist_unlock_read();
513
514 /* Create the pageout daemon kernel thread. */
515 uvm_swap_init();
516 if (kthread_create1(uvm_pageout, NULL, NULL, "pagedaemon"))
517 panic("fork pagedaemon");
518
519 /* Create the process reaper kernel thread. */
520 if (kthread_create1(reaper, NULL, NULL, "reaper"))
521 panic("fork reaper");
522
523 /* Create the filesystem syncer kernel thread. */
524 if (kthread_create1(sched_sync, NULL, NULL, "ioflush"))
525 panic("fork syncer");
526
527 /* Create the aiodone daemon kernel thread. */
528 if (kthread_create1(uvm_aiodone_daemon, NULL, NULL, "aiodoned"))
529 panic("fork aiodoned");
530
531 #if defined(MULTIPROCESSOR)
532 /* Boot the secondary processors. */
533 cpu_boot_secondary_processors();
534 #endif
535
536 /* Initialize exec structures */
537 exec_init(1);
538
539 #ifndef PIPE_SOCKETPAIR
540 /* Initialize pipe structures */
541 pipe_init();
542 #endif
543
544 /*
545 * Okay, now we can let init(8) exec! It's off to userland!
546 */
547 start_init_exec = 1;
548 wakeup((void *)&start_init_exec);
549
550 /* The scheduler is an infinite loop. */
551 uvm_scheduler();
552 /* NOTREACHED */
553 }
554
555 static 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 == 0)
564 vrele(nd.ni_vp);
565 else if (error == ENOENT)
566 printf("warning: no /dev/console\n");
567 else
568 printf("warning: lookup /dev/console: error %d\n", error);
569 }
570
571 /*
572 * List of paths to try when searching for "init".
573 */
574 static const char *initpaths[] = {
575 "/sbin/init",
576 "/sbin/oinit",
577 "/sbin/init.bak",
578 NULL,
579 };
580
581 /*
582 * Start the initial user process; try exec'ing each pathname in "initpaths".
583 * The program is invoked with one argument containing the boot flags.
584 */
585 static void
586 start_init(void *arg)
587 {
588 struct proc *p = arg;
589 vaddr_t addr;
590 struct sys_execve_args /* {
591 syscallarg(const char *) path;
592 syscallarg(char * const *) argp;
593 syscallarg(char * const *) envp;
594 } */ args;
595 int options, i, error;
596 register_t retval[2];
597 char flags[4], *flagsp;
598 const char *path, *slash;
599 char *ucp, **uap, *arg0, *arg1 = NULL;
600 char ipath[129];
601 int ipx, len;
602
603 /*
604 * Now in process 1.
605 */
606 strncpy(p->p_comm, "init", MAXCOMLEN);
607
608 /*
609 * Wait for main() to tell us that it's safe to exec.
610 */
611 while (start_init_exec == 0)
612 (void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0);
613
614 /*
615 * This is not the right way to do this. We really should
616 * hand-craft a descriptor onto /dev/console to hand to init,
617 * but that's a _lot_ more work, and the benefit from this easy
618 * hack makes up for the "good is the enemy of the best" effect.
619 */
620 check_console(p);
621
622 /*
623 * Need just enough stack to hold the faked-up "execve()" arguments.
624 */
625 addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE);
626 if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
627 NULL, UVM_UNKNOWN_OFFSET, 0,
628 UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
629 UVM_ADV_NORMAL,
630 UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0)
631 panic("init: couldn't allocate argument space");
632 p->p_vmspace->vm_maxsaddr = (caddr_t)STACK_MAX(addr, PAGE_SIZE);
633
634 ipx = 0;
635 while (1) {
636 if (boothowto & RB_ASKNAME) {
637 printf("init path");
638 if (initpaths[ipx])
639 printf(" (default %s)", initpaths[ipx]);
640 printf(": ");
641 len = cngetsn(ipath, sizeof(ipath)-1);
642 if (len == 0) {
643 if (initpaths[ipx])
644 path = initpaths[ipx++];
645 else
646 continue;
647 } else {
648 ipath[len] = '\0';
649 path = ipath;
650 }
651 } else {
652 if ((path = initpaths[ipx++]) == NULL)
653 break;
654 }
655
656 ucp = (char *)USRSTACK;
657
658 /*
659 * Construct the boot flag argument.
660 */
661 flagsp = flags;
662 *flagsp++ = '-';
663 options = 0;
664
665 if (boothowto & RB_SINGLE) {
666 *flagsp++ = 's';
667 options = 1;
668 }
669 #ifdef notyet
670 if (boothowto & RB_FASTBOOT) {
671 *flagsp++ = 'f';
672 options = 1;
673 }
674 #endif
675
676 /*
677 * Move out the flags (arg 1), if necessary.
678 */
679 if (options != 0) {
680 *flagsp++ = '\0';
681 i = flagsp - flags;
682 #ifdef DEBUG
683 printf("init: copying out flags `%s' %d\n", flags, i);
684 #endif
685 arg1 = STACK_ALLOC(ucp, i);
686 ucp = STACK_MAX(arg1, i);
687 (void)copyout((caddr_t)flags, arg1, i);
688 }
689
690 /*
691 * Move out the file name (also arg 0).
692 */
693 i = strlen(path) + 1;
694 #ifdef DEBUG
695 printf("init: copying out path `%s' %d\n", path, i);
696 #else
697 if (boothowto & RB_ASKNAME || path != initpaths[0])
698 printf("init: trying %s\n", path);
699 #endif
700 arg0 = STACK_ALLOC(ucp, i);
701 ucp = STACK_MAX(arg0, i);
702 (void)copyout((caddr_t)path, arg0, i);
703
704 /*
705 * Move out the arg pointers.
706 */
707 ucp = (caddr_t)STACK_ALIGN(ucp, ALIGNBYTES);
708 uap = (char **)STACK_ALLOC(ucp, sizeof(char *) * 3);
709 SCARG(&args, path) = arg0;
710 SCARG(&args, argp) = uap;
711 SCARG(&args, envp) = NULL;
712 slash = strrchr(path, '/');
713 if (slash)
714 (void)suword((caddr_t)uap++,
715 (long)arg0 + (slash + 1 - path));
716 else
717 (void)suword((caddr_t)uap++, (long)arg0);
718 if (options != 0)
719 (void)suword((caddr_t)uap++, (long)arg1);
720 (void)suword((caddr_t)uap++, 0); /* terminator */
721
722 /*
723 * Now try to exec the program. If can't for any reason
724 * other than it doesn't exist, complain.
725 */
726 error = sys_execve(p, &args, retval);
727 if (error == 0 || error == EJUSTRETURN) {
728 KERNEL_PROC_UNLOCK(p);
729 return;
730 }
731 printf("exec %s: error %d\n", path, error);
732 }
733 printf("init: not found\n");
734 panic("no init");
735 }
736