From 0e7f85c24a05bdda1c46b80b495bd8a1b88f67c7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 May 2020 12:33:48 +0200 Subject: Kernel: Sending a signal to a process now goes to the main thread Instead of falling back to the suspicious "any_thread()" mechanism, just fail with ESRCH if you try to kill() a PID that doesn't have a corresponding TID. --- Kernel/Process.cpp | 15 +++++++-------- Kernel/Process.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index ce2c65a6d5..e32ed3c116 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2179,7 +2179,7 @@ KResult Process::do_kill(Process& process, int signal) return KResult(-EPERM); } if (signal != 0) - process.send_signal(signal, this); + return process.send_signal(signal, this); return KSuccess; } @@ -3781,15 +3781,14 @@ void Process::terminate_due_to_signal(u8 signal) die(); } -void Process::send_signal(u8 signal, Process* sender) +KResult Process::send_signal(u8 signal, Process* sender) { InterruptDisabler disabler; - if (!m_thread_count) - return; - auto* thread = Thread::from_tid(m_pid); - if (!thread) - thread = &any_thread(); - thread->send_signal(signal, sender); + if (auto* thread = Thread::from_tid(m_pid)) { + thread->send_signal(signal, sender); + return KSuccess; + } + return KResult(-ESRCH); } int Process::sys$create_thread(void* (*entry)(void*), const Syscall::SC_create_thread_params* user_params) diff --git a/Kernel/Process.h b/Kernel/Process.h index 620c8ef82c..29d6f6c17d 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -382,7 +382,7 @@ public: bool is_being_inspected() const { return m_inspector_count; } void terminate_due_to_signal(u8 signal); - void send_signal(u8, Process* sender); + KResult send_signal(u8 signal, Process* sender); u16 thread_count() const { return m_thread_count; } -- cgit v1.2.3