init_main.c revision 1.284 1 /* $NetBSD: init_main.c,v 1.284 2006/12/07 20:23:38 ad 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.284 2006/12/07 20:23:38 ad 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 #include "opt_pax.h"
86
87 #include "rnd.h"
88 #include "veriexec.h"
89
90 #include <sys/param.h>
91 #include <sys/acct.h>
92 #include <sys/filedesc.h>
93 #include <sys/file.h>
94 #include <sys/errno.h>
95 #include <sys/callout.h>
96 #include <sys/kernel.h>
97 #include <sys/kcont.h>
98 #include <sys/kmem.h>
99 #include <sys/mount.h>
100 #include <sys/proc.h>
101 #include <sys/kthread.h>
102 #include <sys/resourcevar.h>
103 #include <sys/signalvar.h>
104 #include <sys/systm.h>
105 #include <sys/vnode.h>
106 #include <sys/tty.h>
107 #include <sys/conf.h>
108 #include <sys/disklabel.h>
109 #include <sys/buf.h>
110 #include <sys/device.h>
111 #include <sys/exec.h>
112 #include <sys/socketvar.h>
113 #include <sys/protosw.h>
114 #include <sys/reboot.h>
115 #include <sys/user.h>
116 #include <sys/sysctl.h>
117 #include <sys/event.h>
118 #include <sys/mbuf.h>
119 #include <sys/iostat.h>
120 #ifdef FAST_IPSEC
121 #include <netipsec/ipsec.h>
122 #endif
123 #ifdef SYSVSHM
124 #include <sys/shm.h>
125 #endif
126 #ifdef SYSVSEM
127 #include <sys/sem.h>
128 #endif
129 #ifdef SYSVMSG
130 #include <sys/msg.h>
131 #endif
132 #ifdef P1003_1B_SEMAPHORE
133 #include <sys/ksem.h>
134 #endif
135 #include <sys/domain.h>
136 #include <sys/namei.h>
137 #if NRND > 0
138 #include <sys/rnd.h>
139 #endif
140 #ifndef PIPE_SOCKETPAIR
141 #include <sys/pipe.h>
142 #endif
143 #ifdef LKM
144 #include <sys/lkm.h>
145 #endif
146 #if NVERIEXEC > 0
147 #include <sys/verified_exec.h>
148 #endif /* NVERIEXEC > 0 */
149 #include <sys/kauth.h>
150 #include <net80211/ieee80211_netbsd.h>
151
152 #include <sys/syscall.h>
153 #include <sys/sa.h>
154 #include <sys/syscallargs.h>
155
156 #ifdef FILEASSOC
157 #include <sys/fileassoc.h>
158 #endif /* FILEASSOC */
159
160 #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD)
161 #include <sys/pax.h>
162 #endif /* PAX_MPROTECT || PAX_SEGVGUARD */
163 #include <ufs/ufs/quota.h>
164
165 #include <miscfs/genfs/genfs.h>
166 #include <miscfs/syncfs/syncfs.h>
167
168 #include <machine/cpu.h>
169
170 #include <uvm/uvm.h>
171
172 #include <dev/cons.h>
173
174 #include <net/if.h>
175 #include <net/raw_cb.h>
176
177 #include <secmodel/secmodel.h>
178
179 extern struct proc proc0;
180 extern struct lwp lwp0;
181 extern struct cwdinfo cwdi0;
182
183 #ifndef curlwp
184 struct lwp *curlwp = &lwp0;
185 #endif
186 struct proc *initproc;
187
188 struct vnode *rootvp, *swapdev_vp;
189 int boothowto;
190 int cold = 1; /* still working on startup */
191 struct timeval boottime; /* time at system startup - will only follow settime deltas */
192 time_t rootfstime; /* recorded root fs time, if known */
193
194 volatile int start_init_exec; /* semaphore for start_init() */
195
196 static void check_console(struct lwp *l);
197 static void start_init(void *);
198 void main(void);
199
200 #if defined(__SSP__) || defined(__SSP_ALL__)
201 long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
202 void __stack_chk_fail(void);
203
204 void
205 __stack_chk_fail(void)
206 {
207 panic("stack overflow detected; terminated");
208 }
209 #endif
210
211 /*
212 * System startup; initialize the world, create process 0, mount root
213 * filesystem, and fork to create init and pagedaemon. Most of the
214 * hard work is done in the lower-level initialization routines including
215 * startup(), which does memory initialization and autoconfiguration.
216 */
217 void
218 main(void)
219 {
220 #ifdef __HAVE_TIMECOUNTER
221 struct timeval time;
222 #endif
223 struct lwp *l;
224 struct proc *p;
225 struct pdevinit *pdev;
226 int s, error;
227 extern struct pdevinit pdevinit[];
228 extern void schedcpu(void *);
229 #ifdef NVNODE_IMPLICIT
230 int usevnodes;
231 #endif
232
233 /*
234 * Initialize the current LWP pointer (curlwp) before
235 * any possible traps/probes to simplify trap processing.
236 */
237 l = &lwp0;
238 curlwp = l;
239 l->l_cpu = curcpu();
240 l->l_proc = &proc0;
241 l->l_lid = 1;
242
243 /*
244 * Attempt to find console and initialize
245 * in case of early panic or other messages.
246 */
247 consinit();
248
249 KERNEL_LOCK_INIT();
250
251 uvm_init();
252
253 kmem_init();
254
255 /* Do machine-dependent initialization. */
256 cpu_startup();
257
258 /* Initialize callouts. */
259 callout_startup();
260
261 /* Initialize the buffer cache */
262 bufinit();
263
264 /*
265 * Initialize mbuf's. Do this now because we might attempt to
266 * allocate mbufs or mbuf clusters during autoconfiguration.
267 */
268 mbinit();
269
270 /* Initialize sockets. */
271 soinit();
272
273 #ifdef KCONT
274 /* Initialize kcont. */
275 kcont_init();
276 #endif
277
278 /*
279 * The following things must be done before autoconfiguration.
280 */
281 evcnt_init(); /* initialize event counters */
282 #if NRND > 0
283 rnd_init(); /* initialize RNG */
284 #endif
285 /* Initialize the sysctl subsystem. */
286 sysctl_init();
287
288 /* Initialize process and pgrp structures. */
289 procinit();
290 lwpinit();
291
292 /* Initialize signal-related data structures. */
293 signal_init();
294
295 /* Create process 0 (the swapper). */
296 proc0_init();
297
298 /*
299 * Charge root for one process.
300 */
301 (void)chgproccnt(0, 1);
302
303 rqinit();
304
305 /* Initialize I/O statistics. */
306 iostat_init();
307
308 /* Initialize the file systems. */
309 #ifdef NVNODE_IMPLICIT
310 /*
311 * If maximum number of vnodes in namei vnode cache is not explicitly
312 * defined in kernel config, adjust the number such as we use roughly
313 * 1.0% of memory for vnode cache (but not less than NVNODE vnodes).
314 */
315 usevnodes = (ptoa((unsigned)physmem) / 100) / sizeof(struct vnode);
316 if (usevnodes > desiredvnodes)
317 desiredvnodes = usevnodes;
318 #endif
319 vfsinit();
320
321
322 #ifdef __HAVE_TIMECOUNTER
323 inittimecounter();
324 ntp_init();
325 #endif /* __HAVE_TIMECOUNTER */
326
327 /* Initialize kauth. */
328 kauth_init();
329
330 /* Configure the system hardware. This will enable interrupts. */
331 configure();
332
333 #if defined(__SSP__) || defined(__SSP_ALL__)
334 {
335 #ifdef DIAGNOSTIC
336 printf("Initializing SSP:");
337 #endif
338 /*
339 * We initialize ssp here carefully:
340 * 1. after we got some entropy
341 * 2. without calling a function
342 */
343 size_t i;
344 long guard[__arraycount(__stack_chk_guard)];
345
346 arc4randbytes(guard, sizeof(guard));
347 for (i = 0; i < __arraycount(guard); i++)
348 __stack_chk_guard[i] = guard[i];
349 #ifdef DIAGNOSTIC
350 for (i = 0; i < __arraycount(guard); i++)
351 printf("%lx ", guard[i]);
352 printf("\n");
353 #endif
354 }
355 #endif
356 ubc_init(); /* must be after autoconfig */
357
358 /* Lock the kernel on behalf of proc0. */
359 KERNEL_PROC_LOCK(l);
360
361 #ifdef SYSVSHM
362 /* Initialize System V style shared memory. */
363 shminit();
364 #endif
365
366 #ifdef SYSVSEM
367 /* Initialize System V style semaphores. */
368 seminit();
369 #endif
370
371 #ifdef SYSVMSG
372 /* Initialize System V style message queues. */
373 msginit();
374 #endif
375
376 #ifdef P1003_1B_SEMAPHORE
377 /* Initialize posix semaphores */
378 ksem_init();
379 #endif
380
381 /* Initialize default security model. */
382 secmodel_start();
383
384 #ifdef FILEASSOC
385 fileassoc_init();
386 #endif /* FILEASSOC */
387
388 #if NVERIEXEC > 0
389 /*
390 * Initialise the Veriexec subsystem.
391 */
392 veriexec_init();
393 #endif /* NVERIEXEC > 0 */
394
395 #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD)
396 pax_init();
397 #endif /* PAX_MPROTECT || PAX_SEGVGUARD */
398
399 /* Attach pseudo-devices. */
400 for (pdev = pdevinit; pdev->pdev_attach != NULL; pdev++)
401 (*pdev->pdev_attach)(pdev->pdev_count);
402
403 #ifdef FAST_IPSEC
404 /* Attach network crypto subsystem */
405 ipsec_attach();
406 #endif
407
408 /*
409 * Initialize protocols. Block reception of incoming packets
410 * until everything is ready.
411 */
412 s = splnet();
413 ifinit();
414 domaininit();
415 if_attachdomain();
416 splx(s);
417
418 #ifdef GPROF
419 /* Initialize kernel profiling. */
420 kmstartup();
421 #endif
422
423 /* Initialize system accouting. */
424 acct_init();
425
426 /* Kick off timeout driven events by calling first time. */
427 schedcpu(NULL);
428
429 /*
430 * Create process 1 (init(8)). We do this now, as Unix has
431 * historically had init be process 1, and changing this would
432 * probably upset a lot of people.
433 *
434 * Note that process 1 won't immediately exec init(8), but will
435 * wait for us to inform it that the root file system has been
436 * mounted.
437 */
438 if (fork1(l, 0, SIGCHLD, NULL, 0, start_init, NULL, NULL, &initproc))
439 panic("fork init");
440
441 /*
442 * Create any kernel threads who's creation was deferred because
443 * initproc had not yet been created.
444 */
445 kthread_run_deferred_queue();
446
447 /*
448 * Now that device driver threads have been created, wait for
449 * them to finish any deferred autoconfiguration. Note we don't
450 * need to lock this semaphore, since we haven't booted any
451 * secondary processors, yet.
452 */
453 while (config_pending)
454 (void) tsleep(&config_pending, PWAIT, "cfpend", 0);
455
456 /*
457 * Finalize configuration now that all real devices have been
458 * found. This needs to be done before the root device is
459 * selected, since finalization may create the root device.
460 */
461 config_finalize();
462
463 /*
464 * Now that autoconfiguration has completed, we can determine
465 * the root and dump devices.
466 */
467 cpu_rootconf();
468 cpu_dumpconf();
469
470 /* Mount the root file system. */
471 do {
472 domountroothook();
473 if ((error = vfs_mountroot())) {
474 printf("cannot mount root, error = %d\n", error);
475 boothowto |= RB_ASKNAME;
476 setroot(root_device,
477 (rootdev != NODEV) ? DISKPART(rootdev) : 0);
478 }
479 } while (error != 0);
480 mountroothook_destroy();
481
482 /*
483 * Initialise the time-of-day clock, passing the time recorded
484 * in the root filesystem (if any) for use by systems that
485 * don't have a non-volatile time-of-day device.
486 */
487 inittodr(rootfstime);
488
489 CIRCLEQ_FIRST(&mountlist)->mnt_flag |= MNT_ROOTFS;
490 CIRCLEQ_FIRST(&mountlist)->mnt_op->vfs_refcount++;
491
492 /*
493 * Get the vnode for '/'. Set filedesc0.fd_fd.fd_cdir to
494 * reference it.
495 */
496 error = VFS_ROOT(CIRCLEQ_FIRST(&mountlist), &rootvnode);
497 if (error)
498 panic("cannot find root vnode, error=%d", error);
499 cwdi0.cwdi_cdir = rootvnode;
500 VREF(cwdi0.cwdi_cdir);
501 VOP_UNLOCK(rootvnode, 0);
502 cwdi0.cwdi_rdir = NULL;
503
504 /*
505 * Now that root is mounted, we can fixup initproc's CWD
506 * info. All other processes are kthreads, which merely
507 * share proc0's CWD info.
508 */
509 initproc->p_cwdi->cwdi_cdir = rootvnode;
510 VREF(initproc->p_cwdi->cwdi_cdir);
511 initproc->p_cwdi->cwdi_rdir = NULL;
512
513 /*
514 * Now can look at time, having had a chance to verify the time
515 * from the file system. Reset p->p_rtime as it may have been
516 * munched in mi_switch() after the time got set.
517 */
518 proclist_lock_read();
519 s = splsched();
520 #ifdef __HAVE_TIMECOUNTER
521 getmicrotime(&time);
522 #else
523 mono_time = time;
524 #endif
525 boottime = time;
526 LIST_FOREACH(p, &allproc, p_list) {
527 KASSERT((p->p_flag & P_MARKER) == 0);
528 p->p_stats->p_start = time;
529 LIST_FOREACH(l, &p->p_lwps, l_sibling) {
530 if (l->l_cpu != NULL)
531 l->l_cpu->ci_schedstate.spc_runtime = time;
532 }
533 p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
534 }
535 splx(s);
536 proclist_unlock_read();
537
538 /* Create the pageout daemon kernel thread. */
539 uvm_swap_init();
540 if (kthread_create1(uvm_pageout, NULL, NULL, "pagedaemon"))
541 panic("fork pagedaemon");
542
543 /* Create the filesystem syncer kernel thread. */
544 if (kthread_create1(sched_sync, NULL, NULL, "ioflush"))
545 panic("fork syncer");
546
547 /* Create the aiodone daemon kernel thread. */
548 if (kthread_create1(uvm_aiodone_daemon, NULL, &uvm.aiodoned_proc,
549 "aiodoned"))
550 panic("fork aiodoned");
551
552 #if defined(MULTIPROCESSOR)
553 /* Boot the secondary processors. */
554 cpu_boot_secondary_processors();
555 #endif
556
557 /* Initialize exec structures */
558 exec_init(1);
559
560 /*
561 * Okay, now we can let init(8) exec! It's off to userland!
562 */
563 start_init_exec = 1;
564 wakeup(&start_init_exec);
565
566 /* The scheduler is an infinite loop. */
567 uvm_scheduler();
568 /* NOTREACHED */
569 }
570
571 void
572 setrootfstime(time_t t)
573 {
574 rootfstime = t;
575 }
576
577 static void
578 check_console(struct lwp *l)
579 {
580 struct nameidata nd;
581 int error;
582
583 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", l);
584 error = namei(&nd);
585 if (error == 0)
586 vrele(nd.ni_vp);
587 else if (error == ENOENT)
588 printf("warning: no /dev/console\n");
589 else
590 printf("warning: lookup /dev/console: error %d\n", error);
591 }
592
593 /*
594 * List of paths to try when searching for "init".
595 */
596 static const char *initpaths[] = {
597 "/sbin/init",
598 "/sbin/oinit",
599 "/sbin/init.bak",
600 NULL,
601 };
602
603 /*
604 * Start the initial user process; try exec'ing each pathname in "initpaths".
605 * The program is invoked with one argument containing the boot flags.
606 */
607 static void
608 start_init(void *arg)
609 {
610 struct lwp *l = arg;
611 struct proc *p = l->l_proc;
612 vaddr_t addr;
613 struct sys_execve_args /* {
614 syscallarg(const char *) path;
615 syscallarg(char * const *) argp;
616 syscallarg(char * const *) envp;
617 } */ args;
618 int options, i, error;
619 register_t retval[2];
620 char flags[4], *flagsp;
621 const char *path, *slash;
622 char *ucp, **uap, *arg0, *arg1 = NULL;
623 char ipath[129];
624 int ipx, len;
625
626 /*
627 * Now in process 1.
628 */
629 strncpy(p->p_comm, "init", MAXCOMLEN);
630
631 /*
632 * Wait for main() to tell us that it's safe to exec.
633 */
634 while (start_init_exec == 0)
635 (void) tsleep(&start_init_exec, PWAIT, "initexec", 0);
636
637 /*
638 * This is not the right way to do this. We really should
639 * hand-craft a descriptor onto /dev/console to hand to init,
640 * but that's a _lot_ more work, and the benefit from this easy
641 * hack makes up for the "good is the enemy of the best" effect.
642 */
643 check_console(l);
644
645 /*
646 * Need just enough stack to hold the faked-up "execve()" arguments.
647 */
648 addr = (vaddr_t)STACK_ALLOC(USRSTACK, PAGE_SIZE);
649 if (uvm_map(&p->p_vmspace->vm_map, &addr, PAGE_SIZE,
650 NULL, UVM_UNKNOWN_OFFSET, 0,
651 UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
652 UVM_ADV_NORMAL,
653 UVM_FLAG_FIXED|UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW)) != 0)
654 panic("init: couldn't allocate argument space");
655 p->p_vmspace->vm_maxsaddr = (caddr_t)STACK_MAX(addr, PAGE_SIZE);
656
657 ipx = 0;
658 while (1) {
659 if (boothowto & RB_ASKNAME) {
660 printf("init path");
661 if (initpaths[ipx])
662 printf(" (default %s)", initpaths[ipx]);
663 printf(": ");
664 len = cngetsn(ipath, sizeof(ipath)-1);
665 if (len == 0) {
666 if (initpaths[ipx])
667 path = initpaths[ipx++];
668 else
669 continue;
670 } else {
671 ipath[len] = '\0';
672 path = ipath;
673 }
674 } else {
675 if ((path = initpaths[ipx++]) == NULL)
676 break;
677 }
678
679 ucp = (char *)USRSTACK;
680
681 /*
682 * Construct the boot flag argument.
683 */
684 flagsp = flags;
685 *flagsp++ = '-';
686 options = 0;
687
688 if (boothowto & RB_SINGLE) {
689 *flagsp++ = 's';
690 options = 1;
691 }
692 #ifdef notyet
693 if (boothowto & RB_FASTBOOT) {
694 *flagsp++ = 'f';
695 options = 1;
696 }
697 #endif
698
699 /*
700 * Move out the flags (arg 1), if necessary.
701 */
702 if (options != 0) {
703 *flagsp++ = '\0';
704 i = flagsp - flags;
705 #ifdef DEBUG
706 printf("init: copying out flags `%s' %d\n", flags, i);
707 #endif
708 arg1 = STACK_ALLOC(ucp, i);
709 ucp = STACK_MAX(arg1, i);
710 (void)copyout((caddr_t)flags, arg1, i);
711 }
712
713 /*
714 * Move out the file name (also arg 0).
715 */
716 i = strlen(path) + 1;
717 #ifdef DEBUG
718 printf("init: copying out path `%s' %d\n", path, i);
719 #else
720 if (boothowto & RB_ASKNAME || path != initpaths[0])
721 printf("init: trying %s\n", path);
722 #endif
723 arg0 = STACK_ALLOC(ucp, i);
724 ucp = STACK_MAX(arg0, i);
725 (void)copyout(path, arg0, i);
726
727 /*
728 * Move out the arg pointers.
729 */
730 ucp = (caddr_t)STACK_ALIGN(ucp, ALIGNBYTES);
731 uap = (char **)STACK_ALLOC(ucp, sizeof(char *) * 3);
732 SCARG(&args, path) = arg0;
733 SCARG(&args, argp) = uap;
734 SCARG(&args, envp) = NULL;
735 slash = strrchr(path, '/');
736 if (slash)
737 (void)suword((caddr_t)uap++,
738 (long)arg0 + (slash + 1 - path));
739 else
740 (void)suword((caddr_t)uap++, (long)arg0);
741 if (options != 0)
742 (void)suword((caddr_t)uap++, (long)arg1);
743 (void)suword((caddr_t)uap++, 0); /* terminator */
744
745 /*
746 * Now try to exec the program. If can't for any reason
747 * other than it doesn't exist, complain.
748 */
749 error = sys_execve(l, &args, retval);
750 if (error == 0 || error == EJUSTRETURN) {
751 KERNEL_PROC_UNLOCK(l);
752 return;
753 }
754 printf("exec %s: error %d\n", path, error);
755 }
756 printf("init: not found\n");
757 panic("no init");
758 }
759