]> git.corax.cc Git - corax/commitdiff
kernel/core: Execute system processes from initfs once the kernel has been initialized
authorMatthias Kruk <m@m10k.eu>
Tue, 5 May 2020 17:24:55 +0000 (02:24 +0900)
committerMatthias Kruk <m@m10k.eu>
Tue, 5 May 2020 17:24:55 +0000 (02:24 +0900)
kernel/core/main.c

index dbadad8626abf449c5e698a11866e9f006d983ee..4f94974186d9a71d4b23d1bf0b1d1b9de4f2da38 100644 (file)
@@ -29,6 +29,7 @@
 #include <sched.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <stdio.h>
 
 void cpu_debug(void);
 int arch_init(void*);
@@ -116,6 +117,7 @@ static void _init(void)
 {
        pid_t pid;
        int err;
+       int i;
 
        /*
         * Instead of something like /sbin/init, this process will behave more
@@ -123,35 +125,54 @@ static void _init(void)
         * spawn the daemons necessary for basic system operation, and restart
         * them in case they should die.
         */
-#if 0
-       pid = fork();
 
-       if(!pid) {
-               /* this is the child */
-               err = execfve(vga_main, NULL, NULL);
+       for(i = 0; i < initfs.ifs_num_entries; i++) {
+               char buffer[128];
+               int len;
 
-               if(err < 0) {
-                       for(;;);
-               }
-       } else if(pid < 0) {
-               /* FIXME: Handle error */
-       }
-#endif
-       pid = fork();
+               len = snprintf(buffer, sizeof(buffer), "Executing %s\n",
+                              initfs.ifs_entries[i].ife_name);
+
+               debug(buffer, len);
+
+               pid = fork();
+
+               len = snprintf(buffer, sizeof(buffer), "pid = %08u\n", pid);
+               debug(buffer, len);
+
+               if(!pid) {
+                       char argv1[16];
+                       char argv0[16];
+                       char *argv[3];
+                       char env1[16];
+                       char env0[16];
+                       char *envp[3];
 
-       if(!pid) {
-               err = execfve(kbd_main, NULL, NULL);
+                       snprintf(argv0, sizeof(argv0), "%s", initfs.ifs_entries[i].ife_name);
+                       snprintf(argv1, sizeof(argv1), "--verbose");
 
-               if(err < 0) {
-                       for(;;);
+                       argv[0] = argv0;
+                       argv[1] = argv1;
+                       argv[2] = NULL;
+
+                       snprintf(env0, sizeof(env0), "PWD=/");
+                       snprintf(env1, sizeof(env1), "USER=root");
+
+                       envp[0] = env0;
+                       envp[1] = env1;
+                       envp[2] = NULL;
+
+                       err = execeve(initfs.ifs_entries[i].ife_base,
+                                     initfs.ifs_entries[i].ife_limit,
+                                     argv, envp);
+
+                       if(err < 0) {
+                               debug("execeve failed\n", 15);
+                       }
                }
-       } else if(pid < 0) {
-               /* FIXME: Handle error */
        }
 
-       while(1) {
-               wait(NULL);
-       }
+       while(1);
 
        return;
 }