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

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