kernel: Add basic process groups
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6546f490b6
commit
7328cfe734
@ -117,6 +117,8 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
|
|||||||
current->signal_handlers[i] = { .sa_handler = SIG_DFL, .sa_mask = 0, .sa_flags = 0 };
|
current->signal_handlers[i] = { .sa_handler = SIG_DFL, .sa_mask = 0, .sa_flags = 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current->has_called_exec = true;
|
||||||
|
|
||||||
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
|
kinfoln("exec: thread %lu was replaced with %s", current->id, path.chars());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -95,6 +95,39 @@ Result<u64> sys_setegid(Registers*, SyscallArgs args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<u64> sys_setpgid(Registers*, SyscallArgs args)
|
||||||
|
{
|
||||||
|
pid_t pid = (pid_t)args[0];
|
||||||
|
pid_t pgid = (pid_t)args[1];
|
||||||
|
|
||||||
|
auto* current = Scheduler::current();
|
||||||
|
if (pid == 0) pid = (pid_t)current->id;
|
||||||
|
if (pgid == 0) pgid = (pid_t)current->id;
|
||||||
|
|
||||||
|
if (pgid < 0) return err(EINVAL);
|
||||||
|
|
||||||
|
auto* thread = TRY(Result<Thread*>::from_option(Scheduler::find_by_pid(pid), ESRCH));
|
||||||
|
if (thread != current && thread->parent != current) return err(ESRCH);
|
||||||
|
|
||||||
|
// FIXME: Weird session stuff, we don't have that currently.
|
||||||
|
|
||||||
|
if (thread->has_called_exec) return err(EPERM);
|
||||||
|
|
||||||
|
if (pgid != (pid_t)current->id)
|
||||||
|
{
|
||||||
|
bool pgid_exists = false;
|
||||||
|
Scheduler::for_each_in_process_group(pgid, [&pgid_exists](Thread*) {
|
||||||
|
pgid_exists = true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (!pgid_exists) return err(EPERM);
|
||||||
|
}
|
||||||
|
|
||||||
|
thread->pgid = (u64)pgid;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
Result<u64> sys_fchmodat(Registers*, SyscallArgs args)
|
Result<u64> sys_fchmodat(Registers*, SyscallArgs args)
|
||||||
{
|
{
|
||||||
int dirfd = (int)args[0];
|
int dirfd = (int)args[0];
|
||||||
|
@ -45,6 +45,19 @@ namespace Scheduler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Callback> void for_each_in_process_group(pid_t group, Callback callback)
|
||||||
|
{
|
||||||
|
for (Thread* current = g_threads.first().value_or(nullptr); current;
|
||||||
|
current = g_threads.next(current).value_or(nullptr))
|
||||||
|
{
|
||||||
|
if (current->pgid == (u64)group)
|
||||||
|
{
|
||||||
|
bool should_continue = callback(current);
|
||||||
|
if (!should_continue) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dump_state();
|
void dump_state();
|
||||||
|
|
||||||
bool has_children(Thread* thread);
|
bool has_children(Thread* thread);
|
||||||
|
@ -57,6 +57,7 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
Registers regs;
|
Registers regs;
|
||||||
|
|
||||||
u64 id;
|
u64 id;
|
||||||
|
u64 pgid { 0 };
|
||||||
|
|
||||||
Credentials auth;
|
Credentials auth;
|
||||||
|
|
||||||
@ -82,14 +83,14 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
|
|
||||||
struct sigaction signal_handlers[NSIG];
|
struct sigaction signal_handlers[NSIG];
|
||||||
sigset_t signal_mask { 0 };
|
sigset_t signal_mask { 0 };
|
||||||
|
sigset_t pending_signals { 0 };
|
||||||
int pending_signals { 0 };
|
|
||||||
|
|
||||||
FPData fp_data;
|
FPData fp_data;
|
||||||
|
|
||||||
ThreadState state = ThreadState::Runnable;
|
ThreadState state = ThreadState::Runnable;
|
||||||
|
|
||||||
bool is_kernel { true };
|
bool is_kernel { true };
|
||||||
|
bool has_called_exec { false };
|
||||||
|
|
||||||
int status { 0 };
|
int status { 0 };
|
||||||
|
|
||||||
|
0
libc/include/math.h
Normal file
0
libc/include/math.h
Normal file
0
libc/include/wchar.h
Normal file
0
libc/include/wchar.h
Normal file
@ -144,6 +144,12 @@ extern "C"
|
|||||||
__errno_return(rc, int);
|
__errno_return(rc, int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int setpgid(pid_t pid, pid_t pgid)
|
||||||
|
{
|
||||||
|
long rc = syscall(SYS_setpgid, pid, pgid);
|
||||||
|
__errno_return(rc, int);
|
||||||
|
}
|
||||||
|
|
||||||
int chown(const char* path, uid_t uid, gid_t gid)
|
int chown(const char* path, uid_t uid, gid_t gid)
|
||||||
{
|
{
|
||||||
long rc = syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0);
|
long rc = syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
_e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(fchmodat) _e(fchownat) _e(ioctl) \
|
_e(getgid) _e(getegid) _e(setuid) _e(setgid) _e(seteuid) _e(setegid) _e(fchmodat) _e(fchownat) _e(ioctl) \
|
||||||
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
_e(fstatat) _e(chdir) _e(getcwd) _e(unlinkat) _e(uname) _e(sethostname) _e(dup2) _e(pipe) _e(mount) \
|
||||||
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
_e(umount) _e(pstat) _e(getrusage) _e(symlinkat) _e(readlinkat) _e(umask) _e(linkat) _e(faccessat) \
|
||||||
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask)
|
_e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid)
|
||||||
|
|
||||||
enum Syscalls
|
enum Syscalls
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user