]> git.corax.cc Git - corax/commitdiff
Make use of fork() and execfve() to spawn STDIO and NET daemons
authorMatthias Kruk <m@m10k.eu>
Sat, 23 Nov 2019 06:45:24 +0000 (15:45 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 23 Nov 2019 06:45:24 +0000 (15:45 +0900)
kernel/core/main.c
kernel/core/net.c
kernel/core/stdio.c

index 8ef85278488608bb3932bf9d1173ee255c75b4df..45dbb3da1afa8dedaf4aa7be9129eef3fb499954 100644 (file)
@@ -23,6 +23,8 @@
 #include <arch.h>
 #include <process.h>
 #include <sys/socket.h>
+#include <crxstd.h>
+#include <unistd.h>
 
 void cpu_debug(void);
 int arch_init(void*);
@@ -97,8 +99,7 @@ static void _idle(void)
 
 static void _init(void)
 {
-       process_t *stdio;
-       process_t *net;
+       pid_t pid;
        int err;
 
        /*
@@ -107,6 +108,39 @@ static void _init(void)
         * operation, and restart them in case they should die.
         */
 
+       pid = fork();
+
+       if(!pid) {
+               /* this is the child */
+               err = execfve(_stdio, NULL, NULL);
+
+               if(err < 0) {
+                       /* FIXME: Print an error message */
+
+                       for(;;);
+               }
+       } else if(pid < 0) {
+               /* FIXME: Print an error message */
+               for(;;);
+       }
+
+       pid = fork();
+
+       if(!pid) {
+               /* this is the child */
+               err = execfve(_net, NULL, NULL);
+
+               if(err < 0) {
+                       /* FIXME: Print an error message */
+                       for(;;);
+               }
+       } else if(pid < 0) {
+               /* FIXME: Print an error message */
+               for(;;);
+       }
+
+#if 0
+
        err = process_create(&stdio, PID_STDIO, 3, (void*)_stdio);
 
        if(err < 0) {
@@ -119,8 +153,9 @@ static void _init(void)
                dbg_printf("Failed to start NET process [err=0x%08x]\n", err);
        }
 
-       /* For now, only start them once */
-       _idle();
+#endif /* 0 */
+
+       wait(NULL);
 
        return;
 }
@@ -207,7 +242,7 @@ int corax(void *mb_info, u32_t magic)
                PANIC("Could not spawn idle process\n");
        }
 
-       err = process_create(&proc, PID_ANY, 0, (void*)_init);
+       err = process_create(&proc, PID_ANY, 3, (void*)_init);
 
        if(err < 0) {
                PANIC("Could not spawn init process\n");
index bbcb3f44ea48a00c661e50f9a4108af22878dc13..3510057891b46ad4aa0d6a56587d8b9fe7c50426 100644 (file)
@@ -2,6 +2,8 @@
 #include <crxstd.h>
 #include <corax/errno.h>
 
+extern int wait(int*);
+
 void _net(void)
 {
        struct cxmsg msg;
@@ -10,6 +12,8 @@ void _net(void)
        while(1) {
                len = cxrecv(PID_ANY, &msg);
 
+               len = 0;
+
                if(len > 0) {
                        /* FIXME: handle message */
 
index fce868dfa81af214f1181946db47607842e2d9dc..4af8b34e4b46c3f7439504bfe66bb302ac2b48c0 100644 (file)
@@ -2,6 +2,8 @@
 #include <crxstd.h>
 #include <corax/errno.h>
 
+extern int wait(int*);
+
 void _stdio(void)
 {
        struct cxmsg msg;
@@ -9,6 +11,7 @@ void _stdio(void)
 
        while(1) {
                err = cxrecv(PID_ANY, &msg);
+               err = 0;
 
                if(err > 0) {
                        /* FIXME: Handle message */