signal: way to signal all processes

This commit is contained in:
Matheus
2024-09-05 16:36:52 -03:00
parent c2e50547cc
commit 2e302a4d38
3 changed files with 29 additions and 6 deletions
+1
View File
@@ -166,5 +166,6 @@ void sched_sleepus(size_t us);
void sched_apentry(); void sched_apentry();
void sched_inactiveproc(proc_t *proc); void sched_inactiveproc(proc_t *proc);
void sched_terminateprogram(int status); void sched_terminateprogram(int status);
int sched_signalall(int signal, proc_t *sender);
#endif #endif
+25
View File
@@ -12,6 +12,7 @@
#include <kernel/devfs.h> #include <kernel/devfs.h>
#include <kernel/jobctl.h> #include <kernel/jobctl.h>
#include <kernel/cmdline.h> #include <kernel/cmdline.h>
#include <kernel/auth.h>
#define QUANTUM_US 100000 #define QUANTUM_US 100000
#define SCHEDULER_STACK_SIZE PAGE_SIZE * 16 #define SCHEDULER_STACK_SIZE PAGE_SIZE * 16
@@ -49,6 +50,30 @@ proc_t *sched_getprocfrompid(int pid) {
return proc; return proc;
} }
int sched_signalall(int signal, proc_t *sender) {
MUTEX_ACQUIRE(&sched_pidtablemutex, false);
pid_t senderpgid = sender ? jobctl_getpgid(sender) : 0;
size_t donecount = 0;
HASHTABLE_FOREACH(&pidtable) {
proc_t *current = entry->value;
// init does not get signaled
if (current->pid == 1)
continue;
pid_t currentpgid = jobctl_getpgid(current);
if (senderpgid == 0 || (signal == SIGCONT && currentpgid == senderpgid) || auth_process_check(&sender->cred, AUTH_ACTIONS_PROCESS_SIGNAL, current)) {
++donecount;
signal_signalproc(current, signal);
}
}
MUTEX_RELEASE(&sched_pidtablemutex);
return donecount == 0 ? EPERM : 0;
}
static void rtdpc(context_t *, dpcarg_t arg) { static void rtdpc(context_t *, dpcarg_t arg) {
signal_signalproc(arg, SIGALRM); signal_signalproc(arg, SIGALRM);
} }
+3 -6
View File
@@ -19,14 +19,9 @@ syscallret_t syscall_kill(context_t *context, int pid, int signal) {
effectivepid = -1; effectivepid = -1;
else if (pid < -1) else if (pid < -1)
effectivepid = -pid; // target specific process group effectivepid = -pid; // target specific process group
if (effectivepid == -1) {
ret.errno = ESRCH;
return ret;
}
proc_t *target = sched_getprocfrompid(effectivepid); proc_t *target = sched_getprocfrompid(effectivepid);
if (target == NULL && pid != 0) { if (target == NULL && pid != 0 && pid != -1) {
ret.errno = ESRCH; ret.errno = ESRCH;
return ret; return ret;
} }
@@ -43,6 +38,8 @@ syscallret_t syscall_kill(context_t *context, int pid, int signal) {
} }
signal_signalproc(target, signal); signal_signalproc(target, signal);
} else if (pid == -1) {
ret.errno = sched_signalall(signal, _cpu()->thread->proc);
} else { } else {
ret.errno = jobctl_signal(target, signal, _cpu()->thread->proc); ret.errno = jobctl_signal(target, signal, _cpu()->thread->proc);
} }