From b64093dee501739f712385e1e29af3a3d5ad1b67 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 12 Jul 2023 13:44:25 +0200 Subject: [PATCH] kernel+libc: Implement getpgid() --- kernel/src/sys/id.cpp | 14 ++++++++++++++ libc/include/unistd.h | 3 +++ libc/src/unistd.cpp | 6 ++++++ libluna/include/luna/Syscall.h | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/kernel/src/sys/id.cpp b/kernel/src/sys/id.cpp index 89645357..1ca81283 100644 --- a/kernel/src/sys/id.cpp +++ b/kernel/src/sys/id.cpp @@ -128,6 +128,20 @@ Result sys_setpgid(Registers*, SyscallArgs args) return 0; } +Result sys_getpgid(Registers*, SyscallArgs args) +{ + pid_t pid = (pid_t)args[0]; + + auto* current = Scheduler::current(); + if (pid == 0) pid = (pid_t)current->id; + + if (pid < 0) return err(EINVAL); + + auto* thread = TRY(Result::from_option(Scheduler::find_by_pid(pid), ESRCH)); + + return (u64)thread->pgid; +} + Result sys_fchmodat(Registers*, SyscallArgs args) { int dirfd = (int)args[0]; diff --git a/libc/include/unistd.h b/libc/include/unistd.h index b06dea68..82ebf8da 100644 --- a/libc/include/unistd.h +++ b/libc/include/unistd.h @@ -45,6 +45,9 @@ extern "C" /* Return the current process' effective group ID. */ gid_t getegid(void); + /* Return a process' process group ID. */ + pid_t getpgid(pid_t pid); + /* Set the current process' user IDs. */ int setuid(uid_t uid); diff --git a/libc/src/unistd.cpp b/libc/src/unistd.cpp index 210da314..7abba431 100644 --- a/libc/src/unistd.cpp +++ b/libc/src/unistd.cpp @@ -120,6 +120,12 @@ extern "C" return (gid_t)syscall(SYS_getegid); } + pid_t getpgid(pid_t pid) + { + long rc = syscall(SYS_getpgid, pid); + __errno_return(rc, pid_t); + } + int setuid(uid_t uid) { long rc = syscall(SYS_setuid, uid); diff --git a/libluna/include/luna/Syscall.h b/libluna/include/luna/Syscall.h index 2577572c..b8ea05d5 100644 --- a/libluna/include/luna/Syscall.h +++ b/libluna/include/luna/Syscall.h @@ -6,7 +6,8 @@ _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(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(setpgid) _e(isatty) + _e(pivot_root) _e(sigreturn) _e(sigaction) _e(kill) _e(sigprocmask) _e(setpgid) _e(isatty) \ + _e(getpgid) enum Syscalls {