Browse Source

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.
Brian Gianforcaro 4 years ago
parent
commit
46c9b1d81c
2 changed files with 12 additions and 3 deletions
  1. 7 2
      Kernel/TTY/TTY.cpp
  2. 5 1
      Userland/Libraries/LibC/unistd.cpp

+ 7 - 2
Kernel/TTY/TTY.cpp

@@ -469,8 +469,13 @@ int TTY::ioctl(FileDescription&, unsigned request, Userspace<void*> arg)
     }
 #endif
     switch (request) {
-    case TIOCGPGRP:
-        return this->pgid().value();
+    case TIOCGPGRP: {
+        auto user_pgid = static_ptr_cast<pid_t*>(arg);
+        auto pgid = this->pgid().value();
+        if (!copy_to_user(user_pgid, &pgid))
+            return -EFAULT;
+        return 0;
+    }
     case TIOCSPGRP: {
         ProcessGroupID pgid = static_cast<pid_t>(arg.ptr());
         if (pgid <= 0)

+ 5 - 1
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)