diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 385f9e4d0..5c555adcd 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2001-07-25 Kazuhiro Fujieda + + * syscalls.cc (setsid): Detach process from its console if the current + controlling tty is the console and already closed. + * dtable.h (class dtable): Add members to count descriptors referring + to the console. + * dtable.cc (dtable::dec_console_fds): New function to detach process + from its console. + (dtable::release): Decrement the counter of console descriptors. + (dtable::build_fhandler): Increment it. + * exception.cc (ctrl_c_handler): Send SIGTERM to myself when catch + CTRL_SHUTDOWN_EVENT. + Tue 24 Jul 2001 02:28:00 PM Trevor Forbes * thread.cc (verifyable_object_isvalid): Don't validate diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index a5477eb98..cc16fdada 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -1,6 +1,6 @@ /* dtable.cc: file descriptor support. - Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions. + Copyright 1996, 1997, 1998, 1999, 2000, 2001 Cygnus Solutions. This file is part of Cygwin. @@ -51,6 +51,13 @@ 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) + FreeConsole (); +} + int dtable::extend (int howmuch) { @@ -146,8 +153,13 @@ dtable::release (int fd) { if (!not_open (fd)) { - if ((fds[fd]->get_device () & FH_DEVMASK) == FH_SOCKET) - dec_need_fixup_before (); + switch (fds[fd]->get_device ()) + { + case FH_SOCKET: + dec_need_fixup_before (); + case FH_CONSOLE: + dec_console_fds (); + } delete fds[fd]; fds[fd] = NULL; } @@ -261,6 +273,7 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit) case FH_CONIN: case FH_CONOUT: fh = new (buf) fhandler_console (name); + inc_console_fds (); break; case FH_PTYM: fh = new (buf) fhandler_pty_master (name); diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index f81d916b7..bfeffa36b 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -1,6 +1,6 @@ /* dtable.h: fd table definition. - Copyright 2000 Red Hat, Inc. + Copyright 2000, 2001 Red Hat, Inc. This file is part of Cygwin. @@ -19,19 +19,26 @@ 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) {} + dtable () : first_fd_for_open(3), cnt_need_fixup_before(0), console_fds(0) {} void init () {first_fd_for_open = 3;} void dec_need_fixup_before () { if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; } void inc_need_fixup_before () - { ++cnt_need_fixup_before; } + { cnt_need_fixup_before++; } 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/exceptions.cc b/winsup/cygwin/exceptions.cc index 3c9198475..7a2061aa5 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -895,14 +895,20 @@ ctrl_c_handler (DWORD type) if (type == CTRL_LOGOFF_EVENT) return TRUE; - if ((type == CTRL_CLOSE_EVENT) || (type == CTRL_SHUTDOWN_EVENT)) - /* Return FALSE to prevent an "End task" dialog box from appearing - for each Cygwin process window that's open when the computer - is shut down or console window is closed. */ + /* Return FALSE to prevent an "End task" dialog box from appearing + for each Cygwin process window that's open when the computer + is shut down or console window is closed. */ + if (type == CTRL_SHUTDOWN_EVENT) + { + sig_send (NULL, SIGTERM); + return FALSE; + } + if (type == CTRL_CLOSE_EVENT) { sig_send (NULL, SIGHUP); return FALSE; } + tty_min *t = cygwin_shared->tty.get_tty (myself->ctty); /* Ignore this if we're not the process group lead since it should be handled *by* the process group leader. */ diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index c8b9cb406..7e37278da 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -240,6 +240,8 @@ setsid (void) /* FIXME: for now */ if (myself->pgid != _getpid ()) { + if (myself->ctty == TTY_CONSOLE && !cygheap->fdtab.has_console_fds ()) + FreeConsole (); myself->ctty = -1; myself->sid = _getpid (); myself->pgid = _getpid ();