From 46c9b1d81c22c6840733e821bc0859dda1d65e7d Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Mon, 26 Jul 2021 03:42:16 -0700 Subject: [PATCH] Kernel+LibC: Use argument for TIOCGPGRP ioctl value In preparation for modifying the Kernel IOCTL API to return KResult instead of int, we need to fix this ioctl to an argument to receive it's return value, instead of using the actual function return value. --- Kernel/TTY/TTY.cpp | 9 +++++++-- Userland/Libraries/LibC/unistd.cpp | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Kernel/TTY/TTY.cpp b/Kernel/TTY/TTY.cpp index a58b882b4e..c5a7802133 100644 --- a/Kernel/TTY/TTY.cpp +++ b/Kernel/TTY/TTY.cpp @@ -469,8 +469,13 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace arg) } #endif switch (request) { - case TIOCGPGRP: - return this->pgid().value(); + case TIOCGPGRP: { + auto user_pgid = static_ptr_cast(arg); + auto pgid = this->pgid().value(); + if (!copy_to_user(user_pgid, &pgid)) + return -EFAULT; + return 0; + } case TIOCSPGRP: { ProcessGroupID pgid = static_cast(arg.ptr()); if (pgid <= 0) diff --git a/Userland/Libraries/LibC/unistd.cpp b/Userland/Libraries/LibC/unistd.cpp index 83c1d465e6..0426054cb9 100644 --- a/Userland/Libraries/LibC/unistd.cpp +++ b/Userland/Libraries/LibC/unistd.cpp @@ -257,7 +257,11 @@ pid_t setsid() pid_t tcgetpgrp(int fd) { - return ioctl(fd, TIOCGPGRP); + pid_t pgrp; + int rc = ioctl(fd, TIOCGPGRP, &pgrp); + if (rc < 0) + return rc; + return pgrp; } int tcsetpgrp(int fd, pid_t pgid)