diff options
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/ProcFileSystem.cpp | 5 | ||||
-rw-r--r-- | Kernel/Process.cpp | 31 | ||||
-rw-r--r-- | Kernel/Process.h | 2 | ||||
-rw-r--r-- | Kernel/Syscall.cpp | 4 | ||||
-rw-r--r-- | Kernel/Syscall.h | 2 | ||||
-rw-r--r-- | Kernel/TTY.h | 4 |
6 files changed, 46 insertions, 2 deletions
diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp index e899f4f314..f7c221f1cb 100644 --- a/Kernel/ProcFileSystem.cpp +++ b/Kernel/ProcFileSystem.cpp @@ -277,10 +277,11 @@ ByteBuffer procfs$summary() auto processes = Process::allProcesses(); auto buffer = ByteBuffer::createUninitialized(processes.size() * 256); char* ptr = (char*)buffer.pointer(); - ptr += ksprintf(ptr, "PID PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n"); + ptr += ksprintf(ptr, "PID TPG PGP SID OWNER STATE PPID NSCHED FDS TTY NAME\n"); for (auto* process : processes) { - ptr += ksprintf(ptr, "% 3u % 3u % 3u % 4u % 8s % 3u % 9u % 3u % 4s %s\n", + ptr += ksprintf(ptr, "% 3u % 3u % 3u % 3u % 4u % 8s % 3u % 9u % 3u % 4s %s\n", process->pid(), + process->tty() ? process->tty()->pgid() : 0, process->pgid(), process->sid(), process->uid(), diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 14deb2812a..24d0bdc16c 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1249,3 +1249,34 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid) process->m_pgid = new_pgid; return 0; } + +pid_t Process::sys$tcgetpgrp(int fd) +{ + auto* handle = fileHandleIfExists(fd); + if (!handle) + return -EBADF; + if (!handle->isTTY()) + return -ENOTTY; + auto& tty = *handle->tty(); + if (&tty != m_tty) + return -ENOTTY; + return tty.pgid(); +} + +int Process::sys$tcsetpgrp(int fd, pid_t pgid) +{ + if (pgid < 0) + return -EINVAL; + if (get_sid_from_pgid(pgid) != m_sid) + return -EINVAL; + auto* handle = fileHandleIfExists(fd); + if (!handle) + return -EBADF; + if (!handle->isTTY()) + return -ENOTTY; + auto& tty = *handle->tty(); + if (&tty != m_tty) + return -ENOTTY; + tty.set_pgid(pgid); + return 0; +} diff --git a/Kernel/Process.h b/Kernel/Process.h index 12302ecbb1..dbec761466 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -86,6 +86,8 @@ public: int sys$setpgid(pid_t pid, pid_t pgid); pid_t sys$getpgrp(); pid_t sys$getpgid(pid_t); + pid_t sys$tcgetpgrp(int fd); + int sys$tcsetpgrp(int fd, pid_t pgid); uid_t sys$getuid(); gid_t sys$getgid(); pid_t sys$getpid(); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index e8163a4465..0ffbe7659e 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -124,6 +124,10 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3) return current->sys$getpgid((pid_t)arg1); case Syscall::PosixGetpgrp: return current->sys$getpgrp(); + case Syscall::PosixTcgetpgrp: + return current->sys$tcgetpgrp((int)arg1); + case Syscall::PosixTcsetpgrp: + return current->sys$tcsetpgrp((int)arg1, (pid_t)arg2); default: kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3); break; diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index f35658bf2a..97116c16f9 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -45,6 +45,8 @@ enum Function { PosixGetpgid = 0x2013, PosixSetpgid = 0x2014, PosixGetpgrp = 0x2015, + PosixTcsetpgrp = 0x2016, + PosixTcgetpgrp = 0x2017, }; void initialize(); diff --git a/Kernel/TTY.h b/Kernel/TTY.h index 76a144e6f9..e352efa1eb 100644 --- a/Kernel/TTY.h +++ b/Kernel/TTY.h @@ -12,6 +12,9 @@ public: virtual String ttyName() const = 0; + void set_pgid(pid_t pgid) { m_pgid = pgid; } + pid_t pgid() const { return m_pgid; } + protected: virtual bool isTTY() const final { return true; } @@ -22,5 +25,6 @@ protected: private: Vector<byte> m_buffer; + pid_t m_pgid { 0 }; }; |