(initial_env): Set jit_debug when we are automatically starting a gdb process.
* dtable.cc (dtable::get_debugger_info): Don't tty tricks when we are being
debugged by our own captive gdb, as determined by jit_debug == true.
(dtable::init_std_file_from_handle): Detect errors when initializing a tty
early rather than at random points later.
* fhandler.h (fhandler_*::init): Return int to indicate success/failure.
* fhandler.cc (fhandler_base::init): Reflect change in return value.
* pipe.cc (fhandler_pipe::init): Ditto.
(fhandler_pipe::create_selectable): Don't say we're retrying when we aren't.
* fhandler_console.cc (fhandler_console::init): Ditto. Return success/failure.
* fhandler_serial.cc (fhandler_serial::init): Ditto.
* fhandler_tty.cc (fhandler_tty_slave::init): Ditto.
(fhandler_tty_slave::open): Make debugging output more detailed.
* tty.cc (tty_list::terminate): Don't close I/O handles before all slaves have
checked in.
(tty::slave_alive): Make a non-inlined function. Check if tty pipe handles can
be created as an additional exists check.
* tty.h (tty::slave_alive): Just define here.
+2009-07-03 Christopher Faylor <me+cygwin@cgf.cx>
+
+ * dcrt0.cc (jit_debug): New global.
+ (initial_env): Set jit_debug when we are automatically starting a gdb
+ process.
+ * dtable.cc (dtable::get_debugger_info): Don't tty tricks when we are
+ being debugged by our own captive gdb, as determined by jit_debug ==
+ true.
+ (dtable::init_std_file_from_handle): Detect errors when initializing a
+ tty early rather than at random points later.
+ * fhandler.h (fhandler_*::init): Return int to indicate
+ success/failure.
+ * fhandler.cc (fhandler_base::init): Reflect change in return value.
+ * pipe.cc (fhandler_pipe::init): Ditto.
+ (fhandler_pipe::create_selectable): Don't say we're retrying when we
+ aren't.
+ * fhandler_console.cc (fhandler_console::init): Ditto. Return
+ success/failure.
+ * fhandler_serial.cc (fhandler_serial::init): Ditto.
+ * fhandler_tty.cc (fhandler_tty_slave::init): Ditto.
+ (fhandler_tty_slave::open): Make debugging output more detailed.
+ * tty.cc (tty_list::terminate): Don't close I/O handles before all
+ slaves have checked in.
+ (tty::slave_alive): Make a non-inlined function. Check if tty pipe
+ handles can be created as an additional exists check.
+ * tty.h (tty::slave_alive): Just define here.
+
2009-07-03 Corinna Vinschen <corinna@vinschen.de>
* posix.sgml: Add fpurge and mkstemps to BSD list.
static char title_buf[TITLESIZE + 1];
+bool NO_COPY jit_debug;
+
static void
do_global_dtors ()
{
if (strstr (buf1, buf))
{
error_start_init (p);
+ jit_debug = true;
try_to_debug ();
console_printf ("*** Sending Break. gdb may issue spurious SIGTRAP message.\n");
break_here ();
void
dtable::get_debugger_info ()
{
- if (being_debugged ())
+ extern bool jit_debug;
+ if (!jit_debug && being_debugged ())
{
char std[3][sizeof ("/dev/ttyNNNN")];
std[0][0] = std[1][0] = std [2][0] = '\0';
This needs further investigation but the workaround not to close
the handles will have a marginal hit of three extra handles per
process at most. */
- fh->init (dev == FH_CONSOLE && wincap.has_console_handle_problem ()
- ? INVALID_HANDLE_VALUE : handle, access, bin);
- set_std_handle (fd);
+ if (fh->init (dev == FH_CONSOLE && wincap.has_console_handle_problem ()
+ ? INVALID_HANDLE_VALUE : handle, access, bin))
+ set_std_handle (fd);
+ else
+ api_fatal ("couldn't initialize fd %d for %s", fd, fh->get_name ());
paranoid_printf ("fd %d, handle %p", fd, handle);
}
}
return fh.fstatvfs (sfs);
}
-void
+int
fhandler_base::init (HANDLE f, DWORD a, mode_t bin)
{
set_io_handle (f);
set_flags (flags | bin);
set_open_status ();
debug_printf ("created new fhandler_base for handle %p, bin %d", f, rbinary ());
+ return 1;
}
int
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
- virtual void init (HANDLE, DWORD, mode_t);
+ virtual int init (HANDLE, DWORD, mode_t);
virtual int tcflush (int);
virtual int tcsendbreak (int);
int __stdcall fadvise (_off64_t, _off64_t, int) __attribute__ ((regparm (3)));
int __stdcall ftruncate (_off64_t, bool) __attribute__ ((regparm (3)));
int ready_for_read (int fd, DWORD howlong);
- void init (HANDLE, DWORD, mode_t);
+ int init (HANDLE, DWORD, mode_t);
static int create (fhandler_pipe *[2], unsigned, int);
static int create_selectable (LPSECURITY_ATTRIBUTES, HANDLE&, HANDLE&, DWORD, const char * = NULL);
friend class fhandler_fifo;
int open (int flags, mode_t mode);
int close ();
- void init (HANDLE h, DWORD a, mode_t flags);
+ int init (HANDLE h, DWORD a, mode_t flags);
void overlapped_setup ();
int dup (fhandler_base *child);
void raw_read (void *ptr, size_t& ulen);
int dup (fhandler_base *child);
int ioctl (unsigned int cmd, void *);
- void init (HANDLE, DWORD, mode_t);
+ int init (HANDLE, DWORD, mode_t);
bool mouse_aware () {return dev_state->use_mouse;}
select_record *select_read (select_stuff *);
int open (int flags, mode_t mode = 0);
int write (const void *ptr, size_t len);
void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
- void init (HANDLE, DWORD, mode_t);
+ int init (HANDLE, DWORD, mode_t);
int tcsetattr (int a, const struct termios *t);
int tcgetattr (struct termios *t);
return NULL;
}
-void
+int
fhandler_console::init (HANDLE f, DWORD a, mode_t bin)
{
// this->fhandler_termios::init (f, mode, bin);
if (f != INVALID_HANDLE_VALUE)
CloseHandle (f); /* Reopened by open */
- tcsetattr (0, &tc->ti);
+ return !tcsetattr (0, &tc->ti);
}
int
return -1;
}
-void
+int
fhandler_serial::init (HANDLE f, DWORD flags, mode_t bin)
{
- open (flags, bin & (O_BINARY | O_TEXT));
+ return open (flags, bin & (O_BINARY | O_TEXT));
}
int
hMainProc, &from_master_local, 0, TRUE,
DUPLICATE_SAME_ACCESS))
{
- termios_printf ("can't duplicate input, %E");
+ termios_printf ("can't duplicate input from %u/%p, %E",
+ get_ttyp ()->master_pid, get_ttyp ()->from_master);
__seterrno ();
return 0;
}
return 1;
}
-void
+int
fhandler_tty_slave::init (HANDLE, DWORD a, mode_t)
{
int flags = 0;
if (a == (GENERIC_READ | GENERIC_WRITE))
flags = O_RDWR;
- open (flags);
+ return open (flags);
}
int
uninterruptible_io (true);
}
-void
+int
fhandler_pipe::init (HANDLE f, DWORD a, mode_t mode)
{
// FIXME: Have to clean this up someday
if (mode & O_NOINHERIT)
close_on_exec (true);
setup_overlapped (opened_properly);
+ return 1;
}
extern "C" int sscanf (const char *, const char *, ...);
case ERROR_PIPE_BUSY:
/* The pipe is already open with compatible parameters.
Pick a new name and retry. */
- debug_printf ("pipe busy, retrying");
+ debug_printf ("pipe busy", name ? ", retrying" : "");
break;
case ERROR_ACCESS_DENIED:
/* The pipe is already open with incompatible parameters.
Pick a new name and retry. */
- debug_printf ("pipe access denied, retrying");
+ debug_printf ("pipe access denied%s", name ? ", retrying" : "");
break;
default:
{
if (ttynum != -1 && tty_master && ttys[ttynum].master_pid == myself->pid)
{
tty *t = ttys + ttynum;
- 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++)
}
lock_ttys here ();
+ CloseHandle (tty_master->from_master);
+ CloseHandle (tty_master->to_master);
termios_printf ("tty %d master about to finish", ttynum);
CloseHandle (tty_master->get_io_handle ());
/* Search for tty class for our console. Allocate new tty if our process is
the only cygwin process in the current console.
Return tty number or -1 if error.
- If flag == 0, just find a free tty.
+ If with_console == 0, just find a free tty.
*/
int
tty_list::allocate (bool with_console)
int freetty = -1;
HANDLE hmaster = NULL;
- /* FIXME: This whole function needs a protective mutex. */
-
lock_ttys here;
if (!with_console)
}
}
- /* There is no tty allocated to console, allocate the first free found */
+ /* There is no tty allocated to console; allocate the first free found */
if (freetty == -1)
goto out;
return alive (TTY_SLAVE_ALIVE);
}
+bool
+tty::exists ()
+{
+ /* Attempt to open the from-master side of the tty. If it is accessible
+ then it exists although it may have been privileges to actually use it. */
+ char pipename[sizeof("ttyNNNN-from-master")];
+ __small_sprintf (pipename, "tty%d-from-master", ntty);
+ HANDLE r, w;
+ int res = fhandler_pipe::create_selectable (&sec_none_nih, r, w, 0, pipename);
+ if (res)
+ return true;
+
+ CloseHandle (r);
+ CloseHandle (w);
+
+ HANDLE h = open_output_mutex ();
+ if (h)
+ {
+ CloseHandle (h);
+ return true;
+ }
+ return slave_alive ();
+}
+
bool
tty::alive (const char *fmt)
{
HANDLE open_mutex (const char *mutex);
HANDLE open_output_mutex ();
HANDLE open_input_mutex ();
- bool exists ()
- {
- if (!master_pid)
- return false;
- HANDLE h = open_output_mutex ();
- if (h)
- {
- CloseHandle (h);
- return 1;
- }
- return slave_alive ();
- }
+ bool exists ();
void set_master_closed () {master_pid = -1;}
static void __stdcall create_master (int);
static void __stdcall init_session ();