summaryrefslogtreecommitdiff
path: root/init.c
blob: 359f1fbe13587b9092cb74e3388bc1d275af0c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "fcntl.h"

/* The initial user-level program */

char *sh_args[] = { "sh", 0 };

int
main(void)
{
  int pid;
  
  if(open("console", O_RDWR) < 0){
    mknod("console", T_DEV, 1, 1);
    open("console", O_RDWR);
  }
  dup(0);
  dup(0);

  while(1){
    pid = fork();
    if(pid < 0){
      puts("init: fork failed\n");
      exit();
    }
    if(pid == 0){
      exec("sh", sh_args);
      puts("init: exec sh failed\n");
      exit();
    } else {
      wait();
    }
  }
}