diff --git a/kernel/include/kernel/Process.h b/kernel/include/kernel/Process.h index de0cf334..0044d586 100644 --- a/kernel/include/kernel/Process.h +++ b/kernel/include/kernel/Process.h @@ -179,6 +179,7 @@ namespace Kernel BAN::ErrorOr sys_sigpending(sigset_t* set); BAN::ErrorOr sys_sigprocmask(int how, const sigset_t* set, sigset_t* oset); + BAN::ErrorOr sys_tcgetpgrp(int fd); BAN::ErrorOr sys_tcsetpgrp(int fd, pid_t pgid); BAN::ErrorOr sys_termid(char*); diff --git a/kernel/kernel/Process.cpp b/kernel/kernel/Process.cpp index 27527f0e..76846a07 100644 --- a/kernel/kernel/Process.cpp +++ b/kernel/kernel/Process.cpp @@ -2012,6 +2012,24 @@ namespace Kernel return 0; } + BAN::ErrorOr Process::sys_tcgetpgrp(int fd) + { + LockGuard _(m_process_lock); + + if (!m_controlling_terminal) + return BAN::Error::from_errno(ENOTTY); + + auto inode = TRY(m_open_file_descriptors.inode_of(fd)); + if (!inode->is_tty()) + return BAN::Error::from_errno(ENOTTY); + + auto* tty = static_cast(inode.ptr()); + if (tty != m_controlling_terminal.ptr()) + return BAN::Error::from_errno(ENOTTY); + + return tty->foreground_pgrp(); + } + BAN::ErrorOr Process::sys_tcsetpgrp(int fd, pid_t pgrp) { LockGuard _(m_process_lock); diff --git a/userspace/libraries/LibC/include/sys/syscall.h b/userspace/libraries/LibC/include/sys/syscall.h index 29f865bc..f8073c6f 100644 --- a/userspace/libraries/LibC/include/sys/syscall.h +++ b/userspace/libraries/LibC/include/sys/syscall.h @@ -39,6 +39,7 @@ __BEGIN_DECLS O(SYS_DUP, dup) \ O(SYS_DUP2, dup2) \ O(SYS_KILL, kill) \ + O(SYS_TCGETPGRP, tcgetpgrp) \ O(SYS_TCSETPGRP, tcsetpgrp) \ O(SYS_GET_PID, getpid) \ O(SYS_GET_PGID, getpgid) \ diff --git a/userspace/libraries/LibC/unistd.cpp b/userspace/libraries/LibC/unistd.cpp index efc577df..48c04bad 100644 --- a/userspace/libraries/LibC/unistd.cpp +++ b/userspace/libraries/LibC/unistd.cpp @@ -483,6 +483,11 @@ pid_t getpgid(pid_t pid) return syscall(SYS_GET_PGID, pid); } +int tcgetpgrp(int fildes) +{ + return syscall(SYS_TCGETPGRP, fildes); +} + int seteuid(uid_t uid) { return syscall(SYS_SET_EUID, uid);