2006-08-11 13:55:18 +00:00
|
|
|
#include "types.h"
|
2006-08-15 15:53:46 +00:00
|
|
|
#include "stat.h"
|
|
|
|
#include "user.h"
|
2006-08-11 13:55:18 +00:00
|
|
|
#include "fs.h"
|
|
|
|
#include "fcntl.h"
|
|
|
|
|
2006-09-06 17:50:20 +00:00
|
|
|
// init: The initial user-level program
|
2006-08-28 18:31:33 +00:00
|
|
|
|
2006-08-11 13:55:18 +00:00
|
|
|
char *sh_args[] = { "sh", 0 };
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
int pid;
|
2006-09-06 17:27:19 +00:00
|
|
|
|
2006-08-29 19:06:37 +00:00
|
|
|
if(open("console", O_RDWR) < 0){
|
2006-08-11 13:55:18 +00:00
|
|
|
mknod("console", T_DEV, 1, 1);
|
2006-08-29 19:06:37 +00:00
|
|
|
open("console", O_RDWR);
|
2006-08-11 13:55:18 +00:00
|
|
|
}
|
2006-09-08 14:36:44 +00:00
|
|
|
dup(0); // stdout
|
|
|
|
dup(0); // stderr
|
2006-08-11 13:55:18 +00:00
|
|
|
|
2006-09-06 18:47:51 +00:00
|
|
|
for(;;){
|
2006-08-11 13:55:18 +00:00
|
|
|
pid = fork();
|
2006-08-29 19:06:37 +00:00
|
|
|
if(pid < 0){
|
|
|
|
puts("init: fork failed\n");
|
|
|
|
exit();
|
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
if(pid == 0){
|
|
|
|
exec("sh", sh_args);
|
2006-08-29 19:06:37 +00:00
|
|
|
puts("init: exec sh failed\n");
|
2006-08-11 13:55:18 +00:00
|
|
|
exit();
|
2006-08-29 19:06:37 +00:00
|
|
|
} else {
|
2006-08-11 13:55:18 +00:00
|
|
|
wait();
|
2006-08-29 19:06:37 +00:00
|
|
|
}
|
2006-08-11 13:55:18 +00:00
|
|
|
}
|
|
|
|
}
|