1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 18:57:42 +00:00

Kernel: kill() with signal 0 should not actually send anything

Also kill() with pid 0 should send to everyone in the same process
group as the calling process.
This commit is contained in:
Andreas Kling 2020-01-03 02:01:45 +01:00
parent 8345f51a24
commit 005313df82

View file

@ -1740,7 +1740,8 @@ KResult Process::do_kill(Process& process, int signal)
kprintf("%s(%u) attempted to send SIGKILL to ring 0 process %s(%u)\n", name().characters(), m_pid, process.name().characters(), process.pid()); kprintf("%s(%u) attempted to send SIGKILL to ring 0 process %s(%u)\n", name().characters(), m_pid, process.name().characters(), process.pid());
return KResult(-EPERM); return KResult(-EPERM);
} }
process.send_signal(signal, this); if (signal != 0)
process.send_signal(signal, this);
return KSuccess; return KSuccess;
} }
@ -1781,17 +1782,21 @@ int Process::sys$kill(pid_t pid, int signal)
{ {
if (signal < 0 || signal >= 32) if (signal < 0 || signal >= 32)
return -EINVAL; return -EINVAL;
if (pid <= 0) { if (pid == 0)
return do_killpg(m_pgid, signal);
if (pid < 0)
return do_killpg(-pid, signal); return do_killpg(-pid, signal);
}
if (pid == -1) { if (pid == -1) {
// FIXME: Send to all processes. // FIXME: Send to all processes.
ASSERT(pid != -1); return -ENOTIMPL;
} }
if (pid == m_pid) { if (pid == m_pid) {
// FIXME: If we ignore this signal anyway, we don't need to block here, right? if (signal == 0)
current->send_signal(signal, this); return 0;
(void)current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal); if (!current->should_ignore_signal(signal)) {
current->send_signal(signal, this);
(void)current->block<Thread::SemiPermanentBlocker>(Thread::SemiPermanentBlocker::Reason::Signal);
}
return 0; return 0;
} }
InterruptDisabler disabler; InterruptDisabler disabler;