mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
setpgid: support changing between process groups and doing it for other processes
This commit is contained in:
@@ -12,10 +12,45 @@ syscallret_t syscall_setsid(context_t *) {
|
||||
|
||||
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;
|
||||
proc_t *proc = NULL;
|
||||
if (pid == 0) {
|
||||
proc = _cpu()->thread->proc;
|
||||
PROC_HOLD(proc);
|
||||
} else {
|
||||
proc = sched_getprocfrompid(pid);
|
||||
}
|
||||
|
||||
if (proc == NULL) {
|
||||
ret.errno = ESRCH;
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc_t *pgrp = NULL;
|
||||
if (pgid == 0) {
|
||||
pgrp = _cpu()->thread->proc;
|
||||
PROC_HOLD(pgrp);
|
||||
} else {
|
||||
pgrp = sched_getprocfrompid(pgid);
|
||||
}
|
||||
|
||||
if (pgrp == NULL) {
|
||||
PROC_RELEASE(proc);
|
||||
ret.errno = EPERM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (pgid == pid || pgid == 0) {
|
||||
// create new group for process
|
||||
ret.errno = jobctl_newgroup(proc);
|
||||
} else {
|
||||
// switch process group
|
||||
ret.errno = jobctl_changegroup(proc, pgrp);
|
||||
}
|
||||
|
||||
PROC_RELEASE(pgrp);
|
||||
PROC_RELEASE(proc);
|
||||
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user