-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit.c
42 lines (36 loc) · 785 Bytes
/
init.c
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
38
39
40
41
42
// init: The initial user-level program
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
char *argv[] = { "login", 0 };
char *envp[] = { "PATH=/bin/", 0 };
int
main(void)
{
int pid, wpid;
if(open("console", O_RDWR) < 0){
mknod("console", 1, 1, 0666);
open("console", O_RDWR);
}
dup(0); // stdout
dup(0); // stderr
mkdir("/proc", 0555);
mount("/proc", "proc");
for(;;){
printf(1, "init: starting login\n");
pid = fork();
if(pid < 0){
printf(1, "init: fork failed\n");
exit();
}
if(pid == 0){
umask(022);
execve("/bin/login", argv, envp);
printf(1, "init: exec login failed\n");
exit();
}
while((wpid=wait()) >= 0 && wpid != pid)
printf(1, "zombie!\n");
}
}