Orion
Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)/* * This file handles signals to tasks. It handles blocking signals, and * registering the signal handlers. It send/dispatches signals to tasks and * runs the registered signal handlers when appropriate. */ #include <stdint.h> #include <errno.h> #include "task.h" extern TaskQueue tasks; /* Handle the signals for a task */ void handle_signals(void) { if (!(current->sigset & ~current->blockedSignals)) return; int signal; for (signal = 0; signal < 32; signal++) { if (!(current->sigset & (1 << (signal - 1)))) continue; current->status = signal; terminate(); } } /* Send a signal to a thread */ int tgkill(pid_t tgid, pid_t tid, int sig) { if (sig < 0 || sig > 31) return -EINVAL; Task *task = find_task(tid); if (!task || task->tgid != tgid) return -ESRCH; if (sig) task->sigset |= (1 << (sig - 1)); return 0; } /* Send a signal to a process */ int kill(pid_t pid, int sig) { if (sig < 0 || sig > 31) return -EINVAL; int sent = 0; Task *task; for (task = tasks.start; task; task = task->tnext) { if (task->tgid != pid) continue; if (sig) task->sigset |= (1 << (sig - 1)); sent++; } return sent ? 0 : -ESRCH; }