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