job control: sessions and process groups

This commit is contained in:
Matheus
2024-05-01 21:42:38 -03:00
parent 1f848fe596
commit 05049a091f
13 changed files with 484 additions and 18 deletions
+2 -1
View File
@@ -3,8 +3,8 @@
#include <errno.h>
#include <kernel/file.h>
#include <kernel/interrupt.h>
#include <kernel/jobctl.h>
#include <logging.h>
syscallret_t syscall_fork(context_t *ctx) {
syscallret_t ret = {
.ret = -1,
@@ -53,6 +53,7 @@ syscallret_t syscall_fork(context_t *ctx) {
CTX_RET(&nthread->context) = 0;
CTX_ERRNO(&nthread->context) = 0;
jobctl_addproc(proc, nproc);
ret.ret = nproc->pid;
+30
View File
@@ -1,5 +1,7 @@
#include <kernel/syscalls.h>
#include <arch/cpu.h>
#include <kernel/jobctl.h>
#include <logging.h>
syscallret_t syscall_getpid(context_t *ctx) {
syscallret_t ret = {
@@ -8,3 +10,31 @@ syscallret_t syscall_getpid(context_t *ctx) {
};
return ret;
}
syscallret_t syscall_getppid(context_t *ctx) {
syscallret_t ret = {
.ret = _cpu()->thread->proc->parent ? _cpu()->thread->proc->parent->pid : 1,
.errno = 0
};
return ret;
}
syscallret_t syscall_getpgid(context_t *ctx, pid_t pid) {
syscallret_t ret = {
.errno = 0
};
__assert(pid == 0);
ret.ret = jobctl_getpgid(_cpu()->thread->proc);
return ret;
}
syscallret_t syscall_getsid(context_t *ctx, pid_t pid) {
syscallret_t ret = {
.errno = 0
};
__assert(pid == 0);
ret.ret = jobctl_getsid(_cpu()->thread->proc);
return ret;
}
+21
View File
@@ -0,0 +1,21 @@
#include <kernel/syscalls.h>
#include <kernel/jobctl.h>
#include <logging.h>
syscallret_t syscall_setsid(context_t *) {
syscallret_t ret;
ret.errno = jobctl_newsession(_cpu()->thread->proc);
ret.ret = ret.errno ? -1 : _cpu()->thread->proc->pid;
return ret;
}
syscallret_t syscall_setpgid(context_t *, pid_t pid, pid_t pgid) {
syscallret_t ret;
__assert(pid == 0 || pid == _cpu()->thread->proc->pid);
__assert(pgid == 0 || pgid == _cpu()->thread->proc->pid);
ret.errno = jobctl_newgroup(_cpu()->thread->proc);
ret.ret = ret.errno ? -1 : _cpu()->thread->proc->pid;
return ret;
}