2004-05-12 Pierre Humblet <pierre.humblet@ieee.org>

* tty.h: Remove the %d or %x from all cygtty strings.
	(tty::open_output_mutex): Only declare.
	(tty::open_input_mutex): Ditto.
	(tty::open_mutex): New definition.
	* fhandlet_tty.cc (fhandler_tty_slave::open): Declare buf with
	size CYG_MAX_PATH and replace __small_printf calls by shared_name.
	* tty.cc (tty::create_inuse): Ditto.
	(tty::get_event): Ditto.
	(tty::common_init): Ditto.
	(tty::open_output_mutex): New method definition.
	(tty::open_input_mutex): Ditto.
	(tty::open_mutex): New method.
This commit is contained in:
Pierre Humblet 2004-05-12 01:44:11 +00:00
parent 5b4c8ae219
commit 8bdfa78a69
4 changed files with 61 additions and 36 deletions

View File

@ -1,3 +1,18 @@
2004-05-12 Pierre Humblet <pierre.humblet@ieee.org>
* tty.h: Remove the %d or %x from all cygtty strings.
(tty::open_output_mutex): Only declare.
(tty::open_input_mutex): Ditto.
(tty::open_mutex): New definition.
* fhandler_tty.cc (fhandler_tty_slave::open): Declare buf with
size CYG_MAX_PATH and replace __small_printf calls by shared_name.
* tty.cc (tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty::common_init): Ditto.
(tty::open_output_mutex): New method definition.
(tty::open_input_mutex): Ditto.
(tty::open_mutex): New method.
2004-05-10 Corinna Vinschen <corinna@vinschen.de> 2004-05-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.cc (fhandler_base::open): Set file attributes to correct * fhandler.cc (fhandler_base::open): Set file attributes to correct

View File

@ -466,14 +466,14 @@ fhandler_tty_slave::open (int flags, mode_t)
set_flags ((flags & ~O_TEXT) | O_BINARY); set_flags ((flags & ~O_TEXT) | O_BINARY);
/* Create synchronisation events */ /* Create synchronisation events */
char buf[40]; char buf[CYG_MAX_PATH];
/* output_done_event may or may not exist. It will exist if the tty /* output_done_event may or may not exist. It will exist if the tty
was opened by fhandler_tty_master::init, normally called at was opened by fhandler_tty_master::init, normally called at
startup if use_tty is non-zero. It will not exist if this is a 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 pty opened by fhandler_pty_master::open. In the former case, tty
output is handled by a separate thread which controls output. */ output is handled by a separate thread which controls output. */
__small_sprintf (buf, OUTPUT_DONE_EVENT, get_unit ()); shared_name (buf, OUTPUT_DONE_EVENT, get_unit ());
output_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf); output_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
if (!(output_mutex = get_ttyp ()->open_output_mutex ())) if (!(output_mutex = get_ttyp ()->open_output_mutex ()))
@ -488,7 +488,7 @@ fhandler_tty_slave::open (int flags, mode_t)
__seterrno (); __seterrno ();
return 0; return 0;
} }
__small_sprintf (buf, INPUT_AVAILABLE_EVENT, get_unit ()); shared_name (buf, INPUT_AVAILABLE_EVENT, get_unit ());
if (!(input_available_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf))) if (!(input_available_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf)))
{ {
termios_printf ("open input event failed, %E"); termios_printf ("open input event failed, %E");
@ -498,9 +498,9 @@ fhandler_tty_slave::open (int flags, mode_t)
/* The ioctl events may or may not exist. See output_done_event, /* The ioctl events may or may not exist. See output_done_event,
above. */ above. */
__small_sprintf (buf, IOCTL_REQUEST_EVENT, get_unit ()); shared_name (buf, IOCTL_REQUEST_EVENT, get_unit ());
ioctl_request_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf); ioctl_request_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
__small_sprintf (buf, IOCTL_DONE_EVENT, get_unit ()); shared_name (buf, IOCTL_DONE_EVENT, get_unit ());
ioctl_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf); ioctl_done_event = OpenEvent (EVENT_ALL_ACCESS, TRUE, buf);
/* FIXME: Needs a method to eliminate tty races */ /* FIXME: Needs a method to eliminate tty races */

View File

