From 3e9c8f2e813c2a97362f91935871f5830efe1c21 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 7 Feb 2012 16:54:14 +0000 Subject: [PATCH] * cygheap.cc (init_cygheap::manage_console_count): Delete. * cygheap.h (init_cygheap::manage_console_count): Ditto. (init_cygheap::console_count): Ditto. * fhandler.h (fhandler_console::has_a): Ditto. (fhandler_console::free_console): Declare new function. * fhandler_console.cc (fhandler_console::free_console): Define new function. (fhandler_console::open_setup): Delete call to manage_console_count. (fhandler_console::close): Ditto. Replace with call to free_console(). * fhandler_tty.cc (fhandler_pty_slave::open): Delete call to manage_console_count. (fhandler_pty_slave::cleanup): Ditto. (fhandler_pty_slave::close): Call fhandler_console::free_console() if this is our controlling tty. * pinfo.cc (_pinfo::set_ctty): Skip function if tty in question == our ctty. Delete call to manage_console_count. * syscalls.cc (close_all_files): Avoid locking and avoid setting errno when iterating over fds. --- winsup/cygwin/ChangeLog | 22 ++++++++++++++++++++++ winsup/cygwin/cygheap.cc | 19 +------------------ winsup/cygwin/cygheap.h | 3 --- winsup/cygwin/fhandler.h | 2 +- winsup/cygwin/fhandler_console.cc | 13 ++++++++++--- winsup/cygwin/fhandler_tty.cc | 10 ++++------ winsup/cygwin/pinfo.cc | 3 +-- winsup/cygwin/release/1.7.11 | 9 +++++++++ winsup/cygwin/syscalls.cc | 3 +-- 9 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 winsup/cygwin/release/1.7.11 diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ec4f1718a..4c6a8d1b3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,25 @@ +2012-02-07 Christopher Faylor + + * cygheap.cc (init_cygheap::manage_console_count): Delete. + * cygheap.h (init_cygheap::manage_console_count): Ditto. + (init_cygheap::console_count): Ditto. + * fhandler.h (fhandler_console::has_a): Ditto. + (fhandler_console::free_console): Declare new function. + * fhandler_console.cc (fhandler_console::free_console): Define new + function. + (fhandler_console::open_setup): Delete call to manage_console_count. + (fhandler_console::close): Ditto. Replace with call to free_console(). + * fhandler_tty.cc (fhandler_pty_slave::open): Delete call to + manage_console_count. + (fhandler_pty_slave::cleanup): Ditto. + (fhandler_pty_slave::close): Call fhandler_console::free_console() if + this is our controlling tty. + * pinfo.cc (_pinfo::set_ctty): Skip function if tty in question == our + ctty. Delete call to manage_console_count. + + * syscalls.cc (close_all_files): Avoid locking and avoid setting errno + when iterating over fds. + 2012-02-07 Christopher Faylor * include/cygwin/version.h: Bump CYGWIN_VERSION_DLL_MINOR to 11. diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc index 9f1a3f513..31212666d 100644 --- a/winsup/cygwin/cygheap.cc +++ b/winsup/cygwin/cygheap.cc @@ -1,7 +1,7 @@ /* cygheap.cc: Cygwin heap manager. Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, - 2010, 2011 Red Hat, Inc. + 2010, 2011, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -89,23 +89,6 @@ cygheap_fixup_in_child (bool execed) } } -int -init_cygheap::manage_console_count (const char *something, int amount, bool avoid_freeing_console) -{ - if (console_count == 0 && amount > 0) - init_console_handler (true); - console_count += amount; - debug_printf ("%s: console_count %d, amount %d, %s, avoid_freeing_console %d", - something, console_count, amount, myctty (), avoid_freeing_console); - if (!avoid_freeing_console && amount <= 0 && !console_count && myself->ctty == -1) - { - BOOL res = FreeConsole (); - debug_printf ("freed console, res %d", res); - init_console_handler (false); - } - return console_count; -} - void init_cygheap::close_ctty () { diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index 2c9077ada..7c2380e4d 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -303,9 +303,6 @@ struct init_cygheap: public mini_cygheap } inode_list; /* Global inode pointer for adv. locking. */ hook_chain hooks; void close_ctty (); - int manage_console_count (const char *, int, bool = false) __attribute__ ((regparm (3))); -private: - int console_count; }; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index d79b677a4..605f59b61 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1357,7 +1357,7 @@ private: void setup (); bool set_unit (); static bool need_invisible (); - static bool has_a () {return !invisible_console;} + static void free_console (); fhandler_console (void *) {} diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 477265fe5..134b26141 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1,7 +1,7 @@ /* fhandler_console.cc Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2008, 2009, 2010, 2011 Red Hat, Inc. + 2006, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -827,7 +827,6 @@ fhandler_console::open (int flags, mode_t) void fhandler_console::open_setup (int flags) { - cygheap->manage_console_count ("fhandler_console::open", 1); set_flags ((flags & ~O_TEXT) | O_BINARY); myself->set_ctty (this, flags); } @@ -838,7 +837,7 @@ fhandler_console::close () CloseHandle (get_io_handle ()); CloseHandle (get_output_handle ()); if (!have_execed) - cygheap->manage_console_count ("fhandler_console::close", -1); + free_console (); return 0; } @@ -2348,6 +2347,14 @@ fhandler_console::create_invisible_console_workaround () return invisible_console = true; } +void +fhandler_console::free_console () +{ + BOOL res = FreeConsole (); + debug_printf ("freed console, res %d", res); + init_console_handler (false); +} + bool fhandler_console::need_invisible () { diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc index 8238f654c..064dc41dc 100644 --- a/winsup/cygwin/fhandler_tty.cc +++ b/winsup/cygwin/fhandler_tty.cc @@ -1,7 +1,7 @@ /* fhandler_tty.cc Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. + 2006, 2007, 2008, 2009, 2010, 2011, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -516,9 +516,8 @@ fhandler_pty_slave::open (int flags, mode_t) set_io_handle (from_master_local); set_output_handle (to_master_local); + fhandler_console::need_invisible (); set_open_status (); - if (cygheap->manage_console_count ("fhandler_pty_slave::open", 1) == 1) - fhandler_console::need_invisible (); return 1; err: @@ -540,7 +539,6 @@ fhandler_pty_slave::open_setup (int flags) { set_flags ((flags & ~O_TEXT) | O_BINARY); myself->set_ctty (this, flags); - cygheap->manage_console_count ("fhandler_pty_slave::open_setup", 1); report_tty_counts (this, "opened", ""); } @@ -552,7 +550,6 @@ fhandler_pty_slave::cleanup () Since close_all_files is not called until after the cygwin process has synced or before a non-cygwin process has exited, it should be safe to just close this normally. cgf 2006-05-20 */ - cygheap->manage_console_count ("fhandler_pty_slave::close", -1); report_tty_counts (this, "closed", ""); } @@ -564,6 +561,8 @@ fhandler_pty_slave::close () termios_printf ("CloseHandle (inuse), %E"); if (!ForceCloseHandle (input_available_event)) termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event); + if ((unsigned) myself->ctty == FHDEV (DEV_PTYS_MAJOR, get_unit ())) + fhandler_console::free_console (); /* assumes that we are the last pty closer */ return fhandler_pty_common::close (); } @@ -900,7 +899,6 @@ int fhandler_pty_slave::dup (fhandler_base *child, int flags) { myself->set_ctty (this, flags); - cygheap->manage_console_count ("fhandler_pty_slave::dup", 1); report_tty_counts (child, "duped slave", ""); return 0; } diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 1de363f7d..04c6b64c8 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -435,7 +435,7 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags) { tty_min& tc = *fh->tc (); debug_printf ("old %s, ctty device number %p, tc.ntty device number %p flags & O_NOCTTY %p", __ctty (), ctty, tc.ntty, flags & O_NOCTTY); - if (fh && &tc && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY)) + if (fh && &tc && (ctty <= 0 || ctty != tc.ntty) && !(flags & O_NOCTTY)) { ctty = tc.ntty; if (cygheap->ctty != fh->archetype) @@ -454,7 +454,6 @@ _pinfo::set_ctty (fhandler_termios *fh, int flags) { fh->archetype_usecount (1); /* guard ctty fh */ - cygheap->manage_console_count ("_pinfo::set_ctty", 1); report_tty_counts (cygheap->ctty, "ctty", ""); } } diff --git a/winsup/cygwin/release/1.7.11 b/winsup/cygwin/release/1.7.11 new file mode 100644 index 000000000..7f0fb42dd --- /dev/null +++ b/winsup/cygwin/release/1.7.11 @@ -0,0 +1,9 @@ +What's new: +----------- + + +What changed: +------------- + +- Fixed problem where background Cygwin processes kept the windows +console window from exiting. diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index a14774e1a..1c82c542f 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -94,7 +94,7 @@ close_all_files (bool norelease) for (int i = 0; i < (int) cygheap->fdtab.size; i++) { - cygheap_fdget cfd (i); + cygheap_fdget cfd (i, false, false); if (cfd >= 0) { debug_only_printf ("closing fd %d", i); @@ -1016,7 +1016,6 @@ setsid (void) else { myself->ctty = -1; - cygheap->manage_console_count ("setsid", 0); myself->sid = getpid (); myself->pgid = getpid (); if (cygheap->ctty)