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:
authorChristopher Faylor <me@cgf.cx>2006-06-02 19:41:34 +0400
committerChristopher Faylor <me@cgf.cx>2006-06-02 19:41:34 +0400
commit3378bdfc0ab5a995ba09d37be67bbf0356a4d3b2 (patch)
treed53f43424240f4d0ea7d8ac66ece2127ca4ee403 /winsup/cygwin/tty.cc
parent5d897c0f5cb400e5b3c30b3ab057abffd128011f (diff)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here.
* fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
Diffstat (limited to 'winsup/cygwin/tty.cc')
-rw-r--r--winsup/cygwin/tty.cc124
1 files changed, 6 insertions, 118 deletions
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index bbc6f21e7..69d6a9b34 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -130,11 +130,11 @@ tty_list::terminate ()
int ttynum = myself->ctty;
/* Keep master running till there are connected clients */
- if (ttynum != -1 && ttys[ttynum].master_pid == GetCurrentProcessId ())
+ if (ttynum != -1 && ttys[ttynum].master_pid == myself->pid)
{
tty *t = ttys + ttynum;
- CloseHandle (t->from_master);
- CloseHandle (t->to_master);
+ CloseHandle (tty_master->from_master);
+ CloseHandle (tty_master->to_master);
/* Wait for children which rely on tty handling in this process to
go away */
for (int i = 0; ; i++)
@@ -155,9 +155,9 @@ tty_list::terminate ()
termios_printf ("WFSO for tty_mutex %p failed, %E", tty_mutex);
termios_printf ("tty %d master about to finish", ttynum);
- ForceCloseHandle1 (t->to_slave, to_pty);
- ForceCloseHandle1 (t->from_slave, from_pty);
- CloseHandle (tty_master->inuse);
+ CloseHandle (tty_master->get_io_handle ());
+ CloseHandle (tty_master->get_output_handle ());
+
t->init ();
char buf[20];
@@ -313,12 +313,6 @@ tty::slave_alive ()
}
bool
-tty::master_alive ()
-{
- return alive (TTY_MASTER_ALIVE);
-}
-
-bool
tty::alive (const char *fmt)
{
HANDLE ev;
@@ -371,8 +365,6 @@ tty::init ()
setsid (0);
pgid = 0;
hwnd = NULL;
- to_slave = NULL;
- from_slave = NULL;
was_opened = 0;
master_pid = 0;
}
@@ -394,107 +386,3 @@ tty::get_event (const char *fmt, BOOL manual_reset)
termios_printf ("created event %s", buf);
return hev;
}
-
-bool
-tty::make_pipes (fhandler_pty_master *ptym)
-{
- /* Create communication pipes */
-
- /* FIXME: should this be sec_none_nih? */
- if (!CreatePipe (&from_master, &to_slave, &sec_all, 128 * 1024))
- {
- termios_printf ("can't create input pipe");
- set_errno (ENOENT);
- return false;
- }
-
- // ProtectHandle1INH (to_slave, to_pty);
- if (!CreatePipe (&from_slave, &to_master, &sec_all, 128 * 1024))
- {
- termios_printf ("can't create output pipe");
- set_errno (ENOENT);
- return false;
- }
- // ProtectHandle1INH (from_slave, from_pty);
- termios_printf ("tty%d from_slave %p, to_slave %p", ntty, from_slave,
- to_slave);
-
- DWORD pipe_mode = PIPE_NOWAIT;
- if (!SetNamedPipeHandleState (to_slave, &pipe_mode, NULL, NULL))
- termios_printf ("can't set to_slave to non-blocking mode");
- ptym->set_io_handle (from_slave);
- ptym->set_output_handle (to_slave);
- return true;
-}
-
-bool
-tty::common_init (fhandler_pty_master *ptym)
-{
- /* Set termios information. Force initialization. */
- ptym->tcinit (this, true);
-
- if (!make_pipes (ptym))
- return false;
- ptym->need_nl = 0;
-
- /* Save our pid */
-
- master_pid = GetCurrentProcessId ();
-
- /* We do not open allow the others to open us (for handle duplication)
- but rely on cygheap->inherited_ctty for descendant processes.
- In the future the cygserver may allow access by others. */
-
-#ifdef USE_SERVER
- if (wincap.has_security ())
- {
- if (cygserver_running == CYGSERVER_UNKNOWN)
- cygserver_init ();
- }
-#endif
-
- /* Create synchronisation events */
-
- if (ptym->get_major () != DEV_TTYM_MAJOR)
- {
- ptym->output_done_event = ptym->ioctl_done_event =
- ptym->ioctl_request_event = NULL;
- }
- else
- {
- if (!(ptym->output_done_event = get_event (OUTPUT_DONE_EVENT)))
- return false;
- if (!(ptym->ioctl_done_event = get_event (IOCTL_DONE_EVENT)))
- return false;
- if (!(ptym->ioctl_request_event = get_event (IOCTL_REQUEST_EVENT)))
- return false;
- }
-
- if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, TRUE)))
- return false;
-
- char buf[CYG_MAX_PATH];
- shared_name (buf, OUTPUT_MUTEX, ntty);
- if (!(ptym->output_mutex = CreateMutex (&sec_all, FALSE, buf)))
- {
- termios_printf ("can't create %s", buf);
- set_errno (ENOENT);
- return false;
- }
-
- shared_name (buf, INPUT_MUTEX, ntty);
- if (!(ptym->input_mutex = CreateMutex (&sec_all, FALSE, buf)))
- {
- termios_printf ("can't create %s", buf);
- set_errno (ENOENT);
- return false;
- }
-
- // /* screws up tty master */ ProtectHandle1INH (ptym->output_mutex, output_mutex);
- // /* screws up tty master */ ProtectHandle1INH (ptym->input_mutex, input_mutex);
- winsize.ws_col = 80;
- winsize.ws_row = 25;
-
- termios_printf ("tty%d opened", ntty);
- return true;
-}