@ -310,21 +310,41 @@ bool
tty::alive (const char *fmt) tty::alive (const char *fmt)
{ {
HANDLE ev; HANDLE ev;
char buf[sizeof (TTY_MASTER_ALIVE) + 16]; char buf[CYG_MAX_PATH];
__small_sprintf (buf, fmt, ntty); shared_name (buf, fmt, ntty);
if ((ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf))) if ((ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf)))
CloseHandle (ev); CloseHandle (ev);
return ev != NULL; return ev != NULL;
} }
HANDLE
tty::open_output_mutex ()
{
return open_mutex (OUTPUT_MUTEX);
}
HANDLE
tty::open_input_mutex ()
{
return open_mutex (INPUT_MUTEX);
}
HANDLE
tty::open_mutex (const char *mutex)
{
char buf[CYG_MAX_PATH];
shared_name (buf, mutex, ntty);
return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
}
HANDLE HANDLE
tty::create_inuse (const char *fmt) tty::create_inuse (const char *fmt)
{ {
HANDLE h; HANDLE h;
char buf[sizeof (TTY_MASTER_ALIVE) + 16]; char buf[CYG_MAX_PATH];
__small_sprintf (buf, fmt, ntty); shared_name (buf, fmt, ntty);
h = CreateEvent (&sec_all, TRUE, FALSE, buf); h = CreateEvent (&sec_all, TRUE, FALSE, buf);
termios_printf ("%s = %p", buf, h); termios_printf ("%s = %p", buf, h);
if (!h) if (!h)
@ -348,9 +368,9 @@ HANDLE
tty::get_event (const char *fmt, BOOL manual_reset) tty::get_event (const char *fmt, BOOL manual_reset)
{ {
HANDLE hev; HANDLE hev;
char buf[40]; char buf[CYG_MAX_PATH];
__small_sprintf (buf, fmt, ntty); shared_name (buf, fmt, ntty);
if (!(hev = CreateEvent (&sec_all, manual_reset, FALSE, buf))) if (!(hev = CreateEvent (&sec_all, manual_reset, FALSE, buf)))
{ {
termios_printf ("couldn't create %s", buf); termios_printf ("couldn't create %s", buf);
@ -440,8 +460,8 @@ tty::common_init (fhandler_pty_master *ptym)
if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, TRUE))) if (!(ptym->input_available_event = get_event (INPUT_AVAILABLE_EVENT, TRUE)))
return false; return false;
char buf[40]; char buf[CYG_MAX_PATH];
__small_sprintf (buf, OUTPUT_MUTEX, ntty); shared_name (buf, OUTPUT_MUTEX, ntty);
if (!(ptym->output_mutex = CreateMutex (&sec_all, FALSE, buf))) if (!(ptym->output_mutex = CreateMutex (&sec_all, FALSE, buf)))
{ {
termios_printf ("can't create %s", buf); termios_printf ("can't create %s", buf);
@ -449,7 +469,7 @@ tty::common_init (fhandler_pty_master *ptym)
return false; return false;
} }
__small_sprintf (buf, INPUT_MUTEX, ntty); shared_name (buf, INPUT_MUTEX, ntty);
if (!(ptym->input_mutex = CreateMutex (&sec_all, FALSE, buf))) if (!(ptym->input_mutex = CreateMutex (&sec_all, FALSE, buf)))
{ {
termios_printf ("can't create %s", buf); termios_printf ("can't create %s", buf);

View File

@ -8,7 +8,6 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */ details. */
/* tty tables */ /* tty tables */
#define INP_BUFFER_SIZE 256 #define INP_BUFFER_SIZE 256
@ -18,15 +17,15 @@ details. */
/* Input/Output/ioctl events */ /* Input/Output/ioctl events */
#define OUTPUT_DONE_EVENT "cygtty%d.output.done" #define OUTPUT_DONE_EVENT "cygtty.output.done"
#define IOCTL_REQUEST_EVENT "cygtty%d.ioctl.request" #define IOCTL_REQUEST_EVENT "cygtty.ioctl.request"
#define IOCTL_DONE_EVENT "cygtty%d.ioctl.done" #define IOCTL_DONE_EVENT "cygtty.ioctl.done"
#define RESTART_OUTPUT_EVENT "cygtty%d.output.restart" #define RESTART_OUTPUT_EVENT "cygtty.output.restart"
#define INPUT_AVAILABLE_EVENT "cygtty%d.input.avail" #define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
#define OUTPUT_MUTEX "cygtty%d.output.mutex" #define OUTPUT_MUTEX "cygtty.output.mutex"
#define INPUT_MUTEX "cygtty%d.input.mutex" #define INPUT_MUTEX "cygtty.input.mutex"
#define TTY_SLAVE_ALIVE "cygtty%x.slave_alive" #define TTY_SLAVE_ALIVE "cygtty.slave_alive"
#define TTY_MASTER_ALIVE "cygtty%x.master_alive" #define TTY_MASTER_ALIVE "cygtty.master_alive"
#include <sys/termios.h> #include <sys/termios.h>
@ -105,18 +104,9 @@ public:
HWND gethwnd () {return hwnd;} HWND gethwnd () {return hwnd;}
void sethwnd (HWND wnd) {hwnd = wnd;} void sethwnd (HWND wnd) {hwnd = wnd;}
bool make_pipes (fhandler_pty_master *ptym); bool make_pipes (fhandler_pty_master *ptym);
HANDLE open_output_mutex () HANDLE open_mutex (const char *mutex);
{ HANDLE open_output_mutex ();
char buf[80]; HANDLE open_input_mutex ();
__small_sprintf (buf, OUTPUT_MUTEX, ntty);
return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
}
HANDLE open_input_mutex ()
{
char buf[80];
__small_sprintf (buf, INPUT_MUTEX, ntty);
return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
}
bool exists () bool exists ()
{ {
HANDLE h = open_output_mutex (); HANDLE h = open_output_mutex ();