Browse Source

feat(init): open all three file descriptors

greatbridf 2 năm trước cách đây
mục cha
commit
5ca22c8baf
1 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 10 0
      user-space-program/init.c

+ 10 - 0
user-space-program/init.c

@@ -1,12 +1,22 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <sys/wait.h>
 
 #define print(str) write(STDERR_FILENO, str, strlen(str))
 
 int main(int argc, char** argv)
 {
+    int fd = 0;
+    // Assumes three file descriptors open.
+    while((fd = open("/dev/console", 0)) >= 0){
+        if(fd >= 3){
+            close(fd);
+            break;
+        }
+    }
+
     print("***** GBOS INIT SYSTEM *****\n");
 
 _run_sh:;