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-04 00:32:07 +0400
committerChristopher Faylor <me@cgf.cx>2006-06-04 00:32:07 +0400
commit71d59a926f9d632b15c531325bad15edb32b8f81 (patch)
tree217f62dffc9dfac5b8142b33a70d1db67e75c201 /winsup/cygwin/fhandler_tty.cc
parenta615ed802386065c9ea3aa409767d4fcd8bfc4ed (diff)
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here.
(dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
Diffstat (limited to 'winsup/cygwin/fhandler_tty.cc')
-rw-r--r--winsup/cygwin/fhandler_tty.cc33
1 files changed, 19 insertions, 14 deletions
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index e006c4ced..b1d840acf 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -471,7 +471,7 @@ fhandler_tty_slave::open (int flags, mode_t)
tcinit (cygwin_shared->tty[get_unit ()]);
- attach_tty (get_unit ());
+ cygwin_shared->tty.attach (get_unit ());
set_flags ((flags & ~O_TEXT) | O_BINARY);
/* Create synchronisation events */
@@ -537,6 +537,12 @@ fhandler_tty_slave::open (int flags, mode_t)
|| !cygserver_attach_tty (&from_master_local, &to_master_local))
#endif
{
+ if (get_ttyp ()->master_pid < 0)
+ {
+ set_errno (EAGAIN);
+ termios_printf ("*** master is closed");
+ return 0;
+ }
pinfo p (get_ttyp ()->master_pid);
if (!p)
{
@@ -1087,7 +1093,8 @@ fhandler_pty_master::open (int flags, mode_t)
goto out;
}
- int ntty = cygwin_shared->tty.allocate_tty (false);
+ int ntty;
+ ntty = cygwin_shared->tty.allocate (false);
if (ntty < 0)
return 0;
@@ -1095,10 +1102,10 @@ fhandler_pty_master::open (int flags, mode_t)
slave.setunit (ntty);
if (!setup (*cygwin_shared->tty[ntty]))
{
- ReleaseMutex (tty_mutex); // lock was set in allocate_tty
+ lock_ttys::release ();
return 0;
}
- ReleaseMutex (tty_mutex); // lock was set in allocate_tty
+ lock_ttys::release ();
set_flags ((flags & ~O_TEXT) | O_BINARY);
set_open_status ();
//
@@ -1112,8 +1119,9 @@ fhandler_pty_master::open (int flags, mode_t)
out:
usecount = 0;
arch->usecount++;
- report_tty_counts (this, "opened master", "");
- termios_printf ("opened pty master tty%d", get_unit ());
+ char buf[sizeof ("opened pty master for ttyNNNNNNNNNNN")];
+ __small_sprintf (buf, "opened pty master for tty%d", get_unit ());
+ report_tty_counts (this, buf, "");
return 1;
}
@@ -1184,8 +1192,10 @@ fhandler_pty_master::close ()
}
fhandler_tty_common::close ();
- if (!hExeced && get_ttyp ()->master_pid == myself->pid)
- get_ttyp ()->init ();
+ if (hExeced || get_ttyp ()->master_pid != myself->pid)
+ termios_printf ("not clearing: %d, master_pid %d", hExeced, get_ttyp ()->master_pid);
+ else
+ get_ttyp ()->set_master_closed ();
return 0;
}
@@ -1337,11 +1347,6 @@ fhandler_pty_master::setup (tty& t)
/* Create communication pipes */
-#if 0 // CGF: don't think this is needed since it is handled by the constructor
- input_handle = io_handle = output_done_event = ioctl_done_event =
- ioctl_request_event = input_available_event = output_mutex = input_mutex NULL;
-#endif
-
/* FIXME: should this be sec_none_nih? */
if (!CreatePipe (&from_master, &get_output_handle (), &sec_all, 128 * 1024))
{
@@ -1355,7 +1360,7 @@ fhandler_pty_master::setup (tty& t)
goto err;
}
- if (!SetNamedPipeHandleState (&get_output_handle (), &pipe_mode, NULL, NULL))
+ if (!SetNamedPipeHandleState (get_output_handle (), &pipe_mode, NULL, NULL))
termios_printf ("can't set output_handle(%p) to non-blocking mode",
get_output_handle ());