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

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