mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
Implement basic sys$kill() and add a /bin/kill
All it can do right now is send SIGKILL which just murders the target task.
This commit is contained in:
parent
7be30a2fa8
commit
3218f00099
10 changed files with 117 additions and 9 deletions
|
@ -80,7 +80,6 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
|
|||
kprintf("syscall: seek(%d, %d)\n", arg1, arg2);
|
||||
return current->sys$seek((int)arg1, (int)arg2);
|
||||
case Syscall::PosixKill:
|
||||
kprintf("syscall: kill(%d, %d)\n", arg1, arg2);
|
||||
return current->sys$kill((pid_t)arg1, (int)arg2);
|
||||
case Syscall::PosixGetuid:
|
||||
return current->sys$getuid();
|
||||
|
|
|
@ -513,6 +513,24 @@ void Task::sys$exit(int status)
|
|||
switchNow();
|
||||
}
|
||||
|
||||
void Task::murder()
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
bool wasCurrent = current == this;
|
||||
setState(Exiting);
|
||||
s_tasks->remove(this);
|
||||
if (wasCurrent) {
|
||||
MM.unmapRegionsForTask(*this);
|
||||
if (!scheduleNewTask()) {
|
||||
kprintf("Task::murder: Failed to schedule a new task :(\n");
|
||||
HANG;
|
||||
}
|
||||
}
|
||||
s_deadTasks->append(this);
|
||||
if (wasCurrent)
|
||||
switchNow();
|
||||
}
|
||||
|
||||
void Task::taskDidCrash(Task* crashedTask)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
|
@ -749,7 +767,7 @@ int Task::sys$seek(int fd, int offset)
|
|||
{
|
||||
auto* handle = fileHandleIfExists(fd);
|
||||
if (!handle)
|
||||
return -EBADF;
|
||||
return -1;
|
||||
return handle->seek(offset, SEEK_SET);
|
||||
}
|
||||
|
||||
|
@ -924,11 +942,15 @@ int Task::sys$kill(pid_t pid, int sig)
|
|||
// FIXME: Send to all processes.
|
||||
ASSERT(pid != -1);
|
||||
}
|
||||
ASSERT_NOT_REACHED();
|
||||
Task* peer = Task::fromPID(pid);
|
||||
if (!peer) {
|
||||
// errno = ESRCH;
|
||||
return -1;
|
||||
ASSERT(pid != current->pid()); // FIXME: Support this scenario.
|
||||
InterruptDisabler disabler;
|
||||
auto* peer = Task::fromPID(pid);
|
||||
if (!peer)
|
||||
return -ESRCH;
|
||||
if (sig == 9) {
|
||||
peer->murder();
|
||||
} else {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -216,6 +216,8 @@ private:
|
|||
|
||||
pid_t m_parentPID { 0 };
|
||||
|
||||
void murder();
|
||||
|
||||
Vector<String> m_arguments;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ cp ../Userland/uname mnt/bin/uname
|
|||
cp ../Userland/clear mnt/bin/clear
|
||||
cp ../Userland/tst mnt/bin/tst
|
||||
cp ../Userland/mm mnt/bin/mm
|
||||
cp ../Userland/kill mnt/bin/kill
|
||||
cp kernel.map mnt/
|
||||
umount mnt
|
||||
sync
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue