bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/4] Don't resolve FD's port and ctty twice for TIOCSCTTY


From: Carl Fredrik Hammar
Subject: [PATCH 1/4] Don't resolve FD's port and ctty twice for TIOCSCTTY
Date: Fri, 14 Aug 2009 16:01:10 +0200

* hurd/hurdioctl.c (tiocsctty): Only get FD ports, do work in...
(tiocsctty_internal): ...this new function.
---
 hurd/hurdioctl.c |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/hurd/hurdioctl.c b/hurd/hurdioctl.c
index 96d910b..13a1a78 100644
--- a/hurd/hurdioctl.c
+++ b/hurd/hurdioctl.c
@@ -246,32 +246,41 @@ _hurd_setcttyid (mach_port_t cttyid)
 /* Make FD be the controlling terminal.
    This function is called for `ioctl (fd, TCIOSCTTY)'.  */
 
-static int
-tiocsctty (int fd,
-          int request)         /* Always TIOCSCTTY.  */
+static error_t
+tiocsctty_internal (io_t port, io_t ctty)
 {
   mach_port_t cttyid;
   error_t err;
 
-  /* Get FD's cttyid port, unless it is already ours.  */
-  err = HURD_DPORT_USE (fd, ctty != MACH_PORT_NULL ? EADDRINUSE :
-                       __term_getctty (port, &cttyid));
-  if (err == EADDRINUSE)
+  if (ctty != MACH_PORT_NULL)
     /* FD is already the ctty.  Nothing to do.  */
     return 0;
-  else if (err)
-    return __hurd_fail (err);
+
+  /* Get FD's cttyid port.  */
+  err =__term_getctty (port, &cttyid);
+  if (err)
+    return err;
 
   /* Change the terminal's pgrp to ours.  */
-  err = HURD_DPORT_USE (fd, __tioctl_tiocspgrp (port, _hurd_pgrp));
+  err = __tioctl_tiocspgrp (port, _hurd_pgrp);
   if (err)
-    return __hurd_fail (err);
+    return err;
 
   /* Make it our own.  */
   install_ctty (cttyid);
 
   return 0;
 }
+
+static int
+tiocsctty (int fd,
+          int request)         /* Always TIOCSCTTY.  */
+{
+  error_t err;
+
+  err = HURD_DPORT_USE (fd, tiocsctty_internal (port, ctty));
+  return __hurd_fail (err);
+}
 _HURD_HANDLE_IOCTL (tiocsctty, TIOCSCTTY);
 
 /* Dissociate from the controlling terminal.  */
-- 
1.6.3.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]