summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2022-04-11 23:00:21 +0200
committerdzwdz2022-04-11 23:00:21 +0200
commit4ebebf6d842e919db5c7499ee3b7cc738980cf25 (patch)
treeadf25148781b089a003e51250c81413fe921cff1 /src
parent5947b9c89b753b32d2e56b6c9ab2f62bbe09310b (diff)
kernel: shutdown when init quits
thanks to this it's easier to power off - instead of waiting for all processses to quit (which now involves writing `quit` both on serial and ps/2), one of those can just somehow kill init. currently this is just done by exiting from any shell - init will return from await and exit too
Diffstat (limited to 'src')
-rw-r--r--src/init/main.c6
-rw-r--r--src/kernel/proc.c5
2 files changed, 7 insertions, 4 deletions
diff --git a/src/init/main.c b/src/init/main.c
index 200d8bd..b5ef22f 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -56,10 +56,8 @@ int main(void) {
__stdout = _syscall_open(argify("/com1"));
if (__stdout < 0) __stdout = _syscall_open(argify("/vga_tty"));
- for (;;) {
- _syscall_await();
- printf("init: something quit\n");
- }
+ _syscall_await();
+ printf("init: something quit\n");
_syscall_exit(0);
}
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index cf5bb1e..74660fa 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -137,6 +137,11 @@ void process_kill(struct process *proc, int ret) {
proc->state = PS_DEAD;
proc->death_msg = ret;
process_try2collect(proc);
+ if (proc == process_first) {
+ tty_const("init killed, quitting...");
+ mem_debugprint();
+ cpu_shutdown();
+ }
}
int process_try2collect(struct process *dead) {