From d34bd9a45440be2ef65d24619af5505b8c05c229 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 21 Sep 2021 17:26:36 +0200 Subject: make await() fail gracefully when callee has no alive children already --- src/kernel/syscalls.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 0ca7867..ac21cdb 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -39,22 +39,26 @@ _Noreturn void _syscall_exit(const char __user *msg, size_t len) { } int _syscall_await(char __user *buf, int len) { + bool has_children = false; process_current->state = PS_WAITS4CHILDDEATH; process_current->death_msg.buf = buf; process_current->death_msg.len = len; // find any already dead children for (struct process *iter = process_current->child; - iter; iter = iter->sibling) - { + iter; iter = iter->sibling) { if (iter->state == PS_DEAD) await_finish(iter, process_current); // doesn't return + if (iter->state != PS_DEADER) + has_children = true; } - // no dead children yet - // TODO check if the process even has children - - process_switch_any(); + if (has_children) + process_switch_any(); // wait until a child dies + else { + process_current->state = PS_RUNNING; + return -1; // error + } } int _syscall_fork(void) { -- cgit v1.2.3