Only bother to deliver non-ignored blocked signals

So we don't accidentally interrupt a read or something.
This commit is contained in:
Kevin Lange 2014-04-29 00:52:36 -07:00
parent 5d4b0df120
commit e16043684a
2 changed files with 44 additions and 38 deletions

View File

@ -174,3 +174,47 @@ void fix_signal_stacks(void) {
switch_next();
}
}
int send_signal(pid_t process, uint32_t signal) {
process_t * receiver = process_from_pid(process);
if (!receiver) {
/* Invalid pid */
return 1;
}
if (receiver->user != current_process->user && current_process->user != USER_ROOT_UID) {
/* No way in hell. */
return 1;
}
if (signal > NUMSIGNALS) {
/* Invalid signal */
return 1;
}
if (receiver->finished) {
/* Can't send signals to finished processes */
return 1;
}
if (!receiver->signals.functions[signal] && !isdeadly[signal]) {
/* If we're blocking a signal and it's not going to kill us, don't deliver it */
return 1;
}
/* Append signal to list */
signal_t * sig = malloc(sizeof(signal_t));
sig->handler = (uintptr_t)receiver->signals.functions[signal];
sig->signum = signal;
memset(&sig->registers_before, 0x00, sizeof(regs_t));
if (!process_is_ready(receiver)) {
make_process_ready(receiver);
}
list_insert(receiver->signal_queue, sig);
return 0;
}

View File

@ -376,44 +376,6 @@ static int uname(struct utsname * name) {
return 0;
}
int send_signal(pid_t process, uint32_t signal) {
process_t * receiver = process_from_pid(process);
if (!receiver) {
/* Invalid pid */
return 1;
}
if (receiver->user != current_process->user && current_process->user != USER_ROOT_UID) {
/* No way in hell. */
return 1;
}
if (signal > NUMSIGNALS) {
/* Invalid signal */
return 1;
}
if (receiver->finished) {
/* Can't send signals to finished processes */
return 1;
}
/* Append signal to list */
signal_t * sig = malloc(sizeof(signal_t));
sig->handler = (uintptr_t)receiver->signals.functions[signal];
sig->signum = signal;
memset(&sig->registers_before, 0x00, sizeof(regs_t));
if (!process_is_ready(receiver)) {
make_process_ready(receiver);
}
list_insert(receiver->signal_queue, sig);
return 0;
}
static uintptr_t sys_signal(uint32_t signum, uintptr_t handler) {
if (signum > NUMSIGNALS) {
return -1;