summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2020-08-09 15:23:31 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-10 11:51:45 +0200
commit083671ef2ccc1fa9e9e2d0f6c8db106ddcf53203 (patch)
tree36e352d7a7eedebcd9d5de429ef94c5350a74906
parentbee08a4b9ff0f2c269a4e3a8159b689fbb8d1ab8 (diff)
downloadserenity-083671ef2ccc1fa9e9e2d0f6c8db106ddcf53203.zip
Kernel: Fix PID/TID confusion in send_signal
This fixes the issue of a specific type of unkillable processes.
-rw-r--r--Kernel/Process.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index d286949cb0..cb5bd298c5 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -790,9 +790,20 @@ void Process::terminate_due_to_signal(u8 signal)
KResult Process::send_signal(u8 signal, Process* sender)
{
InterruptDisabler disabler;
- // FIXME: PID/TID BUG
- if (auto* thread = Thread::from_tid(m_pid.value())) {
- thread->send_signal(signal, sender);
+ Thread* receiver_thread;
+ // Try to send it to the "obvious" main thread:
+ receiver_thread = Thread::from_tid(m_pid.value());
+ // If the main thread has died, there may still be other threads:
+ if (!receiver_thread) {
+ // The first one should be good enough.
+ // Neither kill(2) nor kill(3) specify any selection precedure.
+ for_each_thread([&receiver_thread](Thread& thread) -> IterationDecision {
+ receiver_thread = &thread;
+ return IterationDecision::Break;
+ });
+ }
+ if (receiver_thread) {
+ receiver_thread->send_signal(signal, sender);
return KSuccess;
}
return KResult(-ESRCH);