Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r--winsup/cygwin/fhandler_tty.cc99
1 files changed, 50 insertions, 49 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 1bb3d87a7..9804a9a1b 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -18,8 +18,8 @@ details. */
#include <limits.h>
#include "cygerrno.h"
#include "security.h"
-#include "fhandler.h"
#include "path.h"
+#include "fhandler.h"
#include "dtable.h"
#include "sigproc.h"
#include "pinfo.h"
@@ -36,9 +36,15 @@ static DWORD WINAPI process_input (void *); // Input queue thread
static DWORD WINAPI process_output (void *); // Output queue thread
static DWORD WINAPI process_ioctl (void *); // Ioctl requests thread
-fhandler_tty_master::fhandler_tty_master (int unit)
- : fhandler_pty_master (FH_TTYM, unit), console (NULL)
+fhandler_tty_master::fhandler_tty_master ()
+ : fhandler_pty_master (), console (NULL)
+{
+}
+
+int
+fhandler_tty_slave::get_unit ()
{
+ return dev () == FH_TTY ? myself->ctty : dev ().minor;
}
void
@@ -52,9 +58,11 @@ fhandler_tty_master::set_winsize (bool sendSIGWINCH)
}
int
-fhandler_tty_master::init (int ntty)
+fhandler_tty_master::init ()
{
- termios_printf ("Creating master for tty%d", ntty);
+ termios_printf ("Creating master for tty%d", get_unit ());
+
+ slave = dev ();
if (init_console ())
{
@@ -66,9 +74,7 @@ fhandler_tty_master::init (int ntty)
memset (&ti, 0, sizeof (ti));
console->tcsetattr (0, &ti);
- ttynum = ntty;
-
- cygwin_shared->tty[ttynum]->common_init (this);
+ cygwin_shared->tty[get_unit ()]->common_init (this);
set_winsize (false);
@@ -431,14 +437,8 @@ process_ioctl (void *)
/**********************************************************************/
/* Tty slave stuff */
-fhandler_tty_slave::fhandler_tty_slave (int num)
- : fhandler_tty_common (FH_TTYS, num)
-{
- set_r_no_interrupt (1);
-}
-
fhandler_tty_slave::fhandler_tty_slave ()
- : fhandler_tty_common (FH_TTYS, 0)
+ : fhandler_tty_common ()
{
set_r_no_interrupt (1);
}
@@ -446,12 +446,12 @@ fhandler_tty_slave::fhandler_tty_slave ()
/* FIXME: This function needs to close handles when it has
a failing condition. */
int
-fhandler_tty_slave::open (path_conv *, int flags, mode_t)
+fhandler_tty_slave::open (int flags, mode_t)
{
- tcinit (cygwin_shared->tty[ttynum]);
+ tcinit (cygwin_shared->tty[get_unit ()]);
- attach_tty (ttynum);
- tc->set_ctty (ttynum, flags);
+ attach_tty (get_unit ());
+ tc->set_ctty (get_unit (), flags);
set_flags ((flags & ~O_TEXT) | O_BINARY);
/* Create synchronisation events */
@@ -462,7 +462,7 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
startup if use_tty is non-zero. It will not exist if this is a
pty opened by fhandler_pty_master::open. In the former case, tty
output is handled by a separate thread which controls output. */
- __small_sprintf (buf, OUTPUT_DONE_EVENT, ttynum);
+ __small_sprintf (buf, OUTPUT_DONE_EVENT, get_unit ());
output_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
if (!(output_mutex = get_ttyp ()->open_output_mutex ()))
@@ -477,7 +477,7 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
__seterrno ();
return 0;
}
- __small_sprintf (buf, INPUT_AVAILABLE_EVENT, ttynum);
+ __small_sprintf (buf, INPUT_AVAILABLE_EVENT, get_unit ());
if (!(input_available_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf)))
{
termios_printf ("open input event failed, %E");
@@ -487,9 +487,9 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
/* The ioctl events may or may not exist. See output_done_event,
above. */
- __small_sprintf (buf, IOCTL_REQUEST_EVENT, ttynum);
+ __small_sprintf (buf, IOCTL_REQUEST_EVENT, get_unit ());
ioctl_request_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
- __small_sprintf (buf, IOCTL_DONE_EVENT, ttynum);
+ __small_sprintf (buf, IOCTL_DONE_EVENT, get_unit ());
ioctl_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
/* FIXME: Needs a method to eliminate tty races */
@@ -525,7 +525,7 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
if (tty_owner == NULL)
{
termios_printf ("can't open tty (%d) handle process %d",
- ttynum, get_ttyp ()->master_pid);
+ get_unit (), get_ttyp ()->master_pid);
__seterrno ();
return 0;
}
@@ -577,7 +577,7 @@ fhandler_tty_slave::open (path_conv *, int flags, mode_t)
init_console_handler ();
}
termios_printf ("incremented open_fhs %d", fhandler_console::open_fhs);
- termios_printf ("tty%d opened", ttynum);
+ termios_printf ("tty%d opened", get_unit ());
return 1;
}
@@ -618,17 +618,17 @@ fhandler_tty_slave::cygserver_attach_tty (LPHANDLE from_master_ptr,
void
fhandler_tty_slave::init (HANDLE, DWORD a, mode_t)
{
- int mode = 0;
+ int flags = 0;
a &= GENERIC_READ | GENERIC_WRITE;
if (a == GENERIC_READ)
- mode = O_RDONLY;
+ flags = O_RDONLY;
if (a == GENERIC_WRITE)
- mode = O_WRONLY;
+ flags = O_WRONLY;
if (a == (GENERIC_READ | GENERIC_WRITE))
- mode = O_RDWR;
+ flags = O_RDWR;
- open (0, mode);
+ open (flags);
}
int
@@ -636,7 +636,7 @@ fhandler_tty_slave::write (const void *ptr, size_t len)
{
DWORD n, towrite = len;
- termios_printf ("tty%d, write(%x, %d)", ttynum, ptr, len);
+ termios_printf ("tty%d, write(%x, %d)", get_unit (), ptr, len);
acquire_output_mutex (INFINITE);
@@ -882,11 +882,10 @@ fhandler_tty_common::dup (fhandler_base *child)
fhandler_tty_slave *fts = (fhandler_tty_slave *) child;
int errind;
- fts->ttynum = ttynum;
fts->tcinit (get_ttyp ());
- attach_tty (ttynum);
- tc->set_ctty (ttynum, openflags);
+ attach_tty (get_unit ());
+ tc->set_ctty (get_unit (), openflags);
HANDLE nh;
@@ -1017,7 +1016,7 @@ fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
termios_printf ("ioctl (%x)", cmd);
if (myself->pgid && get_ttyp ()->getpgid () != myself->pgid
- && myself->ctty == ttynum && (get_ttyp ()->ti.c_lflag & TOSTOP))
+ && myself->ctty == get_unit () && (get_ttyp ()->ti.c_lflag & TOSTOP))
{
/* background process */
termios_printf ("bg ioctl pgid %d, tpgid %d, ctty %d",
@@ -1084,24 +1083,26 @@ out:
/*******************************************************
fhandler_pty_master
*/
-fhandler_pty_master::fhandler_pty_master (DWORD devtype, int unit)
- : fhandler_tty_common (devtype, unit)
+fhandler_pty_master::fhandler_pty_master ()
+ : fhandler_tty_common ()
{
}
int
-fhandler_pty_master::open (path_conv *, int flags, mode_t)
+fhandler_pty_master::open (int flags, mode_t)
{
- ttynum = cygwin_shared->tty.allocate_tty (0);
- if (ttynum < 0)
+ int ntty = cygwin_shared->tty.allocate_tty (0);
+ if (ntty < 0)
return 0;
- cygwin_shared->tty[ttynum]->common_init (this);
+ slave = *ttys_dev;
+ slave.setunit (ntty);
+ cygwin_shared->tty[ntty]->common_init (this);
inuse = get_ttyp ()->create_inuse (TTY_MASTER_ALIVE);
set_flags ((flags & ~O_TEXT) | O_BINARY);
set_open_status ();
- termios_printf ("opened pty master tty%d<%p>", ttynum, this);
+ termios_printf ("opened pty master tty%d", get_unit ());
return 1;
}
@@ -1136,7 +1137,7 @@ fhandler_tty_common::close ()
termios_printf ("CloseHandle (get_output_handle ()<%p>), %E", get_output_handle ());
inuse = NULL;
- termios_printf ("tty%d <%p,%p> closed", ttynum, get_handle (), get_output_handle ());
+ termios_printf ("tty%d <%p,%p> closed", get_unit (), get_handle (), get_output_handle ());
return 0;
}
@@ -1151,7 +1152,7 @@ fhandler_pty_master::close ()
if (!get_ttyp ()->master_alive ())
{
- termios_printf ("freeing tty%d (%d)", ttynum, get_ttyp ()->ntty);
+ termios_printf ("freeing tty%d (%d)", get_unit (), get_ttyp ()->ntty);
#if 0
if (get_ttyp ()->to_slave)
ForceCloseHandle1 (get_ttyp ()->to_slave, to_slave);
@@ -1198,14 +1199,14 @@ fhandler_pty_master::read (void *ptr, size_t& len)
int
fhandler_pty_master::tcgetattr (struct termios *t)
{
- *t = cygwin_shared->tty[ttynum]->ti;
+ *t = cygwin_shared->tty[get_unit ()]->ti;
return 0;
}
int
fhandler_pty_master::tcsetattr (int, const struct termios *t)
{
- cygwin_shared->tty[ttynum]->ti = *t;
+ cygwin_shared->tty[get_unit ()]->ti = *t;
return 0;
}
@@ -1257,11 +1258,11 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
}
char *
-fhandler_pty_master::ptsname (void)
+fhandler_pty_master::ptsname ()
{
static char buf[32];
- __small_sprintf (buf, "/dev/tty%d", ttynum);
+ __small_sprintf (buf, "/dev/tty%d", get_unit ());
return buf;
}
@@ -1350,7 +1351,7 @@ fhandler_tty_master::fixup_after_exec (HANDLE)
int
fhandler_tty_master::init_console ()
{
- console = (fhandler_console *) cygheap->fdtab.build_fhandler (-1, FH_CONSOLE, "/dev/ttym");
+ console = (fhandler_console *) build_fh_dev (*console_dev, "/dev/ttym");
if (console == NULL)
return -1;