[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Only resolve FD's port and ctty once for TIOCSCTTY
From: |
Carl Fredrik Hammar |
Subject: |
[PATCH] Only resolve FD's port and ctty once for TIOCSCTTY |
Date: |
Wed, 26 Aug 2009 14:18:57 +0200 |
* hurd/hurdioctl.c (tiocsctty): Only get FD ports, do work in...
(tiocsctty_internal): ...this new function.
---
Hi,
This is another stand-alone patch I have sent earlier.
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 seperete resolves the underlying port can change mid-call.
Regards,
Fredrik
---
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Only resolve FD's port and ctty once for TIOCSCTTY,
Carl Fredrik Hammar <=