init.c (934B)
1 #include <libc.h> 2 3 #define msg_clear "\033[2J\033[H" 4 5 #define msg_welcome "[init] starting...\n" 6 #define msg_proc "[init] mouting /proc...\n" 7 #define msg_sys "[init] mouting /sys...\n" 8 #define msg_dev "[init] mouting /dev...\n" 9 10 int main(void) { 11 write(stdout, msg_clear, strlen(msg_clear)); 12 13 write(stdout, msg_welcome, strlen(msg_welcome)); 14 15 write(stdout, msg_proc, strlen(msg_proc)); 16 mount("proc", "/proc", "proc", 0, NULL); 17 18 write(stdout, msg_sys, strlen(msg_sys)); 19 mount("sysfs", "/sys", "sysfs", 0, NULL); 20 21 write(stdout, msg_dev, strlen(msg_dev)); 22 mount("devtmpfs", "/dev", "devtmpfs", 0, NULL); 23 24 int pid = fork(); 25 if (pid == 0) { 26 char *argv[] = { "/bin/sh", NULL }; 27 char *envp[] = { "PATH=/bin:/sbin", NULL }; 28 29 execve("/bin/sh", argv, envp); 30 31 write(stderr, "[init] Failed to exec /bin/sh!\n", 31); 32 exit(1); 33 } 34 35 while (1) { 36 int status; 37 waitpid(-1, &status, 0); 38 } 39 return 0; 40 }