From c8b308910efa1523f24a935e8d1d38ceb316637f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 7 Nov 2018 19:03:44 +0100 Subject: [PATCH] Signals to processes in userspace now work again. Ugh, how am I going to dispatch signals to processes in the kernel? --- Kernel/Process.cpp | 4 +++- Userland/sh.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 2468c8814bc..4071203e676 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -789,7 +789,7 @@ void Process::dispatch_signal(byte signal) if ((ret_cs & 3) == 0) { // FIXME: Handle send_signal to process currently in kernel code. - kprintf("Boo! dispatch_signal with return to %w:%x\n", ret_cs, ret_eip); + kprintf("Boo! dispatch_signal in %s(%u) with return to %w:%x\n", name().characters(), pid(), ret_cs, ret_eip); ASSERT_NOT_REACHED(); } @@ -827,6 +827,8 @@ void Process::dispatch_signal(byte signal) push_value_on_stack(m_return_from_signal_trampoline.get()); + m_pending_signals &= ~(1 << signal); + dbgprintf("signal: Okay, %s(%u) has been primed\n", name().characters(), pid()); } diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 5d8c224b9a4..19870439644 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -33,10 +33,17 @@ static int sh_pwd(int, const char**) return 0; } +static volatile bool g_got_signal = false; + void did_receive_signal(int signum) { printf("\nMy word, I've received a signal with number %d\n", signum); - //exit(0); + g_got_signal = true; +} + +void handle_sigint(int signum) +{ + printf("Interrupt received by sh\n"); } static int sh_busy(int, const char**) @@ -48,11 +55,14 @@ static int sh_busy(int, const char**) sa.sa_restorer = nullptr; int rc = sigaction(SIGUSR1, &sa, nullptr); assert(rc == 0); - printf("listening for SIGUSR1 while looping in userspace...\n"); + printf("listening for signal SIGUSR1 while looping in userspace...\n"); for (;;) { for (volatile int i = 0; i < 100000; ++i) ; + if (g_got_signal) + break; } + g_got_signal = false; return 0; } @@ -280,6 +290,16 @@ int main(int, char**) g->sid = setsid(); tcsetpgrp(0, getpgrp()); + { + struct sigaction sa; + sa.sa_handler = handle_sigint; + sa.sa_flags = 0; + sa.sa_mask = 0; + sa.sa_restorer = nullptr; + int rc = sigaction(SIGINT, &sa, nullptr); + assert(rc == 0); + } + int rc = gethostname(g->hostname, sizeof(g->hostname)); if (rc < 0) perror("gethostname");