This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[HURD,PATCH] Only resolve FD's port and ctty once in TIOCSCTTY


Hi,

This fixes the handler for TIOCSCTTY so it only resolves the underlying
port of the file descriptor once.  Since the descriptor isn't locked
between the HURD_DPORT_USE calls, the underlying ports can change
mid-call.

I have only tested this lightly.  It fails as expected on a regular file
and doesn't result in an error on a terminal.  As I'm not entirely sure
what a CTTY is for, this is as much as I can do without more digging,
but I don't think anything more is really necessary as the change is
very straight forward.

Regards,
  Fredrik


2010-02-17  Carl Fredrik Hammar  <hammy.lite@gmail.com>

	* hurd/hurdioctl.c (tiocsctty): Only get FD ports, do work in...
	(tiocsctty_port): ...this new function.
---
 hurd/hurdioctl.c |   41 +++++++++++++++++++++++++++--------------
 1 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/hurd/hurdioctl.c b/hurd/hurdioctl.c
index 7c68984..feaf05f 100644
--- a/hurd/hurdioctl.c
+++ b/hurd/hurdioctl.c
@@ -239,35 +239,48 @@ _hurd_setcttyid (mach_port_t cttyid)
 }
 
 
-/* Make FD be the controlling terminal.
-   This function is called for `ioctl (fd, TCIOSCTTY)'.  */
+/* Version of `tiocsctty' that operates on the resolved ports of a file
+   descriptor.  */
 
-static int
-tiocsctty (int fd,
-	   int request)		/* Always TIOCSCTTY.  */
+static error_t
+tiocsctty_port (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)
-    /* FD is already the ctty.  Nothing to do.  */
+  if (ctty != MACH_PORT_NULL)
+    /* PORT is already the ctty.  Nothing to do.  */
     return 0;
-  else if (err)
-    return __hurd_fail (err);
+
+  /* Get PORT'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;
 }
+
+
+/* Make FD be the controlling terminal.
+   This function is called for `ioctl (fd, TCIOSCTTY)'.  */
+
+static int
+tiocsctty (int fd,
+	   int request)		/* Always TIOCSCTTY.  */
+{
+  error_t err;
+
+  err = HURD_DPORT_USE (fd, tiocsctty_port (port, ctty));
+  return __hurd_fail (err);
+}
 _HURD_HANDLE_IOCTL (tiocsctty, TIOCSCTTY);
 
 /* Dissociate from the controlling terminal.  */
-- 
1.6.6.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]