summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/tty.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-04-19 19:52:43 +0000
committerCorinna Vinschen <corinna@vinschen.de>2010-04-19 19:52:43 +0000
commitcc01c77f7e025825151435bf00a6dbeb44b137de (patch)
tree5324b48242c29a1e17e4c8f9386326f47bf15d29 /winsup/cygwin/tty.cc
parent02a33ea774fed6feeeabe2779eef6739e094100e (diff)
downloadcygnal-cc01c77f7e025825151435bf00a6dbeb44b137de.tar.gz
cygnal-cc01c77f7e025825151435bf00a6dbeb44b137de.tar.bz2
cygnal-cc01c77f7e025825151435bf00a6dbeb44b137de.zip
* autoload.cc (GetNamedPipeClientProcessId): Define.
* fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
Diffstat (limited to 'winsup/cygwin/tty.cc')
-rw-r--r--winsup/cygwin/tty.cc49
1 files changed, 19 insertions, 30 deletions
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index e7018106d..0991cd66d 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -1,7 +1,7 @@
/* tty.cc
- Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009
- Red Hat, Inc.
+ Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
+ 2010 Red Hat, Inc.
This file is part of Cygwin.
@@ -287,12 +287,6 @@ out:
}
bool
-tty::slave_alive ()
-{
- return alive (TTY_SLAVE_ALIVE);
-}
-
-bool
tty::exists ()
{
/* Attempt to open the from-master side of the tty. If it is accessible
@@ -307,7 +301,7 @@ tty::exists ()
CloseHandle (r);
CloseHandle (w);
- HANDLE h = open_output_mutex ();
+ HANDLE h = open_output_mutex (READ_CONTROL);
if (h)
{
CloseHandle (h);
@@ -317,45 +311,38 @@ tty::exists ()
}
bool
-tty::alive (const char *fmt)
+tty::slave_alive ()
{
HANDLE ev;
- char buf[MAX_PATH];
-
- shared_name (buf, fmt, ntty);
- if ((ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf)))
+ if ((ev = open_inuse (READ_CONTROL)))
CloseHandle (ev);
return ev != NULL;
}
HANDLE
-tty::open_output_mutex ()
+tty::open_mutex (const char *mutex, ACCESS_MASK access)
{
- return open_mutex (OUTPUT_MUTEX);
-}
-
-HANDLE
-tty::open_input_mutex ()
-{
- return open_mutex (INPUT_MUTEX);
+ char buf[MAX_PATH];
+ shared_name (buf, mutex, ntty);
+ return OpenMutex (access, TRUE, buf);
}
HANDLE
-tty::open_mutex (const char *mutex)
+tty::open_inuse (ACCESS_MASK access)
{
char buf[MAX_PATH];
- shared_name (buf, mutex, ntty);
- return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
+ shared_name (buf, TTY_SLAVE_ALIVE, ntty);
+ return OpenEvent (access, FALSE, buf);
}
HANDLE
-tty::create_inuse (const char *fmt)
+tty::create_inuse (PSECURITY_ATTRIBUTES sa)
{
HANDLE h;
char buf[MAX_PATH];
- shared_name (buf, fmt, ntty);
- h = CreateEvent (&sec_all, TRUE, FALSE, buf);
+ shared_name (buf, TTY_SLAVE_ALIVE, ntty);
+ h = CreateEvent (sa, TRUE, FALSE, buf);
termios_printf ("%s %p", buf, h);
if (!h)
termios_printf ("couldn't open inuse event, %E", buf);
@@ -374,13 +361,15 @@ tty::init ()
}
HANDLE
-tty::get_event (const char *fmt, BOOL manual_reset)
+tty::get_event (const char *fmt, PSECURITY_ATTRIBUTES sa, BOOL manual_reset)
{
HANDLE hev;
char buf[MAX_PATH];
shared_name (buf, fmt, ntty);
- if (!(hev = CreateEvent (&sec_all, manual_reset, FALSE, buf)))
+ if (!sa)
+ sa = &sec_all;
+ if (!(hev = CreateEvent (sa, manual_reset, FALSE, buf)))
{
termios_printf ("couldn't create %s", buf);
set_errno (ENOENT); /* FIXME this can't be the right errno */