diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 7aef2ee44..5c5d53462 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,21 @@ +2003-03-02 Christopher Faylor + + * dll_init.cc (dll_list::load_after_fork): Don't revert to LoadLibrary + if LoadLibraryEx fails. + * dtable.cc (dtable::dec_console_fds): Eliminate. + (dtable::release): Don't treat console specially. + (dtable::build_fhandler): Ditto. + * dtable.h (console_fds): Eliminate. + (dtable::dec_console_fds): Eliminate. + (dtable::inc_console_fds): Eliminate. + * fhandler.h (fhandler_console::open_fhs): New static element. + * fhandler_console.cc (fhandler_console::open): Increment open_fs. + (fhandler_console::close): Call FreeConsole if no more open consoles + and ctty is not associated with the console. + * syscalls.cc (setsid): Simplify check for when to call FreeConsole. + (check_pty_fds): Eliminate definition. + * winsup.h (check_pty_fds): Eliminate declaration. + 2003-03-02 Christopher Faylor * dll_init.cc (dll_list::load_after_fork): Fix typo where result of diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc index 7400c14d7..15d50b229 100644 --- a/winsup/cygwin/dll_init.cc +++ b/winsup/cygwin/dll_init.cc @@ -307,11 +307,6 @@ dll_list::load_after_fork (HANDLE parent, dll *first) bool unload = true; HMODULE h = LoadLibraryEx (d.name, NULL, DONT_RESOLVE_DLL_REFERENCES); - if (!h) - { - unload = false; - h = LoadLibrary (d.name); - } if (!h) system_printf ("can't reload %s", d.name); /* See if DLL will load in proper place. If so, free it and reload diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 73af42e20..3b114a729 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -57,14 +57,6 @@ set_std_handle (int fd) SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ()); } -void -dtable::dec_console_fds () -{ - if (console_fds > 0 && !--console_fds && - myself->ctty != TTY_CONSOLE && !check_pty_fds()) - FreeConsole (); -} - int dtable::extend (int howmuch) { @@ -190,9 +182,6 @@ dtable::release (int fd) case FH_SOCKET: dec_need_fixup_before (); break; - case FH_CONSOLE: - dec_console_fds (); - break; } delete fds[fd]; fds[fd] = NULL; @@ -334,8 +323,7 @@ dtable::build_fhandler (int fd, DWORD dev, char *unix_name, case FH_CONSOLE: case FH_CONIN: case FH_CONOUT: - if ((fh = cnew (fhandler_console) ())) - inc_console_fds (); + fh = cnew (fhandler_console) (); break; case FH_PTYM: fh = cnew (fhandler_pty_master) (); diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 6e382a629..d73288f07 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -20,11 +20,10 @@ class dtable fhandler_base **fds_on_hold; int first_fd_for_open; int cnt_need_fixup_before; - int console_fds; public: size_t size; - dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {} + dtable () : first_fd_for_open(3), cnt_need_fixup_before(0) {} void init () {first_fd_for_open = 3;} void dec_need_fixup_before () @@ -34,12 +33,6 @@ public: BOOL need_fixup_before () { return cnt_need_fixup_before > 0; } - void dec_console_fds (); - void inc_console_fds () - { console_fds++; } - BOOL has_console_fds () - { return console_fds > 0; } - int vfork_child_dup (); void vfork_parent_restore (); void vfork_child_fixup (); diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index cc6ae7c20..0d902ee7f 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -819,6 +819,7 @@ class fhandler_console: public fhandler_termios void set_cursor_maybe (); public: + static int open_fhs; fhandler_console (); diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 3fb91252c..34c1c0da9 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -89,6 +89,8 @@ static console_state NO_COPY *shared_console_info; dev_console NO_COPY *fhandler_console::dev_state; +int NO_COPY fhandler_console::open_fhs; + /* Allocate and initialize the shared record for the current console. Returns a pointer to shared_console_info. */ tty_min * @@ -630,6 +632,8 @@ fhandler_console::open (path_conv *, int flags, mode_t) TTYCLEARF (RSTCONS); set_open_status (); + open_fhs++; + debug_printf ("incremented open_fhs, now %d", open_fhs); debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (), get_output_handle ()); @@ -643,6 +647,9 @@ fhandler_console::close (void) CloseHandle (get_output_handle ()); set_io_handle (NULL); set_output_handle (NULL); + if (--open_fhs <= 0 && myself->ctty != FH_CONSOLE) + FreeConsole (); + debug_printf ("decremented open_fhs, now %d", open_fhs); return 0; } diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index 8121c89ee..453de8c3e 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -77,23 +77,6 @@ close_all_files (void) cygwin_shared->delqueue.process_queue (); } -BOOL __stdcall -check_pty_fds (void) -{ - int res = FALSE; - SetResourceLock (LOCK_FD_LIST, WRITE_LOCK, "check_pty_fds"); - fhandler_base *fh; - for (int i = 0; i < (int) cygheap->fdtab.size; i++) - if ((fh = cygheap->fdtab[i]) != NULL && - (fh->get_device () == FH_TTYS || fh->get_device () == FH_PTYM)) - { - res = TRUE; - break; - } - ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK, "check_pty_fds"); - return res; -} - int dup (int fd) { @@ -302,11 +285,9 @@ setsid (void) if (myself->pgid != myself->pid) { - if (myself->ctty == TTY_CONSOLE - && !cygheap->fdtab.has_console_fds () - && !check_pty_fds ()) - FreeConsole (); myself->ctty = -1; + if (fhandler_console::open_fhs <= 0) + FreeConsole (); myself->sid = getpid (); myself->pgid = getpid (); syscall_printf ("sid %d, pgid %d, ctty %d", myself->sid, myself->pgid, myself->ctty); diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index f3dce68dc..9ab895a3c 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -164,7 +164,6 @@ void events_init (void); void events_terminate (void); void __stdcall close_all_files (void); -BOOL __stdcall check_pty_fds (void); /* Invisible window initialization/termination. */ HWND __stdcall gethwnd (void);