From 3c62c32ca502a9a68b312814ed807bbe254d136d Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 23 Nov 2019 15:45:24 +0900 Subject: [PATCH] Make use of fork() and execfve() to spawn STDIO and NET daemons --- kernel/core/main.c | 45 ++++++++++++++++++++++++++++++++++++++++----- kernel/core/net.c | 4 ++++ kernel/core/stdio.c | 3 +++ 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/kernel/core/main.c b/kernel/core/main.c index 8ef8527..45dbb3d 100644 --- a/kernel/core/main.c +++ b/kernel/core/main.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include 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"); diff --git a/kernel/core/net.c b/kernel/core/net.c index bbcb3f4..3510057 100644 --- a/kernel/core/net.c +++ b/kernel/core/net.c @@ -2,6 +2,8 @@ #include #include +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 */ diff --git a/kernel/core/stdio.c b/kernel/core/stdio.c index fce868d..4af8b34 100644 --- a/kernel/core/stdio.c +++ b/kernel/core/stdio.c @@ -2,6 +2,8 @@ #include #include +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 */ -- 2.47.3