root/init/main.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. _syscall0
  2. get_options
  3. ramdisk_setup
  4. checksetup
  5. calibrate_delay
  6. parse_options
  7. copy_options
  8. copro_timeout
  9. check_fpu
  10. check_hlt
  11. check_bugs
  12. start_kernel
  13. printf
  14. init

   1 /*
   2  *  linux/init/main.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <stdarg.h>
   8 
   9 #include <asm/system.h>
  10 #include <asm/io.h>
  11 
  12 #include <linux/types.h>
  13 #include <linux/fcntl.h>
  14 #include <linux/config.h>
  15 #include <linux/sched.h>
  16 #include <linux/tty.h>
  17 #include <linux/head.h>
  18 #include <linux/unistd.h>
  19 #include <linux/string.h>
  20 #include <linux/timer.h>
  21 #include <linux/fs.h>
  22 #include <linux/ctype.h>
  23 #include <linux/delay.h>
  24 #include <linux/utsname.h>
  25 #include <linux/ioport.h>
  26 
  27 extern unsigned long * prof_buffer;
  28 extern unsigned long prof_len;
  29 extern char edata, end;
  30 extern char *linux_banner;
  31 asmlinkage void lcall7(void);
  32 struct desc_struct default_ldt;
  33 
  34 /*
  35  * we need this inline - forking from kernel space will result
  36  * in NO COPY ON WRITE (!!!), until an execve is executed. This
  37  * is no problem, but for the stack. This is handled by not letting
  38  * main() use the stack at all after fork(). Thus, no function
  39  * calls - which means inline code for fork too, as otherwise we
  40  * would use the stack upon exit from 'fork()'.
  41  *
  42  * Actually only pause and fork are needed inline, so that there
  43  * won't be any messing with the stack from main(), but we define
  44  * some others too.
  45  */
  46 #define __NR__exit __NR_exit
  47 static inline _syscall0(int,idle)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 static inline _syscall0(int,fork)
  49 static inline _syscall0(int,pause)
  50 static inline _syscall0(int,setup)
  51 static inline _syscall0(int,sync)
  52 static inline _syscall0(pid_t,setsid)
  53 static inline _syscall3(int,write,int,fd,const char *,buf,off_t,count)
  54 static inline _syscall1(int,dup,int,fd)
  55 static inline _syscall3(int,execve,const char *,file,char **,argv,char **,envp)
  56 static inline _syscall3(int,open,const char *,file,int,flag,int,mode)
  57 static inline _syscall1(int,close,int,fd)
  58 static inline _syscall1(int,_exit,int,exitcode)
  59 static inline _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options)
  60 
  61 static inline pid_t wait(int * wait_stat)
  62 {
  63         return waitpid(-1,wait_stat,0);
  64 }
  65 
  66 static char printbuf[1024];
  67 
  68 extern int console_loglevel;
  69 
  70 extern char empty_zero_page[PAGE_SIZE];
  71 extern void init(void);
  72 extern void init_IRQ(void);
  73 extern void init_modules(void);
  74 extern long console_init(long, long);
  75 extern long kmalloc_init(long,long);
  76 extern long blk_dev_init(long,long);
  77 extern long chr_dev_init(long,long);
  78 extern void sock_init(void);
  79 extern long rd_init(long mem_start, int length);
  80 unsigned long net_dev_init(unsigned long, unsigned long);
  81 extern long bios32_init(long, long);
  82 
  83 extern void hd_setup(char *str, int *ints);
  84 extern void bmouse_setup(char *str, int *ints);
  85 extern void eth_setup(char *str, int *ints);
  86 extern void xd_setup(char *str, int *ints);
  87 extern void floppy_setup(char *str, int *ints);
  88 extern void mcd_setup(char *str, int *ints);
  89 extern void st_setup(char *str, int *ints);
  90 extern void st0x_setup(char *str, int *ints);
  91 extern void tmc8xx_setup(char *str, int *ints);
  92 extern void t128_setup(char *str, int *ints);
  93 extern void pas16_setup(char *str, int *ints);
  94 extern void generic_NCR5380_setup(char *str, int *intr);
  95 extern void aha152x_setup(char *str, int *ints);
  96 extern void aha1542_setup(char *str, int *ints);
  97 extern void aha274x_setup(char *str, int *ints);
  98 extern void scsi_luns_setup(char *str, int *ints);
  99 extern void sound_setup(char *str, int *ints);
 100 #ifdef CONFIG_SBPCD
 101 extern void sbpcd_setup(char *str, int *ints);
 102 #endif CONFIG_SBPCD
 103 #ifdef CONFIG_CDU31A
 104 extern void cdu31a_setup(char *str, int *ints);
 105 #endif CONFIG_CDU31A
 106 void ramdisk_setup(char *str, int *ints);
 107 
 108 #ifdef CONFIG_SYSVIPC
 109 extern void ipc_init(void);
 110 #endif
 111 #ifdef CONFIG_SCSI
 112 extern unsigned long scsi_dev_init(unsigned long, unsigned long);
 113 #endif
 114 
 115 /*
 116  * This is set up by the setup-routine at boot-time
 117  */
 118 #define PARAM   empty_zero_page
 119 #define EXT_MEM_K (*(unsigned short *) (PARAM+2))
 120 #define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 121 #define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
 122 #define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
 123 #define RAMDISK_SIZE (*(unsigned short *) (PARAM+0x1F8))
 124 #define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
 125 #define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
 126 
 127 /*
 128  * Boot command-line arguments
 129  */
 130 #define MAX_INIT_ARGS 8
 131 #define MAX_INIT_ENVS 8
 132 #define COMMAND_LINE ((char *) (PARAM+2048))
 133 #define COMMAND_LINE_SIZE 256
 134 
 135 extern void time_init(void);
 136 
 137 static unsigned long memory_start = 0;  /* After mem_init, stores the */
 138                                         /* amount of free user memory */
 139 static unsigned long memory_end = 0;
 140 static unsigned long low_memory_start = 0;
 141 
 142 static char term[21];
 143 int rows, cols;
 144 
 145 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
 146 static char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", term, NULL, };
 147 
 148 static char * argv_rc[] = { "/bin/sh", NULL };
 149 static char * envp_rc[] = { "HOME=/", term, NULL };
 150 
 151 static char * argv[] = { "-/bin/sh",NULL };
 152 static char * envp[] = { "HOME=/usr/root", term, NULL };
 153 
 154 struct drive_info_struct { char dummy[32]; } drive_info;
 155 struct screen_info screen_info;
 156 
 157 unsigned char aux_device_present;
 158 int ramdisk_size;
 159 int root_mountflags = 0;
 160 
 161 static char fpu_error = 0;
 162 
 163 static char command_line[COMMAND_LINE_SIZE] = { 0, };
 164 
 165 char *get_options(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167         char *cur = str;
 168         int i=1;
 169 
 170         while (cur && isdigit(*cur) && i <= 10) {
 171                 ints[i++] = simple_strtoul(cur,NULL,0);
 172                 if ((cur = strchr(cur,',')) != NULL)
 173                         cur++;
 174         }
 175         ints[0] = i-1;
 176         return(cur);
 177 }
 178 
 179 struct {
 180         char *str;
 181         void (*setup_func)(char *, int *);
 182 } bootsetups[] = {
 183         { "reserve=", reserve_setup },
 184         { "ramdisk=", ramdisk_setup },
 185 #ifdef CONFIG_INET
 186         { "ether=", eth_setup },
 187 #endif
 188 #ifdef CONFIG_SCSI
 189         { "max_scsi_luns=", scsi_luns_setup },
 190 #endif
 191 #ifdef CONFIG_BLK_DEV_HD
 192         { "hd=", hd_setup },
 193 #endif
 194 #ifdef CONFIG_CHR_DEV_ST
 195         { "st=", st_setup },
 196 #endif
 197 #ifdef CONFIG_BUSMOUSE
 198         { "bmouse=", bmouse_setup },
 199 #endif
 200 #ifdef CONFIG_SCSI_SEAGATE
 201         { "st0x=", st0x_setup },
 202         { "tmc8xx=", tmc8xx_setup },
 203 #endif
 204 #ifdef CONFIG_SCSI_T128
 205         { "t128=", t128_setup },
 206 #endif
 207 #ifdef CONFIG_SCSI_PAS16
 208         { "pas16=", pas16_setup },
 209 #endif
 210 #ifdef CONFIG_SCSI_GENERIC_NCR5380
 211         { "ncr5380=", generic_NCR5380_setup },
 212 #endif
 213 #ifdef CONFIG_SCSI_AHA152X
 214         { "aha152x=", aha152x_setup},
 215 #endif
 216 #ifdef CONFIG_SCSI_AHA1542
 217         { "aha1542=", aha1542_setup},
 218 #endif
 219 #ifdef CONFIG_SCSI_AHA274X
 220         { "aha274x=", aha274x_setup},
 221 #endif
 222 #ifdef CONFIG_BLK_DEV_XD
 223         { "xd=", xd_setup },
 224 #endif
 225 #ifdef CONFIG_BLK_DEV_FD
 226         { "floppy=", floppy_setup },
 227 #endif
 228 #ifdef CONFIG_MCD
 229         { "mcd=", mcd_setup },
 230 #endif
 231 #ifdef CONFIG_SOUND
 232         { "sound=", sound_setup },
 233 #endif
 234 #ifdef CONFIG_SBPCD
 235         { "sbpcd=", sbpcd_setup },
 236 #endif CONFIG_SBPCD
 237 #ifdef CONFIG_CDU31A
 238         { "cdu31a=", cdu31a_setup },
 239 #endif CONFIG_CDU31A
 240         { 0, 0 }
 241 };
 242 
 243 void ramdisk_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 244 {
 245    if (ints[0] > 0 && ints[1] >= 0)
 246       ramdisk_size = ints[1];
 247 }
 248 
 249 static int checksetup(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 250 {
 251         int i = 0;
 252         int ints[11];
 253 
 254         while (bootsetups[i].str) {
 255                 int n = strlen(bootsetups[i].str);
 256                 if (!strncmp(line,bootsetups[i].str,n)) {
 257                         bootsetups[i].setup_func(get_options(line+n,ints), ints);
 258                         return 1;
 259                 }
 260                 i++;
 261         }
 262         return 0;
 263 }
 264 
 265 unsigned long loops_per_sec = 1;
 266 
 267 static void calibrate_delay(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 268 {
 269         int ticks;
 270 
 271         printk("Calibrating delay loop.. ");
 272         while (loops_per_sec <<= 1) {
 273                 /* wait for "start of" clock tick */
 274                 ticks = jiffies;
 275                 while (ticks == jiffies)
 276                         /* nothing */;
 277                 /* Go .. */
 278                 ticks = jiffies;
 279                 __delay(loops_per_sec);
 280                 ticks = jiffies - ticks;
 281                 if (ticks >= HZ) {
 282                         __asm__("mull %1 ; divl %2"
 283                                 :"=a" (loops_per_sec)
 284                                 :"d" (HZ),
 285                                  "r" (ticks),
 286                                  "0" (loops_per_sec)
 287                                 :"dx");
 288                         printk("ok - %lu.%02lu BogoMips\n",
 289                                 loops_per_sec/500000,
 290                                 (loops_per_sec/5000) % 100);
 291                         return;
 292                 }
 293         }
 294         printk("failed\n");
 295 }
 296 
 297 
 298 /*
 299  * This is a simple kernel command line parsing function: it parses
 300  * the command line, and fills in the arguments/environment to init
 301  * as appropriate. Any cmd-line option is taken to be an environment
 302  * variable if it contains the character '='.
 303  *
 304  *
 305  * This routine also checks for options meant for the kernel - currently
 306  * only the "root=XXXX" option is recognized. These options are not given
 307  * to init - they are for internal kernel use only.
 308  */
 309 static void parse_options(char *line)
     /* [previous][next][first][last][top][bottom][index][help] */
 310 {
 311         char *next;
 312         char *devnames[] = { "hda", "hdb", "sda", "sdb", "sdc", "sdd", "sde", "fd", "xda", "xdb", NULL };
 313         int devnums[]    = { 0x300, 0x340, 0x800, 0x810, 0x820, 0x830, 0x840, 0x200, 0xD00, 0xD40, 0};
 314         int args, envs;
 315 
 316         if (!*line)
 317                 return;
 318         args = 0;
 319         envs = 1;       /* TERM is set to 'console' by default */
 320         next = line;
 321         while ((line = next) != NULL) {
 322                 if ((next = strchr(line,' ')) != NULL)
 323                         *next++ = 0;
 324                 /*
 325                  * check for kernel options first..
 326                  */
 327                 if (!strncmp(line,"root=",5)) {
 328                         int n;
 329                         line += 5;
 330                         if (strncmp(line,"/dev/",5)) {
 331                                 ROOT_DEV = simple_strtoul(line,NULL,16);
 332                                 continue;
 333                         }
 334                         line += 5;
 335                         for (n = 0 ; devnames[n] ; n++) {
 336                                 int len = strlen(devnames[n]);
 337                                 if (!strncmp(line,devnames[n],len)) {
 338                                         ROOT_DEV = devnums[n]+simple_strtoul(line+len,NULL,0);
 339                                         break;
 340                                 }
 341                         }
 342                         continue;
 343                 }
 344                 if (!strcmp(line,"ro")) {
 345                         root_mountflags |= MS_RDONLY;
 346                         continue;
 347                 }
 348                 if (!strcmp(line,"rw")) {
 349                         root_mountflags &= ~MS_RDONLY;
 350                         continue;
 351                 }
 352                 if (!strcmp(line,"debug")) {
 353                         console_loglevel = 10;
 354                         continue;
 355                 }
 356                 if (!strcmp(line,"no-hlt")) {
 357                         hlt_works_ok = 0;
 358                         continue;
 359                 }
 360                 if (!strcmp(line,"no387")) {
 361                         hard_math = 0;
 362                         __asm__("movl %%cr0,%%eax\n\t"
 363                                 "orl $0xE,%%eax\n\t"
 364                                 "movl %%eax,%%cr0\n\t" : : : "ax");
 365                         continue;
 366                 }
 367                 if (checksetup(line))
 368                         continue;
 369                 /*
 370                  * Then check if it's an environment variable or
 371                  * an option.
 372                  */
 373                 if (strchr(line,'=')) {
 374                         if (envs >= MAX_INIT_ENVS)
 375                                 break;
 376                         envp_init[++envs] = line;
 377                 } else {
 378                         if (args >= MAX_INIT_ARGS)
 379                                 break;
 380                         argv_init[++args] = line;
 381                 }
 382         }
 383         argv_init[args+1] = NULL;
 384         envp_init[envs+1] = NULL;
 385 }
 386 
 387 static void copy_options(char * to, char * from)
     /* [previous][next][first][last][top][bottom][index][help] */
 388 {
 389         char c = ' ';
 390         int len = 0;
 391 
 392         for (;;) {
 393                 if (c == ' ' && *(unsigned long *)from == *(unsigned long *)"mem=")
 394                         memory_end = simple_strtoul(from+4, &from, 0);
 395                 c = *(from++);
 396                 if (!c)
 397                         break;
 398                 if (COMMAND_LINE_SIZE <= ++len)
 399                         break;
 400                 *(to++) = c;
 401         }
 402         *to = '\0';
 403 }
 404 
 405 static void copro_timeout(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 406 {
 407         fpu_error = 1;
 408         timer_table[COPRO_TIMER].expires = jiffies+100;
 409         timer_active |= 1<<COPRO_TIMER;
 410         printk("387 failed: trying to reset\n");
 411         send_sig(SIGFPE, last_task_used_math, 1);
 412         outb_p(0,0xf1);
 413         outb_p(0,0xf0);
 414 }
 415 
 416 static void check_fpu(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418         static double x = 4195835.0;
 419         static double y = 3145727.0;
 420         unsigned short control_word;
 421         extern int fdiv_bug;
 422 
 423         if (!hard_math) {
 424 #ifndef CONFIG_MATH_EMULATION
 425                 printk("No coprocessor found and no math emulation present.\n");
 426                 printk("Giving up.\n");
 427                 for (;;) ;
 428 #endif
 429                 return;
 430         }
 431         /*
 432          * check if exception 16 works correctly.. This is truly evil
 433          * code: it disables the high 8 interrupts to make sure that
 434          * the irq13 doesn't happen. But as this will lead to a lockup
 435          * if no exception16 arrives, it depends on the fact that the
 436          * high 8 interrupts will be re-enabled by the next timer tick.
 437          * So the irq13 will happen eventually, but the exception 16
 438          * should get there first..
 439          */
 440         printk("Checking 386/387 coupling... ");
 441         timer_table[COPRO_TIMER].expires = jiffies+50;
 442         timer_table[COPRO_TIMER].fn = copro_timeout;
 443         timer_active |= 1<<COPRO_TIMER;
 444         __asm__("clts ; fninit ; fnstcw %0 ; fwait":"=m" (*&control_word));
 445         control_word &= 0xffc0;
 446         __asm__("fldcw %0 ; fwait": :"m" (*&control_word));
 447         outb_p(inb_p(0x21) | (1 << 2), 0x21);
 448         __asm__("fldz ; fld1 ; fdiv %st,%st(1) ; fwait");
 449         timer_active &= ~(1<<COPRO_TIMER);
 450         if (fpu_error)
 451                 return;
 452         if (!ignore_irq13) {
 453                 printk("Ok, fpu using old IRQ13 error reporting\n");
 454                 return;
 455         }
 456         __asm__("fninit\n\t"
 457                 "fldl %1\n\t"
 458                 "fdivl %2\n\t"
 459                 "fmull %2\n\t"
 460                 "fldl %1\n\t"
 461                 "fsubp %%st,%%st(1)\n\t"
 462                 "fistpl %0\n\t"
 463                 "fwait\n\t"
 464                 "fninit"
 465                 : "=m" (*&fdiv_bug)
 466                 : "m" (*&x), "m" (*&y));
 467         if (!fdiv_bug) {
 468                 printk("Ok, fpu using exception 16 error reporting.\n");
 469                 return;
 470 
 471         }
 472         printk("Ok, FDIV bug i%c86 system\n", '0'+x86);
 473 }
 474 
 475 static void check_hlt(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 476 {
 477         printk("Checking 'hlt' instruction... ");
 478         if (!hlt_works_ok) {
 479                 printk("disabled\n");
 480                 return;
 481         }
 482         __asm__ __volatile__("hlt ; hlt ; hlt ; hlt");
 483         printk("Ok.\n");
 484 }
 485 
 486 static void check_bugs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 487 {
 488         check_fpu();
 489         check_hlt();
 490 }
 491 
 492 asmlinkage void start_kernel(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 493 {
 494 /*
 495  * Interrupts are still disabled. Do necessary setups, then
 496  * enable them
 497  */
 498         set_call_gate(&default_ldt,lcall7);
 499         ROOT_DEV = ORIG_ROOT_DEV;
 500         drive_info = DRIVE_INFO;
 501         screen_info = SCREEN_INFO;
 502         aux_device_present = AUX_DEVICE_INFO;
 503         memory_end = (1<<20) + (EXT_MEM_K<<10);
 504         memory_end &= PAGE_MASK;
 505         ramdisk_size = RAMDISK_SIZE;
 506         copy_options(command_line,COMMAND_LINE);
 507 #ifdef CONFIG_MAX_16M
 508         if (memory_end > 16*1024*1024)
 509                 memory_end = 16*1024*1024;
 510 #endif
 511         if (MOUNT_ROOT_RDONLY)
 512                 root_mountflags |= MS_RDONLY;
 513         if ((unsigned long)&end >= (1024*1024)) {
 514                 memory_start = (unsigned long) &end;
 515                 low_memory_start = PAGE_SIZE;
 516         } else {
 517                 memory_start = 1024*1024;
 518                 low_memory_start = (unsigned long) &end;
 519         }
 520         low_memory_start = PAGE_ALIGN(low_memory_start);
 521         memory_start = paging_init(memory_start,memory_end);
 522         if (strncmp((char*)0x0FFFD9, "EISA", 4) == 0)
 523                 EISA_bus = 1;
 524         trap_init();
 525         init_IRQ();
 526         sched_init();
 527         parse_options(command_line);
 528         init_modules();
 529 #ifdef CONFIG_PROFILE
 530         prof_buffer = (unsigned long *) memory_start;
 531         prof_len = (unsigned long) &end;
 532         prof_len >>= 2;
 533         memory_start += prof_len * sizeof(unsigned long);
 534 #endif
 535         memory_start = console_init(memory_start,memory_end);
 536         memory_start = bios32_init(memory_start,memory_end);
 537         memory_start = kmalloc_init(memory_start,memory_end);
 538         memory_start = chr_dev_init(memory_start,memory_end);
 539         memory_start = blk_dev_init(memory_start,memory_end);
 540         sti();
 541         calibrate_delay();
 542 #ifdef CONFIG_SCSI
 543         memory_start = scsi_dev_init(memory_start,memory_end);
 544 #endif
 545 #ifdef CONFIG_INET
 546         memory_start = net_dev_init(memory_start,memory_end);
 547 #endif
 548         memory_start = inode_init(memory_start,memory_end);
 549         memory_start = file_table_init(memory_start,memory_end);
 550         memory_start = name_cache_init(memory_start,memory_end);
 551         mem_init(low_memory_start,memory_start,memory_end);
 552         buffer_init();
 553         time_init();
 554         sock_init();
 555 #ifdef CONFIG_SYSVIPC
 556         ipc_init();
 557 #endif
 558         sti();
 559         check_bugs();
 560 
 561         system_utsname.machine[1] = '0' + x86;
 562         printk(linux_banner);
 563 
 564         move_to_user_mode();
 565         if (!fork())            /* we count on this going ok */
 566                 init();
 567 /*
 568  * task[0] is meant to be used as an "idle" task: it may not sleep, but
 569  * it might do some general things like count free pages or it could be
 570  * used to implement a reasonable LRU algorithm for the paging routines:
 571  * anything that can be useful, but shouldn't take time from the real
 572  * processes.
 573  *
 574  * Right now task[0] just does a infinite idle loop.
 575  */
 576         for(;;)
 577                 idle();
 578 }
 579 
 580 static int printf(const char *fmt, ...)
     /* [previous][next][first][last][top][bottom][index][help] */
 581 {
 582         va_list args;
 583         int i;
 584 
 585         va_start(args, fmt);
 586         write(1,printbuf,i=vsprintf(printbuf, fmt, args));
 587         va_end(args);
 588         return i;
 589 }
 590 
 591 void init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 592 {
 593         int pid,i;
 594 
 595         setup();
 596         sprintf(term, "TERM=con%dx%d", ORIG_VIDEO_COLS, ORIG_VIDEO_LINES);
 597 
 598         #ifdef CONFIG_UMSDOS_FS
 599         {
 600                 /*
 601                         When mounting a umsdos fs as root, we detect
 602                         the pseudo_root (/linux) and initialise it here.
 603                         pseudo_root is defined in fs/umsdos/inode.c
 604                 */
 605                 extern struct inode *pseudo_root;
 606                 if (pseudo_root != NULL){
 607                         current->fs->root = pseudo_root;
 608                         current->fs->pwd  = pseudo_root;
 609                 }
 610         }
 611         #endif
 612 
 613         (void) open("/dev/tty1",O_RDWR,0);
 614         (void) dup(0);
 615         (void) dup(0);
 616 
 617         execve("/etc/init",argv_init,envp_init);
 618         execve("/bin/init",argv_init,envp_init);
 619         execve("/sbin/init",argv_init,envp_init);
 620         /* if this fails, fall through to original stuff */
 621 
 622         if (!(pid=fork())) {
 623                 close(0);
 624                 if (open("/etc/rc",O_RDONLY,0))
 625                         _exit(1);
 626                 execve("/bin/sh",argv_rc,envp_rc);
 627                 _exit(2);
 628         }
 629         if (pid>0)
 630                 while (pid != wait(&i))
 631                         /* nothing */;
 632         while (1) {
 633                 if ((pid = fork()) < 0) {
 634                         printf("Fork failed in init\n\r");
 635                         continue;
 636                 }
 637                 if (!pid) {
 638                         close(0);close(1);close(2);
 639                         setsid();
 640                         (void) open("/dev/tty1",O_RDWR,0);
 641                         (void) dup(0);
 642                         (void) dup(0);
 643                         _exit(execve("/bin/sh",argv,envp));
 644                 }
 645                 while (1)
 646                         if (pid == wait(&i))
 647                                 break;
 648                 printf("\n\rchild %d died with code %04x\n\r",pid,i);
 649                 sync();
 650         }
 651         _exit(0);
 652 }

/* [previous][next][first][last][top][bottom][index][help] */